00001
00002
00003
00004
00005 package org.hfbk.vis.visnode;
00006
00007
00008 import java.awt.event.MouseEvent;
00009
00010 import org.dronus.gl.*;
00011 import org.dronus.graph.Node;
00012 import org.hfbk.vid.VideoFetcher;
00013 import org.hfbk.vid.VideoTexture;
00014 import org.lwjgl.opengl.GL11;
00015 import org.lwjgl.util.vector.Vector3f;
00016
00023 public class VisVideoImage extends VisNodeDraggable {
00024
00025 final float SCALE=15f;
00026
00027 Texture tex=null;
00028
00029 VideoFetcher fetcher;
00030
00031 String large;
00032
00036 public VisVideoImage(Node n, Vector3f position) {
00037 super(n, position);
00038
00039 String imageURL=n.getSubNodeText("thumbnail");
00040
00041
00042 fetcher=new VideoFetcher(imageURL);
00043
00044 large=n.text;
00045 if (large==null)
00046 large=imageURL;
00047
00048 }
00049
00053 public void add(VisNode node) {}
00054
00055 public VisVideoImage(String imageUrl, String contextUrl, Vector3f position, boolean asThumbnail) {
00056 super(null, position);
00057 url=contextUrl;
00058
00059 fetcher=new VideoFetcher(imageUrl);
00060 large=imageUrl;
00061 }
00062
00063
00064 void renderSelf() {
00065 if (tex!=null){
00066 tex.render();
00067
00068 Vector3f pos=new Vector3f(GLUtil.getPosition());
00069
00070 float alpha=Math.max(Math.min(-pos.z/20,1),0);
00071 GL11.glColor4f(1,1,1,alpha);
00072
00073 GLUtil.renderQuad(-w/2,-h/2,w/2,h/2, tex.imagewidth, tex.imageheight);
00074 }else if (fetcher.streamer!=null){
00075
00076 tex=new VideoTexture(fetcher.streamer);
00077 w=tex.width; h=tex.height;
00078 float scale=Math.max(w,h);
00079 scale=SCALE/scale;
00080 w*=scale; h*=scale;
00081 radius=(float)Math.sqrt(w*w+h*h)/2;
00082 fetcher=null;
00083 }
00084 }
00085
00086 void handleEvent(VisMouseEvent evt) {
00087 super.handleEvent(evt);
00088 if (evt.getID()==MouseEvent.MOUSE_CLICKED){
00089
00090 if (evt.getButton()==1)
00091 if (getRoot() instanceof VisHUD)
00092 getRoot().remove(this);
00093 else
00094
00095 getRoot().client.hud.add(new VisVideoImage(large, url, new Vector3f(0,0,-20),false));
00096 else if(evt.getButton()==3 && url!=null)
00097 getRoot().fetch("spider", url, this);
00098
00099 }
00100 }
00101 }