aboutsummaryrefslogtreecommitdiff
path: root/src/Java/binnie/craftgui/controls/listbox/ControlOption.java
blob: 7a643101cf0492f025187ae4a5dfa8d450b59273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package binnie.craftgui.controls.listbox;

import binnie.craftgui.controls.core.Control;
import binnie.craftgui.controls.core.IControlValue;
import binnie.craftgui.core.Attribute;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.renderer.Renderer;
import binnie.craftgui.events.EventMouse.Down;
import binnie.craftgui.events.EventMouse.Down.Handler;
import binnie.craftgui.resource.minecraft.CraftGUITexture;

public class ControlOption<T>
  extends Control
  implements IControlValue<T>
{
  T value;
  
  public void onUpdateClient()
  {
    if (getValue() == null) {
      return;
    }
    int colour = 10526880;
    if (isCurrentSelection()) {
      colour = 16777215;
    }
    setColour(colour);
  }
  
  public ControlOption(ControlList<T> controlList, T option)
  {
    this(controlList, option, 16);
  }
  
  public ControlOption(ControlList<T> controlList, T option, int height)
  {
    super(controlList, 0.0F, height, controlList.getSize().x(), 20.0F);
    this.value = option;
    if (this.value != null) {
      addAttribute(Attribute.MouseOver);
    }
    addSelfEventHandler(new EventMouse.Down.Handler()
    {
      public void onEvent(EventMouse.Down event)
      {
        ((IControlValue)ControlOption.this.getParent()).setValue(ControlOption.this.getValue());
      }
    });
  }
  
  public T getValue()
  {
    return this.value;
  }
  
  public void setValue(T value)
  {
    this.value = value;
  }
  
  public boolean isCurrentSelection()
  {
    return (getValue() != null) && (getValue().equals(((IControlValue)getParent()).getValue()));
  }
  
  public void onRenderForeground()
  {
    if (isCurrentSelection()) {
      CraftGUI.Render.texture(CraftGUITexture.Outline, getArea());
    }
  }
}