func_maxgui_redrawgadget.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .. _func_maxgui_redrawgadget:
  2. ============
  3. RedrawGadget
  4. ============
  5. RedrawGadget -
  6. Description
  7. ===========
  8. .. code-block:: blitzmax
  9. RedrawGadget( gadget:TGadget )
  10. Redraws a gadget.
  11. The RedrawGadget command causes the gadget to be redrawn by the underlying
  12. Operating System and is not guaranteed to happen immediately.
  13. In the case of a @Canvas gadget an EVENT_GADGETPAINT event is emitted
  14. when the Operating System begins the actual redraw. The following example
  15. illustrates how to manage this feature:
  16. Parameters
  17. ==========
  18. Return Values
  19. =============
  20. Nothing.
  21. Examples
  22. ========
  23. .. code-block:: blitzmax
  24. ' redrawgadget.bmx
  25. ' version 2 - improved TApplet behavior
  26. ' moved AddHook from New to Run, as firing OnEvent
  27. ' before object has been initialized was problematic
  28. Import MaxGui.Drivers
  29. Strict
  30. Type TApplet
  31. Method OnEvent(Event:TEvent) Abstract
  32. Method Run()
  33. AddHook EmitEventHook,eventhook,Self
  34. End Method
  35. Function eventhook:Object(id,data:Object,context:Object)
  36. Local event:TEvent
  37. Local app:TApplet
  38. event=TEvent(data)
  39. app=TApplet(context)
  40. app.OnEvent event
  41. End Function
  42. End Type
  43. Type TSpinningApplet Extends TApplet
  44. Field window:TGadget
  45. Field canvas:TGadget
  46. Field timer:TTimer
  47. Field image:TImage
  48. Method Draw()
  49. SetGraphics CanvasGraphics(canvas)
  50. SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
  51. SetBlend ALPHABLEND
  52. SetRotation MilliSecs()*.1
  53. SetClsColor 255,0,0
  54. Cls
  55. DrawImage image,GraphicsWidth()/2,GraphicsHeight()/2
  56. Flip
  57. End Method
  58. Method OnEvent(Event:TEvent)
  59. Select event.id
  60. Case EVENT_WINDOWCLOSE
  61. End
  62. Case EVENT_TIMERTICK
  63. RedrawGadget canvas
  64. Case EVENT_GADGETPAINT
  65. Draw
  66. End Select
  67. End Method
  68. Method Create:TSpinningApplet(name$)
  69. Local w,h
  70. image=LoadImage("fltkwindow.png")
  71. window=CreateWindow(name,20,20,512,512)
  72. w=ClientWidth(window)
  73. h=ClientHeight(window)
  74. canvas=CreateCanvas(0,0,w,h,window)
  75. canvas.SetLayout 1,1,1,1
  76. timer=CreateTimer(100)
  77. Run
  78. Return Self
  79. End Method
  80. End Type
  81. AutoMidHandle True
  82. Local spinner:TSpinningApplet
  83. spinner=New TSpinningApplet.Create("Spinning Applet")
  84. While True
  85. WaitEvent
  86. Wend
  87. See Also
  88. ========