User Tools

Site Tools


built_in:glview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
built_in:glview [2015/11/02 10:49]
octazid completed
built_in:glview [2016/09/02 02:49] (current)
Line 142: Line 142:
 ---- ----
  
-===== Sample ===== +===== Touch drawn images ===== 
-//(Sample code by Chris Hopkin taken from the DroidScript Google Group)//+//(Sample code by Alex, idea from Chris Hopkin)//
  
 If you need to want to simulate OnTouch for a GLView Image, you will need to keep track of the position, width and height that it has been drawn with. Then use the GLView OnTouch event to determine if the touch coordinates are within the GLView Image yourself. Something like this: If you need to want to simulate OnTouch for a GLView Image, you will need to keep track of the position, width and height that it has been drawn with. Then use the GLView OnTouch event to determine if the touch coordinates are within the GLView Image yourself. Something like this:
  
-<code javascript>glview = app.CreateGLView( 1, 1, "Fast2d" );   +<code javascript> 
-glview.SetOnTouch(glview_OnTouch);+//Called when application is started. 
 +function OnStart() { 
 + //Create layout 
 + lay = app.CreateLayout( "linear" );  
 +  
 + //Create GLView 
 + glv= app.CreateGLView( 1,1,"Fast2d" ); 
 + glv.SetOnTouchUptouch ); 
 +  
 + //set first image 
 + img1= glv.CreateImage( "/Sys/Img/Hello.png" ); 
 + img1.X= 0.1; img1.Y= 0.3; 
 + img1.W= 0.7; img1.H= 0.4; 
 +  
 + //set second image 
 + img2= glv.CreateImage( "/Sys/Img/Droid1.png", startRender ); 
 + img2.X= 0.5; img2.Y= 0.5; 
 + img2.W= 0.5; img2.H= 0.3; 
 +  
 + lay.AddChild( glv ); 
 +  
 + //Add layout to app.  
 + app.AddLayout( lay ); 
 +}
  
-glImg = glview.CreateImage( "/Sys/Img/Hello.png", StartRendering );+//draw images 
 +function startRender() { 
 + draw( img1 ); 
 + draw( img2 ); 
 + glv.Render(); 
 +}
  
-glImgX 0.1; +//check which image was touched 
-glImgY 0.1+function touch(ev) { 
-glImgW 0.25+ var object="nothing" 
-glImgH = 0.25;+  
 + if( touched( img1,ev ) ) object="img1"
 + if( touched( img2,ev ) ) object="img2"
 +  
 + app.ShowPopup( "touched "+object ); 
 +}
  
-.... +///subfunctions 
- +function draw(img,ev) { 
-glview.DrawImage(glImgglImgXglImgYglImgWglImgH, 0); + glv.DrawImage( imgimg.Ximg.Yimg.Wimg.H, 0); 
- +} 
-... +function touched(img,ev) { 
- + return (img.X<ev.X && img.X+img.W>ev.X 
-function glview_OnTouch(ev) + && img.Y<ev.Y && img.Y+img.H>ev.Y
-+
-  if(ev.action=="Up"+</code>
-  { +
-    if( (ev.X >= glImgX) && (ev.X <= glImgX+glImgW) && +
-        (ev.Y >= glImgY) && (ev.Y <= glImgY+glImgH) ) +
-    { +
-      app.ShowPopup("glImg Touched"); +
-    +
-  } +
-}</code>+
built_in/glview.1446461343.txt.gz · Last modified: 2015/11/02 18:49 (external edit)