Ooops
January 26, 2021, 06:31:18 AM

Author Topic: [bmx] MaxGUI: Window positioning/resizing with a canvas by Fabian. [ 1+ years ago ]  (Read 607 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : MaxGUI: Window positioning/resizing with a canvas
Author : Fabian.
Posted : 1+ years ago

Description : The user can position the window by clicking in the dark gray area and resize it by clicking in the bright gray area.

Code :
Code: BlitzMax
  1. Strict
  2. Framework brl.blitz
  3.  
  4. Import brl.d3d7max2d
  5. Import brl.glmax2d
  6. Import brl.win32maxgui
  7. Import brl.fltkmaxgui
  8. Import brl.cocoamaxgui
  9.  
  10. Global Stop
  11. Global MX , MY , MD
  12. Global Window:TGadget = CreateWindow ( "TestWin" , 400 , 400 , 400 , 400 , Desktop ( ) , 0 )
  13. Global Canvas:TGadget = CreateCanvas ( 0 , 0 , ClientWidth ( Window ) , ClientHeight ( Window ) , Window )
  14. SetGadgetLayout Canvas , 1 , 1 , 1 , 1
  15. AddHook EmitEventHook , Hook
  16. While Not Stop
  17.   WaitSystem
  18. Wend
  19.  
  20. Function Hook:Object ( ID , Data:Object , Context:Object )
  21.   Local Event:TEvent = TEvent ( Data )
  22.   Select Event.source
  23.     Case Window
  24.       If Event.id = EVENT_WINDOWCLOSE
  25.         Stop = True
  26.       EndIf
  27.     Case Canvas
  28.       If Event.id = EVENT_GADGETPAINT
  29.         SetGraphics CanvasGraphics ( Canvas )
  30.         SetViewport 0 , 0 , ClientWidth ( Canvas ) , ClientHeight ( Canvas )
  31.         SetClsColor 200 , 200 , 200
  32.         Cls
  33.         SetViewport 10 , 30 , ClientWidth ( Canvas ) - 20 , ClientHeight ( Canvas ) - 40
  34.         SetClsColor 100 , 100 , 100
  35.         Cls
  36.         SetViewport 10 , 10 , ClientWidth ( Canvas ) - 20 , 20
  37.         SetClsColor 0 , 0 , 255
  38.         Cls
  39.         SetColor 255 , 255 , 255
  40.         DrawText "Window Title" , 12 , 12
  41.         SetColor 200 , 200 , 200
  42.         DrawRect ClientWidth ( Canvas ) - 28 , 12 , 16 , 16
  43.         SetColor 0 , 0 , 0
  44.         DrawLine ClientWidth ( Canvas ) - 28 , 12 , ClientWidth ( Canvas ) - 13 , 27
  45.         DrawLine ClientWidth ( Canvas ) - 13 , 12 , ClientWidth ( Canvas ) - 28 , 27
  46.         Flip
  47.       EndIf
  48.       If Event.id = EVENT_MOUSEDOWN And Event.data = 1
  49.         If Event.x >= ClientWidth ( Canvas ) - 28 And Event.x < ClientWidth ( Canvas ) - 12 And Event.y >= 12 And Event.y < 28
  50.           Stop = True
  51.         Else
  52.           MX = Event.x
  53.           MY = Event.y
  54.           MD = ( MY > 10 ) + ( MY >= ClientHeight ( Canvas ) - 10 )
  55.           MD :* 3
  56.           MD :+ ( MX > 10 ) + ( MX >= ClientWidth ( Canvas ) - 10 )
  57.           MD :+ 1
  58.         EndIf
  59.       EndIf
  60.       If Event.id = EVENT_MOUSEMOVE And MD
  61.         Local DX = Event.x - MX
  62.         Local DY = Event.y - MY
  63.         Local X = GadgetX ( Window )
  64.         Local Y = GadgetY ( Window )
  65.         Local W = GadgetWidth ( Window )
  66.         Local H = GadgetHeight ( Window )
  67.         Select MD
  68.           Case 1 ; X :+ DX ; W :- DX ; Y :+ DY ; H :- DY
  69.           Case 2 ; Y :+ DY ; H :- DY
  70.           Case 3 ; W :+ DX ; MX :+ DX ; Y :+ DY ; H :- DY
  71.           Case 4 ; X :+ DX ; W :- DX
  72.           Case 5 ; X :+ DX ; Y :+ DY
  73.           Case 6 ; W :+ DX ; MX :+ DX
  74.           Case 7 ; X :+ DX ; W :- DX ; H :+ DY ; MY :+ DY
  75.           Case 8 ; H :+ DY ; MY :+ DY
  76.           Case 9 ; W :+ DX ; MX :+ DX ; H :+ DY ; MY :+ DY
  77.         EndSelect
  78.         SetGadgetShape Window , X , Y , W , H
  79.       EndIf
  80.       If Event.id = EVENT_MOUSEUP And Event.data = 1
  81.         MD = 0
  82.       EndIf
  83.   EndSelect
  84.   Return Data
  85. EndFunction


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal