It locks up on my puter, but adding the EVENT_GADGETPAINT to the hook makes it responsive.
About the SetTransform.. I assume your resetting it here?
SetTransform 1, 0, 0
' should be
SetTransform 0, 1,1
' or just
SetTransform
Scaling something to 0,0 just makes it disappear ;)
And when your doing SetTransform (or any of the other transform commands), its a good idea to reset it each loop so you know your starting point.
Heres the modified code:
SuperStrict
Global gApplicationWindow:TApplicationWindow = TApplicationWindow.create()
Global gPrinterDriver:TPrinterDriver = TPrinterDriver.create()
CreateTimer(60)
EnablePolledInput()
AddHook EmitEventHook, paint
gApplicationWindow.open()
Local iEventID%
While True
PollEvent()
iEventID = EventID()
If gPrinterDriver.isOpen() Then
gPrinterDriver.update(iEventID)
gPrinterDriver.draw()
Else
gApplicationWindow.update(iEventID)
gApplicationWindow.draw()
End If
Wend
End
Function paint:Object( id:Int, data:Object, context:Object)
Local ev:TEvent = TEvent(data)
If Not ev Then Return data
If ev.ID = EVENT_TIMERTICK Then
gApplicationWindow.update(ev.ID)
ElseIf ev.ID = EVENT_GADGETPAINT Then '<--
gApplicationWindow.draw()
Else
Return data
EndIf
Return Null
End Function
Type TColor
Field ir%, ig%, ib%
Function create:TColor(r%, g%, b%)
Local c:TColor = New TColor
c.ir = r
c.ig = g
c.ib = b
Return c
End Function
Method setThisColor()
SetColor(ir, ig, ib)
End Method
End Type
Type TWindow
Field poWindow:TGadget
Field poCanvas:TGadget
Method open()
draw()
ActivateWindow(poWindow)
ShowGadget(poWindow)
End Method
Method close()
HideGadget(poWindow)
End Method
Method isOpen:Byte()
Return (Not GadgetHidden(poWindow))
End Method
Method getWindow:TGadget()
Return poWindow
End Method
Method getCanvas:TGadget()
Return poCanvas
End Method
Method update(iEventID%) Abstract
Method draw() Abstract
End Type
Type TApplicationWindow Extends TWindow
Const MENU_NEW%=101
Const MENU_OPEN%=102
Const MENU_SAVE%=103
Const MENU_CLOSE%=104
Const MENU_PRINT%=105
Const MENU_EXIT%=106
Const MENU_CUT%=107
Const MENU_COPY%=108
Const MENU_PASTE%=109
Const MENU_VIEW1% = 110
Const MENU_VIEW2% = 111
Const MENU_VIEW3% = 112
Const MENU_VIEW4% = 113
Const MENU_ABOUT%=114
Field ploViewMenu:TGadget[4]
Field ploBgnd:TColor[4]
Field piBgnd% = 0
Function create:TApplicationWindow()
Local a:TApplicationWindow = New TApplicationWindow
Local filemenu:TGadget
Local editmenu:TGadget
Local viewmenu:TGadget
Local helpmenu:TGadget
Local style% = WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS | WINDOW_MENU| WINDOW_HIDDEN
a.poWindow = CreateWindow("Application", 400, 150, 1024, 768, Null, style)
filemenu=CreateMenu("&File",0,WindowMenu(a.poWindow))
CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"&Print...", MENU_PRINT,filemenu,KEY_P,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND
editmenu=CreateMenu("&Edit",0,WindowMenu(a.poWindow))
CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND
viewmenu=CreateMenu("&View",0,WindowMenu(a.poWindow))
a.ploViewMenu[0] = CreateMenu("Background 1",MENU_VIEW1,viewmenu,KEY_1,MODIFIER_COMMAND)
a.ploViewMenu[1] = CreateMenu("Background 2",MENU_VIEW2,viewmenu,KEY_2,MODIFIER_COMMAND)
a.ploViewMenu[2] = CreateMenu("Background 3",MENU_VIEW3,viewmenu,KEY_3,MODIFIER_COMMAND)
a.ploViewMenu[3] = CreateMenu("Background 4",MENU_VIEW4,viewmenu,KEY_4,MODIFIER_COMMAND)
helpmenu=CreateMenu("&Help",0,WindowMenu(a.poWindow))
CreateMenu "&About",MENU_ABOUT,helpmenu
Local dw% = GadgetWidth(a.poWindow)
Local dh% = GadgetHeight(a.poWindow)
a.poCanvas:TGadget = CreateCanvas(0, 0, dw, dh, a.poWindow)
a.ploBgnd[0] = TColor.create(250, 250, 200)
a.ploBgnd[1] = TColor.create(200, 250, 200)
a.ploBgnd[2] = TColor.create(200, 200, 250)
a.ploBgnd[3] = TColor.create(250, 200, 200)
a.selectBgnd(0)
Return a
End Function
Method update(iEventID%)
Select iEventID
Case EVENT_WINDOWCLOSE
End
Case EVENT_MENUACTION
Select EventData()
Case MENU_EXIT
End
Case MENU_PRINT
gPrinterDriver.open()
Case MENU_ABOUT
draw()
Notify("My First Multiple Window Application", False)
Case MENU_VIEW1
selectBgnd(0)
Case MENU_VIEW2
selectBgnd(1)
Case MENU_VIEW3
selectBgnd(2)
Case MENU_VIEW4
selectBgnd(3)
End Select
End Select
End Method
Method draw()
SetGraphics CanvasGraphics(poCanvas)
Cls
SetTransform '<--
' **** function like setTransform result in strange behavior (rem the next line to see the correct behavior)
'SetTransform 1, 0, 0
ploBgnd[piBgnd].setThisColor()
DrawRect(0, 0, GadgetWidth(poCanvas), GadgetHeight(poCanvas))
Flip
End Method
Method selectBgnd(iBgnd%)
piBgnd = iBgnd
For Local i% = 0 To 3
If i = piBgnd Then
CheckMenu(ploViewMenu[i])
Else
UncheckMenu(ploViewMenu[i])
End If
Next
UpdateWindowMenu poWindow
End Method
End Type
Type TPrinterDriver Extends TWindow
Field poImage:TImage
Function create:TPrinterDriver()
Local p:TPrinterDriver = New TPrinterDriver
Local dw% = GadgetWidth(Desktop())
Local dh% = GadgetHeight(Desktop())
Local dww% = 800
Local dwh% = 600
p.poWindow = CreateWindow("Print",(dw - dww) / 2, (dh -dwh) / 2, dww, dwh, Null, WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS|WINDOW_HIDDEN)
p.poCanvas:TGadget = CreateCanvas(0, 0, dww, dwh, p.poWindow)
p.poImage = CreateImage(100, 100)
Return p
End Function
Method update(iEventID%)
Select iEventID
Case EVENT_WINDOWCLOSE
HideGadget(poWindow)
End Select
End Method
Method draw()
SetGraphics CanvasGraphics(poCanvas)
SetClsColor 255, 255, 255
Cls
SetTransform '<--
SetColor 0, 0, 0
DrawText String(MouseX()) +","+String(MouseY()),10,10
'Rem **** if you remove te next 4 lines you see that the screen-refresh works ok
SetColor 255, 255, 255
SetTransform(45, 2, 2)
DrawImage(poImage, 100, 100)
SetTransform(1, 0, 0)
'End Rem
Flip
End Method
End Type