func_maxgui_canvases_createcanvas.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. .. _func_maxgui_canvases_createcanvas:
  2. ============
  3. CreateCanvas
  4. ============
  5. CreateCanvas -
  6. Description
  7. ===========
  8. .. code-block:: blitzmax
  9. CreateCanvas:TGadget(x,y,w,h,group:TGadget,style=0)
  10. Create a Canvas gadget.
  11. A Canvas provides a #Graphics interface for realtime drawing purposes.
  12. Once a Canvas is created, the #CanvasGraphics() Function can be used with the
  13. #SetGraphics command to direct #Max2D drawing commands to be
  14. drawn directly on the Canvas.
  15. An EVENT_GADGETPAINT event is generated whenever the gadget must be redrawn by either
  16. the system (for instance when it is first shown) or due to the #RedrawGadget command.
  17. An EVENT_GADGETPAINT handler should always call #SetGraphics
  18. with the canvas's Max2D graphics context to ensure the viewport and similar
  19. properties are in their correct state.
  20. When a Canvas is active using either the #ActivateGadget command or clicking
  21. on the Canvas when the application is running, the following event's will also
  22. be sent from the Canvas:
  23. [ @{Event ID} | @Description
  24. * EVENT_MOUSEDOWN | Mouse button pressed. Event data contains mouse button code.
  25. * EVENT_MOUSEMOVE | Mouse moved. Event x and y contain mouse coordinates.
  26. * EVENT_MOUSEWHEEL | Mouse wheel spun. Event data contains delta clicks.
  27. * EVENT_MOUSEENTER | Mouse entered gadget area.
  28. * EVENT_MOUSELEAVE | Mouse left gadget area.
  29. * EVENT_KEYDOWN | Key pressed. Event data contains keycode.
  30. * EVENT_KEYUP | Key released. Event data contains keycode.
  31. * EVENT_KEYCHAR | Key character. Event data contains unicode value.
  32. ]
  33. See Also: #ActivateGadget, #RedrawGadget, #CanvasGraphics
  34. Parameters
  35. ==========
  36. Return Values
  37. =============
  38. Nothing.
  39. Examples
  40. ========
  41. .. code-block:: blitzmax
  42. ' createcanvas.bmx
  43. Import MaxGui.Drivers
  44. Strict
  45. Global GAME_WIDTH=320
  46. Global GAME_HEIGHT=240
  47. ' create a centered window with client size GAME_WIDTH,GAME_HEIGHT
  48. Local wx=(ClientWidth(Desktop())-GAME_WIDTH)/2
  49. Local wy=(ClientHeight(Desktop())-GAME_HEIGHT)/2
  50. Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
  51. ' create a canvas for our game
  52. Local canvas:TGadget=CreateCanvas(0,0,320,240,window)
  53. ' create an update timer
  54. CreateTimer 60
  55. While WaitEvent()
  56. Select EventID()
  57. Case EVENT_TIMERTICK
  58. RedrawGadget canvas
  59. Case EVENT_GADGETPAINT
  60. SetGraphics CanvasGraphics(canvas)
  61. SetOrigin 160,120
  62. SetLineWidth 5
  63. Cls
  64. Local t=MilliSecs()
  65. DrawLine 0,0,120*Cos(t),120*Sin(t)
  66. DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
  67. Flip
  68. Case EVENT_MOUSEMOVE
  69. Print "MOVE!"
  70. Case EVENT_WINDOWCLOSE
  71. FreeGadget canvas
  72. End
  73. Case EVENT_APPTERMINATE
  74. End
  75. End Select
  76. Wend
  77. See Also
  78. ========