00001
00002
00003
00004
00005 package org.hfbk.vis.visnode;
00006
00007 import java.awt.AWTEvent;
00008 import java.awt.event.KeyAdapter;
00009 import java.awt.event.KeyEvent;
00010 import java.util.List;
00011 import java.util.Map;
00012
00013 import org.dronus.gl.GLTextOverlay;
00014 import org.dronus.gl.GLUtil;
00015 import org.hfbk.util.Counter;
00016 import org.hfbk.vis.BirdsEye;
00017 import org.hfbk.vis.FileUtils;
00018 import org.hfbk.vis.Logger;
00019 import org.hfbk.vis.Prefs;
00020 import org.hfbk.vis.VisClient;
00021 import org.hfbk.vis.visnode.VisUI;
00022 import org.lwjgl.opengl.GL11;
00023 import org.lwjgl.util.vector.Vector3f;
00024
00043 public class VisHUD extends VisRoot {
00044
00045 public VisKeyboard osk;
00046 BirdsEye map=new BirdsEye();
00047
00053 public VisHUD(final VisClient vclient) {
00054 super(vclient);
00055
00056 add(osk=new VisKeyboard());
00057
00058
00059
00060 add(new VisButton("automate",new Vector3f(-10,-5.2f,-16)){
00061 Automator automator=new Automator();
00062 public void handleClick() {
00063 toggled=!toggled;
00064 if (toggled){
00065 automator.focus=vclient.root.lastVisNode;
00066 client.root.add(automator);
00067 }else{
00068 client.root.remove(automator);
00069 client.animateViewpoint(false);
00070 }
00071 Logger.enabled=!toggled;
00072 }
00073 });
00074 add(new VisButton("animate viewpoint",new Vector3f(-10,-4,-16)){
00075 public void handleClick() {
00076
00077 client.animateViewpoint(!client.animateViewpoint);
00078 toggled=client.animateViewpoint;
00079 }
00080 });
00081 add(new VisButton("save viewpoint",new Vector3f(-10,-2.8f,-16)){
00082 public void handleClick() {
00083 if (client.saveVewpoint())
00084 notifyUser();
00085 }
00086 });
00087 add(new VisButton("show edges",new Vector3f(-10,-1.0f,-16)){
00088 VisEdges edges;
00089 public void handleClick() {
00090
00091 toggled=!toggled;
00092 if (edges==null)
00093 edges=new VisEdges();
00094 if (!client.root.children.contains(edges))
00095 client.root.add(edges);
00096 else
00097 client.root.remove(edges);
00098 }
00099 });
00100
00101 add(new VisButton("show extents",new Vector3f(-10,1.2f,-16)){
00102 public void handleClick() {
00103 toggled=!toggled;
00104 GLUtil.showExtents=toggled;
00105 }
00106 });
00107
00108
00109 vclient.panel.addKeyListener(new KeyAdapter(){
00110 public void keyReleased(KeyEvent e) {
00111 int kc=e.getKeyCode();
00112 switch(kc){
00113 case KeyEvent.VK_ESCAPE:
00114 clear();
00115 break;
00116 case KeyEvent.VK_S:
00117 if (e.isControlDown())
00118 saveImages();
00119 break;
00120 case KeyEvent.VK_B:
00121 VisNode hoovered=client.hoovered;
00122 if (hoovered!=null && hoovered.url!=null){
00123 FileUtils.browse(hoovered.url);
00124 break;
00125 }
00126 }
00127 if (kc>KeyEvent.VK_F1 && kc<=KeyEvent.VK_F12){
00128 int fn=kc-KeyEvent.VK_F2;
00129 int i=0;
00130 for (VisNode child:children)
00131 if (child instanceof VisButton)
00132 if (i++==fn)
00133 ((VisButton)child).handleClick();
00134
00135 }
00136 }
00137 });
00138
00139
00140
00141 radius=0;
00142 }
00143
00144
00145
00146 public void render(List<AWTEvent> events){
00147 float dt=client.dt;
00148 client.dt=0;
00149 if (Prefs.current.map)
00150 map.render(client.root);
00151 client.dt=dt;
00152
00153 GL11.glLoadIdentity();
00154
00155
00156 GL11.glDisable(GL11.GL_DEPTH_TEST);
00157 super.render(events);
00158
00159 if (notify-->0){
00160 super.render(events);
00161 super.render(events);
00162 }
00163
00164 GLTextOverlay.render();
00165 GL11.glEnable(GL11.GL_DEPTH_TEST);
00166 }
00167
00168 void renderChildren(List<AWTEvent> events) {
00169 for (VisNode n: children)
00170 if (client.hudEnabled || !(n instanceof VisUI))
00171 n.render(events);
00172 }
00173
00177 public void add(VisNode n){
00178 int l=children.size();
00179 if (l>0 && !(children.get(l-1) instanceof VisUI))
00180 n.position.z=children.get(l-1).position.z+.001f;
00181 children.add(n);
00182 n.parent=this;
00183 }
00184
00191 public void notifyUser(){ notify=20; }
00192 int notify=0;
00193
00194 float dtAvg;
00195
00201 void renderSelf() {
00202
00203 for (VisNode n: children)
00204 if (n instanceof VisButton)
00205 n.position.x=-7*GLUtil.aspect;
00206
00207 if (client.timescale<.9f || client.timescale>1.1f)
00208 GLTextOverlay.print("Speed: "+String.format("%4.1fx",client.timescale));
00209
00210
00211 Counter<String> counter=new Counter<String>();
00212
00213
00214 int count=Thread.activeCount();
00215 Thread[] threads=new Thread[count];
00216 Thread.enumerate(threads);
00217
00218
00219 for (Thread t: threads)
00220 if (t!=null && t.isAlive())
00221 counter.add(t.getClass().getSimpleName());
00222
00223 String text="";
00224
00225 if (Prefs.current.debug) {
00226 float d=.03f;
00227 dtAvg=d*client.dt+(1-d)*dtAvg;
00228 int fps=(int)(1/dtAvg);
00229 text+="FPS: "+fps+"\n";
00230 }
00231
00232 for(Map.Entry<String,Integer> entry : counter.entrySet()){
00233 String name=entry.getKey();
00234 if(name.matches(".*?(VideoFetcher|Image|Graph|Source).*"))
00235 text+=entry.getValue()+" "+name+" pending.\n";
00236 }
00237
00238
00239 if (text.length()>0)
00240 GLTextOverlay.print(text);
00241 }
00242
00246 public void clear() {
00247 for (VisNode n: children)
00248 if (! (n instanceof VisButton))
00249 remove(n);
00250 }
00251
00256 public void saveImages(){
00257 notifyUser();
00258 for (VisNode child : children)
00259 if (child instanceof VisImage)
00260 FileUtils.saveLocal(((VisImage)child).large);
00261
00262 clear();
00263 }
00264
00265 }