[Win/OSX] ButtonImageGadget for Touch panel
Posted: Fri Dec 26, 2008 11:38 am
This tips is image touch for Touch panel
Use ImageGadget and OpenWindowedScreen
and No use MouseInit()
But, Linux run, hide cursol. then for Win and OSX only.
MacOSX CreateExecute, Need .app (sample.app)
NeedImg:300px * 100px Image
Use ImageGadget and OpenWindowedScreen
and No use MouseInit()
Code: Select all
Procedure CreateMainWindow()
WindowID_Main = OpenWindow(#PB_Any,0,0,1000,550,"Keita Fox Three", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If WindowID_Main
ImageGadget(#PB_Any, 0,0, 1000, 550, 0)
If OpenWindowedScreen(WindowID(WindowID_Main), 0, 0, 1000, 550, 0, 0, 0)
RedrawWin()
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
EndProcedure
MacOSX CreateExecute, Need .app (sample.app)
NeedImg:300px * 100px Image
Code: Select all
; Author oryaaaaa
;
UsePNGImageDecoder()
DataSection
FirefoxImage: ; 300 px X 100 px
IncludeBinary "firefox.png"
Data.b 0
EndDataSection
Structure Button
Handle.l
PosX.l
PosY.l
Width.l
Height.l
EndStructure
Global NewList CB.Button()
Global WindowID_Main.l, CreateID.l
If InitSprite() = 0
MessageRequester("Error", "Can't open the sprite system", 0)
End
EndIf
Procedure RedrawWin()
; Wrote 11/20/2008
While WindowEvent(): Delay(1) : Wend
EndProcedure
Procedure.l CreateButtonImage(PosX, PosY, Imagefile.l)
Handle.l = CatchSprite(#PB_Any,Imagefile)
AddElement(CB())
CB()\Width = SpriteWidth(Handle)
CB()\PosX = PosX
CB()\PosY = PosY
CB()\Height = SpriteHeight(Handle)
CB()\Handle = Handle
ProcedureReturn Handle
EndProcedure
Procedure.l ClickDown()
; Get Mouse Position on Sprites
ForEach CB()
If CB()\PosX<WindowMouseX(WindowID_Main) And CB()\PosY<WindowMouseY(WindowID_Main) And (CB()\PosX+CB()\Width)>WindowMouseX(WindowID_Main) And (CB()\PosY+CB()\Height)>WindowMouseY(WindowID_Main)
ProcedureReturn ListIndex(CB())
EndIf
Next
ProcedureReturn 9999
EndProcedure
Procedure CreateMainWindow()
WindowID_Main = OpenWindow(#PB_Any,0,0,1000,550,"Keita Fox Three", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If WindowID_Main
ImageGadget(#PB_Any, 0,0, 1000, 550, 0)
If OpenWindowedScreen(WindowID(WindowID_Main), 0, 0, 1000, 550, 0, 0, 0)
RedrawWin()
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
EndProcedure
CreateMainWindow()
CreateID = CreateButtonImage(100, 100, ?FirefoxImage)
Repeat
; Always process all the events to flush the queue at every frame
Event = WindowEvent()
Eventtype = EventType()
If Event = #PB_Event_Gadget And Eventtype = #PB_EventType_LeftClick
If ClickDown()<>9999
For x=0 To 1024 Step 32
FlipBuffers(#PB_Screen_NoSynchronization)
RedrawWin() : Delay(10)
ClearScreen(RGB(0,0,0))
DisplaySprite(CB()\Handle,CB()\PosX+x,CB()\PosY)
Next
EndIf
EndIf
Select Event
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Gadget = EventGadget()
Select Gadget
Case 1, 2, 3
EndSelect
Default
FlipBuffers()
ClearScreen(RGB(0,0,0))
ForEach CB()
If ClickDown()<>9999
DisplaySprite(CB()\Handle,CB()\PosX+Random(1),CB()\PosY+Random(1))
Else
DisplaySprite(CB()\Handle,CB()\PosX,CB()\PosY)
EndIf
Next
EndSelect
Until Quit=1
End