This shows you the differences between two versions of the page.
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 | + | //(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> | + | <code javascript> |
- | glview.SetOnTouch(glview_OnTouch); | + | //Called when application is started. |
+ | function OnStart() { | ||
+ | //Create layout | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | //Create GLView | ||
+ | glv= app.CreateGLView( 1, | ||
+ | glv.SetOnTouchUp( touch ); | ||
+ | |||
+ | //set first image | ||
+ | img1= glv.CreateImage( "/ | ||
+ | img1.X= 0.1; img1.Y= 0.3; | ||
+ | img1.W= 0.7; img1.H= 0.4; | ||
+ | |||
+ | //set second image | ||
+ | img2= glv.CreateImage( "/ | ||
+ | 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 | + | //check which image was touched |
- | glImgY | + | function touch(ev) { |
- | glImgW | + | var object=" |
- | glImgH = 0.25; | + | |
+ | if( touched( img1,ev ) ) object=" | ||
+ | if( touched( img2,ev ) ) object=" | ||
+ | |||
+ | app.ShowPopup( " | ||
+ | } | ||
- | .... | + | /// |
- | + | function draw(img, | |
- | glview.DrawImage(glImg, glImgX, glImgY, glImgW, glImgH, 0); | + | glv.DrawImage( |
- | + | } | |
- | ... | + | function |
- | + | return | |
- | function | + | && |
- | { | + | } |
- | if(ev.action==" | + | </ |
- | { | + | |
- | if( (ev.X >= glImgX) | + | |
- | (ev.Y >= glImgY) | + | |
- | { | + | |
- | app.ShowPopup(" | + | |
- | | + | |
- | } | + | |
- | }</ | + |