$search
00001 package edu.tum.cs.ias.knowrob.vis.actions; 00002 00003 import java.awt.Color; 00004 00005 import javax.vecmath.Vector2f; 00006 00007 import processing.core.PApplet; 00008 import processing.core.PConstants; 00009 00017 public class ActionSelectHistoryInfo { 00018 00022 private Action action; 00026 private boolean isHover = false; 00027 00032 private boolean draw = true; 00033 00037 private Vector2f pos; 00041 private Vector2f dim; 00042 00046 private final static Color borderColor = new Color(80, 80, 80); 00047 private final static Color backgroundColor = new Color(30,30,30); 00048 private final static Color textColor = new Color(80,80,80); 00049 00053 private final static Color hoverBorderColor = new Color(100, 100, 100); 00054 private final static Color hoverBackgroundColor = new Color(50,50,50); 00055 private final static Color hoverTextColor = new Color(150,150,150); 00056 00060 private Color currentBorderColor = borderColor; 00061 private Color currentBackgroundColor = backgroundColor; 00062 private Color currentTextColor = textColor; 00063 00067 private final static float PADDING_LEFT_RIGHT = 10; 00068 00073 public ActionSelectHistoryInfo(Action a) 00074 { 00075 this.action = a; 00076 dim = new Vector2f(a.getDrawInfo().getNameWidth()+2f * PADDING_LEFT_RIGHT,a.getDrawInfo().getNameBoxHeight()); 00077 } 00078 00085 public void setPosition(float x, float y, boolean isCurrent) 00086 { 00087 pos = new Vector2f(x,y); 00088 draw = (x+dim.x > 0); 00089 if (isCurrent) 00090 { 00091 currentBorderColor = hoverBorderColor; 00092 currentBackgroundColor = hoverBackgroundColor; 00093 currentTextColor = hoverTextColor; 00094 } else 00095 { 00096 currentBorderColor = borderColor; 00097 currentBackgroundColor = backgroundColor; 00098 currentTextColor = textColor; 00099 } 00100 } 00101 00106 public Action getAction() 00107 { 00108 return action; 00109 } 00110 00115 public Vector2f getDimension() 00116 { 00117 return new Vector2f(dim); 00118 } 00119 00124 public void setHover(boolean hover) 00125 { 00126 if (hover) 00127 { 00128 currentBorderColor = hoverBorderColor; 00129 currentBackgroundColor = hoverBackgroundColor; 00130 currentTextColor = hoverTextColor; 00131 } else 00132 { 00133 currentBorderColor = borderColor; 00134 currentBackgroundColor = backgroundColor; 00135 currentTextColor = textColor; 00136 } 00137 isHover = hover; 00138 } 00139 00146 public boolean checkHover(float x, float y) 00147 { 00148 if (x>pos.x && x<pos.x+dim.x+PADDING_LEFT_RIGHT*0.5f && y>pos.y && y<pos.y+dim.y) 00149 { 00150 setHover(true); 00151 return true; 00152 } else { 00153 setHover(false); 00154 return false; 00155 } 00156 } 00157 00162 public void Draw(PApplet applet) 00163 { 00164 if (!draw) 00165 return; 00166 if (dim.y == 0) //Not yet correctly initialized 00167 dim = new Vector2f(action.getDrawInfo().getNameWidth()+2f * PADDING_LEFT_RIGHT,action.getDrawInfo().getNameBoxHeight()); 00168 00169 applet.stroke(currentBorderColor.getRed(), currentBorderColor.getGreen(), currentBorderColor.getBlue(), currentBorderColor.getAlpha()); 00170 applet.fill(currentBackgroundColor.getRed(), currentBackgroundColor.getGreen(), currentBackgroundColor.getBlue(), currentBackgroundColor.getAlpha()); 00171 applet.beginShape(); 00172 00173 applet.vertex(pos.x,pos.y); 00174 applet.vertex(pos.x+dim.x,pos.y); 00175 applet.vertex(pos.x+dim.x+10,pos.y+dim.y/2f); 00176 applet.vertex(pos.x+dim.x,pos.y+dim.y); 00177 applet.vertex(pos.x,pos.y+dim.y); 00178 00179 applet.endShape(PConstants.CLOSE); 00180 00181 applet.fill(currentTextColor.getRed(), currentTextColor.getGreen(), currentTextColor.getBlue(), currentTextColor.getAlpha()); 00182 applet.text(action.getLabel(),pos.x + PADDING_LEFT_RIGHT*1.5f,pos.y + action.getDrawInfo().getTextHeight()*2f); 00183 00184 } 00185 00190 public boolean IsHover() 00191 { 00192 return isHover; 00193 } 00194 00195 }