QB64.org Forum

Active Forums => Programs => Topic started by: TempodiBasic on January 26, 2020, 10:38:22 am

Title: child windows into window of the program: a demonstration
Post by: TempodiBasic on January 26, 2020, 10:38:22 am
Hy guys

programming is like to go on bike, you never forget it but you must empower your coding muscles to travel far...

so I have done a demo for  this thread https://www.qb64.org/forum/index.php?topic=2115.msg113538#msg113538 (https://www.qb64.org/forum/index.php?topic=2115.msg113538#msg113538)
but when I wanted to empower the demo with multiple windows (yes there are only 3 but code works for more than 3 windows) I loose myself in the hood of my imagination! So for a little but essential change in the order of the operations of the code I have had an hard session of debugging of 4-6 h  ... so it is clear that my Debugging muscles are very weak!

At the end this is the result, what is the content of each window is specific and I leave at your fantasy what put into it.
Originally I wanted to do a monitor of health with BMI and weight. But after all these hours of debugging for now I stop here.

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8.  
  9. ' 2020 01 25  A program with child windows into it
  10. ' we need a system to manage multiple windows
  11. ' and a system to manage input/output
  12. ' and a system to make graphic report
  13.  
  14. ' settings-------------------------------------------------------
  15. SCREEN _NEWIMAGE(800, 600, 32)
  16. _TITLE "Child windows"
  17. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  18. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  19. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  20. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 3, aNull = 0, aQuit = 9999
  21. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  22. CONST Dragging = 300, Focusing = 200
  23.  
  24.  
  25.  
  26. 'dataset  -----------------------------------------------
  27. TYPE person
  28.     name AS STRING * 10
  29.     age AS INTEGER
  30.     weight AS INTEGER
  31.     height AS INTEGER
  32.     BMI AS INTEGER
  33.  
  34. TYPE wChild
  35.     X AS INTEGER
  36.     Y AS INTEGER
  37.     Height AS INTEGER
  38.     Zorder AS INTEGER
  39.     Status AS INTEGER
  40.  
  41. REDIM Windows(0 TO wMin) AS wChild
  42. wMax = UBOUND(windows)
  43.  
  44. ' windows(0) is for Dragging
  45.  
  46. Windows(1).X = 1
  47. Windows(1).Y = 1
  48. Windows(1).Width = 300
  49. Windows(1).Height = 400
  50. Windows(1).Zorder = 1
  51. Windows(1).Status = Minim
  52. Windows(1).Color = Blu
  53.  
  54. Windows(2).X = 100
  55. Windows(2).Y = 1
  56. Windows(2).Width = 300
  57. Windows(2).Height = 400
  58. Windows(2).Zorder = 2
  59. Windows(2).Status = Minim
  60. Windows(2).Color = Yellow
  61.  
  62. Windows(3).X = 200
  63. Windows(3).Y = 1
  64. Windows(3).Width = 300
  65. Windows(3).Height = 400
  66. Windows(3).Zorder = 3
  67. Windows(3).Status = Minim
  68. Windows(3).Color = Green
  69.  
  70. DIM Action AS INTEGER
  71.  
  72.  
  73. ' main loop -----------------------------------------------
  74.     ' set the main window
  75.     Action = aNull
  76.     CLS , Orange
  77.     DrawAllWin
  78.  
  79.     GetInput Action
  80.  
  81.     DoAction Action
  82.     _LIMIT 20
  83.  
  84. ' SUBs and FUNCTIONs --------------------------------------
  85. SUB DrawAllWin
  86.     SHARED Windows() AS wChild
  87.     DIM Finished AS INTEGER
  88.     Finished = wMax
  89.     DO
  90.         FOR a = 1 TO wMax
  91.             IF Windows(a).Zorder = Finished THEN
  92.                 DrawWindow Windows(a)
  93.                 Finished = Finished - 1
  94.                 EXIT FOR
  95.             END IF
  96.         NEXT a
  97.     LOOP UNTIL Finished = 0
  98.  
  99. SUB Focus (Index AS INTEGER)
  100.     SHARED Windows() AS wChild
  101.     DIM b AS INTEGER
  102.     FOR b = 1 TO wMax
  103.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  104.     NEXT b
  105.     SWAP Windows(Index).Zorder, Windows(b).Zorder
  106.     DrawAllWin
  107.  
  108. SUB DoAction (Act AS INTEGER)
  109.     SHARED Windows() AS wChild
  110.     DIM a AS INTEGER
  111.  
  112.     SELECT CASE Act
  113.         CASE aQuit
  114.             END
  115.  
  116.         CASE Maxim
  117.             _FULLSCREEN
  118.  
  119.         CASE Minim
  120.             _FULLSCREEN _OFF
  121.  
  122.         CASE mLeft
  123.             DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER, Actio AS INTEGER
  124.             mX = _MOUSEX
  125.             mY = _MOUSEY
  126.             ' search where and what mouse has touched by leftclick
  127.             FOR a = 1 TO wMax ' windows(0) is out of action
  128.                 Actio = IsInWindow(mX, mY, Windows(a))
  129.                 IF Actio THEN EXIT FOR ' if windows(a) is on the stack it gets the click of mouse
  130.             NEXT a
  131.  
  132.             SELECT CASE Actio
  133.                 CASE Dragging
  134.                     Focus a
  135.                     Windows(0).X = Windows(a).X
  136.                     Windows(0).Y = Windows(a).Y
  137.                     Windows(0).Width = Windows(a).Width
  138.                     Windows(0).Height = Windows(a).Height
  139.                     Windows(0).Status = Windows(a).Status
  140.                     Windows(0).Color = Windows(a).Color
  141.                     OmX = _MOUSEX - Windows(0).X
  142.                     OmY = _MOUSEY - Windows(0).Y
  143.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  144.                     DO WHILE _MOUSEBUTTON(1)
  145.                         IF _MOUSEINPUT THEN
  146.                             CLS , Orange
  147.                             DrawAllWin
  148.                             Windows(0).X = (_MOUSEX - OmX)
  149.                             Windows(0).Y = (_MOUSEY - OmY)
  150.                             dragWindow Windows(0)
  151.                         END IF
  152.                     LOOP
  153.                     ' new position of window
  154.                     Windows(a).X = Windows(0).X
  155.                     Windows(a).Y = Windows(0).Y
  156.                     Windows(a).Width = Windows(0).Width
  157.                     Windows(a).Height = Windows(0).Height
  158.                     Windows(a).Status = Windows(0).Status
  159.                     Windows(a).Color = Windows(0).Color
  160.                     Windows(a).Zorder = 1
  161.  
  162.                 CASE Focusing
  163.                     Focus a
  164.             END SELECT
  165.         CASE ELSE
  166.     END SELECT
  167.  
  168. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  169.     IsInWindow = mFalse
  170.     IF IsInTheRange%(X, Win.X, Win.X + Win.Width) THEN
  171.         IF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  172.             IsInWindow = Dragging
  173.         ELSEIF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  174.             IsInWindow = Focusing
  175.         END IF
  176.     END IF
  177.  
  178. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  179.     IF Min > Max THEN SWAP Min, Max
  180.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  181.  
  182. SUB dragWindow (Win AS wChild)
  183.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  184.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  185.  
  186.  
  187. SUB DrawWindow (Win AS wChild)
  188.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  189.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Red, BF 'title bar for dragging window
  190.  
  191. SUB GetInput (Act AS INTEGER)
  192.     DIM mInput AS INTEGER
  193.  
  194.  
  195.     ' keyboard input
  196.     a$ = INKEY$
  197.     IF a$ = CHR$(27) THEN Act = aQuit
  198.  
  199.     'mouse input
  200.     mInput = mFalse
  201.     IF _MOUSEINPUT THEN mInput = mTrue
  202.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  203.     LOOP
  204.     IF mInput THEN
  205.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  206.             mInput = mLR
  207.         ELSEIF _MOUSEBUTTON(1) THEN
  208.             mInput = mLeft
  209.         ELSEIF _MOUSEBUTTON(2) THEN
  210.             mInput = mRight
  211.         ELSEIF _MOUSEBUTTON(3) THEN
  212.             mInput = mMiddle
  213.         END IF
  214.     END IF
  215.  
  216.     IF mInput = mLR THEN
  217.         Act = aQuit
  218.     ELSEIF mInput = mMiddle THEN
  219.         Act = Minim
  220.     ELSEIF mInput = mRight THEN
  221.         Act = Maxim
  222.     ELSEIF mInput = mLeft THEN
  223.         Act = mInput
  224.     END IF

Instruction:
Click by right mouse button to _Fullscreen
Click by Middle mouse button to _Minimize to normal window
Click by left mouse button into a child window  to choose a child window (there are 3 windows Blu, Green and Yellow)
click by left mouse button on Red top bar of a child window to move it by dragging in the main window of the program

Thanks to take a look!
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on January 26, 2020, 11:18:57 am
Looks like a start, you know that _DISPLAY will stop the annoying blinking.
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on January 26, 2020, 11:23:35 am
Yes but I must remember it! :-)
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on January 26, 2020, 11:42:40 am
Yes but I must remember it! :-)

Then remember also, once you start using it, you have to use it ever where OR switch it OFF with _AUTODISPLAY, otherwise you will wonder why nothing seems to be working. ;-)) (like when you want to drag the window)

I say this not to you particularly TempodiBasic but to all the poor souls who could get fouled up and lost by this one little problem. Oh the frustration... ;-(
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on January 27, 2020, 10:22:49 am
Yes  one of the black beasts is _DISPLAY  vs  _AUTODISPLAY,  followed by  settings of color when you pass from a program written for ASCII screen or Qb45's legacy SCREEN to _NEWIMAGE (Width,Height,32)... remembering the exact sinthax and extension of each color command _RGB _RGBA  _RGB32 _RGBA32  for this case is a good advance the $COLOR of version 1.4 to use HTML code scheme.


Title: Re: child windows into window of the program: a demonstration
Post by: SMcNeill on January 27, 2020, 10:54:53 am
Here's a quick and simple demo of how I'd do multiple windows like this:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32) 'the main screen
  2. DIM Windows(3) AS _UNSIGNED LONG 'handles to hold extra windows
  3. FOR i = 0 TO 3: Windows(i) = _NEWIMAGE(640, 480, 32): NEXT 'make some extra windows
  4.  
  5. _DEST Windows(0) 'window 0
  6. CLS , Blue
  7. COLOR Red, 0
  8. PRINT "This is just some text on the first window, which I'm writing as an illustration.  It doesn't really mean anything, and doesn't do anything, except show that this is an independent screen, unaffected by any others."
  9.  
  10. _DEST Windows(1) 'window 1
  11. CLS , Silver
  12. LINE (100, 100)-(540, 380), Purple, BF
  13. CIRCLE (300, 300), 100, Green
  14. PAINT (300, 300), Green
  15.  
  16. _DEST Windows(2) 'window 2
  17. CLS , Yellow
  18. COLOR Red
  19. PRINT "Once upon a time, long ago and far away, Steve wrote a program in QB64!"
  20.  
  21. COLOR Black, 0
  22.     _DEST 0
  23.     CLS , 0
  24.     FOR i = 0 TO 3
  25.         LINE (100 + 163 * i, 70)-STEP(150, 20), Silver, BF
  26.         _PRINTSTRING (100 + 163 * i, 72), "      Window" + STR$(i)
  27.     NEXT
  28.     LINE (100, 100)-(740, 580), Silver, B
  29.  
  30.     _DEST Windows(3)
  31.     CLS , 0
  32.     LINE (x, 150)-STEP(100, 100), _RGB32(RND * 256, RND * 256, RND * 256), BF
  33.     x = (x + 5) MOD 640
  34.  
  35.     k = _KEYHIT
  36.     SELECT CASE k
  37.         CASE 48, 49, 50, 51: W = k - 48
  38.         CASE 27: SYSTEM
  39.     END SELECT
  40.     _PUTIMAGE (100, 100), Windows(W), 0
  41.     _LIMIT 30
  42.     _DISPLAY

I didn't bother to code in any mouse handling routine, though they'd be simple enough to add if someone wants them.  For this, just use the number keys for 0, 1, 2, 3 to swap between the 4 different window displays.

Window 0 is just a simple text window which I typed some junk on.
Window 1 is a graphical image, which could represent whatever my program needs.
Window 2 is another independent text window. 
Window 3 is an animated window where there's a simple box which scrolls from one side of the screen to the other.
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on January 27, 2020, 04:10:08 pm
Hi Steve

Your alternative way to build child windows as panel/Layer on which build output and to show on the main window is very cool. So I have decided to give another perspective to your idea, instead to use alternatively panels here the panels have different size among them and are on stack and user pressing 0123 can choose how the stack is build up. The program shows all the active panels together following the order of stack.
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32) 'the main screen
  2. DIM Windows(3) AS _UNSIGNED LONG 'handles to hold extra windows
  3. FOR i = 0 TO 3: Windows(i) = _NEWIMAGE(200 + (i * 100), 400, 32): NEXT 'make some extra windows
  4.  
  5. _DEST Windows(0) 'window 0
  6. CLS , Blue
  7. COLOR Red, 0
  8. PRINT "This is just some text on the first window, which I'm writing as an illustration.  It doesn't really mean anything, and doesn't do anything, except show that this is an independent screen, unaffected by any others."
  9.  
  10. _DEST Windows(1) 'window 1
  11. CLS , Silver
  12. LINE (100, 100)-(540, 380), Purple, BF
  13. CIRCLE (300, 300), 100, Green
  14. PAINT (300, 300), Green
  15.  
  16. _DEST Windows(2) 'window 2
  17. CLS , Yellow
  18. COLOR Red
  19. PRINT "Once upon a time, long ago and far away, Steve wrote a program in QB64!"
  20.  
  21. COLOR Black, 0
  22.  
  23. DIM Zorder AS STRING
  24. Zorder = "0123"
  25.  
  26.     _DEST 0
  27.     CLS , Pink
  28.     LOCATE 10, 2: PRINT Zorder
  29.     FOR i = 0 TO 3
  30.         LINE (100 + 163 * i, 70)-STEP(150, 20), Silver, BF
  31.         _PRINTSTRING (100 + 163 * i, 72), "      Window" + STR$(i)
  32.     NEXT
  33.     LINE (100, 100)-(740, 580), Silver, B
  34.  
  35.     _DEST Windows(3)
  36.     CLS , 0
  37.     LINE (x, 150)-STEP(100, 100), _RGB32(RND * 256, RND * 256, RND * 256), BF
  38.     x = (x + 5) MOD 640
  39.  
  40.     k = _KEYHIT
  41.     SELECT CASE k
  42.         CASE 48, 49, 50, 51: W = k - 48
  43.  
  44.             z = INSTR(Zorder, LTRIM$(STR$(W)))
  45.             Zorder = LTRIM$(STR$(W)) + LEFT$(Zorder, z - 1) + RIGHT$(Zorder, 4 - z)
  46.  
  47.         CASE 27: SYSTEM
  48.     END SELECT
  49.     FOR z = 0 TO 3
  50.         W = VAL(MID$(Zorder, z, 1))
  51.         _PUTIMAGE (100, 100), Windows(W), 0
  52.     NEXT z
  53.     _LIMIT 30
  54.     _DISPLAY
  55.  
  56.  

 
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on January 28, 2020, 07:27:26 pm
@Bplus
Here a no flickering version...
only for your eyes ... also a more smooth aspect of child windows
Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8.  
  9. ' 2020 01 25  A program with child windows into it
  10. ' we need a system to manage multiple windows
  11. ' and a system to manage input/output
  12. ' and a system to make graphic report
  13.  
  14. ' settings-------------------------------------------------------
  15. SCREEN _NEWIMAGE(800, 600, 32)
  16. _TITLE "Child windows"
  17. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  18. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  19. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  20. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 3, aNull = 0, aQuit = 9999
  21. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  22. CONST Dragging = 300, Focusing = 200
  23.  
  24.  
  25.  
  26. 'dataset  -----------------------------------------------
  27. TYPE person
  28.     name AS STRING * 10
  29.     age AS INTEGER
  30.     weight AS INTEGER
  31.     height AS INTEGER
  32.     BMI AS INTEGER
  33.  
  34. TYPE wChild
  35.     X AS INTEGER
  36.     Y AS INTEGER
  37.     Height AS INTEGER
  38.     Zorder AS INTEGER
  39.     Status AS INTEGER
  40.  
  41. REDIM Windows(0 TO wMin) AS wChild
  42. wMax = UBOUND(windows)
  43.  
  44.  
  45. ' windows(0) is for Dragging
  46.  
  47. Windows(1).X = 1
  48. Windows(1).Y = 1
  49. Windows(1).Width = 300
  50. Windows(1).Height = 400
  51. Windows(1).Zorder = 1
  52. Windows(1).Status = Minim
  53. Windows(1).Color = Blu
  54.  
  55. Windows(2).X = 100
  56. Windows(2).Y = 1
  57. Windows(2).Width = 300
  58. Windows(2).Height = 400
  59. Windows(2).Zorder = 2
  60. Windows(2).Status = Minim
  61. Windows(2).Color = Yellow
  62.  
  63. Windows(3).X = 200
  64. Windows(3).Y = 1
  65. Windows(3).Width = 300
  66. Windows(3).Height = 400
  67. Windows(3).Zorder = 3
  68. Windows(3).Status = Minim
  69. Windows(3).Color = Green
  70.  
  71. DIM Action AS INTEGER
  72.  
  73.  
  74. ' main loop -----------------------------------------------
  75.  
  76.     ' set the main window
  77.     Action = aNull
  78.     CLS , Orange
  79.     DrawAllWin
  80.     GetInput Action
  81.     DoAction Action
  82.     _LIMIT 30
  83.  
  84. ' SUBs and FUNCTIONs --------------------------------------
  85. SUB DrawAllWin
  86.     SHARED Windows() AS wChild
  87.     DIM Finished AS INTEGER
  88.     Finished = wMax
  89.     DO
  90.         FOR a = 1 TO wMax
  91.             IF Windows(a).Zorder = Finished THEN
  92.                 DrawWindow Windows(a)
  93.                 Finished = Finished - 1
  94.                 EXIT FOR
  95.             END IF
  96.         NEXT a
  97.     LOOP UNTIL Finished = 0
  98.     _DISPLAY
  99.  
  100. SUB Focus (Index AS INTEGER)
  101.     SHARED Windows() AS wChild
  102.     DIM b AS INTEGER
  103.     FOR b = 1 TO wMax
  104.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  105.     NEXT b
  106.     SWAP Windows(Index).Zorder, Windows(b).Zorder
  107.     DrawAllWin
  108.  
  109. SUB DoAction (Act AS INTEGER)
  110.     SHARED Windows() AS wChild
  111.     DIM a AS INTEGER
  112.  
  113.     SELECT CASE Act
  114.         CASE aQuit
  115.             END
  116.  
  117.         CASE Maxim
  118.             _FULLSCREEN
  119.  
  120.         CASE Minim
  121.             _FULLSCREEN _OFF
  122.  
  123.         CASE mLeft
  124.             DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER, Actio AS INTEGER
  125.             mX = _MOUSEX
  126.             mY = _MOUSEY
  127.             ' search where and what mouse has touched by leftclick
  128.             FOR a = 1 TO wMax ' windows(0) is out of action
  129.                 Actio = IsInWindow(mX, mY, Windows(a))
  130.                 IF Actio THEN EXIT FOR ' if windows(a) is on the stack it gets the click of mouse
  131.             NEXT a
  132.             SELECT CASE Actio
  133.                 CASE Dragging
  134.                     Focus a
  135.                     Windows(0).X = Windows(a).X
  136.                     Windows(0).Y = Windows(a).Y
  137.                     Windows(0).Width = Windows(a).Width
  138.                     Windows(0).Height = Windows(a).Height
  139.                     Windows(0).Status = Windows(a).Status
  140.                     Windows(0).Color = Windows(a).Color
  141.                     OmX = _MOUSEX - Windows(0).X
  142.                     OmY = _MOUSEY - Windows(0).Y
  143.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  144.                     DO WHILE _MOUSEBUTTON(1)
  145.                         IF _MOUSEINPUT THEN
  146.                             CLS , Orange
  147.                             DrawAllWin
  148.                             Windows(0).X = (_MOUSEX - OmX)
  149.                             Windows(0).Y = (_MOUSEY - OmY)
  150.                             dragWindow Windows(0)
  151.                         END IF
  152.                     LOOP
  153.                     ' new position of window
  154.                     Windows(a).X = Windows(0).X
  155.                     Windows(a).Y = Windows(0).Y
  156.                     Windows(a).Width = Windows(0).Width
  157.                     Windows(a).Height = Windows(0).Height
  158.                     Windows(a).Status = Windows(0).Status
  159.                     Windows(a).Color = Windows(0).Color
  160.                     Windows(a).Zorder = 1
  161.                 CASE Focusing
  162.                     Focus a
  163.             END SELECT
  164.  
  165.         CASE ELSE
  166.     END SELECT
  167.  
  168. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  169.     IsInWindow = mFalse
  170.     IF IsInTheRange%(X, Win.X, Win.X + Win.Width) THEN
  171.         IF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  172.             IsInWindow = Dragging
  173.         ELSEIF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  174.             IsInWindow = Focusing
  175.         END IF
  176.     END IF
  177.  
  178. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  179.     IF Min > Max THEN SWAP Min, Max
  180.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  181.  
  182. SUB dragWindow (Win AS wChild)
  183.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  184.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  185.     _DISPLAY
  186.  
  187.  
  188. SUB DrawWindow (Win AS wChild)
  189.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  190.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  191.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  192.     LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  193.     LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  194.  
  195. SUB GetInput (Act AS INTEGER)
  196.     DIM mInput AS INTEGER
  197.  
  198.  
  199.     ' keyboard input
  200.     a$ = INKEY$
  201.     IF a$ = CHR$(27) THEN Act = aQuit
  202.  
  203.     'mouse input
  204.     mInput = mFalse
  205.     IF _MOUSEINPUT THEN mInput = mTrue
  206.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  207.     LOOP
  208.     IF mInput THEN
  209.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  210.             mInput = mLR
  211.         ELSEIF _MOUSEBUTTON(1) THEN
  212.             mInput = mLeft
  213.         ELSEIF _MOUSEBUTTON(2) THEN
  214.             mInput = mRight
  215.         ELSEIF _MOUSEBUTTON(3) THEN
  216.             mInput = mMiddle
  217.         END IF
  218.     END IF
  219.  
  220.     IF mInput = mLR THEN
  221.         Act = aQuit
  222.     ELSEIF mInput = mMiddle THEN
  223.         Act = Minim
  224.     ELSEIF mInput = mRight THEN
  225.         Act = Maxim
  226.     ELSEIF mInput = mLeft THEN
  227.         Act = mInput
  228.     END IF

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on January 28, 2020, 10:28:58 pm
Very nice start TempodiBasic they drag nicely alright and fetching colors too :)
Title: Re: child windows into window of the program: a demonstration
Post by: keybone on January 28, 2020, 10:40:45 pm
looks like something I've been trying to accomplish for a long time.

Well, here's my attempt:
http://keybone.epizy.com/files/234178487/winsys.bas

The windows can be moved, resized, maximized, and restored from maximized (if the functionality is enabled on a per-window basis).
Minimize/iconify functionality is not implemented yet.

And I havent figured out how im going to have events handled within the windows yet.
Still a work in progress...
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on January 29, 2020, 09:22:53 am
Fine Keybone!

... I have seen that also rightclick menu is work in progress. Good one!


about
Quote
And I havent figured out how im going to have events handled within the windows yet.
Still a work in progress...
I think that there are so many ways to do this....

for interaction among objects of the same window or objects of different windows  I can imagine a timer control that activates a short loop or a message system like windows OS...
for events triggered by I/O of user  I imagine a defauld univocal keypress (keyboard or joystick) or area of screen sensible to mouse events or /and a focus system to address and to react in the right manner to the Input (you get the input and pass it to the focused object)
... well , after lunch these are the results of my imagination...
Good work and Good Imagination!
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 05, 2020, 07:39:57 pm
Hi
I go on with child windows...
now there are 3 button on the bar of the window to Maximize to the application window or to Restore default dimension or to reduce to the bar of the child window.
Here the code.

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 05 fixed a minor bug on mouse click events
  9. '            activated events Maxim Minim and Closed
  10.  
  11.  
  12. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  13. '            removed vMax SHARED variable
  14. '            added 3 buttons on the rightest site of the bar of the child window
  15. '            SUB wClosed, wMaxim, wMinim
  16. '            In this version the user can maximize one child window to the application window
  17. '            In the status of Maxim the child window has the focus and can be only
  18. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  19.  
  20.  
  21. ' 2020 01 30 fixed bug on focusing a child window
  22. '
  23.  
  24. ' 2020 01 25  A program with child windows into it
  25. ' we need a system to manage multiple windows
  26. ' and a system to manage input/output
  27. ' and a system to make graphic report
  28.  
  29. ' settings-------------------------------------------------------
  30. SCREEN _NEWIMAGE(800, 600, 32)
  31. _TITLE "Child windows"
  32. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  33. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  34. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  35. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 5, aNull = 0, aQuit = 9999
  36. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  37. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  38.  
  39.  
  40.  
  41. 'dataset  -----------------------------------------------
  42. TYPE person
  43.     name AS STRING * 10
  44.     age AS INTEGER
  45.     weight AS INTEGER
  46.     height AS INTEGER
  47.     BMI AS INTEGER
  48.  
  49. TYPE wChild
  50.     X AS INTEGER
  51.     Y AS INTEGER
  52.     Height AS INTEGER
  53.     Zorder AS INTEGER
  54.     Status AS INTEGER
  55.  
  56. REDIM Windows(0 TO wMin) AS wChild
  57.  
  58. InitWin
  59.  
  60. DIM Action AS INTEGER
  61.  
  62.  
  63. ' main loop -----------------------------------------------
  64.  
  65.     ' set the main window
  66.     Action = aNull
  67.     CLS , Orange
  68.     DrawAllWin
  69.     GetInput Action
  70.     DoAction Action
  71.     _LIMIT 30
  72.  
  73. ' SUBs and FUNCTIONs --------------------------------------
  74. SUB InitWin
  75.     SHARED Windows() AS wChild
  76.     ' windows(0) is for Dragging or Maximize
  77.     Windows(0).X = 0
  78.     Windows(0).Y = 0
  79.     Windows(0).Width = 0
  80.     Windows(0).Height = 0
  81.     Windows(0).Zorder = 0
  82.     Windows(0).Status = 0
  83.     Windows(0).Color = 0
  84.  
  85.     Windows(1).X = 1
  86.     Windows(1).Y = 1
  87.     Windows(1).Width = 300
  88.     Windows(1).Height = 400
  89.     Windows(1).Zorder = 1
  90.     Windows(1).Status = Minim
  91.     Windows(1).Color = Blu
  92.  
  93.     Windows(2).X = 100
  94.     Windows(2).Y = 1
  95.     Windows(2).Width = 300
  96.     Windows(2).Height = 400
  97.     Windows(2).Zorder = 2
  98.     Windows(2).Status = Minim
  99.     Windows(2).Color = Yellow
  100.  
  101.     Windows(3).X = 200
  102.     Windows(3).Y = 1
  103.     Windows(3).Width = 300
  104.     Windows(3).Height = 400
  105.     Windows(3).Zorder = 3
  106.     Windows(3).Status = Minim
  107.     Windows(3).Color = Green
  108.  
  109.     Windows(4).X = 300
  110.     Windows(4).Y = 1
  111.     Windows(4).Width = 300
  112.     Windows(4).Height = 400
  113.     Windows(4).Zorder = 4
  114.     Windows(4).Status = Minim
  115.     Windows(4).Color = Red
  116.  
  117.     Windows(5).X = 400
  118.     Windows(5).Y = 1
  119.     Windows(5).Width = 300
  120.     Windows(5).Height = 400
  121.     Windows(5).Zorder = 5
  122.     Windows(5).Status = Minim
  123.     Windows(5).Color = Cyan
  124.  
  125. SUB DrawAllWin
  126.     SHARED Windows() AS wChild
  127.     DIM Finished AS INTEGER
  128.     Finished = wMin
  129.     DO
  130.         FOR a = 1 TO wMin
  131.             IF Windows(a).Zorder = Finished THEN
  132.                 DrawWindow Windows(a)
  133.                 Finished = Finished - 1
  134.                 EXIT FOR
  135.             END IF
  136.         NEXT a
  137.     LOOP UNTIL Finished = 0
  138.     _DISPLAY
  139.  
  140. SUB Focus (Index AS INTEGER)
  141.     SHARED Windows() AS wChild
  142.     DIM b AS INTEGER
  143.     FOR b = 1 TO wMin
  144.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  145.     NEXT b
  146.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  147.     DrawAllWin
  148.  
  149.  
  150. SUB DoAction (Act AS INTEGER)
  151.     SHARED Windows() AS wChild
  152.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  153.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  154.  
  155.     SELECT CASE Act
  156.         CASE aQuit
  157.             END
  158.  
  159.         CASE Maxim
  160.             _FULLSCREEN
  161.  
  162.         CASE Minim
  163.             _FULLSCREEN _OFF
  164.  
  165.         CASE mLeft
  166.             mX = _MOUSEX
  167.             mY = _MOUSEY
  168.  
  169.             ' search where and what mouse has touched by leftclick
  170.             OldA = 0
  171.             OldActio = 0
  172.             FOR a = 1 TO wMin ' windows(0) is out of action
  173.                 Actio = IsInWindow(mX, mY, Windows(a))
  174.                 IF Actio THEN
  175.                     IF OldA <= 0 THEN
  176.                         OldA = a
  177.                         OldActio = Actio
  178.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  179.                         OldA = a
  180.                         OldActio = Actio
  181.                     END IF
  182.                 END IF
  183.             NEXT a
  184.             IF a > OldA THEN
  185.                 a = OldA ' restore the last windows interacting
  186.                 Actio = OldActio
  187.             END IF
  188.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  189.  
  190.  
  191.             Focus a 'set zorder on the (a) window that gets the input
  192.  
  193.  
  194.             SELECT CASE Actio
  195.                 CASE cMinim
  196.                     ' here restore to  standard status of child window
  197.                     IF NOT Windows(a).Status = Minim THEN
  198.                         Windows(a).X = Windows(0).X
  199.                         Windows(a).Y = Windows(0).Y
  200.                         Windows(a).Width = Windows(0).Width
  201.                         Windows(a).Height = Windows(0).Height
  202.                         Windows(a).Status = Minim
  203.                         Windows(a).Zorder = 1
  204.                     END IF
  205.  
  206.                 CASE cMaxim
  207.                     ' here convert the window to full size of main window of the program
  208.                     IF NOT Windows(a).Status = Maxim THEN
  209.                         ' memorize window's data
  210.                         Windows(0).X = Windows(a).X
  211.                         Windows(0).Y = Windows(a).Y
  212.                         Windows(0).Width = Windows(a).Width
  213.                         Windows(0).Height = Windows(a).Height
  214.                         ' change status
  215.                         Windows(a).Status = Maxim
  216.                         Windows(a).Width = _WIDTH
  217.                         Windows(a).Height = _HEIGHT
  218.                         Windows(a).X = 1
  219.                         Windows(a).Y = 1
  220.                     END IF
  221.                 CASE cClosed
  222.                     ' here minimize the child window to its window bar
  223.                     IF Windows(a).Status = Minim THEN
  224.                         ' memorize window's data
  225.                         Windows(0).X = Windows(a).X
  226.                         Windows(0).Y = Windows(a).Y
  227.                         Windows(0).Width = Windows(a).Width
  228.                         Windows(0).Height = Windows(a).Height
  229.                         ' change status
  230.                         Windows(a).Status = Closed
  231.                     END IF
  232.                 CASE Dragging
  233.                     ' dragging is not possible for maximized window
  234.                     ' but it is possible for status Minim child window and
  235.                     ' for status Closed that shows only Bar window
  236.                     IF NOT Windows(a).Status = Maxim THEN
  237.                         Windows(0).X = Windows(a).X
  238.                         Windows(0).Y = Windows(a).Y
  239.                         Windows(0).Width = Windows(a).Width
  240.                         Windows(0).Height = Windows(a).Height
  241.                         Windows(0).Status = Windows(a).Status
  242.                         Windows(0).Color = Windows(a).Color
  243.                         OmX = _MOUSEX - Windows(0).X
  244.                         OmY = _MOUSEY - Windows(0).Y
  245.                         DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  246.                         DO WHILE _MOUSEBUTTON(1)
  247.                             IF _MOUSEINPUT THEN
  248.                                 CLS , Orange
  249.                                 DrawAllWin
  250.                                 Windows(0).X = (_MOUSEX - OmX)
  251.                                 Windows(0).Y = (_MOUSEY - OmY)
  252.                                 dragWindow Windows(0)
  253.                             END IF
  254.                         LOOP
  255.                         ' new position of window
  256.                         Windows(a).X = Windows(0).X
  257.                         Windows(a).Y = Windows(0).Y
  258.                         Windows(a).Width = Windows(0).Width
  259.                         Windows(a).Height = Windows(0).Height
  260.                         Windows(a).Status = Windows(0).Status
  261.                         Windows(a).Color = Windows(0).Color
  262.                         Windows(a).Zorder = 1
  263.                     END IF
  264.                 CASE Focusing
  265.                     Focus a
  266.             END SELECT
  267.  
  268.         CASE ELSE
  269.     END SELECT
  270.  
  271. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  272.     IsInWindow = mFalse
  273.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  274.         ' if window is closed to its bar it cannot get focus on the window area
  275.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status <> Closed) THEN IsInWindow = Focusing
  276.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  277.         ' if is the window bar area
  278.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width - 31) THEN
  279.             ' if it is to the left of buttons on the bar
  280.             ' maximized window cannot be dragged
  281.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = Dragging
  282.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  283.             ' if it is on the leftest button on the bar
  284.             IsInWindow = cMinim ' icon minimize--> restore to child default
  285.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  286.             ' if it is on the middle button on the bar
  287.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  288.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  289.             ' if is on the rightest button on the bar
  290.             ' maximized child window cannot become minimized to bar of child window
  291.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  292.         END IF
  293.     END IF
  294.  
  295. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  296.     IF Min > Max THEN SWAP Min, Max
  297.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  298.  
  299. SUB dragWindow (Win AS wChild)
  300.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  301.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  302.     _DISPLAY
  303.  
  304. SUB wClosed (Win AS wChild)
  305.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  306.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  307.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  308.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  309.  
  310. SUB wMaxim (win AS wChild)
  311.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  312.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  313.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  314.  
  315. SUB wMinim (Win AS wChild)
  316.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  317.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  318.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  319.  
  320.  
  321. SUB DrawWindow (Win AS wChild)
  322.     ' the window
  323.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  324.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  325.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  326.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  327.     END IF
  328.     ' the status bar
  329.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  330.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  331.     wMinim Win
  332.     wMaxim Win
  333.     wClosed Win
  334.  
  335. SUB GetInput (Act AS INTEGER)
  336.     DIM mInput AS INTEGER
  337.  
  338.  
  339.     ' keyboard input
  340.     a$ = INKEY$
  341.     IF a$ = CHR$(27) THEN Act = aQuit
  342.  
  343.     'mouse input
  344.     mInput = mFalse
  345.     IF _MOUSEINPUT THEN mInput = mTrue
  346.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  347.     LOOP
  348.     IF mInput THEN
  349.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  350.             mInput = mLR
  351.         ELSEIF _MOUSEBUTTON(1) THEN
  352.             mInput = mLeft
  353.         ELSEIF _MOUSEBUTTON(2) THEN
  354.             mInput = mRight
  355.         ELSEIF _MOUSEBUTTON(3) THEN
  356.             mInput = mMiddle
  357.         END IF
  358.     END IF
  359.  
  360.     IF mInput = mLR THEN
  361.         Act = aQuit
  362.     ELSEIF mInput = mMiddle THEN
  363.         Act = Minim
  364.     ELSEIF mInput = mRight THEN
  365.         Act = Maxim
  366.     ELSEIF mInput = mLeft THEN
  367.         Act = mInput
  368.     END IF
  369.  

Thanks to try
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 09, 2020, 04:44:17 am
another step forward, for each window a shadow of info
it fixs a bug of the previous version that stack the chil windows on the same position if you close more windows at different positions and then you click on restore/minimize button (the first from the left) on the windows bar.

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8.  
  9. ' 2020 02 08  using a second array we store windows information indipendently so
  10. '             now each window can be modified and restored
  11.  
  12.  
  13. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  14. '             to it the last value used in windows(0) so the info of the last
  15. '             window that is dragged or maximize when we use Minimize button on
  16. '             another child window
  17. '             the fix can be got using a shadow array that stores windows informations
  18. '             or windows(0) as the child window that takes the information of the
  19. '             child window that must be acted (Minimize, Maximize and Closed)
  20. '             and we use it as template to make graphic output
  21.  
  22. ' 2020 02 05 fixed a minor bug on mouse click events
  23. '            activated events Maxim Minim and Closed
  24.  
  25.  
  26. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  27. '            removed vMax SHARED variable
  28. '            added 3 buttons on the rightest site of the bar of the child window
  29. '            SUB wClosed, wMaxim, wMinim
  30. '            In this version the user can maximize one child window to the application window
  31. '            In the status of Maxim the child window has the focus and can be only
  32. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  33.  
  34.  
  35. ' 2020 01 30 fixed bug on focusing a child window
  36. '
  37.  
  38. ' 2020 01 25  A program with child windows into it
  39. ' we need a system to manage multiple windows
  40. ' and a system to manage input/output
  41. ' and a system to make graphic report
  42.  
  43. ' settings-------------------------------------------------------
  44. SCREEN _NEWIMAGE(800, 600, 32)
  45. _TITLE "Child windows"
  46. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  47. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  48. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  49. CONST Minim = 20, Maxim = 10, Closed = 100, wMin = 5, aNull = 0, aQuit = 9999
  50. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  51. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  52.  
  53.  
  54.  
  55. 'dataset  -----------------------------------------------
  56. TYPE person
  57.     name AS STRING * 10
  58.     age AS INTEGER
  59.     weight AS INTEGER
  60.     height AS INTEGER
  61.     BMI AS INTEGER
  62.  
  63. TYPE wChild
  64.     X AS INTEGER
  65.     Y AS INTEGER
  66.     Height AS INTEGER
  67.     Zorder AS INTEGER
  68.     Status AS INTEGER
  69.  
  70. REDIM Windows(1 TO wMin) AS wChild, OldW(1 TO wMin) AS wChild
  71.  
  72. InitWin
  73.  
  74. DIM Action AS INTEGER
  75.  
  76.  
  77. ' main loop -----------------------------------------------
  78.  
  79.     ' set the main window
  80.     Action = aNull
  81.     CLS , Orange
  82.     DrawAllWin
  83.     GetInput Action
  84.     DoAction Action
  85.     _DISPLAY
  86.     _LIMIT 30
  87.  
  88. ' SUBs and FUNCTIONs --------------------------------------
  89. SUB InitWin
  90.     SHARED Windows() AS wChild, OldW() AS wChild
  91.     DIM a AS INTEGER
  92.  
  93.     Windows(1).X = 1
  94.     Windows(1).Y = 1
  95.     Windows(1).Width = 300
  96.     Windows(1).Height = 400
  97.     Windows(1).Zorder = 1
  98.     Windows(1).Status = Minim
  99.     Windows(1).Color = Blu
  100.  
  101.     Windows(2).X = 100
  102.     Windows(2).Y = 1
  103.     Windows(2).Width = 300
  104.     Windows(2).Height = 400
  105.     Windows(2).Zorder = 2
  106.     Windows(2).Status = Minim
  107.     Windows(2).Color = Yellow
  108.  
  109.     Windows(3).X = 200
  110.     Windows(3).Y = 1
  111.     Windows(3).Width = 300
  112.     Windows(3).Height = 400
  113.     Windows(3).Zorder = 3
  114.     Windows(3).Status = Minim
  115.     Windows(3).Color = Green
  116.  
  117.     Windows(4).X = 300
  118.     Windows(4).Y = 1
  119.     Windows(4).Width = 300
  120.     Windows(4).Height = 400
  121.     Windows(4).Zorder = 4
  122.     Windows(4).Status = Minim
  123.     Windows(4).Color = Red
  124.  
  125.     Windows(5).X = 400
  126.     Windows(5).Y = 1
  127.     Windows(5).Width = 300
  128.     Windows(5).Height = 400
  129.     Windows(5).Zorder = 5
  130.     Windows(5).Status = Minim
  131.     Windows(5).Color = Cyan
  132.  
  133.     FOR a = 1 TO wMin STEP 1
  134.         AdjournWin a
  135.     NEXT a
  136.  
  137. SUB RestoreWin (a AS INTEGER)
  138.     SHARED Windows() AS wChild, OldW() AS wChild
  139.  
  140.     Windows(a).X = OldW(a).X
  141.     Windows(a).Y = OldW(a).Y
  142.     Windows(a).Width = OldW(a).Width
  143.     Windows(a).Height = OldW(a).Height
  144.     Windows(a).Zorder = OldW(a).Zorder
  145.     Windows(a).Color = OldW(a).Color
  146.  
  147. SUB AdjournWin (a AS INTEGER)
  148.     SHARED Windows() AS wChild, OldW() AS wChild
  149.  
  150.     OldW(a).X = Windows(a).X
  151.     OldW(a).Y = Windows(a).Y
  152.     OldW(a).Width = Windows(a).Width
  153.     OldW(a).Height = Windows(a).Height
  154.     OldW(a).Zorder = Windows(a).Zorder
  155.     OldW(a).Color = Windows(a).Color
  156.  
  157. SUB DrawAllWin
  158.     SHARED Windows() AS wChild
  159.     DIM Finished AS INTEGER
  160.     Finished = wMin
  161.     DO
  162.         FOR a = 1 TO wMin
  163.             IF Windows(a).Zorder = Finished THEN
  164.                 DrawWindow Windows(a)
  165.                 Finished = Finished - 1
  166.                 EXIT FOR
  167.             END IF
  168.         NEXT a
  169.     LOOP UNTIL Finished = 0
  170.  
  171. SUB Focus (Index AS INTEGER)
  172.     SHARED Windows() AS wChild
  173.     DIM b AS INTEGER
  174.     FOR b = 1 TO wMin
  175.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  176.     NEXT b
  177.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  178.     DrawAllWin
  179.  
  180.  
  181. SUB DoAction (Act AS INTEGER)
  182.     SHARED Windows() AS wChild, OldW() AS wChild
  183.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  184.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  185.  
  186.     SELECT CASE Act
  187.         CASE aQuit
  188.             END
  189.  
  190.         CASE Maxim
  191.             _FULLSCREEN
  192.  
  193.         CASE Minim
  194.             _FULLSCREEN _OFF
  195.  
  196.         CASE mLeft
  197.             mX = _MOUSEX
  198.             mY = _MOUSEY
  199.  
  200.             ' search where and what mouse has touched by leftclick
  201.             OldA = 0
  202.             OldActio = 0
  203.             FOR a = 1 TO wMin ' windows(0) is out of action
  204.                 Actio = IsInWindow(mX, mY, Windows(a))
  205.                 IF Actio THEN
  206.                     IF OldA <= 0 THEN
  207.                         OldA = a
  208.                         OldActio = Actio
  209.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  210.                         OldA = a
  211.                         OldActio = Actio
  212.                     END IF
  213.                 END IF
  214.             NEXT a
  215.             IF a > OldA THEN
  216.                 a = OldA ' restore the last windows interacting
  217.                 Actio = OldActio
  218.             END IF
  219.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  220.  
  221.  
  222.             Focus a 'set zorder on the (a) window that gets the input
  223.  
  224.  
  225.             SELECT CASE Actio
  226.                 CASE cMinim
  227.                     ' here restore to  standard status of child window
  228.                     IF NOT Windows(a).Status = Minim THEN
  229.                         RestoreWin a
  230.                         Windows(a).Status = Minim
  231.                     END IF
  232.  
  233.                 CASE cMaxim
  234.                     ' here convert the window to full size of main window of the program
  235.                     IF NOT Windows(a).Status = Maxim THEN
  236.                         ' memorize window's data
  237.                         AdjournWin a
  238.                         ' change status
  239.                         Windows(a).Status = Maxim
  240.                         Windows(a).Width = _WIDTH
  241.                         Windows(a).Height = _HEIGHT
  242.                         Windows(a).X = 1
  243.                         Windows(a).Y = 1
  244.                     END IF
  245.                 CASE cClosed
  246.                     ' here minimize the child window to its window bar
  247.                     IF Windows(a).Status = Minim THEN
  248.                         'save data of window
  249.                         AdjournWin a
  250.                         ' change status
  251.                         Windows(a).Status = Closed
  252.                     END IF
  253.                 CASE Dragging
  254.                     ' dragging is not possible for maximized window
  255.                     ' but it is possible for status Minim child window and
  256.                     ' for status Closed that shows only Bar window
  257.                     IF NOT Windows(a).Status = Maxim THEN
  258.                         AdjournWin a
  259.                         OmX = _MOUSEX - OldW(a).X
  260.                         OmY = _MOUSEY - OldW(a).Y
  261.                         DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  262.                         DO WHILE _MOUSEBUTTON(1)
  263.                             IF _MOUSEINPUT THEN
  264.                                 CLS , Orange
  265.  
  266.                                 OldW(a).X = (_MOUSEX - OmX)
  267.                                 OldW(a).Y = (_MOUSEY - OmY)
  268.                                 DrawAllWin
  269.                                 dragWindow OldW(a)
  270.                             END IF
  271.                         LOOP
  272.                         ' new position of window
  273.                         RestoreWin a
  274.                     END IF
  275.                 CASE Focusing
  276.                     Focus a
  277.             END SELECT
  278.  
  279.         CASE ELSE
  280.     END SELECT
  281.  
  282. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  283.     IsInWindow = mFalse
  284.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  285.         ' if window is closed to its bar it cannot get focus on the window area
  286.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status <> Closed) THEN IsInWindow = Focusing
  287.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  288.         ' if is the window bar area
  289.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width - 31) THEN
  290.             ' if it is to the left of buttons on the bar
  291.             ' maximized window cannot be dragged
  292.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = Dragging
  293.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  294.             ' if it is on the leftest button on the bar
  295.             IsInWindow = cMinim ' icon minimize--> restore to child default
  296.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  297.             ' if it is on the middle button on the bar
  298.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  299.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  300.             ' if is on the rightest button on the bar
  301.             ' maximized child window cannot become minimized to bar of child window
  302.             IF NOT (Win.Status AND Maxim) THEN IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  303.         END IF
  304.     END IF
  305.  
  306. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  307.     IF Min > Max THEN SWAP Min, Max
  308.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  309.  
  310. SUB dragWindow (Win AS wChild)
  311.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B
  312.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  313.     _DISPLAY
  314.  
  315. SUB wClosed (Win AS wChild)
  316.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  317.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  318.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  319.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  320.  
  321. SUB wMaxim (win AS wChild)
  322.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  323.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  324.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  325.  
  326. SUB wMinim (Win AS wChild)
  327.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  328.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  329.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  330.  
  331.  
  332. SUB DrawWindow (Win AS wChild)
  333.     ' the window
  334.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  335.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  336.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  337.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  338.     END IF
  339.     ' the status bar
  340.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  341.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  342.     wMinim Win
  343.     wMaxim Win
  344.     wClosed Win
  345.  
  346. SUB GetInput (Act AS INTEGER)
  347.     DIM mInput AS INTEGER
  348.  
  349.  
  350.     ' keyboard input
  351.     a$ = INKEY$
  352.     IF a$ = CHR$(27) THEN Act = aQuit
  353.  
  354.     'mouse input
  355.     mInput = mFalse
  356.     IF _MOUSEINPUT THEN mInput = mTrue
  357.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  358.     LOOP
  359.     IF mInput THEN
  360.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  361.             mInput = mLR
  362.         ELSEIF _MOUSEBUTTON(1) THEN
  363.             mInput = mLeft
  364.         ELSEIF _MOUSEBUTTON(2) THEN
  365.             mInput = mRight
  366.         ELSEIF _MOUSEBUTTON(3) THEN
  367.             mInput = mMiddle
  368.         END IF
  369.     END IF
  370.  
  371.     IF mInput = mLR THEN
  372.         Act = aQuit
  373.     ELSEIF mInput = mMiddle THEN
  374.         Act = Minim
  375.     ELSEIF mInput = mRight THEN
  376.         Act = Maxim
  377.     ELSEIF mInput = mLeft THEN
  378.         Act = mInput
  379.     END IF
 [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 09, 2020, 06:17:39 pm
Hi
here a more complex but versatle system of windowing child windows

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 09  with the power of the second array we implement a different
  9. '             child windows' system:
  10. '             all child windows can be Closed to window's bar
  11. '             all child windows can be dragged on the screen
  12.  
  13. ' 2020 02 08  using a second array we store windows information indipendently so
  14. '             now each window can be modified and restored
  15.  
  16.  
  17. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  18. '             to it the last value used in windows(0) so the info of the last
  19. '             window that is dragged or maximize when we use Minimize button on
  20. '             another child window
  21. '             the fix can be got using a shadow array that stores windows informations
  22. '             or windows(0) as the child window that takes the information of the
  23. '             child window that must be acted (Minimize, Maximize and Closed)
  24. '             and we use it as template to make graphic output
  25.  
  26. ' 2020 02 05 fixed a minor bug on mouse click events
  27. '            activated events Maxim Minim and Closed
  28.  
  29.  
  30. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  31. '            removed vMax SHARED variable
  32. '            added 3 buttons on the rightest site of the bar of the child window
  33. '            SUB wClosed, wMaxim, wMinim
  34. '            In this version the user can maximize one child window to the application window
  35. '            In the status of Maxim the child window has the focus and can be only
  36. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  37.  
  38.  
  39. ' 2020 01 30 fixed bug on focusing a child window
  40. '
  41.  
  42. ' 2020 01 25  A program with child windows into it
  43. ' we need a system to manage multiple windows
  44. ' and a system to manage input/output
  45. ' and a system to make graphic report
  46.  
  47. ' settings-------------------------------------------------------
  48. SCREEN _NEWIMAGE(800, 600, 32)
  49. _TITLE "Child windows"
  50. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  51. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  52. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  53. CONST Minim = 10, Maxim = 20, Closed = 100
  54. CONST wMin = 5, aNull = 0, aQuit = 9999
  55. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  56. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  57.  
  58.  
  59.  
  60. 'dataset  -----------------------------------------------
  61. TYPE person
  62.     name AS STRING * 10
  63.     age AS INTEGER
  64.     weight AS INTEGER
  65.     height AS INTEGER
  66.     BMI AS INTEGER
  67.  
  68. TYPE wChild
  69.     X AS INTEGER
  70.     Y AS INTEGER
  71.     Height AS INTEGER
  72.     Zorder AS INTEGER
  73.     Status AS INTEGER
  74.  
  75. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  76.  
  77. InitWin
  78.  
  79. DIM Action AS INTEGER
  80.  
  81.  
  82. ' main loop -----------------------------------------------
  83.  
  84.     ' set the main window
  85.     Action = aNull
  86.     CLS , Orange
  87.     DrawAllWin
  88.     GetInput Action
  89.     DoAction Action
  90.     _DISPLAY
  91.     _LIMIT 30
  92.  
  93. ' SUBs and FUNCTIONs --------------------------------------
  94. SUB InitWin
  95.     SHARED Windows() AS wChild, OldW() AS wChild
  96.     DIM a AS INTEGER
  97.  
  98.     Windows(1).X = 1
  99.     Windows(1).Y = 1
  100.     Windows(1).Width = 300
  101.     Windows(1).Height = 400
  102.     Windows(1).Zorder = 1
  103.     Windows(1).Status = Minim
  104.     Windows(1).Color = Blu
  105.  
  106.     Windows(2).X = 100
  107.     Windows(2).Y = 1
  108.     Windows(2).Width = 300
  109.     Windows(2).Height = 400
  110.     Windows(2).Zorder = 2
  111.     Windows(2).Status = Minim
  112.     Windows(2).Color = Yellow
  113.  
  114.     Windows(3).X = 200
  115.     Windows(3).Y = 1
  116.     Windows(3).Width = 300
  117.     Windows(3).Height = 400
  118.     Windows(3).Zorder = 3
  119.     Windows(3).Status = Minim
  120.     Windows(3).Color = Green
  121.  
  122.     Windows(4).X = 300
  123.     Windows(4).Y = 1
  124.     Windows(4).Width = 300
  125.     Windows(4).Height = 400
  126.     Windows(4).Zorder = 4
  127.     Windows(4).Status = Minim
  128.     Windows(4).Color = Red
  129.  
  130.     Windows(5).X = 400
  131.     Windows(5).Y = 1
  132.     Windows(5).Width = 300
  133.     Windows(5).Height = 400
  134.     Windows(5).Zorder = 5
  135.     Windows(5).Status = Minim
  136.     Windows(5).Color = Cyan
  137.  
  138.     FOR a = 1 TO wMin STEP 1
  139.         AdjournWin a
  140.     NEXT a
  141.  
  142. SUB RestoreWin (a AS INTEGER)
  143.     SHARED Windows() AS wChild, OldW() AS wChild
  144.  
  145.     Windows(a).X = OldW(a).X
  146.     Windows(a).Y = OldW(a).Y
  147.     Windows(a).Width = OldW(a).Width
  148.     Windows(a).Height = OldW(a).Height
  149.     Windows(a).Zorder = OldW(a).Zorder
  150.     Windows(a).Color = OldW(a).Color
  151.  
  152. SUB AdjournWin (a AS INTEGER)
  153.     SHARED Windows() AS wChild, OldW() AS wChild
  154.  
  155.     OldW(a).X = Windows(a).X
  156.     OldW(a).Y = Windows(a).Y
  157.     OldW(a).Width = Windows(a).Width
  158.     OldW(a).Height = Windows(a).Height
  159.     OldW(a).Zorder = Windows(a).Zorder
  160.     OldW(a).Color = Windows(a).Color
  161.  
  162. SUB DrawAllWin
  163.     SHARED Windows() AS wChild
  164.     DIM Finished AS INTEGER
  165.     Finished = wMin
  166.     DO
  167.         FOR a = 1 TO wMin
  168.             IF Windows(a).Zorder = Finished THEN
  169.                 DrawWindow Windows(a)
  170.                 Finished = Finished - 1
  171.                 EXIT FOR
  172.             END IF
  173.         NEXT a
  174.     LOOP UNTIL Finished = 0
  175.  
  176. SUB Focus (Index AS INTEGER)
  177.     SHARED Windows() AS wChild
  178.     DIM b AS INTEGER
  179.     FOR b = 1 TO wMin
  180.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  181.     NEXT b
  182.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  183.     DrawAllWin
  184.  
  185.  
  186. SUB DoAction (Act AS INTEGER)
  187.     SHARED Windows() AS wChild, OldW() AS wChild
  188.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  189.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  190.  
  191.     SELECT CASE Act
  192.         CASE aQuit
  193.             END
  194.  
  195.         CASE Maxim
  196.             _FULLSCREEN
  197.  
  198.         CASE Minim
  199.             _FULLSCREEN _OFF
  200.  
  201.         CASE mLeft
  202.             mX = _MOUSEX
  203.             mY = _MOUSEY
  204.  
  205.             ' search where and what mouse has touched by leftclick
  206.             OldA = 0
  207.             OldActio = 0
  208.             FOR a = 1 TO wMin ' windows(0) is out of action
  209.                 Actio = IsInWindow(mX, mY, Windows(a))
  210.                 IF Actio THEN
  211.                     IF OldA <= 0 THEN
  212.                         OldA = a
  213.                         OldActio = Actio
  214.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  215.                         OldA = a
  216.                         OldActio = Actio
  217.                     END IF
  218.                 END IF
  219.             NEXT a
  220.             IF a > OldA THEN
  221.                 a = OldA ' restore the last windows interacting
  222.                 Actio = OldActio
  223.             END IF
  224.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  225.  
  226.  
  227.             Focus a 'set zorder on the (a) window that gets the input
  228.  
  229.  
  230.             SELECT CASE Actio
  231.                 CASE cMinim
  232.                     ' here restore to  standard (bar + area of window) status of child window
  233.                     IF Windows(a).Status = Closed + Maxim THEN
  234.                         ' if windows is a closed maximized window
  235.                         ' we restore its status of maximized
  236.                         Windows(a).Status = Maxim
  237.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  238.                         ' if windows is a closed minimized window
  239.                         ' we restore its status of minimized
  240.                         Windows(a).Status = Minim
  241.                     ELSEIF Windows(a).Status = Maxim THEN
  242.                         ' if is a window maximized it gets back all info setting
  243.                         ' we restore its status of minimized
  244.                         RestoreWin a
  245.                         Windows(a).Status = Minim
  246.                     END IF
  247.  
  248.  
  249.                 CASE cMaxim
  250.                     ' here convert the window to full size of main window of the program
  251.                     ' OR gives 1 if both parameter are true or al last one is true
  252.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  253.                         ' it acts if windows if not still maximized
  254.                         ' it is minimized window opened or closed
  255.                         ' memorize window's data when it is not maximized
  256.                         '                        IF Windows(a).Width < _WIDTH THEN
  257.                         AdjournWin a
  258.                         ' it sets maximized status
  259.                         Windows(a).Width = _WIDTH
  260.                         Windows(a).Height = _HEIGHT
  261.                         Windows(a).X = 1
  262.                         Windows(a).Y = 1
  263.                         ' change status
  264.                         Windows(a).Status = Maxim
  265.                     END IF
  266.  
  267.                 CASE cClosed
  268.                     ' here minimize the child window to its window bar
  269.                     IF NOT Windows(a).Status > Closed THEN
  270.                         Windows(a).Status = Windows(a).Status + Closed
  271.                     END IF
  272.  
  273.                 CASE Dragging
  274.                     ' dragging is possible for all status of windows
  275.                     '
  276.                     ' if minimized or Closed and minimized window we save data info
  277.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  278.                     ' it sets variables for dragging
  279.                     OldW(0).X = Windows(a).X
  280.                     OldW(0).Y = Windows(a).Y
  281.                     OldW(0).Width = Windows(a).Width
  282.                     OldW(0).Height = Windows(a).Height
  283.  
  284.                     OmX = _MOUSEX - OldW(0).X
  285.                     OmY = _MOUSEY - OldW(0).Y
  286.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  287.                     DO WHILE _MOUSEBUTTON(1)
  288.                         IF _MOUSEINPUT THEN
  289.                             CLS , Orange
  290.  
  291.                             OldW(0).X = (_MOUSEX - OmX)
  292.                             OldW(0).Y = (_MOUSEY - OmY)
  293.                             DrawAllWin
  294.                             dragWindow OldW(0)
  295.                         END IF
  296.                     LOOP
  297.                     ' new position of window
  298.                     Windows(a).X = OldW(0).X
  299.                     Windows(a).Y = OldW(0).Y
  300.                     OldW(a).X = Windows(a).X
  301.                     OldW(a).Y = Windows(a).Y
  302.  
  303.                 CASE Focusing
  304.                     Focus a
  305.             END SELECT
  306.  
  307.         CASE ELSE
  308.     END SELECT
  309.  
  310. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  311.     IsInWindow = mFalse
  312.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  313.         ' if window is closed to its bar it cannot get focus on the window area
  314.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  315.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  316.         ' if is the window bar area
  317.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width - 31) THEN
  318.             ' if it is to the left of buttons on the bar
  319.             IsInWindow = Dragging
  320.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  321.             ' if it is on the leftest button on the bar
  322.             IsInWindow = cMinim ' icon minimize--> restore to child default
  323.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  324.             ' if it is on the middle button on the bar
  325.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  326.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  327.             ' if is on the rightest button on the bar
  328.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  329.         END IF
  330.     END IF
  331.  
  332. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  333.     IF Min > Max THEN SWAP Min, Max
  334.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  335.  
  336. SUB dragWindow (Win AS wChild)
  337.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B ' windows size
  338.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  339.     _DISPLAY
  340.  
  341. SUB wClosed (Win AS wChild)
  342.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  343.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  344.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  345.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  346.  
  347. SUB wMaxim (win AS wChild)
  348.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  349.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  350.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  351.  
  352. SUB wMinim (Win AS wChild)
  353.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  354.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  355.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  356.  
  357.  
  358. SUB DrawWindow (Win AS wChild)
  359.     ' the window
  360.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  361.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  362.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  363.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  364.     END IF
  365.     ' the status bar
  366.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  367.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  368.     wMinim Win
  369.     wMaxim Win
  370.     wClosed Win
  371.  
  372. SUB GetInput (Act AS INTEGER)
  373.     DIM mInput AS INTEGER
  374.  
  375.  
  376.     ' keyboard input
  377.     a$ = INKEY$
  378.     IF a$ = CHR$(27) THEN Act = aQuit
  379.  
  380.     'mouse input
  381.     mInput = mFalse
  382.     IF _MOUSEINPUT THEN mInput = mTrue
  383.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  384.     LOOP
  385.     IF mInput THEN
  386.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  387.             mInput = mLR
  388.         ELSEIF _MOUSEBUTTON(1) THEN
  389.             mInput = mLeft
  390.         ELSEIF _MOUSEBUTTON(2) THEN
  391.             mInput = mRight
  392.         ELSEIF _MOUSEBUTTON(3) THEN
  393.             mInput = mMiddle
  394.         END IF
  395.     END IF
  396.  
  397.     IF mInput = mLR THEN
  398.         Act = aQuit
  399.     ELSEIF mInput = mMiddle THEN
  400.         Act = Minim
  401.     ELSEIF mInput = mRight THEN
  402.         Act = Maxim
  403.     ELSEIF mInput = mLeft THEN
  404.         Act = mInput
  405.     END IF

Thanks to take a look!
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 13, 2020, 04:14:38 pm
another little step:
resizing wchild into main program's window

Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 12  with the power of the second array we implement the feature
  9. '             of resizable of child window
  10.  
  11. ' 2020 02 09  with the power of the second array we implement a different
  12. '             child windows' system:
  13. '             all child windows can be Closed to window's bar
  14. '             all child windows can be dragged on the screen
  15.  
  16. ' 2020 02 08  using a second array we store windows information indipendently so
  17. '             now each window can be modified and restored
  18.  
  19.  
  20. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  21. '             to it the last value used in windows(0) so the info of the last
  22. '             window that is dragged or maximize when we use Minimize button on
  23. '             another child window
  24. '             the fix can be got using a shadow array that stores windows informations
  25. '             or windows(0) as the child window that takes the information of the
  26. '             child window that must be acted (Minimize, Maximize and Closed)
  27. '             and we use it as template to make graphic output
  28.  
  29. ' 2020 02 05 fixed a minor bug on mouse click events
  30. '            activated events Maxim Minim and Closed
  31.  
  32.  
  33. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  34. '            removed vMax SHARED variable
  35. '            added 3 buttons on the rightest site of the bar of the child window
  36. '            SUB wClosed, wMaxim, wMinim
  37. '            In this version the user can maximize one child window to the application window
  38. '            In the status of Maxim the child window has the focus and can be only
  39. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  40.  
  41.  
  42. ' 2020 01 30 fixed bug on focusing a child window
  43. '
  44.  
  45. ' 2020 01 25  A program with child windows into it
  46. ' we need a system to manage multiple windows
  47. ' and a system to manage input/output
  48. ' and a system to make graphic report
  49.  
  50. ' settings-------------------------------------------------------
  51. SCREEN _NEWIMAGE(800, 600, 32)
  52. _TITLE "Child windows"
  53. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  54. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  55. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  56. CONST Minim = 10, Maxim = 20, Closed = 100
  57. CONST wMin = 5, aNull = 0, aQuit = 9999
  58. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  59. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  60. CONST cResize = 700, LResize = 710, RResize = 720, StopResize = 730
  61.  
  62.  
  63.  
  64. 'dataset  -----------------------------------------------
  65. TYPE person
  66.     name AS STRING * 10
  67.     age AS INTEGER
  68.     weight AS INTEGER
  69.     height AS INTEGER
  70.     BMI AS INTEGER
  71.  
  72. TYPE wChild
  73.     X AS INTEGER
  74.     Y AS INTEGER
  75.     Height AS INTEGER
  76.     Zorder AS INTEGER
  77.     Status AS INTEGER
  78.  
  79. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  80.  
  81. InitWin
  82.  
  83. DIM Action AS INTEGER
  84.  
  85.  
  86. ' main loop -----------------------------------------------
  87.  
  88.     ' set the main window
  89.     Action = aNull
  90.     CLS , Orange
  91.     DrawAllWin
  92.     GetInput Action
  93.     DoAction Action
  94.     _DISPLAY
  95.     _LIMIT 30
  96.  
  97. ' SUBs and FUNCTIONs --------------------------------------
  98. SUB InitWin
  99.     SHARED Windows() AS wChild, OldW() AS wChild
  100.     DIM a AS INTEGER
  101.  
  102.     Windows(1).X = 1
  103.     Windows(1).Y = 1
  104.     Windows(1).Width = 300
  105.     Windows(1).Height = 400
  106.     Windows(1).Zorder = 1
  107.     Windows(1).Status = Minim
  108.     Windows(1).Color = Blu
  109.  
  110.     Windows(2).X = 100
  111.     Windows(2).Y = 1
  112.     Windows(2).Width = 300
  113.     Windows(2).Height = 400
  114.     Windows(2).Zorder = 2
  115.     Windows(2).Status = Minim
  116.     Windows(2).Color = Yellow
  117.  
  118.     Windows(3).X = 200
  119.     Windows(3).Y = 1
  120.     Windows(3).Width = 300
  121.     Windows(3).Height = 400
  122.     Windows(3).Zorder = 3
  123.     Windows(3).Status = Minim
  124.     Windows(3).Color = Green
  125.  
  126.     Windows(4).X = 300
  127.     Windows(4).Y = 1
  128.     Windows(4).Width = 300
  129.     Windows(4).Height = 400
  130.     Windows(4).Zorder = 4
  131.     Windows(4).Status = Minim
  132.     Windows(4).Color = Red
  133.  
  134.     Windows(5).X = 400
  135.     Windows(5).Y = 1
  136.     Windows(5).Width = 300
  137.     Windows(5).Height = 400
  138.     Windows(5).Zorder = 5
  139.     Windows(5).Status = Minim
  140.     Windows(5).Color = Cyan
  141.  
  142.     FOR a = 1 TO wMin STEP 1
  143.         AdjournWin a
  144.     NEXT a
  145.  
  146. SUB RestoreWin (a AS INTEGER)
  147.     SHARED Windows() AS wChild, OldW() AS wChild
  148.  
  149.     Windows(a).X = OldW(a).X
  150.     Windows(a).Y = OldW(a).Y
  151.     Windows(a).Width = OldW(a).Width
  152.     Windows(a).Height = OldW(a).Height
  153.     Windows(a).Zorder = OldW(a).Zorder
  154.     Windows(a).Color = OldW(a).Color
  155.  
  156. SUB AdjournWin (a AS INTEGER)
  157.     SHARED Windows() AS wChild, OldW() AS wChild
  158.  
  159.     OldW(a).X = Windows(a).X
  160.     OldW(a).Y = Windows(a).Y
  161.     OldW(a).Width = Windows(a).Width
  162.     OldW(a).Height = Windows(a).Height
  163.     OldW(a).Zorder = Windows(a).Zorder
  164.     OldW(a).Color = Windows(a).Color
  165.  
  166. SUB DrawAllWin
  167.     SHARED Windows() AS wChild
  168.     DIM Finished AS INTEGER
  169.     Finished = wMin
  170.     DO
  171.         FOR a = 1 TO wMin
  172.             IF Windows(a).Zorder = Finished THEN
  173.                 DrawWindow Windows(a)
  174.                 Finished = Finished - 1
  175.                 EXIT FOR
  176.             END IF
  177.         NEXT a
  178.     LOOP UNTIL Finished = 0
  179.  
  180. SUB Focus (Index AS INTEGER)
  181.     SHARED Windows() AS wChild
  182.     DIM b AS INTEGER
  183.     FOR b = 1 TO wMin
  184.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  185.     NEXT b
  186.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  187.     DrawAllWin
  188.  
  189.  
  190. SUB DoAction (Act AS INTEGER)
  191.     SHARED Windows() AS wChild, OldW() AS wChild
  192.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  193.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  194.  
  195.     SELECT CASE Act
  196.         CASE aQuit
  197.             END
  198.  
  199.         CASE Maxim
  200.             _FULLSCREEN
  201.  
  202.         CASE Minim
  203.             _FULLSCREEN _OFF
  204.  
  205.         CASE mLeft
  206.             mX = _MOUSEX
  207.             mY = _MOUSEY
  208.  
  209.             ' search where and what mouse has touched by leftclick
  210.             OldA = 0
  211.             OldActio = 0
  212.             FOR a = 1 TO wMin ' windows(0) is out of action
  213.                 Actio = IsInWindow(mX, mY, Windows(a))
  214.                 IF Actio THEN
  215.                     IF OldA <= 0 THEN
  216.                         OldA = a
  217.                         OldActio = Actio
  218.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  219.                         OldA = a
  220.                         OldActio = Actio
  221.                     END IF
  222.                 END IF
  223.             NEXT a
  224.             IF a > OldA THEN
  225.                 a = OldA ' restore the last windows interacting
  226.                 Actio = OldActio
  227.             END IF
  228.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  229.  
  230.  
  231.             Focus a 'set zorder on the (a) window that gets the input
  232.  
  233.  
  234.             SELECT CASE Actio
  235.                 CASE cMinim
  236.                     ' here restore to  standard (bar + area of window) status of child window
  237.                     IF Windows(a).Status = Closed + Maxim THEN
  238.                         ' if windows is a closed maximized window
  239.                         ' we restore its status of maximized
  240.                         Windows(a).Status = Maxim
  241.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  242.                         ' if windows is a closed minimized window
  243.                         ' we restore its status of minimized
  244.                         Windows(a).Status = Minim
  245.                     ELSEIF Windows(a).Status = Maxim THEN
  246.                         ' if is a window maximized it gets back all info setting
  247.                         ' we restore its status of minimized
  248.                         RestoreWin a
  249.                         Windows(a).Status = Minim
  250.                     END IF
  251.  
  252.  
  253.                 CASE cMaxim
  254.                     ' here convert the window to full size of main window of the program
  255.                     ' OR gives 1 if both parameter are true or al last one is true
  256.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  257.                         ' it acts if windows if not still maximized
  258.                         ' it is minimized window opened or closed
  259.                         ' memorize window's data when it is not maximized
  260.                         '                        IF Windows(a).Width < _WIDTH THEN
  261.                         AdjournWin a
  262.                         ' it sets maximized status
  263.                         Windows(a).Width = _WIDTH
  264.                         Windows(a).Height = _HEIGHT
  265.                         Windows(a).X = 1
  266.                         Windows(a).Y = 1
  267.                         ' change status
  268.                         Windows(a).Status = Maxim
  269.                     END IF
  270.  
  271.                 CASE cClosed
  272.                     ' here minimize the child window to its window bar
  273.                     IF NOT Windows(a).Status > Closed THEN
  274.                         Windows(a).Status = Windows(a).Status + Closed
  275.                     END IF
  276.  
  277.                 CASE Dragging
  278.                     ' dragging is possible for all status of windows
  279.                     '
  280.                     ' if minimized or Closed and minimized window we save data info
  281.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  282.                     ' it sets variables for dragging
  283.                     OldW(0).X = Windows(a).X
  284.                     OldW(0).Y = Windows(a).Y
  285.                     OldW(0).Width = Windows(a).Width
  286.                     OldW(0).Height = Windows(a).Height
  287.  
  288.                     OmX = _MOUSEX - OldW(0).X
  289.                     OmY = _MOUSEY - OldW(0).Y
  290.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  291.                     DO WHILE _MOUSEBUTTON(1)
  292.                         IF _MOUSEINPUT THEN
  293.                             CLS , Orange
  294.  
  295.                             OldW(0).X = (_MOUSEX - OmX)
  296.                             OldW(0).Y = (_MOUSEY - OmY)
  297.                             DrawAllWin
  298.                             dragWindow OldW(0)
  299.                         END IF
  300.                     LOOP
  301.                     ' new position of window
  302.                     Windows(a).X = OldW(0).X
  303.                     Windows(a).Y = OldW(0).Y
  304.                     OldW(a).X = Windows(a).X
  305.                     OldW(a).Y = Windows(a).Y
  306.  
  307.                 CASE Focusing
  308.                     Focus a
  309.  
  310.                 CASE cResize
  311.                     ' resizing is possible only for minimized opened child windows
  312.                     IF Windows(a).Status = Minim THEN
  313.                         Windows(a).Status = cResize
  314.                         DO WHILE _MOUSEBUTTON(1) OR _MOUSEINPUT: LOOP
  315.                         DO WHILE Windows(a).Status = cResize
  316.                             CLS , Orange
  317.                             DrawAllWin
  318.                             ShowDimension Windows(a)
  319.  
  320.  
  321.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN
  322.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  323.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  324.                             END IF
  325.                             _DISPLAY
  326.                         LOOP
  327.                     END IF
  328.  
  329.             END SELECT
  330.         CASE ELSE
  331.     END SELECT
  332.  
  333. SUB IsResizing (Win AS wChild, mX AS INTEGER, mY AS INTEGER)
  334.     SHARED Windows() AS wChild, OldW() AS wChild
  335.     DIM Actio AS INTEGER, OldmX AS INTEGER, OldmY AS INTEGER
  336.     Actio = 0
  337.  
  338.     IF IsInTheRange%(mX, Win.X, Win.X + Win.Width) THEN
  339.         IF IsInTheRange%(mY, Win.Y, Win.Y + Win.Height) THEN
  340.             ' do nothing if is in the range of window
  341.         ELSE
  342.             ' user click out of area  of window to resize
  343.             Actio = StopResize
  344.         END IF
  345.     ELSE
  346.         ' user click out of area  of window to resize
  347.         Actio = StopResize
  348.     END IF
  349.  
  350.  
  351.  
  352.  
  353.  
  354.     IF IsInTheRange%(mX, Win.X, Win.X + 10) THEN
  355.         IF IsInTheRange%(mY, Win.Y, Win.Y + 10) THEN
  356.             ' user click on lefttop square to resize
  357.             Actio = LResize
  358.         END IF
  359.     END IF
  360.  
  361.     IF IsInTheRange%(mX, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  362.         IF IsInTheRange%(mY, Win.Y + Win.Height - 10, Win.Y + Win.Height) THEN
  363.             ' user click on the rightbottom square to resize
  364.             Actio = RResize
  365.         END IF
  366.     END IF
  367.  
  368.     IF Actio = 0 THEN
  369.         ' no action done
  370.     ELSEIF Actio = LResize THEN
  371.         ' choosen LeftTop buttom to resize
  372.         OldW(0).X = Win.X
  373.         OldW(0).Y = Win.Y
  374.         OldW(0).Width = Win.Width
  375.         OldW(0).Height = Win.Height
  376.         OldmX = _MOUSEX
  377.         OldmY = _MOUSEY
  378.         DO WHILE Actio = LResize
  379.             IF _MOUSEINPUT THEN
  380.                 IF (OldW(0).X + OldW(0).Width - OldmX) >= 50 THEN OldW(0).Width = OldW(0).X + OldW(0).Width - OldmX
  381.                 IF (OldW(0).Y + OldW(0).Height - OldmY) >= 30 THEN OldW(0).Height = OldW(0).Y + OldW(0).Height - OldmY
  382.                 CLS , Orange
  383.                 DrawAllWin
  384.                 ShowDimension OldW(0)
  385.                 OldW(0).X = OldmX
  386.                 OldW(0).Y = OldmY
  387.  
  388.                 OldmX = _MOUSEX
  389.                 OldmY = _MOUSEY
  390.             ELSE
  391.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  392.             END IF
  393.         LOOP
  394.         Win.X = OldW(0).X
  395.         Win.Y = OldW(0).Y
  396.         Win.Width = OldW(0).Width
  397.         Win.Height = OldW(0).Height
  398.  
  399.  
  400.     ELSEIF Actio = RResize THEN
  401.         ' choosen bottomright square
  402.         OldW(0).X = Win.X
  403.         OldW(0).Y = Win.Y
  404.         OldW(0).Width = Win.Width
  405.         OldW(0).Height = Win.Height
  406.         OldmX = _MOUSEX
  407.         OldmY = _MOUSEY
  408.         DO WHILE Actio = RResize
  409.             IF _MOUSEINPUT THEN
  410.                 IF OldmX - OldW(0).X >= 50 THEN OldW(0).Width = OldmX - OldW(0).X
  411.                 IF OldmY - OldW(0).Y >= 30 THEN OldW(0).Height = OldmY - OldW(0).Y
  412.                 CLS , Orange
  413.                 DrawAllWin
  414.                 ShowDimension OldW(0)
  415.                 OldmX = _MOUSEX
  416.                 OldmY = _MOUSEY
  417.             ELSE
  418.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  419.             END IF
  420.         LOOP
  421.         Win.X = OldW(0).X
  422.         Win.Y = OldW(0).Y
  423.         Win.Width = OldW(0).Width
  424.         Win.Height = OldW(0).Height
  425.  
  426.     ELSEIF Actio = StopResize THEN
  427.         ' click out of window to stop resize action
  428.         Win.Status = Minim
  429.     END IF
  430.  
  431. SUB ShowDimension (win AS wChild)
  432.     LINE (win.X, win.Y)-(win.X + win.Width, win.Y + win.Height), White, B ' windows size
  433.     LINE (win.X, win.Y)-(win.X + 10, win.Y + 10), White, BF 'button for resizing window
  434.     LINE (win.X + win.Width - 10, win.Y + win.Height - 10)-(win.X + win.Width, win.Y + win.Height), White, BF 'button for resizing window
  435.     _DISPLAY
  436.  
  437. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  438.     IsInWindow = mFalse
  439.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  440.         ' if window is closed to its bar it cannot get focus on the window area
  441.         IF IsInTheRange%(X, Win.X, Win.X + Win.Width) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  442.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  443.         ' if is the window bar area
  444.         IF IsInTheRange%(X, Win.X + 10, Win.X + Win.Width - 31) THEN
  445.             ' if it is to the left of buttons on the bar
  446.             IsInWindow = Dragging
  447.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 30, Win.X + Win.Width - 21) THEN
  448.             ' if it is on the leftest button on the bar
  449.             IsInWindow = cMinim ' icon minimize--> restore to child default
  450.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 20, Win.X + Win.Width - 11) THEN
  451.             ' if it is on the middle button on the bar
  452.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  453.         ELSEIF IsInTheRange%(X, Win.X + Win.Width - 10, Win.X + Win.Width) THEN
  454.             ' if is on the rightest button on the bar
  455.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  456.         ELSEIF IsInTheRange%(X, Win.X, Win.X + 10) THEN
  457.             IsInWindow = cResize
  458.         END IF
  459.     END IF
  460.  
  461. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  462.     IF Min > Max THEN SWAP Min, Max
  463.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  464.  
  465. SUB dragWindow (Win AS wChild)
  466.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), White, B ' windows size
  467.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), White, BF 'title bar for dragging window
  468.     _DISPLAY
  469.  
  470. SUB wClosed (Win AS wChild)
  471.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  472.     LINE (Win.X + Win.Width - 10, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Black, B
  473.     LINE (Win.X + Win.Width - 7, Win.Y + 3)-(Win.X + Win.Width - 3, Win.Y + 7), Black
  474.     LINE (Win.X + Win.Width - 7, Win.Y + 7)-(Win.X + Win.Width - 3, Win.Y + 3), Black
  475.  
  476. SUB wMaxim (win AS wChild)
  477.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  478.     LINE (win.X + win.Width - 20, win.Y)-(win.X + win.Width - 10, win.Y + 10), Black, B
  479.     LINE (win.X + win.Width - 17, win.Y + 3)-(win.X + win.Width - 13, win.Y + 7), Black, B
  480.  
  481. SUB wMinim (Win AS wChild)
  482.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  483.     LINE (Win.X + Win.Width - 30, Win.Y)-(Win.X + Win.Width - 20, Win.Y + 10), Black, B
  484.     LINE (Win.X + Win.Width - 27, Win.Y + 7)-(Win.X + Win.Width - 23, Win.Y + 7), Black
  485.  
  486. SUB wResize (Win AS wChild)
  487.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  488.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Black, B
  489.     LINE (Win.X + 2, Win.Y + 2)-(Win.X + 7, Win.Y + 7), Black, B , &B1010101010101010
  490.  
  491. SUB DrawWindow (Win AS wChild)
  492.     ' the window
  493.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  494.         LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Win.Color, BF
  495.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  496.         LINE (Win.X + Win.Width, Win.Y)-(Win.X + Win.Width, Win.Y + Win.Height), Black
  497.     END IF
  498.     ' the status bar
  499.     LINE (Win.X, Win.Y)-(Win.X + Win.Width, Win.Y + 10), Pink, BF 'title bar for dragging window
  500.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.Width, Win.Y + 10), Black
  501.     wMinim Win
  502.     wMaxim Win
  503.     wClosed Win
  504.     wResize Win
  505.  
  506. SUB GetInput (Act AS INTEGER)
  507.     DIM mInput AS INTEGER
  508.  
  509.  
  510.     ' keyboard input
  511.     a$ = INKEY$
  512.     IF a$ = CHR$(27) THEN Act = aQuit
  513.  
  514.     'mouse input
  515.     mInput = mFalse
  516.     IF _MOUSEINPUT THEN mInput = mTrue
  517.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  518.     LOOP
  519.     IF mInput THEN
  520.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  521.             mInput = mLR
  522.         ELSEIF _MOUSEBUTTON(1) THEN
  523.             mInput = mLeft
  524.         ELSEIF _MOUSEBUTTON(2) THEN
  525.             mInput = mRight
  526.         ELSEIF _MOUSEBUTTON(3) THEN
  527.             mInput = mMiddle
  528.         END IF
  529.     END IF
  530.  
  531.     IF mInput = mLR THEN
  532.         Act = aQuit
  533.     ELSEIF mInput = mMiddle THEN
  534.         Act = Minim
  535.     ELSEIF mInput = mRight THEN
  536.         Act = Maxim
  537.     ELSEIF mInput = mLeft THEN
  538.         Act = mInput
  539.     END IF

here 2 screenshot
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
 [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: child windows into window of the program: a demonstration
Post by: keybone on February 14, 2020, 04:11:42 pm
Looks like it's coming along nicely...
One question though, where do you drag the window from for resizing?
I try dragging it from the lower right corner but it doesnt seem to work.

Anyways, nice job so far. It's nice to see someone else working on this :-)
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 14, 2020, 06:24:49 pm
Hi keybone
thanks for feedback and the fine words...

sorry I haven't been very clear: in resizing I have build up a system of click move and click to confirm. No dragging action.
So after you activate the resizing mode by leftclick on the alone and the leftest button on the window's bar, you'll see a white big square, that has at origin the same dimensions of the window,  and two little full white squares... LeftTop square and RightBottom square. To resize you must click by left button of mouse on one of these two buttons and then  you move the mouse to the desidered position, no more press leftbutton, , and you see the white square adapting  its shape to pointer of mouse. When you like the new shape you must left click  and the window changes to acquire that shape.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: child windows into window of the program: a demonstration
Post by: keybone on February 15, 2020, 04:03:53 am
Hi keybone
thanks for feedback and the fine words...

sorry I haven't been very clear: in resizing I have build up a system of click move and click to confirm. No dragging action.
So after you activate the resizing mode by leftclick on the alone and the leftest button on the window's bar, you'll see a white big square, that has at origin the same dimensions of the window,  and two little full white squares... LeftTop square and RightBottom square. To resize you must click by left button of mouse on one of these two buttons and then  you move the mouse to the desidered position, no more press leftbutton, , and you see the white square adapting  its shape to pointer of mouse. When you like the new shape you must left click  and the window changes to acquire that shape.

 


Its not working for me, I click on the resize button and the white box appears.
There is no response when i click one of the corner white boxes but when i click outside the window it turns back to normal.
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 15, 2020, 11:50:33 am
Ok we must define what is that makes the difference between our experience with this code.

To be sure I have taken the code from codebox (so it is the same that you have )
I have compiled it both by QB1.4 both by QB1.3 and I get the same program that works...
I'm using QB64 in Windows 10

.... to give a different feedback  when resizing is active I have made this little mod for output.
Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 12  with the power of the second array we implement the feature
  9. '             of resizable of child window
  10.  
  11. ' 2020 02 09  with the power of the second array we implement a different
  12. '             child windows' system:
  13. '             all child windows can be Closed to window's bar
  14. '             all child windows can be dragged on the screen
  15.  
  16. ' 2020 02 08  using a second array we store windows information indipendently so
  17. '             now each window can be modified and restored
  18.  
  19.  
  20. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  21. '             to it the last value used in windows(0) so the info of the last
  22. '             window that is dragged or maximize when we use Minimize button on
  23. '             another child window
  24. '             the fix can be got using a shadow array that stores windows informations
  25. '             or windows(0) as the child window that takes the information of the
  26. '             child window that must be acted (Minimize, Maximize and Closed)
  27. '             and we use it as template to make graphic output
  28.  
  29. ' 2020 02 05 fixed a minor bug on mouse click events
  30. '            activated events Maxim Minim and Closed
  31.  
  32.  
  33. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  34. '            removed vMax SHARED variable
  35. '            added 3 buttons on the rightest site of the bar of the child window
  36. '            SUB wClosed, wMaxim, wMinim
  37. '            In this version the user can maximize one child window to the application window
  38. '            In the status of Maxim the child window has the focus and can be only
  39. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  40.  
  41.  
  42. ' 2020 01 30 fixed bug on focusing a child window
  43. '
  44.  
  45. ' 2020 01 25  A program with child windows into it
  46. ' we need a system to manage multiple windows
  47. ' and a system to manage input/output
  48. ' and a system to make graphic report
  49.  
  50. ' settings-------------------------------------------------------
  51. SCREEN _NEWIMAGE(800, 600, 32)
  52. _TITLE "Child windows"
  53. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  54. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  55. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  56. CONST Minim = 10, Maxim = 20, Closed = 100
  57. CONST wMin = 5, aNull = 0, aQuit = 9999
  58. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  59. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  60. CONST cResize = 700, LResize = 710, RResize = 720, StopResize = 730
  61.  
  62.  
  63.  
  64. 'dataset  -----------------------------------------------
  65. TYPE person
  66.     NAME AS STRING * 10
  67.     age AS INTEGER
  68.     weight AS INTEGER
  69.     height AS INTEGER
  70.     BMI AS INTEGER
  71.  
  72. TYPE wChild
  73.     X AS INTEGER
  74.     Y AS INTEGER
  75.     Height AS INTEGER
  76.     Zorder AS INTEGER
  77.     Status AS INTEGER
  78.  
  79. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  80.  
  81. InitWin
  82.  
  83. DIM Action AS INTEGER
  84.  
  85.  
  86. ' main loop -----------------------------------------------
  87.  
  88.     ' set the main window
  89.     Action = aNull
  90.     CLS , Orange
  91.     DrawAllWin
  92.     GetInput Action
  93.     DoAction Action
  94.     _DISPLAY
  95.     _LIMIT 30
  96.  
  97. ' SUBs and FUNCTIONs --------------------------------------
  98. SUB InitWin
  99.     SHARED Windows() AS wChild, OldW() AS wChild
  100.     DIM a AS INTEGER
  101.  
  102.     Windows(1).X = 1
  103.     Windows(1).Y = 1
  104.     Windows(1).WIDTH = 300
  105.     Windows(1).Height = 400
  106.     Windows(1).Zorder = 1
  107.     Windows(1).Status = Minim
  108.     Windows(1).COLOR = Blu
  109.  
  110.     Windows(2).X = 100
  111.     Windows(2).Y = 1
  112.     Windows(2).WIDTH = 300
  113.     Windows(2).Height = 400
  114.     Windows(2).Zorder = 2
  115.     Windows(2).Status = Minim
  116.     Windows(2).COLOR = Yellow
  117.  
  118.     Windows(3).X = 200
  119.     Windows(3).Y = 1
  120.     Windows(3).WIDTH = 300
  121.     Windows(3).Height = 400
  122.     Windows(3).Zorder = 3
  123.     Windows(3).Status = Minim
  124.     Windows(3).COLOR = Green
  125.  
  126.     Windows(4).X = 300
  127.     Windows(4).Y = 1
  128.     Windows(4).WIDTH = 300
  129.     Windows(4).Height = 400
  130.     Windows(4).Zorder = 4
  131.     Windows(4).Status = Minim
  132.     Windows(4).COLOR = Red
  133.  
  134.     Windows(5).X = 400
  135.     Windows(5).Y = 1
  136.     Windows(5).WIDTH = 300
  137.     Windows(5).Height = 400
  138.     Windows(5).Zorder = 5
  139.     Windows(5).Status = Minim
  140.     Windows(5).COLOR = Cyan
  141.  
  142.     FOR a = 1 TO wMin STEP 1
  143.         AdjournWin a
  144.     NEXT a
  145.  
  146. SUB RestoreWin (a AS INTEGER)
  147.     SHARED Windows() AS wChild, OldW() AS wChild
  148.  
  149.     Windows(a).X = OldW(a).X
  150.     Windows(a).Y = OldW(a).Y
  151.     Windows(a).WIDTH = OldW(a).WIDTH
  152.     Windows(a).Height = OldW(a).Height
  153.     Windows(a).Zorder = OldW(a).Zorder
  154.     Windows(a).COLOR = OldW(a).COLOR
  155.  
  156. SUB AdjournWin (a AS INTEGER)
  157.     SHARED Windows() AS wChild, OldW() AS wChild
  158.  
  159.     OldW(a).X = Windows(a).X
  160.     OldW(a).Y = Windows(a).Y
  161.     OldW(a).WIDTH = Windows(a).WIDTH
  162.     OldW(a).Height = Windows(a).Height
  163.     OldW(a).Zorder = Windows(a).Zorder
  164.     OldW(a).COLOR = Windows(a).COLOR
  165.  
  166. SUB DrawAllWin
  167.     SHARED Windows() AS wChild
  168.     DIM Finished AS INTEGER
  169.     Finished = wMin
  170.     DO
  171.         FOR a = 1 TO wMin
  172.             IF Windows(a).Zorder = Finished THEN
  173.                 DrawWindow Windows(a)
  174.                 Finished = Finished - 1
  175.                 EXIT FOR
  176.             END IF
  177.         NEXT a
  178.     LOOP UNTIL Finished = 0
  179.  
  180. SUB Focus (Index AS INTEGER)
  181.     SHARED Windows() AS wChild
  182.     DIM b AS INTEGER
  183.     FOR b = 1 TO wMin
  184.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  185.     NEXT b
  186.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  187.     DrawAllWin
  188.  
  189.  
  190. SUB DoAction (Act AS INTEGER)
  191.     SHARED Windows() AS wChild, OldW() AS wChild
  192.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  193.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  194.  
  195.     SELECT CASE Act
  196.         CASE aQuit
  197.             END
  198.  
  199.         CASE Maxim
  200.             _FULLSCREEN
  201.  
  202.         CASE Minim
  203.             _FULLSCREEN _OFF
  204.  
  205.         CASE mLeft
  206.             mX = _MOUSEX
  207.             mY = _MOUSEY
  208.  
  209.             ' search where and what mouse has touched by leftclick
  210.             OldA = 0
  211.             OldActio = 0
  212.             FOR a = 1 TO wMin ' windows(0) is out of action
  213.                 Actio = IsInWindow(mX, mY, Windows(a))
  214.                 IF Actio THEN
  215.                     IF OldA <= 0 THEN
  216.                         OldA = a
  217.                         OldActio = Actio
  218.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  219.                         OldA = a
  220.                         OldActio = Actio
  221.                     END IF
  222.                 END IF
  223.             NEXT a
  224.             IF a > OldA THEN
  225.                 a = OldA ' restore the last windows interacting
  226.                 Actio = OldActio
  227.             END IF
  228.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  229.  
  230.  
  231.             Focus a 'set zorder on the (a) window that gets the input
  232.  
  233.  
  234.             SELECT CASE Actio
  235.                 CASE cMinim
  236.                     ' here restore to  standard (bar + area of window) status of child window
  237.                     IF Windows(a).Status = Closed + Maxim THEN
  238.                         ' if windows is a closed maximized window
  239.                         ' we restore its status of maximized
  240.                         Windows(a).Status = Maxim
  241.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  242.                         ' if windows is a closed minimized window
  243.                         ' we restore its status of minimized
  244.                         Windows(a).Status = Minim
  245.                     ELSEIF Windows(a).Status = Maxim THEN
  246.                         ' if is a window maximized it gets back all info setting
  247.                         ' we restore its status of minimized
  248.                         RestoreWin a
  249.                         Windows(a).Status = Minim
  250.                     END IF
  251.  
  252.  
  253.                 CASE cMaxim
  254.                     ' here convert the window to full size of main window of the program
  255.                     ' OR gives 1 if both parameter are true or al last one is true
  256.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  257.                         ' it acts if windows if not still maximized
  258.                         ' it is minimized window opened or closed
  259.                         ' memorize window's data when it is not maximized
  260.                         '                        IF Windows(a).Width < _WIDTH THEN
  261.                         AdjournWin a
  262.                         ' it sets maximized status
  263.                         Windows(a).WIDTH = _WIDTH
  264.                         Windows(a).Height = _HEIGHT
  265.                         Windows(a).X = 1
  266.                         Windows(a).Y = 1
  267.                         ' change status
  268.                         Windows(a).Status = Maxim
  269.                     END IF
  270.  
  271.                 CASE cClosed
  272.                     ' here minimize the child window to its window bar
  273.                     IF NOT Windows(a).Status > Closed THEN
  274.                         Windows(a).Status = Windows(a).Status + Closed
  275.                     END IF
  276.  
  277.                 CASE Dragging
  278.                     ' dragging is possible for all status of windows
  279.                     '
  280.                     ' if minimized or Closed and minimized window we save data info
  281.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  282.                     ' it sets variables for dragging
  283.                     OldW(0).X = Windows(a).X
  284.                     OldW(0).Y = Windows(a).Y
  285.                     OldW(0).WIDTH = Windows(a).WIDTH
  286.                     OldW(0).Height = Windows(a).Height
  287.  
  288.                     OmX = _MOUSEX - OldW(0).X
  289.                     OmY = _MOUSEY - OldW(0).Y
  290.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  291.                     DO WHILE _MOUSEBUTTON(1)
  292.                         IF _MOUSEINPUT THEN
  293.                             CLS , Orange
  294.  
  295.                             OldW(0).X = (_MOUSEX - OmX)
  296.                             OldW(0).Y = (_MOUSEY - OmY)
  297.                             DrawAllWin
  298.                             dragWindow OldW(0)
  299.                         END IF
  300.                     LOOP
  301.                     ' new position of window
  302.                     Windows(a).X = OldW(0).X
  303.                     Windows(a).Y = OldW(0).Y
  304.                     OldW(a).X = Windows(a).X
  305.                     OldW(a).Y = Windows(a).Y
  306.  
  307.                 CASE Focusing
  308.                     Focus a
  309.  
  310.                 CASE cResize
  311.                     ' resizing is possible only for minimized opened child windows
  312.                     IF Windows(a).Status = Minim THEN
  313.                         Windows(a).Status = cResize
  314.                         DO WHILE _MOUSEBUTTON(1) OR _MOUSEINPUT: LOOP
  315.                         DO WHILE Windows(a).Status = cResize
  316.                             CLS , Orange
  317.                             DrawAllWin
  318.                             ShowDimension Windows(a), 0
  319.  
  320.  
  321.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN
  322.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  323.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  324.                             END IF
  325.                             _DISPLAY
  326.                         LOOP
  327.                     END IF
  328.  
  329.             END SELECT
  330.         CASE ELSE
  331.     END SELECT
  332.  
  333. SUB IsResizing (Win AS wChild, mX AS INTEGER, mY AS INTEGER)
  334.     SHARED Windows() AS wChild, OldW() AS wChild
  335.     DIM Actio AS INTEGER, OldmX AS INTEGER, OldmY AS INTEGER
  336.     Actio = 0
  337.  
  338.     IF IsInTheRange%(mX, Win.X, Win.X + Win.WIDTH) THEN
  339.         IF IsInTheRange%(mY, Win.Y, Win.Y + Win.Height) THEN
  340.             ' do nothing if is in the range of window
  341.         ELSE
  342.             ' user click out of area  of window to resize
  343.             Actio = StopResize
  344.         END IF
  345.     ELSE
  346.         ' user click out of area  of window to resize
  347.         Actio = StopResize
  348.     END IF
  349.  
  350.  
  351.  
  352.  
  353.  
  354.     IF IsInTheRange%(mX, Win.X, Win.X + 10) THEN
  355.         IF IsInTheRange%(mY, Win.Y, Win.Y + 10) THEN
  356.             ' user click on lefttop square to resize
  357.             Actio = LResize
  358.         END IF
  359.     END IF
  360.  
  361.     IF IsInTheRange%(mX, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  362.         IF IsInTheRange%(mY, Win.Y + Win.Height - 10, Win.Y + Win.Height) THEN
  363.             ' user click on the rightbottom square to resize
  364.             Actio = RResize
  365.         END IF
  366.     END IF
  367.  
  368.     IF Actio = 0 THEN
  369.         ' no action done
  370.     ELSEIF Actio = LResize THEN
  371.         ' choosen LeftTop buttom to resize
  372.         OldW(0).X = Win.X
  373.         OldW(0).Y = Win.Y
  374.         OldW(0).WIDTH = Win.WIDTH
  375.         OldW(0).Height = Win.Height
  376.         OldmX = _MOUSEX
  377.         OldmY = _MOUSEY
  378.         DO WHILE Actio = LResize
  379.             IF _MOUSEINPUT THEN
  380.                 IF (OldW(0).X + OldW(0).WIDTH - OldmX) >= 50 THEN OldW(0).WIDTH = OldW(0).X + OldW(0).WIDTH - OldmX
  381.                 IF (OldW(0).Y + OldW(0).Height - OldmY) >= 30 THEN OldW(0).Height = OldW(0).Y + OldW(0).Height - OldmY
  382.                 CLS , Orange
  383.                 DrawAllWin
  384.                 ShowDimension OldW(0), Actio
  385.                 OldW(0).X = OldmX
  386.                 OldW(0).Y = OldmY
  387.  
  388.                 OldmX = _MOUSEX
  389.                 OldmY = _MOUSEY
  390.             ELSE
  391.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  392.             END IF
  393.         LOOP
  394.         Win.X = OldW(0).X
  395.         Win.Y = OldW(0).Y
  396.         Win.WIDTH = OldW(0).WIDTH
  397.         Win.Height = OldW(0).Height
  398.  
  399.  
  400.     ELSEIF Actio = RResize THEN
  401.         ' choosen bottomright square
  402.         OldW(0).X = Win.X
  403.         OldW(0).Y = Win.Y
  404.         OldW(0).WIDTH = Win.WIDTH
  405.         OldW(0).Height = Win.Height
  406.         OldmX = _MOUSEX
  407.         OldmY = _MOUSEY
  408.         DO WHILE Actio = RResize
  409.             IF _MOUSEINPUT THEN
  410.                 IF OldmX - OldW(0).X >= 50 THEN OldW(0).WIDTH = OldmX - OldW(0).X
  411.                 IF OldmY - OldW(0).Y >= 30 THEN OldW(0).Height = OldmY - OldW(0).Y
  412.                 CLS , Orange
  413.                 DrawAllWin
  414.                 ShowDimension OldW(0), Actio
  415.                 OldmX = _MOUSEX
  416.                 OldmY = _MOUSEY
  417.             ELSE
  418.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  419.             END IF
  420.         LOOP
  421.         Win.X = OldW(0).X
  422.         Win.Y = OldW(0).Y
  423.         Win.WIDTH = OldW(0).WIDTH
  424.         Win.Height = OldW(0).Height
  425.  
  426.     ELSEIF Actio = StopResize THEN
  427.         ' click out of window to stop resize action
  428.         Win.Status = Minim
  429.     END IF
  430.  
  431. SUB ShowDimension (win AS wChild, Actio AS INTEGER)
  432.     IF win.Status = cResize AND Actio = 0 THEN
  433.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B ' windows size
  434.     ELSEIF Actio = LResize THEN
  435.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 45 ' windows size
  436.     ELSEIF Actio = RResize THEN
  437.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 200 ' windows size
  438.     END IF
  439.     LINE (win.X, win.Y)-(win.X + 10, win.Y + 10), White, BF 'button for resizing window
  440.     LINE (win.X + win.WIDTH - 10, win.Y + win.Height - 10)-(win.X + win.WIDTH, win.Y + win.Height), White, BF 'button for resizing window
  441.     _DISPLAY
  442.  
  443. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  444.     IsInWindow = mFalse
  445.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  446.         ' if window is closed to its bar it cannot get focus on the window area
  447.         IF IsInTheRange%(X, Win.X, Win.X + Win.WIDTH) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  448.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  449.         ' if is the window bar area
  450.         IF IsInTheRange%(X, Win.X + 10, Win.X + Win.WIDTH - 31) THEN
  451.             ' if it is to the left of buttons on the bar
  452.             IsInWindow = Dragging
  453.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 30, Win.X + Win.WIDTH - 21) THEN
  454.             ' if it is on the leftest button on the bar
  455.             IsInWindow = cMinim ' icon minimize--> restore to child default
  456.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 20, Win.X + Win.WIDTH - 11) THEN
  457.             ' if it is on the middle button on the bar
  458.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  459.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  460.             ' if is on the rightest button on the bar
  461.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  462.         ELSEIF IsInTheRange%(X, Win.X, Win.X + 10) THEN
  463.             IsInWindow = cResize
  464.         END IF
  465.     END IF
  466.  
  467. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  468.     IF Min > Max THEN SWAP Min, Max
  469.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  470.  
  471. SUB dragWindow (Win AS wChild)
  472.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), White, B ' windows size
  473.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), White, BF 'title bar for dragging window
  474.     _DISPLAY
  475.  
  476. SUB wClosed (Win AS wChild)
  477.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  478.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Black, B
  479.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 3)-(Win.X + Win.WIDTH - 3, Win.Y + 7), Black
  480.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 7)-(Win.X + Win.WIDTH - 3, Win.Y + 3), Black
  481.  
  482. SUB wMaxim (win AS wChild)
  483.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  484.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Black, B
  485.     LINE (win.X + win.WIDTH - 17, win.Y + 3)-(win.X + win.WIDTH - 13, win.Y + 7), Black, B
  486.  
  487. SUB wMinim (Win AS wChild)
  488.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  489.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Black, B
  490.     LINE (Win.X + Win.WIDTH - 27, Win.Y + 7)-(Win.X + Win.WIDTH - 23, Win.Y + 7), Black
  491.  
  492. SUB wResize (Win AS wChild)
  493.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  494.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Black, B
  495.     LINE (Win.X + 2, Win.Y + 2)-(Win.X + 7, Win.Y + 7), Black, B , &B1010101010101010
  496.  
  497. SUB DrawWindow (Win AS wChild)
  498.     ' the window
  499.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  500.         LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Win.COLOR, BF
  501.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  502.         LINE (Win.X + Win.WIDTH, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  503.     END IF
  504.     ' the status bar
  505.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF 'title bar for dragging window
  506.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.WIDTH, Win.Y + 10), Black
  507.     wMinim Win
  508.     wMaxim Win
  509.     wClosed Win
  510.     wResize Win
  511.  
  512. SUB GetInput (Act AS INTEGER)
  513.     DIM mInput AS INTEGER
  514.  
  515.  
  516.     ' keyboard input
  517.     a$ = INKEY$
  518.     IF a$ = CHR$(27) THEN Act = aQuit
  519.  
  520.     'mouse input
  521.     mInput = mFalse
  522.     IF _MOUSEINPUT THEN mInput = mTrue
  523.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  524.     LOOP
  525.     IF mInput THEN
  526.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  527.             mInput = mLR
  528.         ELSEIF _MOUSEBUTTON(1) THEN
  529.             mInput = mLeft
  530.         ELSEIF _MOUSEBUTTON(2) THEN
  531.             mInput = mRight
  532.         ELSEIF _MOUSEBUTTON(3) THEN
  533.             mInput = mMiddle
  534.         END IF
  535.     END IF
  536.  
  537.     IF mInput = mLR THEN
  538.         Act = aQuit
  539.     ELSEIF mInput = mMiddle THEN
  540.         Act = Minim
  541.     ELSEIF mInput = mRight THEN
  542.         Act = Maxim
  543.     ELSEIF mInput = mLeft THEN
  544.         Act = mInput
  545.     END IF
  546.  

Now the border of the big white square (the shadow of the window in resizing) is different if  no click on resizing squares, or left mouse button on left square or on right square.
Waiting your and others feedback
Thanks for time and energy spent
Title: Re: child windows into window of the program: a demonstration
Post by: keybone on February 17, 2020, 05:48:44 am
Ok we must define what is that makes the difference between our experience with this code.

To be sure I have taken the code from codebox (so it is the same that you have )
I have compiled it both by QB1.4 both by QB1.3 and I get the same program that works...
I'm using QB64 in Windows 10

.... to give a different feedback  when resizing is active I have made this little mod for output.
Code: QB64: [Select]
  1. ' Question of QB64Forum
  2. ' Basically I want to write a program to input data, store the data,  <-- this is DATABASE
  3. ' retrieve the data, add to it, etc.
  4. ' I would like the ability to have a new window/app, run concurrently <-- this is a graphic plotter
  5. ' with the main window/app, but be able to display/plot the data
  6. ' I retrieved from the main window/app.
  7.  
  8. ' 2020 02 12  with the power of the second array we implement the feature
  9. '             of resizable of child window
  10.  
  11. ' 2020 02 09  with the power of the second array we implement a different
  12. '             child windows' system:
  13. '             all child windows can be Closed to window's bar
  14. '             all child windows can be dragged on the screen
  15.  
  16. ' 2020 02 08  using a second array we store windows information indipendently so
  17. '             now each window can be modified and restored
  18.  
  19.  
  20. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  21. '             to it the last value used in windows(0) so the info of the last
  22. '             window that is dragged or maximize when we use Minimize button on
  23. '             another child window
  24. '             the fix can be got using a shadow array that stores windows informations
  25. '             or windows(0) as the child window that takes the information of the
  26. '             child window that must be acted (Minimize, Maximize and Closed)
  27. '             and we use it as template to make graphic output
  28.  
  29. ' 2020 02 05 fixed a minor bug on mouse click events
  30. '            activated events Maxim Minim and Closed
  31.  
  32.  
  33. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  34. '            removed vMax SHARED variable
  35. '            added 3 buttons on the rightest site of the bar of the child window
  36. '            SUB wClosed, wMaxim, wMinim
  37. '            In this version the user can maximize one child window to the application window
  38. '            In the status of Maxim the child window has the focus and can be only
  39. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  40.  
  41.  
  42. ' 2020 01 30 fixed bug on focusing a child window
  43. '
  44.  
  45. ' 2020 01 25  A program with child windows into it
  46. ' we need a system to manage multiple windows
  47. ' and a system to manage input/output
  48. ' and a system to make graphic report
  49.  
  50. ' settings-------------------------------------------------------
  51. SCREEN _NEWIMAGE(800, 600, 32)
  52. _TITLE "Child windows"
  53. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  54. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  55. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  56. CONST Minim = 10, Maxim = 20, Closed = 100
  57. CONST wMin = 5, aNull = 0, aQuit = 9999
  58. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  59. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  60. CONST cResize = 700, LResize = 710, RResize = 720, StopResize = 730
  61.  
  62.  
  63.  
  64. 'dataset  -----------------------------------------------
  65. TYPE person
  66.     NAME AS STRING * 10
  67.     age AS INTEGER
  68.     weight AS INTEGER
  69.     height AS INTEGER
  70.     BMI AS INTEGER
  71.  
  72. TYPE wChild
  73.     X AS INTEGER
  74.     Y AS INTEGER
  75.     Height AS INTEGER
  76.     Zorder AS INTEGER
  77.     Status AS INTEGER
  78.  
  79. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  80.  
  81. InitWin
  82.  
  83. DIM Action AS INTEGER
  84.  
  85.  
  86. ' main loop -----------------------------------------------
  87.  
  88.     ' set the main window
  89.     Action = aNull
  90.     CLS , Orange
  91.     DrawAllWin
  92.     GetInput Action
  93.     DoAction Action
  94.     _DISPLAY
  95.     _LIMIT 30
  96.  
  97. ' SUBs and FUNCTIONs --------------------------------------
  98. SUB InitWin
  99.     SHARED Windows() AS wChild, OldW() AS wChild
  100.     DIM a AS INTEGER
  101.  
  102.     Windows(1).X = 1
  103.     Windows(1).Y = 1
  104.     Windows(1).WIDTH = 300
  105.     Windows(1).Height = 400
  106.     Windows(1).Zorder = 1
  107.     Windows(1).Status = Minim
  108.     Windows(1).COLOR = Blu
  109.  
  110.     Windows(2).X = 100
  111.     Windows(2).Y = 1
  112.     Windows(2).WIDTH = 300
  113.     Windows(2).Height = 400
  114.     Windows(2).Zorder = 2
  115.     Windows(2).Status = Minim
  116.     Windows(2).COLOR = Yellow
  117.  
  118.     Windows(3).X = 200
  119.     Windows(3).Y = 1
  120.     Windows(3).WIDTH = 300
  121.     Windows(3).Height = 400
  122.     Windows(3).Zorder = 3
  123.     Windows(3).Status = Minim
  124.     Windows(3).COLOR = Green
  125.  
  126.     Windows(4).X = 300
  127.     Windows(4).Y = 1
  128.     Windows(4).WIDTH = 300
  129.     Windows(4).Height = 400
  130.     Windows(4).Zorder = 4
  131.     Windows(4).Status = Minim
  132.     Windows(4).COLOR = Red
  133.  
  134.     Windows(5).X = 400
  135.     Windows(5).Y = 1
  136.     Windows(5).WIDTH = 300
  137.     Windows(5).Height = 400
  138.     Windows(5).Zorder = 5
  139.     Windows(5).Status = Minim
  140.     Windows(5).COLOR = Cyan
  141.  
  142.     FOR a = 1 TO wMin STEP 1
  143.         AdjournWin a
  144.     NEXT a
  145.  
  146. SUB RestoreWin (a AS INTEGER)
  147.     SHARED Windows() AS wChild, OldW() AS wChild
  148.  
  149.     Windows(a).X = OldW(a).X
  150.     Windows(a).Y = OldW(a).Y
  151.     Windows(a).WIDTH = OldW(a).WIDTH
  152.     Windows(a).Height = OldW(a).Height
  153.     Windows(a).Zorder = OldW(a).Zorder
  154.     Windows(a).COLOR = OldW(a).COLOR
  155.  
  156. SUB AdjournWin (a AS INTEGER)
  157.     SHARED Windows() AS wChild, OldW() AS wChild
  158.  
  159.     OldW(a).X = Windows(a).X
  160.     OldW(a).Y = Windows(a).Y
  161.     OldW(a).WIDTH = Windows(a).WIDTH
  162.     OldW(a).Height = Windows(a).Height
  163.     OldW(a).Zorder = Windows(a).Zorder
  164.     OldW(a).COLOR = Windows(a).COLOR
  165.  
  166. SUB DrawAllWin
  167.     SHARED Windows() AS wChild
  168.     DIM Finished AS INTEGER
  169.     Finished = wMin
  170.     DO
  171.         FOR a = 1 TO wMin
  172.             IF Windows(a).Zorder = Finished THEN
  173.                 DrawWindow Windows(a)
  174.                 Finished = Finished - 1
  175.                 EXIT FOR
  176.             END IF
  177.         NEXT a
  178.     LOOP UNTIL Finished = 0
  179.  
  180. SUB Focus (Index AS INTEGER)
  181.     SHARED Windows() AS wChild
  182.     DIM b AS INTEGER
  183.     FOR b = 1 TO wMin
  184.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  185.     NEXT b
  186.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  187.     DrawAllWin
  188.  
  189.  
  190. SUB DoAction (Act AS INTEGER)
  191.     SHARED Windows() AS wChild, OldW() AS wChild
  192.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  193.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  194.  
  195.     SELECT CASE Act
  196.         CASE aQuit
  197.             END
  198.  
  199.         CASE Maxim
  200.             _FULLSCREEN
  201.  
  202.         CASE Minim
  203.             _FULLSCREEN _OFF
  204.  
  205.         CASE mLeft
  206.             mX = _MOUSEX
  207.             mY = _MOUSEY
  208.  
  209.             ' search where and what mouse has touched by leftclick
  210.             OldA = 0
  211.             OldActio = 0
  212.             FOR a = 1 TO wMin ' windows(0) is out of action
  213.                 Actio = IsInWindow(mX, mY, Windows(a))
  214.                 IF Actio THEN
  215.                     IF OldA <= 0 THEN
  216.                         OldA = a
  217.                         OldActio = Actio
  218.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN
  219.                         OldA = a
  220.                         OldActio = Actio
  221.                     END IF
  222.                 END IF
  223.             NEXT a
  224.             IF a > OldA THEN
  225.                 a = OldA ' restore the last windows interacting
  226.                 Actio = OldActio
  227.             END IF
  228.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB
  229.  
  230.  
  231.             Focus a 'set zorder on the (a) window that gets the input
  232.  
  233.  
  234.             SELECT CASE Actio
  235.                 CASE cMinim
  236.                     ' here restore to  standard (bar + area of window) status of child window
  237.                     IF Windows(a).Status = Closed + Maxim THEN
  238.                         ' if windows is a closed maximized window
  239.                         ' we restore its status of maximized
  240.                         Windows(a).Status = Maxim
  241.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  242.                         ' if windows is a closed minimized window
  243.                         ' we restore its status of minimized
  244.                         Windows(a).Status = Minim
  245.                     ELSEIF Windows(a).Status = Maxim THEN
  246.                         ' if is a window maximized it gets back all info setting
  247.                         ' we restore its status of minimized
  248.                         RestoreWin a
  249.                         Windows(a).Status = Minim
  250.                     END IF
  251.  
  252.  
  253.                 CASE cMaxim
  254.                     ' here convert the window to full size of main window of the program
  255.                     ' OR gives 1 if both parameter are true or al last one is true
  256.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  257.                         ' it acts if windows if not still maximized
  258.                         ' it is minimized window opened or closed
  259.                         ' memorize window's data when it is not maximized
  260.                         '                        IF Windows(a).Width < _WIDTH THEN
  261.                         AdjournWin a
  262.                         ' it sets maximized status
  263.                         Windows(a).WIDTH = _WIDTH
  264.                         Windows(a).Height = _HEIGHT
  265.                         Windows(a).X = 1
  266.                         Windows(a).Y = 1
  267.                         ' change status
  268.                         Windows(a).Status = Maxim
  269.                     END IF
  270.  
  271.                 CASE cClosed
  272.                     ' here minimize the child window to its window bar
  273.                     IF NOT Windows(a).Status > Closed THEN
  274.                         Windows(a).Status = Windows(a).Status + Closed
  275.                     END IF
  276.  
  277.                 CASE Dragging
  278.                     ' dragging is possible for all status of windows
  279.                     '
  280.                     ' if minimized or Closed and minimized window we save data info
  281.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  282.                     ' it sets variables for dragging
  283.                     OldW(0).X = Windows(a).X
  284.                     OldW(0).Y = Windows(a).Y
  285.                     OldW(0).WIDTH = Windows(a).WIDTH
  286.                     OldW(0).Height = Windows(a).Height
  287.  
  288.                     OmX = _MOUSEX - OldW(0).X
  289.                     OmY = _MOUSEY - OldW(0).Y
  290.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  291.                     DO WHILE _MOUSEBUTTON(1)
  292.                         IF _MOUSEINPUT THEN
  293.                             CLS , Orange
  294.  
  295.                             OldW(0).X = (_MOUSEX - OmX)
  296.                             OldW(0).Y = (_MOUSEY - OmY)
  297.                             DrawAllWin
  298.                             dragWindow OldW(0)
  299.                         END IF
  300.                     LOOP
  301.                     ' new position of window
  302.                     Windows(a).X = OldW(0).X
  303.                     Windows(a).Y = OldW(0).Y
  304.                     OldW(a).X = Windows(a).X
  305.                     OldW(a).Y = Windows(a).Y
  306.  
  307.                 CASE Focusing
  308.                     Focus a
  309.  
  310.                 CASE cResize
  311.                     ' resizing is possible only for minimized opened child windows
  312.                     IF Windows(a).Status = Minim THEN
  313.                         Windows(a).Status = cResize
  314.                         DO WHILE _MOUSEBUTTON(1) OR _MOUSEINPUT: LOOP
  315.                         DO WHILE Windows(a).Status = cResize
  316.                             CLS , Orange
  317.                             DrawAllWin
  318.                             ShowDimension Windows(a), 0
  319.  
  320.  
  321.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN
  322.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  323.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  324.                             END IF
  325.                             _DISPLAY
  326.                         LOOP
  327.                     END IF
  328.  
  329.             END SELECT
  330.         CASE ELSE
  331.     END SELECT
  332.  
  333. SUB IsResizing (Win AS wChild, mX AS INTEGER, mY AS INTEGER)
  334.     SHARED Windows() AS wChild, OldW() AS wChild
  335.     DIM Actio AS INTEGER, OldmX AS INTEGER, OldmY AS INTEGER
  336.     Actio = 0
  337.  
  338.     IF IsInTheRange%(mX, Win.X, Win.X + Win.WIDTH) THEN
  339.         IF IsInTheRange%(mY, Win.Y, Win.Y + Win.Height) THEN
  340.             ' do nothing if is in the range of window
  341.         ELSE
  342.             ' user click out of area  of window to resize
  343.             Actio = StopResize
  344.         END IF
  345.     ELSE
  346.         ' user click out of area  of window to resize
  347.         Actio = StopResize
  348.     END IF
  349.  
  350.  
  351.  
  352.  
  353.  
  354.     IF IsInTheRange%(mX, Win.X, Win.X + 10) THEN
  355.         IF IsInTheRange%(mY, Win.Y, Win.Y + 10) THEN
  356.             ' user click on lefttop square to resize
  357.             Actio = LResize
  358.         END IF
  359.     END IF
  360.  
  361.     IF IsInTheRange%(mX, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  362.         IF IsInTheRange%(mY, Win.Y + Win.Height - 10, Win.Y + Win.Height) THEN
  363.             ' user click on the rightbottom square to resize
  364.             Actio = RResize
  365.         END IF
  366.     END IF
  367.  
  368.     IF Actio = 0 THEN
  369.         ' no action done
  370.     ELSEIF Actio = LResize THEN
  371.         ' choosen LeftTop buttom to resize
  372.         OldW(0).X = Win.X
  373.         OldW(0).Y = Win.Y
  374.         OldW(0).WIDTH = Win.WIDTH
  375.         OldW(0).Height = Win.Height
  376.         OldmX = _MOUSEX
  377.         OldmY = _MOUSEY
  378.         DO WHILE Actio = LResize
  379.             IF _MOUSEINPUT THEN
  380.                 IF (OldW(0).X + OldW(0).WIDTH - OldmX) >= 50 THEN OldW(0).WIDTH = OldW(0).X + OldW(0).WIDTH - OldmX
  381.                 IF (OldW(0).Y + OldW(0).Height - OldmY) >= 30 THEN OldW(0).Height = OldW(0).Y + OldW(0).Height - OldmY
  382.                 CLS , Orange
  383.                 DrawAllWin
  384.                 ShowDimension OldW(0), Actio
  385.                 OldW(0).X = OldmX
  386.                 OldW(0).Y = OldmY
  387.  
  388.                 OldmX = _MOUSEX
  389.                 OldmY = _MOUSEY
  390.             ELSE
  391.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  392.             END IF
  393.         LOOP
  394.         Win.X = OldW(0).X
  395.         Win.Y = OldW(0).Y
  396.         Win.WIDTH = OldW(0).WIDTH
  397.         Win.Height = OldW(0).Height
  398.  
  399.  
  400.     ELSEIF Actio = RResize THEN
  401.         ' choosen bottomright square
  402.         OldW(0).X = Win.X
  403.         OldW(0).Y = Win.Y
  404.         OldW(0).WIDTH = Win.WIDTH
  405.         OldW(0).Height = Win.Height
  406.         OldmX = _MOUSEX
  407.         OldmY = _MOUSEY
  408.         DO WHILE Actio = RResize
  409.             IF _MOUSEINPUT THEN
  410.                 IF OldmX - OldW(0).X >= 50 THEN OldW(0).WIDTH = OldmX - OldW(0).X
  411.                 IF OldmY - OldW(0).Y >= 30 THEN OldW(0).Height = OldmY - OldW(0).Y
  412.                 CLS , Orange
  413.                 DrawAllWin
  414.                 ShowDimension OldW(0), Actio
  415.                 OldmX = _MOUSEX
  416.                 OldmY = _MOUSEY
  417.             ELSE
  418.                 IF _MOUSEBUTTON(1) THEN Actio = 0
  419.             END IF
  420.         LOOP
  421.         Win.X = OldW(0).X
  422.         Win.Y = OldW(0).Y
  423.         Win.WIDTH = OldW(0).WIDTH
  424.         Win.Height = OldW(0).Height
  425.  
  426.     ELSEIF Actio = StopResize THEN
  427.         ' click out of window to stop resize action
  428.         Win.Status = Minim
  429.     END IF
  430.  
  431. SUB ShowDimension (win AS wChild, Actio AS INTEGER)
  432.     IF win.Status = cResize AND Actio = 0 THEN
  433.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B ' windows size
  434.     ELSEIF Actio = LResize THEN
  435.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 45 ' windows size
  436.     ELSEIF Actio = RResize THEN
  437.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 200 ' windows size
  438.     END IF
  439.     LINE (win.X, win.Y)-(win.X + 10, win.Y + 10), White, BF 'button for resizing window
  440.     LINE (win.X + win.WIDTH - 10, win.Y + win.Height - 10)-(win.X + win.WIDTH, win.Y + win.Height), White, BF 'button for resizing window
  441.     _DISPLAY
  442.  
  443. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild)
  444.     IsInWindow = mFalse
  445.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  446.         ' if window is closed to its bar it cannot get focus on the window area
  447.         IF IsInTheRange%(X, Win.X, Win.X + Win.WIDTH) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  448.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  449.         ' if is the window bar area
  450.         IF IsInTheRange%(X, Win.X + 10, Win.X + Win.WIDTH - 31) THEN
  451.             ' if it is to the left of buttons on the bar
  452.             IsInWindow = Dragging
  453.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 30, Win.X + Win.WIDTH - 21) THEN
  454.             ' if it is on the leftest button on the bar
  455.             IsInWindow = cMinim ' icon minimize--> restore to child default
  456.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 20, Win.X + Win.WIDTH - 11) THEN
  457.             ' if it is on the middle button on the bar
  458.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  459.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  460.             ' if is on the rightest button on the bar
  461.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  462.         ELSEIF IsInTheRange%(X, Win.X, Win.X + 10) THEN
  463.             IsInWindow = cResize
  464.         END IF
  465.     END IF
  466.  
  467. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  468.     IF Min > Max THEN SWAP Min, Max
  469.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  470.  
  471. SUB dragWindow (Win AS wChild)
  472.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), White, B ' windows size
  473.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), White, BF 'title bar for dragging window
  474.     _DISPLAY
  475.  
  476. SUB wClosed (Win AS wChild)
  477.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  478.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Black, B
  479.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 3)-(Win.X + Win.WIDTH - 3, Win.Y + 7), Black
  480.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 7)-(Win.X + Win.WIDTH - 3, Win.Y + 3), Black
  481.  
  482. SUB wMaxim (win AS wChild)
  483.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  484.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Black, B
  485.     LINE (win.X + win.WIDTH - 17, win.Y + 3)-(win.X + win.WIDTH - 13, win.Y + 7), Black, B
  486.  
  487. SUB wMinim (Win AS wChild)
  488.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  489.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Black, B
  490.     LINE (Win.X + Win.WIDTH - 27, Win.Y + 7)-(Win.X + Win.WIDTH - 23, Win.Y + 7), Black
  491.  
  492. SUB wResize (Win AS wChild)
  493.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Pink, BF 'title bar for restore to original dimensions
  494.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Black, B
  495.     LINE (Win.X + 2, Win.Y + 2)-(Win.X + 7, Win.Y + 7), Black, B , &B1010101010101010
  496.  
  497. SUB DrawWindow (Win AS wChild)
  498.     ' the window
  499.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  500.         LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Win.COLOR, BF
  501.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  502.         LINE (Win.X + Win.WIDTH, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  503.     END IF
  504.     ' the status bar
  505.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF 'title bar for dragging window
  506.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.WIDTH, Win.Y + 10), Black
  507.     wMinim Win
  508.     wMaxim Win
  509.     wClosed Win
  510.     wResize Win
  511.  
  512. SUB GetInput (Act AS INTEGER)
  513.     DIM mInput AS INTEGER
  514.  
  515.  
  516.     ' keyboard input
  517.     a$ = INKEY$
  518.     IF a$ = CHR$(27) THEN Act = aQuit
  519.  
  520.     'mouse input
  521.     mInput = mFalse
  522.     IF _MOUSEINPUT THEN mInput = mTrue
  523.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  524.     LOOP
  525.     IF mInput THEN
  526.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  527.             mInput = mLR
  528.         ELSEIF _MOUSEBUTTON(1) THEN
  529.             mInput = mLeft
  530.         ELSEIF _MOUSEBUTTON(2) THEN
  531.             mInput = mRight
  532.         ELSEIF _MOUSEBUTTON(3) THEN
  533.             mInput = mMiddle
  534.         END IF
  535.     END IF
  536.  
  537.     IF mInput = mLR THEN
  538.         Act = aQuit
  539.     ELSEIF mInput = mMiddle THEN
  540.         Act = Minim
  541.     ELSEIF mInput = mRight THEN
  542.         Act = Maxim
  543.     ELSEIF mInput = mLeft THEN
  544.         Act = mInput
  545.     END IF
  546.  

Now the border of the big white square (the shadow of the window in resizing) is different if  no click on resizing squares, or left mouse button on left square or on right square.
Waiting your and others feedback
Thanks for time and energy spent

I tried it on version 1.3 and 1.4 and same result. It compiles fine and everything works except for the resizing.
Im using Linux to compile, i dont have a windows machine to test on. Who knows, maybe im just doing it wrong.
Title: Re: child windows into window of the program: a demonstration
Post by: Dimster on February 17, 2020, 09:20:40 am
Hi Tempodi ..what a great way to display multiple windows. Thanks for this. I have a lot of different menu options for the program I have been messing with and my program is very large. Is there a limit to the data each window can display? For example, I can display a lot more in 1000,800,32 than I can in 500,250,32. Also can each window have it's own size (like 750,250,32 & 1000,750,500,32 & 1600,800,32 etc.) or do they all need to be the same size? And lastly, when a window is resized, does the data in the window automatically resize?

I realize I should just try it all out myself and learn something but it's just so time consuming to do it only to find out "you can't do that". I'm into the instant gratification this digital world is providing rather that the "live and learn by trial and error" of last year.
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on February 17, 2020, 11:54:55 am
Hi TempodiBasic,

Feedback from Win 10-64: I am also having troubles with response when I click white square, rarely does the outline of window come up for me to resize it.
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 19, 2020, 09:58:58 am
@Keybone
I'll try to run my demo app in Ubuntu in VirtualMachine , see later

@Bplus
please tell me, after you have done a left click on the resize button on the bar of window, have you no response after a single left click on both the little white boxes or only with one?
In my experience there is sometimes a latency of response of a second but I have no found the reason for now.

@Dimster
Thanks for kind words.
It is an application demonstration to use child window into the main window like it did Windows 3.1!

The application for now uses only a minimum limit to the dimension of a window opened (showed) but the size possible is ranging from minimum set to main window of program.

For now there is no routines to show data or graphics into each child window, for me it is a work in progress as I gain more time to use for this I'll go on. However I remember 4-5 routines-demonstrations posted by clever QB64 coders to show text and graphic in size and resizable area of the screen.
 
About the amount of data the limiti is the output routine and the RAM of PC.

Thans to all for feedbacks
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on February 19, 2020, 10:27:28 am
Quote
@Bplus
please tell me, after you have done a left click on the resize button on the bar of window, have you no response after a single left click on both the little white boxes or only with one?
In my experience there is sometimes a latency of response of a second but I have no found the reason for now.

After I click the right top corner, the two white boxes come up reliably, but when I click either white box it seems totally random whether they decide to do the white outline for resizing. Sometimes it works right off (either white box) sometimes I click and click and click... nothing happens. The resizing, once the outlines are showing, also seems to work reliably.
Title: Re: child windows into window of the program: a demonstration
Post by: TerryRitchie on February 19, 2020, 02:57:06 pm
I was tinkering around with GUI structures a few years back. Here is the code. It may give you some ideas for your code. You can resize the windows by clicking and holding the bottom right corner of the window, just like Windows.

Code: QB64: [Select]
  1. 'GUI 02/27/16
  2.  
  3. CONST BYWINDOW = 0
  4. CONST BYSCREEN = -1
  5. CONST ALLWINDOWS = 0
  6.  
  7. TYPE MOUSEFLAGS
  8.     OnWindow AS INTEGER '              current window pointer is hovering over
  9.     Icon AS INTEGER '                  current mouse pointer icon
  10.     X AS INTEGER '                     current desktop mouse x coordinate
  11.     Y AS INTEGER '                     current desktop mouse y coordinate
  12.     PX AS INTEGER '                    previous desktop mouse x coordinate
  13.     PY AS INTEGER '                    previous desktop mouse y coordinate
  14.     WindowX AS INTEGER '               current window mouse x coordinate
  15.     WindowY AS INTEGER '               current window mouse y coordinate
  16.     SurfaceX AS INTEGER '              current work space mouse x coordinate
  17.     SurfaceY AS INTEGER '              current work space mouse y coordinate
  18.     OnSurface AS INTEGER '      [BOOL] mouse currently hovering over surface?
  19.     OnTitlebar AS INTEGER '     [BOOL] mouse currently hovering over title bar?
  20.     OnBorder AS INTEGER '       [BOOL] mouse currently hovering over a border?
  21.     Border AS INTEGER '                border(s) mouse hovering (1-top, 2-right, 4-bottom, 8-left ... i.e. 6 = bottom right corner)
  22.     LeftClick AS INTEGER '      [BOOL] mouse left button currently pressed?
  23.     RightClick AS INTEGER '     [BOOL] mouse right button currently pressed?
  24.     Move AS INTEGER '                  window currently in the process of being moved
  25.     Resize AS INTEGER '                current window being resized
  26.     LeftReleased AS INTEGER '   [BOOL] left mouse button released?
  27.     RightReleased AS INTEGER '  [BOOL] right mouse button released?
  28.  
  29.     OnButton AS INTEGER '              current button pointer is hovering over
  30.     ButtonPressed AS INTEGER '         current button being held down
  31.     ButtonClicked AS INTEGER '         button that was clicked then released
  32.  
  33.  
  34.  
  35. TYPE WINDOWFLAGS
  36.     X AS INTEGER '                     x location of current window
  37.     Y AS INTEGER '                     y location of current window
  38.     Width AS INTEGER '                 width of current window
  39.     Height AS INTEGER '                height of current window
  40.     Surface AS LONG '            [IMG]  window surface image
  41.     SurfaceX AS INTEGER '              x location of current work space
  42.     SurfaceY AS INTEGER '              y location of current workspace
  43.     SWidth AS INTEGER '                width of current surface
  44.     SHeight AS INTEGER '               height of current surface
  45.     Focus AS INTEGER '                 the window that has focus
  46.     HasFocus AS INTEGER '       [BOOL] current window has focus?
  47.  
  48. TYPE WIN
  49.     Width AS INTEGER '                 overall window width
  50.     Height AS INTEGER '                overall window height
  51.  
  52.     OWidth AS INTEGER '                original width
  53.     OHeight AS INTEGER
  54.  
  55.     SWidth AS INTEGER '                surface width
  56.     SHeight AS INTEGER '               surface height
  57.  
  58.     SIWidth AS INTEGER '               surface image width
  59.     SIHeight AS INTEGER '              surface image height
  60.  
  61.     MinWidth AS INTEGER
  62.     MaxWidth AS INTEGER
  63.     MinHeight AS INTEGER
  64.     MaxHeight AS INTEGER
  65.  
  66.  
  67.     X AS INTEGER '                     window x location
  68.     Y AS INTEGER '                     window y location
  69.     SurfaceX AS INTEGER '              surface x location
  70.     SurfaceY AS INTEGER '              surface y location
  71.     Font AS LONG '              [FONT] window font
  72.     InUse AS INTEGER '          [BOOL] window in use?
  73.     Window AS LONG '            [IMG]  window image
  74.     Surface AS LONG '           [IMG]  surface image
  75.     BGImage AS LONG '           [IMG]  background image under window
  76.     TBFImage AS LONG '          [IMG]  title bar image when window has focus
  77.     TBNFImage AS LONG '         [IMG]  title bar image when window has lost focus
  78.     Shadow AS INTEGER '         [BOOL] shadow present
  79.     BWidth AS INTEGER '                border width
  80.     TBHeight AS INTEGER '              title bar height
  81.     WColor AS _UNSIGNED LONG '  [CLR]  window color
  82.     Wred AS INTEGER '           [CLR]  red component of Wcolor
  83.     Wgreen AS INTEGER '         [CLR]  green component of Wcolor
  84.     Wblue AS INTEGER '          [CLR]  blue component of Wcolor
  85.     TBColor AS _UNSIGNED LONG ' [CLR]  title bar color
  86.     TTColor AS _UNSIGNED LONG ' [CLR]  title text color
  87.     Title AS STRING * 128 '            window title
  88.     Visible AS INTEGER '        [BOOL] window on screen?
  89.     Focus AS INTEGER '          [BOOL] window has focus?
  90.  
  91.     'ByMethod AS INTEGER '       [BOOL] -1 = window dimensions by surface, 0 = dimensions by window
  92.  
  93.     Move AS INTEGER '           [BOOL] window currently being moved?
  94.     Resize AS INTEGER '         [BOOL] window currently being resized
  95.     Lighter AS _UNSIGNED LONG ' [CLR]  border colors
  96.     Light AS _UNSIGNED LONG '   [CLR]
  97.     Dark AS _UNSIGNED LONG '    [CLR]
  98.     Darker AS _UNSIGNED LONG '  [CLR]
  99.     Darkest AS _UNSIGNED LONG ' [CLR]
  100.     Icon AS LONG '              [IMG]  window icon
  101.     TBSolid AS INTEGER '        [BOOL] solid title bar?
  102.     Size AS INTEGER '           [BOOL] window resizable?
  103.  
  104.     CloseButton AS INTEGER '           0 = no button, >0 = button handle number
  105.     MaxButton AS INTEGER
  106.     MinButton AS INTEGER
  107.     RestoreButton AS INTEGER
  108.     SUButton AS INTEGER
  109.     SDButton AS INTEGER
  110.     SLButton AS INTEGER
  111.     SRButton AS INTEGER
  112.  
  113.     Maximized AS INTEGER '             -1 window currently maximized, 0 = normal  (use 'state' instead for max/min/normal?)
  114.     Minimized AS INTEGER '             -1 window currently minimized
  115.  
  116.     Rwidth AS INTEGER '                restore width  (when max or min - values to restore window size)
  117.     Rheight AS INTEGER '               restore height
  118.  
  119.  
  120. TYPE BUTTON
  121.     InUse AS INTEGER '          [BOOL] button in use?
  122.     X AS INTEGER
  123.     Y AS INTEGER
  124.     Height AS INTEGER
  125.     State AS INTEGER '                 state of button: -1 = pressed, 0 = normal, 1 = disabled
  126.     Normal AS LONG '            [IMG]  normal button
  127.     Pressed AS LONG '           [IMG]  pressed button
  128.     Disabled AS LONG '          [IMG]  disabled button
  129.     Window AS INTEGER '                window button belongs to
  130.     WinButton AS INTEGER '      [BOOL] indicates a button for window use only (scroll bar buttons, etc..)
  131.  
  132. TYPE MOUSEPOINTERS
  133.     Icon AS LONG '              [IMG]  mouse pointer image
  134.     X AS INTEGER '                     x offset of pointer
  135.     Y AS INTEGER '                     y offset of pointer
  136.  
  137. REDIM WIN(1) AS WIN
  138. REDIM BUT(1) AS BUTTON
  139. REDIM WinOrder%(0)
  140. DIM POINTER(15) AS MOUSEPOINTERS
  141. DIM QB64Icon&
  142. DIM WIN AS WINDOWFLAGS
  143. DIM MOUSE AS MOUSEFLAGS
  144.  
  145. DIM DeskTop&
  146.  
  147. DIM untitled%(10)
  148.  
  149.  
  150. POINTERS
  151.  
  152. WINDOW_DESKTOP 1024, 768, 0, ""
  153.  
  154.  
  155.  
  156.  
  157. 'FOR i% = 1 TO 10
  158. '    untitled%(i%) = WINDOW_NEW(320, 240)
  159. '    WINDOW_SETTITLE untitled%(i%), "Untitled-" + LTRIM$(STR$(i%))
  160. '    WIN(untitled%(i%)).TBSolid = 0
  161. '    WINDOW_MAKE untitled%(i%)
  162. '    WINDOW_SHOW untitled%(i%)
  163. '    WINDOW_PUT untitled%(i%), 140 + i% * 25, 20 + i% * 25, BYWINDOW
  164. '    WIN(untitled%(i%)).Size = -1
  165. 'NEXT i%
  166.  
  167.  
  168. untitled1% = WINDOW_NEW(640, 480)
  169. untitled2% = WINDOW_NEW(320, 240)
  170. untitled3% = WINDOW_NEW(160, 120)
  171.  
  172. WINDOW_SETTITLE untitled1%, "Untitled-1"
  173. WINDOW_SETTITLE untitled2%, "Untitled-2"
  174. WINDOW_SETTITLE untitled3%, "Untitled-3"
  175.  
  176. WIN(untitled2%).TBSolid = 0 '                    need to create library command for this
  177.  
  178.  
  179. WINDOW_MAKE untitled3%
  180. WINDOW_MAKE untitled2%
  181. WINDOW_MAKE untitled1%
  182.  
  183. WINDOW_SHOW untitled1%
  184. WINDOW_SHOW untitled2%
  185. WINDOW_SHOW untitled3%
  186.  
  187. WINDOW_PUT untitled3%, 150, 25, BYWINDOW
  188. WINDOW_PUT untitled2%, 200, 100, BYWINDOW
  189. WINDOW_PUT untitled1%, 300, 200, BYWINDOW
  190.  
  191.  
  192. WIN(untitled1%).Size = -1 '                      need to create library command for this
  193. WIN(untitled2%).Size = -1 '                      need to create library command for this
  194. WIN(untitled3%).Size = -1 '                      need to create library command for this
  195.  
  196.  
  197.     IF _MOUSEINPUT THEN WINDOW_MOUSE
  198.     WINDOW_REFRESH
  199.     LOCATE 1, 1
  200.     PRINT " Focus ------> "; WinOrder%(1)
  201.     PRINT " Mouse X ----> "; MOUSE.X
  202.     PRINT " Mouse Y ----> "; MOUSE.Y
  203.     PRINT " On Window --> "; MOUSE.OnWindow
  204.     PRINT " Window X ---> "; MOUSE.WindowX
  205.     PRINT " Window Y ---> "; MOUSE.WindowY
  206.     PRINT " On Surface -> "; MOUSE.OnSurface
  207.     PRINT " Surface X---> "; MOUSE.SurfaceX
  208.     PRINT " Surface Y --> "; MOUSE.SurfaceY
  209.     PRINT " On TitleBar > "; MOUSE.OnTitlebar
  210.     PRINT " On Border --> "; MOUSE.OnBorder
  211.     PRINT " Border -----> "; MOUSE.Border
  212.     PRINT " Left Click -> "; MOUSE.LeftClick
  213.     PRINT " Right Click > "; MOUSE.RightClick
  214.     PRINT " Moving -----> "; MOUSE.Move
  215.     PRINT " Resizing ---> "; MOUSE.Resize
  216.     PRINT " On Button --> "; MOUSE.OnButton
  217.     PRINT " Button Press> "; MOUSE.ButtonPressed
  218.     PRINT " Button Click> "; MOUSE.ButtonClicked
  219.     _DISPLAY
  220.  
  221.  
  222.  
  223.  
  224.  
  225. '--------------------------------------------------------------------------------------------------------------------------------
  226. '                                                                                                                         TBIMAGE
  227. SUB TBIMAGE (h%, f%)
  228.  
  229. ' h% = window handle
  230. ' f% = focus 1, no focus 0
  231.  
  232. SHARED WIN() AS WIN ' window array
  233. SHARED BUT() AS BUTTON
  234.  
  235. DIM c% '                  generic counter
  236. DIM Red!, Green!, Blue!
  237. DIM Redinc!, Greeninc!, Blueinc!
  238.  
  239. IF f% THEN
  240.     _DEST WIN(h%).TBFImage '                                                                draw on title bar focus image
  241.     _FONT WIN(h%).Font '                                                                    set title bar font
  242.     _PRINTMODE _KEEPBACKGROUND '                                                            font will be transparent
  243.     COLOR WIN(h%).TTColor '                                                                 set font color
  244.     CLS , WIN(h%).TBColor '                                                             yes, color title bar
  245.     IF NOT WIN(h%).TBSolid THEN
  246.         Red! = _RED(WIN(h%).TBColor) '                                                      get title bar color components
  247.         Green! = _GREEN(WIN(h%).TBColor)
  248.         Blue! = _BLUE(WIN(h%).TBColor)
  249.         Redinc! = (255 - Red!) / WIN(h%).SWidth / 2 '                                       calculate color fade values
  250.         Greeninc! = (255 - Green!) / WIN(h%).SWidth / 2
  251.         Blueinc! = (255 - Blue!) / WIN(h%).SWidth / 2
  252.     END IF
  253.     _DEST WIN(h%).TBNFImage
  254.     _FONT WIN(h%).Font
  255.     COLOR _RGB32(212, 208, 200)
  256.     CLS , _RGB32(128, 128, 128)
  257.     IF NOT WIN(h%).TBSolid THEN
  258.         Red! = 128
  259.         Green! = 128
  260.         Blue! = 128
  261.         Redinc! = 63 / WIN(h%).SWidth
  262.         Greeninc! = 63 / WIN(h%).SWidth
  263.         Blueinc! = 63 / WIN(h%).SWidth
  264.     END IF
  265. IF NOT WIN(h%).TBSolid THEN
  266.     FOR c% = 0 TO WIN(h%).SWidth - 1
  267.         LINE (c%, 0)-(c%, WIN(h%).TBHeight - 1), _RGB32(Red!, Green!, Blue!)
  268.         Red! = Red! + Redinc!
  269.         Green! = Green! + Greeninc!
  270.         Blue! = Blue! + Blueinc!
  271.     NEXT c%
  272. w% = _PRINTWIDTH("#") + 6
  273.  
  274. IF WIN(h%).CloseButton THEN w% = w% + BUT(WIN(h%).CloseButton).Width
  275. IF WIN(h%).MaxButton THEN w% = w% + BUT(WIN(h%).MaxButton).Width
  276. IF WIN(h%).MinButton THEN w% = w% + BUT(WIN(h%).MinButton).Width
  277.  
  278. mw% = WIN(h%).SWidth - (WIN(h%).TBHeight + 2) - w%
  279. t$ = RTRIM$(WIN(h%).Title)
  280. WIN(h%).MinWidth = _PRINTWIDTH(LEFT$(t$, 3) + "...") + WIN(h%).TBHeight + 2 + w%
  281. nt$ = t$
  282. WHILE _PRINTWIDTH(nt$) > mw%
  283.     t$ = LEFT$(t$, LEN(t$) - 1)
  284.     nt$ = t$ + "..."
  285. _PRINTSTRING (WIN(h%).TBHeight + 2, 4), nt$ '                         print title on title bar
  286. _PUTIMAGE (2, 1)-(WIN(h%).TBHeight - 1, WIN(h%).TBHeight - 2), WIN(h%).Icon '           place icon on title bar
  287.  
  288.  
  289. '--------------------------------------------------------------------------------------------------------------------------------
  290. '                                                                                                                          WITHIN
  291. FUNCTION WITHIN (x%, y%, x2%, y2%)
  292.  
  293. '*
  294. '* Returns true if mouse pointer within given coordinate pairs.
  295. '*
  296.  
  297. SHARED MOUSE AS MOUSEFLAGS
  298.  
  299. IF MOUSE.X >= x% THEN '              mouse pointer inside given rectangle?
  300.     IF MOUSE.X <= x2% THEN
  301.         IF MOUSE.Y >= y% THEN
  302.             IF MOUSE.Y <= y2% THEN
  303.                 WITHIN = -1 '        yes, return true
  304.             END IF
  305.         END IF
  306.     END IF
  307.  
  308.  
  309. '--------------------------------------------------------------------------------------------------------------------------------
  310. '                                                                                                                      BUTTON_PUT
  311. SUB BUTTON_PUT (b%, x%, y%, state%) ' state% needed?
  312.  
  313. SHARED WIN() AS WIN
  314. SHARED BUT() AS BUTTON
  315.  
  316. IF BUT(b%).WinButton THEN '                                                                  is button for window use only?
  317.     SELECT CASE BUT(b%).State '                                                              which state is title bar button in?
  318.         CASE -1 '                                                                            pressed state
  319.             _PUTIMAGE (BUT(b%).X, BUT(b%).Y), BUT(b%).Pressed, WIN(BUT(b%).Window).Window '  draw pressed button on window
  320.         CASE 0 '                                                                             normal (depressed) state
  321.             _PUTIMAGE (BUT(b%).X, BUT(b%).Y), BUT(b%).Normal, WIN(BUT(b%).Window).Window '   draw normal button on window
  322.         CASE 1 '                                                                             disabled state
  323.             _PUTIMAGE (BUT(b%).X, BUT(b%).Y), BUT(b%).Disabled, WIN(BUT(b%).Window).Window ' draw disabled button on window
  324.     END SELECT
  325.  
  326.     '*
  327.     '* Custom made buttons here
  328.     '*
  329.  
  330.  
  331.  
  332. '--------------------------------------------------------------------------------------------------------------------------------
  333. '                                                                                                                      BUTTON_NEW
  334. FUNCTION BUTTON_NEW (win%, w%, h%, t$, f&, c~&, t~&)
  335. '*
  336. '* win% - window button belongs to (negative value sent in means a title bar button is being created)
  337. '* w%   - width of button (ignored if title bar button is being created)
  338. '* h%   - height of button (ignored if title bar button is being created)
  339. '* t$   - text to be placed on button (if title bar button then "CLOSE", "MAXIMIZE", "MINIMIZE', and "RESTORE")
  340. '* f&   - text font (ignored if title bar button is being created)
  341. '* c~&  - button color (if 0 then window color is used)
  342. '* t~&  - text color (if 0 then balck is used)
  343. '*
  344. SHARED WIN() AS WIN
  345. SHARED BUT() AS BUTTON
  346.  
  347. DIM i% ' next available button array index
  348. DIM c% ' generic counter
  349.  
  350. i% = UBOUND(BUT) '                                                              get last button index
  351. WHILE NOT BUT(i%).InUse AND i% > 1 '                                            is button in use?
  352.     REDIM _PRESERVE BUT(i% - 1) AS BUTTON '                                     no, remove it
  353.     i% = i% - 1 '                                                               go to previous index
  354. WEND '                                                                          leave when last button still being used
  355. i% = 0 '                                                                        start at beginning
  356. c% = 1
  357. DO '                                                                            cycle through button indexes
  358.     IF NOT BUT(c%).InUse THEN '                                                 button in use?
  359.         i% = c% '                                                               no, use this index
  360.     ELSE '                                                                      yes
  361.         c% = c% + 1 '                                                           increment index counter
  362.         IF c% > UBOUND(BUT) THEN '                                              reached end of buttons?
  363.             REDIM _PRESERVE BUT(c%) AS BUTTON '                                 yes, create a new button
  364.             i% = c% '                                                           use this index
  365.         END IF
  366.     END IF
  367. LOOP UNTIL i% '                                                                 leave when available index found
  368. IF win% < 0 THEN '                                                              button belong to a title bar?
  369.     win% = -win% '                                                              yes, correct window handle
  370.     BUT(i%).WinButton = -1 '                                                    mark button as belonging to a title bar
  371. BUT(i%).Window = win% '                                                         button belongs to window (0 for desktop)
  372. BUT(i%).InUse = -1 '                                                            mark index as used
  373. BUT(i%).State = 0 '                                                             default to normal
  374. BUT(i%).X = 0 '                                                                 reset x coordinate
  375. BUT(i%).Y = 0 '                                                                 reset y coordinate
  376. IF BUT(i%).WinButton THEN '                                                     creating a title bar button?
  377.     BUT(i%).Height = WIN(win%).TBHeight - 4 '                                   calculate button height
  378.     BUT(i%).Width = INT(BUT(i%).Height * 1.14286) '                             calculate button width
  379.     IF w% THEN BUT(i%).Height = BUT(i%).Width '                                 yes, height=width
  380.     x2% = BUT(i%).Width - 1 '                                                   calculate right bottom corner button X
  381.     y2% = BUT(i%).Height - 1 '                                                  calculate right bottom corner button Y
  382.     BUT(i%).State = 0 '                                                         set button as normal (depressed)
  383.     BUT(i%).Normal = _NEWIMAGE(BUT(i%).Width, BUT(i%).Height, 32) '             create normal image holder
  384.     _DEST BUT(i%).Normal '                                                      draw on image
  385.     CLS , WIN(win%).Darkest '                                                   create common button image
  386.     LINE (0, 0)-(x2% - 1, y2% - 1), WIN(win%).Lighter, B '                      draw background
  387.     LINE (1, 1)-(x2% - 1, y2% - 1), WIN(win%).Darker, B
  388.     LINE (1, 1)-(x2% - 2, y2% - 2), WIN(win%).WColor, BF
  389.     BUT(i%).Pressed = _NEWIMAGE(BUT(i%).Width, BUT(i%).Height, 32) '            create pressed image holder
  390.     _DEST BUT(i%).Pressed '                                                     draw on image
  391.     CLS , WIN(win%).Lighter '                                                   create common button image
  392.     LINE (0, 0)-(x2% - 1, y2% - 1), WIN(win%).Darkest, B '                      draw background
  393.     LINE (1, 1)-(x2% - 1, y2% - 1), WIN(win%).WColor, B
  394.     LINE (1, 1)-(x2% - 2, y2% - 2), WIN(win%).Darker, B
  395.     LINE (2, 2)-(x2% - 1, y2% - 1), WIN(win%).WColor, BF
  396.     BUT(i%).Disabled = _NEWIMAGE(BUT(i%).Width, BUT(i%).Height, 32) '           create disabled image holder
  397.     IF NOT w% THEN '                                                            title bar button?
  398.         _DEST BUT(i%).Disabled '                                                yes, draw on image
  399.         CLS , WIN(win%).Darkest '                                               create common button image
  400.         LINE (0, 0)-(x2% - 1, y2% - 1), WIN(win%).Lighter, B '                  draw background
  401.         LINE (1, 1)-(x2% - 1, y2% - 1), WIN(win%).Darker, B
  402.         LINE (1, 1)-(x2% - 2, y2% - 2), WIN(win%).WColor, BF
  403.     END IF
  404.     SELECT CASE t$ '                                                            yes, which window button being created?
  405.         CASE "CLOSE" '                                                          close button
  406.             _DEST BUT(i%).Normal '                                              work on normal
  407.             LINE (4, 3)-(x2% - 5, y2% - 4), _RGB32(0, 0, 0) '                   draw depressed button
  408.             LINE (5, 3)-(x2% - 4, y2% - 4), _RGB32(0, 0, 0)
  409.             LINE (4, y2% - 4)-(x2% - 5, 3), _RGB32(0, 0, 0)
  410.             LINE (5, y2% - 4)-(x2% - 4, 3), _RGB32(0, 0, 0)
  411.             _DEST BUT(i%).Pressed '                                             work on pressed
  412.             LINE (5, 4)-(x2% - 4, y2% - 3), _RGB32(0, 0, 0) '                   draw pressed button
  413.             LINE (6, 4)-(x2% - 3, y2% - 3), _RGB32(0, 0, 0)
  414.             LINE (5, y2% - 3)-(x2% - 4, 4), _RGB32(0, 0, 0)
  415.             LINE (6, y2% - 3)-(x2% - 3, 4), _RGB32(0, 0, 0)
  416.             _DEST BUT(i%).Disabled '                                            work on disabled
  417.             LINE (5, y2% - 4)-(x2% - 4, 4), _RGB32(255, 255, 255) '             draw disabled button
  418.             LINE (6, y2% - 4)-(x2% - 3, 4), _RGB32(255, 255, 255)
  419.             LINE (x2% - 4, y2% - 3)-(x2% - 3, y2% - 3), _RGB32(255, 255, 255) '
  420.             LINE (4, 3)-(x2% - 5, y2% - 4), _RGB32(128, 128, 128)
  421.             LINE (5, 3)-(x2% - 4, y2% - 4), _RGB32(128, 128, 128)
  422.             LINE (4, y2% - 4)-(x2% - 5, 3), _RGB32(128, 128, 128)
  423.             LINE (5, y2% - 4)-(x2% - 4, 3), _RGB32(128, 128, 128)
  424.         CASE "MAXIMIZE" '                                                       maximize button
  425.             _DEST BUT(i%).Normal '                                              work on normal
  426.             LINE (3, 3)-(x2% - 4, y2% - 3), _RGB32(0, 0, 0), B '                draw depressed button
  427.             LINE (3, 2)-(x2% - 4, 2), _RGB32(0, 0, 0)
  428.             _DEST BUT(i%).Pressed '                                             work on pressed
  429.             LINE (4, 4)-(x2% - 3, y2% - 2), _RGB32(0, 0, 0), B '                draw pressed button
  430.             LINE (4, 3)-(x2% - 3, 3), _RGB32(0, 0, 0)
  431.             _DEST BUT(i%).Disabled '                                            work on disabled
  432.             LINE (4, 4)-(x2% - 3, y2% - 2), _RGB32(255, 255, 255), B '          draw disabled button
  433.             PSET (x2% - 3, 3), _RGB32(255, 255, 255)
  434.             LINE (3, 3)-(x2% - 4, y2% - 3), _RGB32(128, 128, 128), B
  435.             LINE (3, 2)-(x2% - 4, 2), _RGB32(128, 128, 128)
  436.         CASE "MINIMIZE" '                                                       minimize button
  437.             _DEST BUT(i%).Normal '                                              work on normal
  438.             LINE (4, y2% - 4)-(x2% - 6, y2% - 3), _RGB32(0, 0, 0), B '          draw depressed button
  439.             _DEST BUT(i%).Pressed '                                             work on pressed
  440.             LINE (5, y2% - 3)-(x2% - 5, y2% - 2), _RGB32(0, 0, 0), B '          draw pressed button
  441.             _DEST BUT(i%).Disabled '                                            work on disabled
  442.             LINE (5, y2% - 3)-(x2% - 5, y2% - 2), _RGB32(255, 255, 255), B '    draw disabled button
  443.             LINE (4, y2% - 4)-(x2% - 6, y2% - 3), _RGB32(128, 128, 128), B
  444.         CASE "RESTORE" '                                                        restore button
  445.             _DEST BUT(i%).Normal '                                              work on normal
  446.             LINE (3, 6)-(x2% - 7, y2% - 3), _RGB32(0, 0, 0), B '                draw depressed button
  447.             LINE (3, 5)-(x2% - 7, 5), _RGB32(0, 0, 0)
  448.             PSET (5, 4), _RGB32(0, 0, 0)
  449.             PSET (x2% - 6, y2% - 6), _RGB32(0, 0, 0)
  450.             LINE (5, 2)-(x2% - 5, 3), _RGB32(0, 0, 0), B
  451.             LINE (x2% - 5, 4)-(x2% - 5, y2% - 6), _RGB32(0, 0, 0)
  452.             _DEST BUT(i%).Pressed '                                             work on pressed
  453.             LINE (4, 7)-(x2% - 6, y2% - 2), _RGB32(0, 0, 0), B '                draw pressed button
  454.             LINE (4, 6)-(x2% - 6, 6), _RGB32(0, 0, 0)
  455.             PSET (6, 5), _RGB32(0, 0, 0)
  456.             PSET (x2% - 5, y2% - 5), _RGB32(0, 0, 0)
  457.             LINE (6, 3)-(x2% - 4, 4), _RGB32(0, 0, 0), B
  458.             LINE (x2% - 4, 5)-(x2% - 4, y2% - 5), _RGB32(0, 0, 0)
  459.             _DEST BUT(i%).Disabled '                                            work on disabled
  460.             LINE (4, 7)-(x2% - 6, y2% - 2), _RGB32(255, 255, 255), B '          draw disabled button
  461.             LINE (6, 4)-(x2% - 6, 4), _RGB32(255, 255, 255)
  462.             LINE (x2% - 5, 3)-(x2% - 4, y2% - 5), _RGB32(255, 255, 255), B
  463.             LINE (3, 6)-(x2% - 7, y2% - 3), _RGB32(128, 128, 128), B
  464.             LINE (3, 5)-(x2% - 7, 5), _RGB32(128, 128, 128)
  465.             PSET (5, 4), _RGB32(128, 128, 128)
  466.             PSET (x2% - 6, y2% - 6), _RGB32(128, 128, 128)
  467.             LINE (5, 2)-(x2% - 5, 3), _RGB32(128, 128, 128), B
  468.             LINE (x2% - 5, 4)-(x2% - 5, y2% - 6), _RGB32(128, 128, 128)
  469.         CASE "SCROLLUP"
  470.             _DEST BUT(i%).Normal
  471.             LINE (BUT(i%).Width \ 2, 6)-(4, y2% - 6), _RGB32(0, 0, 0)
  472.             LINE -(x2% - 4, y2% - 6), _RGB32(0, 0, 0)
  473.             LINE -(BUT(i%).Width \ 2, 6), _RGB32(0, 0, 0)
  474.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  475.             _DEST BUT(i%).Pressed
  476.             LINE (BUT(i%).Width \ 2 + 1, 7)-(5, y2% - 5), _RGB32(0, 0, 0)
  477.             LINE -(x2% - 3, y2% - 5), _RGB32(0, 0, 0)
  478.             LINE -(BUT(i%).Width \ 2 + 1, 7), _RGB32(0, 0, 0)
  479.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  480.         CASE "SCROLLDOWN"
  481.             _DEST BUT(i%).Normal
  482.             LINE (BUT(i%).Width \ 2, y2% - 6)-(4, 6), _RGB32(0, 0, 0)
  483.             LINE -(y2% - 4, 6), _RGB32(0, 0, 0)
  484.             LINE -(BUT(i%).Width \ 2, y2% - 6), _RGB32(0, 0, 0)
  485.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  486.             _DEST BUT(i%).Pressed
  487.             LINE (BUT(i%).Width \ 2 + 1, y2% - 5)-(5, 7), _RGB32(0, 0, 0)
  488.             LINE -(x2% - 3, 7), _RGB32(0, 0, 0)
  489.             LINE -(BUT(i%).Width \ 2 + 1, y2% - 5), _RGB32(0, 0, 0)
  490.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  491.         CASE "SCROLLLEFT"
  492.             _DEST BUT(i%).Normal
  493.             LINE (5, BUT(i%).Height \ 2)-(x2% - 7, 4), _RGB32(0, 0, 0)
  494.             LINE -(x2% - 7, y2% - 5), _RGB32(0, 0, 0)
  495.             LINE -(5, BUT(i%).Height \ 2), _RGB32(0, 0, 0)
  496.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  497.             _DEST BUT(i%).Pressed
  498.             LINE (6, BUT(i%).Height \ 2 + 1)-(x2% - 6, 5), _RGB32(0, 0, 0)
  499.             LINE -(x2% - 6, y2% - 4), _RGB32(0, 0, 0)
  500.             LINE -(6, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0)
  501.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  502.         CASE "SCROLLRIGHT"
  503.             _DEST BUT(i%).Normal
  504.             LINE (x2% - 6, BUT(i%).Height \ 2)-(6, 4), _RGB32(0, 0, 0)
  505.             LINE -(6, y2% - 5), _RGB32(0, 0, 0)
  506.             LINE -(x2% - 6, BUT(i%).Height \ 2), _RGB32(0, 0, 0)
  507.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  508.             _DEST BUT(i%).Pressed
  509.             LINE (x2% - 5, BUT(i%).Height \ 2 + 1)-(7, 5), _RGB32(0, 0, 0)
  510.             LINE -(7, y2% - 4), _RGB32(0, 0, 0)
  511.             LINE -(x2% - 5, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0)
  512.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  513.     END SELECT
  514.  
  515.     '*
  516.     '* custom made buttons here
  517.     '*
  518.  
  519.  
  520. BUTTON_NEW = i%
  521.  
  522.  
  523. '--------------------------------------------------------------------------------------------------------------------------------
  524. '                                                                                                                    WINDOW_MOUSE
  525. SUB WINDOW_MOUSE ()
  526. '
  527. ' work in progress (only called when there has been mouse activity)
  528. '
  529. SHARED WIN() AS WIN
  530. SHARED WinOrder%()
  531. SHARED WIN AS WINDOWFLAGS
  532. SHARED MOUSE AS MOUSEFLAGS
  533. SHARED BUT() AS BUTTON
  534.  
  535. DIM c% ' current window being checked for mouse hover
  536. DIM o% ' order of windows
  537. DIM x% ' x offset movement of mouse
  538. DIM y% ' y offset movement of mouse
  539. DIM tx%
  540. DIM ty%
  541.  
  542. MOUSE.PX = MOUSE.X '                                                                         save last mouse x position
  543. MOUSE.PY = MOUSE.Y '                                                                         save last mouse y position
  544. WHILE _MOUSEINPUT: WEND '                                                                    get latest mouse status
  545. MOUSE.X = _MOUSEX '                                                                          set desktop x coordinate flag
  546. MOUSE.Y = _MOUSEY '                                                                          set desktop y coordinate flag
  547. MOUSE.LeftClick = _MOUSEBUTTON(1) '                                                          set left mouse button status
  548. MOUSE.RightClick = _MOUSEBUTTON(2) '                                                         set right mouse button status
  549. IF NOT MOUSE.LeftClick THEN
  550.     MOUSE.LeftReleased = -1 '                                                                left mouse button has been released?
  551.     WIN(MOUSE.Move).Move = 0 '                                                               yes, window no longer being moved
  552.     MOUSE.Move = 0 '                                                                         end window movement
  553.     WIN(MOUSE.Resize).Resize = 0 '                                                           window no longer being resized
  554.     MOUSE.Resize = 0 '                                                                       end window resizing
  555.     MOUSE.Icon = 0 '                                                                         mouse pointer to default
  556.     IF MOUSE.ButtonPressed THEN '                                                            was a button being held down?
  557.         MOUSE.ButtonClicked = MOUSE.ButtonPressed '                                          yes, this button has now been clicked
  558.         MOUSE.ButtonPressed = 0 '                                                            button no longer being held down
  559.         BUT(MOUSE.ButtonClicked).State = 0 '                                                 set button state back to normal
  560.     END IF
  561.     IF MOUSE.Move THEN '                                                                     window currently being moved?
  562.         WINDOW_PUT MOUSE.move, WIN(MOUSE.move).X + MOUSEMOVEMENTX,_
  563.                               WIN(MOUSE.move).Y + MOUSEMOVEMENTY,_
  564.                               BYWINDOW '                                                     yes, update window position
  565.     ELSEIF MOUSE.Resize THEN '                                                               window currently being resized?
  566.         x% = MOUSEMOVEMENTX '                                                                yes, get change in x position
  567.         y% = MOUSEMOVEMENTY '                                                                get change in y position
  568.         IF MOUSE.Border AND 1 THEN '                                                         mouse on top border?
  569.             ty% = WIN(MOUSE.Resize).Height - y% '                                            yes, calculate possible y value
  570.             IF ty% >= WIN(MOUSE.Resize).MinHeight AND ty% <= WIN(MOUSE.Resize).MaxHeight THEN ' outside limits?
  571.                 WIN(MOUSE.Resize).Y = WIN(MOUSE.Resize).Y + y% '                             no, adjust window y location
  572.                 WIN(MOUSE.Resize).Height = ty% '                                             adjust overall window height
  573.  
  574.                 WIN(MOUSE.Resize).SHeight = WIN(MOUSE.Resize).SHeight - y% '                 adjust window screen height
  575.  
  576.             ELSE '                                                                           yes, minimum reached
  577.                 _MOUSEMOVE MOUSE.X, MOUSE.PY '                                               force pointer back       (not working correctly in GL)
  578.                 MOUSE.Y = MOUSE.PY '                                                         update mouse y position
  579.                 MOUSE.PY = MOUSEMOVEMENTY '                                                  seed new y offset position
  580.             END IF
  581.         ELSEIF MOUSE.Border AND 4 THEN '                                                     no, mouse on bottom border?
  582.             ty% = WIN(MOUSE.Resize).Height + y% '                                            calculate possible y value
  583.             IF ty% >= WIN(MOUSE.Resize).MinHeight AND ty% <= WIN(MOUSE.Resize).MaxHeight THEN ' outside limits?
  584.                 WIN(MOUSE.Resize).Height = ty% '                                             no, adjust overall window height
  585.  
  586.                 WIN(MOUSE.Resize).SHeight = WIN(MOUSE.Resize).SHeight + y% '                 adjust window screen height
  587.  
  588.             ELSE '                                                                           yes, minimum reached
  589.                 _MOUSEMOVE MOUSE.X, MOUSE.PY '                                               force pointer back       (not working correclty in GL)
  590.                 MOUSE.Y = MOUSE.PY '                                                         update mouse y position
  591.                 MOUSE.PY = MOUSEMOVEMENTY '                                                  seed new y offset position
  592.             END IF
  593.         END IF
  594.         IF MOUSE.Border AND 2 THEN '                                                         mouse on right border?
  595.             tx% = WIN(MOUSE.Resize).Width + x% '                                             yes, calculate possible x value
  596.             IF tx% >= WIN(MOUSE.Resize).MinWidth AND tx% <= WIN(MOUSE.Resize).MaxWidth THEN ' outside limits?
  597.                 WIN(MOUSE.Resize).Width = tx% '                                              no, adjust overall window width
  598.  
  599.                 WIN(MOUSE.Resize).SWidth = WIN(MOUSE.Resize).SWidth + x% '                   adjust window screen width
  600.  
  601.             ELSE '                                                                           yes, minimum reached
  602.                 _MOUSEMOVE MOUSE.PX, MOUSE.Y '                                               force pointer back       (not working correclty in GL)
  603.                 MOUSE.X = MOUSE.PX '                                                         update mouse x position
  604.                 MOUSE.PX = MOUSEMOVEMENTX '                                                  seed new x offset position
  605.             END IF
  606.         ELSEIF MOUSE.Border AND 8 THEN '                                                     no, mouse on left border?
  607.             tx% = WIN(MOUSE.Resize).Width - x% '                                             calculate possible x value
  608.             IF tx% >= WIN(MOUSE.Resize).MinWidth AND tx% <= WIN(MOUSE.Resize).MaxWidth THEN ' outside limits?
  609.                 WIN(MOUSE.Resize).X = WIN(MOUSE.Resize).X + x% '                             no, adjust window x location
  610.                 WIN(MOUSE.Resize).Width = tx% '                                              adjust overall window width
  611.  
  612.                 WIN(MOUSE.Resize).SWidth = WIN(MOUSE.Resize).SWidth - x% '                   adjust window screen width
  613.  
  614.             ELSE '                                                                           yes, minimum reached
  615.                 _MOUSEMOVE MOUSE.PX, MOUSE.Y '                                               force pointer back       (not working correctly in GL)
  616.                 MOUSE.X = MOUSE.PX '                                                         update mouse x position
  617.                 MOUSE.PX = MOUSEMOVEMENTX '                                                  seed new x offset position
  618.             END IF
  619.         END IF
  620.         WINDOW_MAKE MOUSE.Resize '                                                           redraw window
  621.     ELSE
  622.         MOUSE.WindowX = MOUSE.X - WIN(MOUSE.OnWindow).X '                                    set window x coordinate flag
  623.         MOUSE.WindowY = MOUSE.Y - WIN(MOUSE.OnWindow).Y '                                    set window y coordinate flag
  624.         MOUSE.SurfaceX = MOUSE.WindowX - WIN(MOUSE.OnWindow).SurfaceX '                        yes, set work space x flag
  625.         MOUSE.SurfaceY = MOUSE.WindowY - WIN(MOUSE.OnWindow).SurfaceY '                        set work space y flag
  626.     END IF
  627.  
  628. IF NOT MOUSE.LeftReleased THEN EXIT SUB '                                                    don't interact if left button being held down
  629.  
  630. WIN.X = 0 '                                                                                  reset window flags
  631. WIN.Y = 0
  632. WIN.Width = 0
  633. WIN.Height = 0
  634. WIN.Surface = 0
  635. WIN.SurfaceX = 0
  636. WIN.SurfaceY = 0
  637. WIN.SWidth = 0
  638. WIN.SHeight = 0
  639. WIN.HasFocus = 0
  640. MOUSE.Icon = 0
  641. MOUSE.OnWindow = 0 '                                                                         reset remaining mouse flags
  642. MOUSE.WindowX = 0
  643. MOUSE.WindowY = 0
  644. MOUSE.OnSurface = 0
  645. MOUSE.SurfaceX = 0
  646. MOUSE.SurfaceY = 0
  647. MOUSE.OnTitlebar = 0
  648. MOUSE.OnBorder = 0
  649. MOUSE.Border = 0
  650. MOUSE.OnButton = 0
  651. DO '                                                                                         loop through window order array
  652.     c% = c% + 1 '                                                                            increment array index
  653.     o% = WinOrder%(c%) '                                                                     next window to check
  654.     IF WIN(o%).Visible THEN '                                                                is window visible on screen?
  655.         IF WITHIN(WIN(o%).X,_
  656.                   WIN(o%).Y,_
  657.                   WIN(o%).X + WIN(o%).Width - 1,_
  658.                   WIN(o%).Y + WIN(o%).Height - 1) THEN '                                     yes, mouse within window coordinates?
  659.             MOUSE.OnWindow = o% '                                                            yes, set pointer flag to hovered window
  660.             MOUSE.WindowX = MOUSE.X - WIN(o%).X '                                            set window x coordinate flag
  661.             MOUSE.WindowY = MOUSE.Y - WIN(o%).Y '                                            set window y coordinate flag
  662.  
  663.             WIN.X = WIN(o%).X
  664.             WIN.Y = WIN(o%).Y
  665.             WIN.Width = WIN(o%).Width '                                                      set window width flag
  666.             WIN.Height = WIN(o%).Height '                                                    set window height flag
  667.             WIN.Surface = WIN(o%).Surface
  668.             WIN.SurfaceX = WIN(o%).SurfaceX
  669.             WIN.SurfaceY = WIN(o%).SurfaceY
  670.             WIN.SWidth = WIN(o%).SWidth '                                                    set window work space width flag
  671.             WIN.SHeight = WIN(o%).SHeight '                                                  set window work space height flag
  672.             WIN.HasFocus = WIN(o%).Focus
  673.  
  674.             IF WITHIN(WIN(o%).X + WIN(o%).SurfaceX,_
  675.                       WIN(o%).Y + WIN(o%).SurfaceY,_
  676.                       WIN(o%).X + WIN(o%).SurfaceX + WIN(o%).SWidth - 1,_
  677.                       WIN(o%).Y + WIN(o%).SurfaceY + WIN(o%).SHeight - 1) THEN '              mouse within screen coordinates?
  678.                 MOUSE.SurfaceX = MOUSE.WindowX - WIN(o%).SurfaceX '                            yes, set screen x flag
  679.                 MOUSE.SurfaceY = MOUSE.WindowY - WIN(o%).SurfaceY '                            set screen y flag
  680.                 MOUSE.OnSurface = -1 '                                                        set screen flag
  681.             ELSEIF WITHIN(WIN(o%).X + WIN(o%).SurfaceX,_
  682.                           WIN(o%).Y + WIN(o%).BWidth,_
  683.                           WIN(o%).X + WIN(o%).SurfaceX + WIN(o%).SWidth - 1,_
  684.                           WIN(o%).Y + WIN(o%).BWidth + WIN(o%).TBHeight - 1) THEN '          no, mouse within title bar?
  685.                 IF WIN(o%).CloseButton THEN '                                                yes, does this window have a close button?
  686.                     IF WITHIN(WIN(o%).X + BUT(WIN(o%).CloseButton).X,_
  687.                               WIN(o%).Y + BUT(WIN(o%).CloseButton).Y,_
  688.                               WIN(o%).X + BUT(WIN(o%).CloseButton).X + BUT(WIN(o%).CloseButton).Width - 1,_
  689.                               WIN(o%).Y + BUT(WIN(o%).CloseButton).Y + BUT(WIN(o%).CloseButton).Height - 1) THEN ' yes, on button?
  690.                         MOUSE.OnButton = WIN(o%).CloseButton '                               yes, set flag
  691.                     END IF
  692.                 END IF
  693.                 IF WIN(o%).MaxButton THEN '                                                  does this window have a maximize button?
  694.                     IF WITHIN(WIN(o%).X + BUT(WIN(o%).MaxButton).X,_
  695.                               WIN(o%).Y + BUT(WIN(o%).MaxButton).Y,_
  696.                               WIN(o%).X + BUT(WIN(o%).MaxButton).X + BUT(WIN(o%).MaxButton).Width - 1,_
  697.                               WIN(o%).Y + BUT(WIN(o%).MaxButton).Y + BUT(WIN(o%).MaxButton).Height - 1) THEN ' yes, on button?
  698.                         MOUSE.OnButton = WIN(o%).MaxButton '                                 yes, set flag
  699.                     END IF
  700.                 END IF
  701.                 IF WIN(o%).MinButton THEN '                                                  does this window have a minimize button?
  702.                     IF WITHIN(WIN(o%).X + BUT(WIN(o%).MinButton).X,_
  703.                               WIN(o%).Y + BUT(WIN(o%).MinButton).Y,_
  704.                               WIN(o%).X + BUT(WIN(o%).MinButton).X + BUT(WIN(o%).MinButton).Width - 1,_
  705.                               WIN(o%).Y + BUT(WIN(o%).MinButton).Y + BUT(WIN(o%).MinButton).Height - 1) THEN ' yes, on button?
  706.                         MOUSE.OnButton = WIN(o%).MinButton '                                 yes, set flag
  707.                     END IF
  708.                 END IF
  709.                 IF MOUSE.OnButton = 0 THEN MOUSE.OnTitlebar = -1 '                           if not on button then must be on title bar
  710.             END IF
  711.             IF WIN(o%).Size THEN '                                                           is window resizable?
  712.                 IF MOUSE.OnSurface + MOUSE.OnTitlebar + MOUSE.OnButton = 0 THEN '             yes, mouse on anything?
  713.                     MOUSE.OnBorder = -1 '                                                    no, mouse must be on a border
  714.                     IF MOUSE.Y <= WIN(o%).Y + WIN(o%).BWidth - 1 THEN '                      on top border?
  715.                         MOUSE.Border = 1 '                                                   yes, set border value
  716.                     ELSEIF MOUSE.Y >= WIN(o%).Y + WIN(o%).Height - WIN(o%).BWidth - 1 THEN ' no, on bottom border?
  717.                         MOUSE.Border = MOUSE.Border + 4 '                                    yes, add border value
  718.                     END IF
  719.                     IF MOUSE.X >= WIN(o%).X + WIN(o%).Width - WIN(o%).BWidth - 1 THEN '      on right border?
  720.                         MOUSE.Border = MOUSE.Border + 2 '                                    yes, add border value
  721.                     ELSEIF MOUSE.X <= WIN(o%).X + WIN(o%).BWidth - 1 THEN '                  no, on left border?
  722.                         MOUSE.Border = MOUSE.Border + 8 '                                    yes, add border value
  723.                     END IF
  724.                     MOUSE.Icon = MOUSE.Border '                                              mouse icon to resize
  725.                 END IF
  726.             END IF
  727.         END IF
  728.     END IF
  729. LOOP UNTIL MOUSE.OnWindow OR c% = UBOUND(WinOrder%) '                                        leave when hovering or entire array scanned
  730. IF MOUSE.LeftClick THEN MOUSE.LeftReleased = 0 '                                             left mouse button currently held down
  731. IF MOUSE.OnWindow AND MOUSE.LeftClick THEN '                                                 is pointer on a window and left button pressed?
  732.     WINDOW_SETFOCUS MOUSE.OnWindow '                                                         yes, this window now has focus
  733.     c% = MOUSEMOVEMENTX '                                                                    seed mouse x offset function
  734.     c% = MOUSEMOVEMENTY '                                                                    seed mouse y offset function
  735.     IF MOUSE.OnTitlebar AND MOUSE.Move = 0 THEN '                                            is pointer on title bar and window not moving?
  736.         MOUSE.Move = MOUSE.OnWindow '                                                        yes, this window can now be moved
  737.         WIN(MOUSE.Move).Move = -1 '                                                          set window state to moving
  738.     ELSEIF MOUSE.OnBorder AND MOUSE.Resize = 0 THEN '                                        is mouse on border and not resizing?
  739.         MOUSE.Resize = MOUSE.OnWindow '                                                      yes, this window can now be resized
  740.         WIN(MOUSE.Resize).Resize = -1 '                                                      set window state to resizing
  741.     ELSEIF MOUSE.OnButton THEN '                                                             pointer on button?
  742.         MOUSE.ButtonPressed = MOUSE.OnButton '                                               yes, button is currently being pressed
  743.         BUT(MOUSE.ButtonPressed).State = -1 '                                                set button state to pressed
  744.     END IF
  745.  
  746.  
  747. '--------------------------------------------------------------------------------------------------------------------------------
  748. '                                                                                                                 WINDOW_SETFOCUS
  749. SUB WINDOW_SETFOCUS (h%)
  750. '
  751. ' h% = handle of window to set focus ******************** NEEDS FIXED for only 1 window
  752. '
  753. SHARED WIN() AS WIN
  754. SHARED WinOrder%()
  755.  
  756. DIM c%
  757. DIM o%
  758.  
  759. IF h% < 1 THEN EXIT SUB '                                                       leave if no window selected
  760. IF WIN(h%).Focus THEN EXIT SUB '                                                leave if window already in focus
  761. IF NOT WIN(h%).Visible THEN EXIT SUB '                                          leave if window is not on screen
  762. DO '                                                                            loop through window order array
  763.     c% = c% + 1 '                                                               increment array index
  764. LOOP UNTIL h% = WinOrder%(c%) OR c% = UBOUND(WinOrder%) '                       leave if window found or end of array reached
  765. IF c% = UBOUND(WinOrder%) AND WinOrder%(c%) <> h% THEN EXIT SUB '               window does not exist, leave subroutine
  766. FOR o% = c% - 1 TO 1 STEP -1 '                                                  cycle through array
  767.     WinOrder%(o% + 1) = WinOrder%(o%) '                                         move windows above h% down one
  768. NEXT o%
  769. WinOrder%(1) = h% '                                                             make this window the new focus
  770. c% = WinOrder%(2)
  771. WIN(h%).Focus = -1 '                                                            this window now has focus
  772.  
  773. _PUTIMAGE (WIN(h%).BWidth, WIN(h%).BWidth), WIN(h%).TBFImage, WIN(h%).Window '  place focused title bar image on window
  774.  
  775. WIN(WinOrder%(2)).Focus = 0 '                                                   previous window lost focus
  776.  
  777. _PUTIMAGE (WIN(c%).BWidth, WIN(c%).BWidth), WIN(c%).TBNFImage, WIN(c%).Window ' unfocused
  778.  
  779.  
  780. '--------------------------------------------------------------------------------------------------------------------------------
  781. '                                                                                                                  WINDOW_DESKTOP
  782. SUB WINDOW_DESKTOP (w%, h%, c~&, i$)
  783. '
  784. ' w%  = desktop width  (0 for default 640 or to use optional desktop image width)
  785. ' h%  = desktop height (0 for default 480 or to use optional desktop image height)
  786. ' c~& = desktop color  (0 for none)
  787. ' i$  = desktop image  (null for none)
  788. '
  789. ' If width and height are supplied then desktop is created with those dimensions and optional desktop image stretched across
  790. '
  791. SHARED DeskTop&
  792.  
  793. DIM Back& ' desktop background image
  794.  
  795. IF w% <> 0 AND h% <> 0 THEN '                                 dimensions supplied?
  796.     DeskTop& = _NEWIMAGE(w%, h%, 32) '                        yes, create desktop screen with dimensions
  797.     IF _FILEEXISTS(i$) THEN '                                 does background image exist?
  798.         Back& = _LOADIMAGE(i$, 32) '                          yes, load background image
  799.         _PUTIMAGE , Back&, DeskTop& '                         put background image on desktop screen
  800.         _FREEIMAGE Back& '                                    background image no longer needed
  801.     ELSE '                                                    no, background image does not exist
  802.         _DEST DeskTop& '                                      draw on desktop screen
  803.         IF c~& <> 0 THEN CLS , c~& ELSE CLS '                 color desktop background
  804.     END IF
  805. ELSE '                                                        no dimensions supplied
  806.     IF _FILEEXISTS(i$) THEN '                                 does background image exist?
  807.         DeskTop& = _LOADIMAGE(i$, 32) '                       yes, use this as the desktop
  808.     ELSE '                                                    no, background image does not exist
  809.         DeskTop& = _NEWIMAGE(640, 480, 32) '                  create default 640x480 desktop screen
  810.         _DEST DeskTop& '                                      draw on desktop screen
  811.         IF c~& <> 0 THEN CLS , c~& ELSE CLS '                 color desktop background
  812.     END IF
  813. SCREEN _NEWIMAGE(_WIDTH(DeskTop&), _HEIGHT(DeskTop&), 32) '   make main screen that matches desktop dimensions
  814. CLS '                                                         clear screen (remove transparency)
  815. _SCREENMOVE _MIDDLE '                                         move screen to the center of the programmer's desktop
  816.  
  817.  
  818. '--------------------------------------------------------------------------------------------------------------------------------
  819. '                                                                                                                  WINDOW_REFRESH
  820. SUB WINDOW_REFRESH ()
  821.  
  822. SHARED WIN() AS WIN ' window array
  823. SHARED BUT() AS BUTTON
  824. SHARED DeskTop&
  825. SHARED WinOrder%()
  826. SHARED POINTER() AS MOUSEPOINTERS
  827. SHARED MOUSE AS MOUSEFLAGS
  828.  
  829. DIM o%
  830. DIM h%
  831.  
  832. IF DeskTop& THEN _PUTIMAGE (0, 0), DeskTop& '                                               place background image if exist
  833. FOR o% = UBOUND(WinOrder%) TO 1 STEP -1 '                                                   cycle through window order eversed
  834.     h% = WinOrder%(o%) '                                                                    get next window handle
  835.     IF WIN(h%).Visible THEN '                                                               is this window visible?
  836.  
  837.         IF WIN(h%).CloseButton THEN BUTTON_PUT WIN(h%).CloseButton, 0, 0, 0 '               draw close button if exist
  838.         IF WIN(h%).MaxButton THEN BUTTON_PUT WIN(h%).MaxButton, 0, 0, 0 '                   draw maximize button if exist
  839.         IF WIN(h%).MinButton THEN BUTTON_PUT WIN(h%).MinButton, 0, 0, 0 '                   draw minimize button if exist
  840.  
  841.         _PUTIMAGE (WIN(h%).X, WIN(h%).Y), WIN(h%).Window '                                  place window onto desktop
  842.     END IF
  843. NEXT o%
  844. _PUTIMAGE (MOUSE.X + POINTER(MOUSE.Icon).X, MOUSE.Y + POINTER(MOUSE.Icon).Y), POINTER(MOUSE.Icon).Icon ' place mouse pointer
  845.  
  846.  
  847. '--------------------------------------------------------------------------------------------------------------------------------
  848. '                                                                                                                      WINDOW_PUT
  849. SUB WINDOW_PUT (h%, x%, y%, m%)
  850. '
  851. ' h% - handle of window to move
  852. ' x% - new window x coordinate
  853. ' y% - new window y coordinate
  854. ' m% - method of move (by work space origin coordinates (BYSCREEN) or by entire window origin coordinates (BYWINDOW))
  855. '
  856. SHARED WIN() AS WIN ' window array
  857.  
  858. IF m% THEN '                                                BYSCREEN
  859.     WIN(h%).X = x% - WIN(h%).BWidth
  860.     WIN(h%).Y = y% - WIN(h%).BWidth - WIN(h%).TBHeight
  861. ELSE '                                                      BYWINDOW
  862.     WIN(h%).X = x%
  863.     WIN(h%).Y = y%
  864.  
  865. 'IF WIN(h%).Visible THEN WINDOW_SETFOCUS h% ' *************************************** focus routine needs fixing for only 1 window
  866.  
  867.  
  868. '--------------------------------------------------------------------------------------------------------------------------------
  869. '                                                                                                                     WINDOW_MAKE
  870. SUB WINDOW_MAKE (h%)
  871. '
  872. ' h% - handle of window to create
  873. '
  874. SHARED WIN() AS WIN ' window array
  875. SHARED MOUSE AS MOUSEFLAGS
  876. SHARED BUT() AS BUTTON '             needed?
  877.  
  878. DIM p&(1)
  879. DIM c% '                  generic counter
  880. DIM Red!, Green!, Blue!
  881. DIM Redinc!, Greeninc!, Blueinc!
  882. DIM x%, y%
  883.  
  884. DIM CurrentDest&
  885.  
  886. p&(0) = 43690 '                                                                             scroll bar background pattern 1
  887. p&(1) = 21845 '                                                                             scroll bar background pattern 2
  888.  
  889. CurrentDest& = _DEST '                                                                      remember calling destination
  890.  
  891. IF WIN(h%).Resize THEN '                                                                    window being resized?
  892.     _FREEIMAGE WIN(h%).Window '                                                             remove window image from RAM
  893.     IF (MOUSE.Border AND 2) OR (MOUSE.Border AND 8) THEN '                                  resizing right or left border?
  894.         _FREEIMAGE WIN(h%).TBFImage '                                                       yes, remove title bar focus image
  895.         _FREEIMAGE WIN(h%).TBNFImage '                                                      remove title bar no focus image
  896.     END IF
  897. ELSE '                                                                                      no, window being created
  898.     CALCULATECOLORS h% '                                                                    calculate window color shades
  899.     WIN(h%).TBHeight = _FONTHEIGHT(WIN(h%).Font) + 8 '                                      calculate title bar height
  900.     WIN(h%).Width = WIN(h%).SWidth + WIN(h%).BWidth * 2 '                                   yes, calculate window width
  901.     WIN(h%).Height = WIN(h%).SHeight + WIN(h%).BWidth * 2 + WIN(h%).TBHeight + 1 '          calculate window height
  902.     WIN(h%).OWidth = WIN(h%).Width
  903.     WIN(h%).OHeight = WIN(h%).Height
  904.     WIN(h%).MaxWidth = WIN(h%).OWidth '                                                     save maximim width of window
  905.     WIN(h%).MaxHeight = WIN(h%).OHeight '                                                   save maximim height of window
  906.     WIN(h%).SurfaceX = WIN(h%).BWidth '                                                      calculate screen x location
  907.     WIN(h%).SurfaceY = WIN(h%).BWidth + WIN(h%).TBHeight '                                   calculate screen y location
  908.  
  909.  
  910.     WIN(h%).CloseButton = BUTTON_NEW(-h%, 0, 0, "CLOSE", 0, 0, 0) '                         create close title bar button
  911.     WIN(h%).MaxButton = BUTTON_NEW(-h%, 0, 0, "MAXIMIZE", 0, 0, 0) '                        create maximize title bar button
  912.     WIN(h%).MinButton = BUTTON_NEW(-h%, 0, 0, "MINIMIZE", 0, 0, 0) '                        create minimize title bar button
  913.     WIN(h%).RestoreButton = BUTTON_NEW(-h%, 0, 0, "RESTORE", 0, 0, 0) '                     create restore title bar button
  914.     WIN(h%).SUButton = BUTTON_NEW(-h%, 1, 0, "SCROLLUP", 0, 0, 0) '                         create scroll bar up button
  915.     WIN(h%).SDButton = BUTTON_NEW(-h%, 1, 0, "SCROLLDOWN", 0, 0, 0) '                       create scroll bar down button
  916.     WIN(h%).SLButton = BUTTON_NEW(-h%, 1, 0, "SCROLLLEFT", 0, 0, 0) '                       create scroll bar left button
  917.     WIN(h%).SRButton = BUTTON_NEW(-h%, 1, 0, "SCROLLRIGHT", 0, 0, 0) '                      create scroll bar right button
  918.     WIN(h%).MinHeight = WIN(h%).TBHeight + WIN(h%).BWidth * 2 + BUT(WIN(h%).SUButton).Height * 4 ' calculate min window height
  919.  
  920.     WIN(h%).TBFImage = _NEWIMAGE(WIN(h%).SWidth, WIN(h%).TBHeight, 32) '                    create title bar with focus
  921.     WIN(h%).TBNFImage = _COPYIMAGE(WIN(h%).TBFImage) '                                      create title bar without focus
  922.     WIN(h%).Surface = _NEWIMAGE(WIN(h%).SWidth, WIN(h%).SHeight, 32) '                       create screen image container
  923.  
  924.  
  925.     BUT(WIN(h%).CloseButton).Y = WIN(h%).BWidth + 2 '                                       close button Y location
  926.     BUT(WIN(h%).MaxButton).Y = WIN(h%).BWidth + 2 '                                         maximize buttun Y location
  927.     BUT(WIN(h%).MinButton).Y = WIN(h%).BWidth + 2 '                                         minimize button Y location
  928.     BUT(WIN(h%).RestoreButton).Y = WIN(h%).BWidth + 2 '                                     restore button Y location
  929.     BUT(WIN(h%).SUButton).Y = WIN(h%).BWidth + WIN(h%).TBHeight + 1 '                       scroll up button Y location
  930.     BUT(WIN(h%).SLButton).X = WIN(h%).BWidth '                                              scroll left button X location
  931.  
  932.  
  933. WIN(h%).Window = _NEWIMAGE(WIN(h%).Width, WIN(h%).Height, 32) '                             create window image container
  934.  
  935.  
  936. BUT(WIN(h%).CloseButton).X = WIN(h%).Width - WIN(h%).BWidth - BUT(WIN(h%).CloseButton).Width - 2 ' close button X location
  937. BUT(WIN(h%).MaxButton).X = BUT(WIN(h%).CloseButton).X - BUT(WIN(h%).MaxButton).Width - 2 '  maximize button X location
  938. BUT(WIN(h%).MinButton).X = BUT(WIN(h%).MaxButton).X - BUT(WIN(h%).MinButton).Width '        minimize button X location
  939. BUT(WIN(h%).RestoreButton).X = BUT(WIN(h%).MaxButton).X '                                   restore button X location
  940.  
  941.  
  942. BUT(WIN(h%).SUButton).X = BUT(WIN(h%).CloseButton).X '                                      scroll up buttom X location
  943. BUT(WIN(h%).SDButton).X = BUT(WIN(h%).CloseButton).X '                                      scroll down button X location
  944. BUT(WIN(h%).SRButton).X = BUT(WIN(h%).CloseButton).X '                                      scroll right button X location
  945. BUT(WIN(h%).SDButton).Y = WIN(h%).Height - WIN(h%).BWidth - BUT(WIN(h%).SDButton).Height '  scroll down button Y location
  946. BUT(WIN(h%).SLButton).Y = WIN(h%).Height - WIN(h%).BWidth - BUT(WIN(h%).SDButton).Height '  scroll left button Y location
  947. BUT(WIN(h%).SRButton).Y = BUT(WIN(h%).SLButton).Y '                                         scroll left button X location
  948.  
  949.  
  950. IF NOT (WIN(h%).Resize AND ((MOUSE.Border = 1) OR (MOUSE.Border = 4))) THEN '               resizing right or left border?
  951.     WIN(h%).TBFImage = _NEWIMAGE(WIN(h%).SWidth, WIN(h%).TBHeight, 32) '                    yes, create title bar with focus
  952.     WIN(h%).TBNFImage = _COPYIMAGE(WIN(h%).TBFImage) '                                      create title bar without focus
  953.     TBIMAGE h%, 0 '                                                                         draw focused image
  954.     TBIMAGE h%, 1 '                                                                         draw unfocused image
  955.  
  956.  
  957. _DEST WIN(h%).Window '                                                                      draw on window image
  958. CLS , WIN(h%).Lighter '                                                                     clear window image
  959. IF WIN(h%).Focus THEN '                                                             does this window have focus?
  960.     _PUTIMAGE (WIN(h%).BWidth, WIN(h%).BWidth), WIN(h%).TBFImage, WIN(h%).Window '  yes, draw focused title bar
  961. ELSE '                                                                              no
  962.     _PUTIMAGE (WIN(h%).BWidth, WIN(h%).BWidth), WIN(h%).TBNFImage, WIN(h%).Window ' draw unfocused title bar
  963.  
  964.  
  965.  
  966.  
  967.  
  968. IF WIN(h%).SWidth < WIN(h%).SIWidth THEN
  969.  
  970.     BUT(WIN(h%).SDButton).Y = BUT(WIN(h%).SDButton).Y - BUT(WIN(h%).SDButton).Height '      yes, adjust scroll down button Y
  971.  
  972.     LINE (BUT(WIN(h%).SLButton).X + BUT(WIN(h%).SLButton).Width - 1, BUT(WIN(h%).SLButton).Y)-(BUT(WIN(h%).SRButton).X, BUT(WIN(h%).SRButton).Y + BUT(WIN(h%).SRButton).Height - 1), _RGB32(255, 255, 255), BF
  973.     FOR y% = BUT(WIN(h%).SLButton).Y TO BUT(WIN(h%).SLButton).Y + BUT(WIN(h%).SLButton).Height - 1
  974.         LINE (BUT(WIN(h%).SLButton).X + BUT(WIN(h%).SLButton).Width - 1, y%)-(BUT(WIN(h%).SRButton).X, y%), _RGB32(212, 208, 200), , p&(y% AND 1) ' alternate odd/even pattern
  975.     NEXT y%
  976.     BUTTON_PUT WIN(h%).SLButton, 0, 0, 0
  977.     BUTTON_PUT WIN(h%).SRButton, 0, 0, 0
  978.  
  979. IF WIN(h%).SHeight < WIN(h%).SIHeight THEN
  980.  
  981.     BUT(WIN(h%).SRButton).X = BUT(WIN(h%).SRButton).X - BUT(WIN(h%).SRButton).Width '       yes, adjust scroll right button X
  982.  
  983.     LINE (BUT(WIN(h%).SUButton).X, BUT(WIN(h%).SUButton).Y + BUT(WIN(h%).SUButton).Height)-(BUT(WIN(h%).SDButton).X + BUT(WIN(h%).SDButton).Width - 1, BUT(WIN(h%).SDButton).Y), _RGB32(255, 255, 255), BF
  984.     FOR x% = BUT(WIN(h%).SUButton).X TO BUT(WIN(h%).SUButton).X + BUT(WIN(h%).SUButton).Width - 1
  985.         LINE (x%, BUT(WIN(h%).SUButton).Y + BUT(WIN(h%).SUButton).Height)-(x%, BUT(WIN(h%).SDButton).Y), _RGB32(212, 208, 200), , p&(x% AND 1)
  986.     NEXT x%
  987.     BUTTON_PUT WIN(h%).SUButton, 0, 0, 0
  988.     BUTTON_PUT WIN(h%).SDButton, 0, 0, 0
  989.  
  990.  
  991.  
  992. '**
  993. '** Calculate where screen needs to sit inside viewport
  994. '**
  995. '** place window at viewport
  996. '**
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003. IF WIN(h%).BWidth THEN '                                                                    draw a border?
  1004.     IF WIN(h%).BWidth = 1 THEN '                                                            yes, 1 pixel border?
  1005.         LINE (WIN(h%).Width - 1, 0)-(WIN(h%).Width - 1, WIN(h%).Height - 1), WIN(h%).Dark ' yes, draw border
  1006.         LINE -(0, WIN(h%).Height - 1), WIN(h%).Dark
  1007.     END IF
  1008.     IF WIN(h%).BWidth = 2 THEN '                                                            2 pixel border?
  1009.         LINE (0, 0)-(WIN(h%).Width - 1, WIN(h%).Height - 1), WIN(h%).Dark, B '              yes, draw bottom and right border
  1010.         LINE (0, 0)-(WIN(h%).Width - 2, WIN(h%).Height - 2), WIN(h%).Light, B '             draw top and left border
  1011.     END IF
  1012.     IF WIN(h%).BWidth > 2 THEN '                                                            more than 2 pixel border?
  1013.         LINE (0, 0)-(WIN(h%).Width - 1, WIN(h%).Height - 1), WIN(h%).Darker, B '            yes, draw bottom and right border
  1014.         LINE (0, 0)-(WIN(h%).Width - 2, WIN(h%).Height - 2), WIN(h%).Lighter, B '           draw top and left border
  1015.         LINE (1, 1)-(WIN(h%).Width - 2, WIN(h%).Height - 2), WIN(h%).Dark, B '              draw bottom and right middle border
  1016.         LINE (1, 1)-(WIN(h%).Width - 3, WIN(h%).Height - 3), WIN(h%).Light, B '             draw top and left middle border
  1017.         LINE (2, 2)-(WIN(h%).Width - 3, WIN(h%).Height - 3), WIN(h%).WColor, B
  1018.     END IF
  1019.     IF WIN(h%).BWidth > 3 THEN '                                                            more than 3 pixel border?
  1020.         LINE (WIN(h%).BWidth - 1, WIN(h%).BWidth - 1)-(WIN(h%).Width - WIN(h%).BWidth, WIN(h%).Height - WIN(h%).BWidth), WIN(h%).Light, B
  1021.         LINE (WIN(h%).BWidth - 1, WIN(h%).BWidth - 1)-(WIN(h%).Width - WIN(h%).BWidth - 1, WIN(h%).Height - WIN(h%).BWidth - 1), WIN(h%).Dark, B
  1022.     END IF
  1023.  
  1024.     LINE (WIN(h%).BWidth, WIN(h%).BWidth + WIN(h%).TBHeight)-(WIN(h%).Width - WIN(h%).BWidth - 1, WIN(h%).BWidth + WIN(h%).TBHeight), _RGB32(0, 0, 0)
  1025.  
  1026.  
  1027.  
  1028. _DEST CurrentDest&
  1029.  
  1030.  
  1031. '--------------------------------------------------------------------------------------------------------------------------------
  1032. '                                                                                                                      WINDOW_NEW
  1033. FUNCTION WINDOW_NEW (w%, h%)
  1034. '
  1035. ' w% = width of window work space
  1036. ' h% = height of window work space
  1037. '
  1038. ' returns = integer handle number to reference window with
  1039. '
  1040. SHARED WIN() AS WIN ' window array
  1041. SHARED WinOrder%()
  1042. SHARED QB64Icon&
  1043.  
  1044. DIM i% ' next available window array index
  1045. DIM c% ' generic counter
  1046.  
  1047. i% = UBOUND(WIN) '                                 get last window index
  1048. WHILE NOT WIN(i%).InUse AND i% > 1 '               is window in use?
  1049.     REDIM _PRESERVE WIN(i% - 1) AS WIN '           no, remove it
  1050.     i% = i% - 1 '                                  go to previous index
  1051. i% = 0 '                                           start at beginning
  1052. c% = 1
  1053. DO '                                               cycle through window indexes
  1054.     IF NOT WIN(c%).InUse THEN '                    window is use?
  1055.         i% = c% '                                  no, use this index
  1056.     ELSE '                                         yes
  1057.         c% = c% + 1 '                              increment index counter
  1058.         IF c% > UBOUND(WIN) THEN '                 reached end of windows?
  1059.             REDIM _PRESERVE WIN(c%) AS WIN '       yes, create a new window
  1060.             i% = c% '                              use this index
  1061.         END IF
  1062.     END IF
  1063. LOOP UNTIL i% '                                    leave when available index found
  1064. WIN(i%).InUse = -1 '                               mark index as used
  1065. WIN(i%).Visible = 0 '                              set window invisible
  1066.  
  1067. WIN(i%).SIWidth = w% '                             set screen image width
  1068. WIN(i%).SIHeight = h% '                            set screen image height
  1069. WIN(i%).SWidth = w% '                              set window screen width
  1070. WIN(i%).SHeight = h% '                             set window screen  height
  1071.  
  1072. WIN(i%).X = 0 '                                    set window x location
  1073. WIN(i%).Y = 0 '                                    set window y location
  1074. WIN(i%).BWidth = 3 '                               set border width
  1075. WIN(i%).Font = _FONT
  1076. WIN(i%).Title = ""
  1077. WIN(i%).Icon = QB64Icon&
  1078. WIN(i%).WColor = _RGB32(212, 208, 200) '           set window color
  1079. WIN(i%).TBColor = _RGB32(10, 40, 100) '            set title bar color
  1080. WIN(i%).TTColor = _RGB32(255, 255, 255) '          set title bar text color
  1081. WIN(i%).TBSolid = -1
  1082. WIN(i%).Shadow = 0 '                               set window shadow (off)
  1083. WIN(i%).Focus = 0 '                                set window without focus
  1084. WIN(i%).Move = 0
  1085. WIN(i%).Resize = 0
  1086. WIN(i%).Size = 0
  1087. WIN(i%).CloseButton = 0
  1088. WIN(i%).MaxButton = 0
  1089. WIN(i%).MinButton = 0
  1090. WIN(i%).RestoreButton = 0
  1091. WIN(i%).SUButton = 0
  1092. WIN(i%).SDButton = 0
  1093. WIN(i%).SLButton = 0
  1094. WIN(i%).SRButton = 0
  1095. WIN(i%).Maximized = 0
  1096. WIN(i%).Minimized = 0
  1097. REDIM _PRESERVE WinOrder%(UBOUND(WinOrder%) + 1) ' increase window order array
  1098. WinOrder%(UBOUND(WinOrder%)) = i% '                add window to order array
  1099. WINDOW_NEW = i% '                                  return window handle
  1100.  
  1101.  
  1102.  
  1103. '--------------------------------------------------------------------------------------------------------------------------------
  1104. '                                                                                                                 WINDOW_SETTITLE
  1105. SUB WINDOW_SETTITLE (h%, t$)
  1106.  
  1107. SHARED WIN() AS WIN ' window array
  1108.  
  1109. WIN(h%).Title = t$ '                                                               set title of window
  1110.  
  1111.  
  1112. '--------------------------------------------------------------------------------------------------------------------------------
  1113. '                                                                                                                  WINDOW_SETFONT
  1114. SUB WINDOW_SETFONT (h%, f&)
  1115.  
  1116. SHARED WIN() AS WIN ' window array
  1117.  
  1118. WIN(h%).Font = f& '                                                                set window font
  1119.  
  1120.  
  1121. '--------------------------------------------------------------------------------------------------------------------------------
  1122. '                                                                                                                WINDOW_SETBORDER
  1123. SUB WINDOW_SETBORDER (h%, w%)
  1124.  
  1125. SHARED WIN() AS WIN ' window array
  1126.  
  1127. WIN(h%).BWidth = w%
  1128.  
  1129.  
  1130. '--------------------------------------------------------------------------------------------------------------------------------
  1131. '                                                                                                                 WINDOW_SETCOLOR
  1132. SUB WINDOW_SETCOLOR (h%, c~&)
  1133.  
  1134. SHARED WIN() AS WIN ' window array
  1135.  
  1136. WIN(h%).WColor = c~& '                                              set window color
  1137.  
  1138.  
  1139. '--------------------------------------------------------------------------------------------------------------------------------
  1140. '                                                                                                         WINDOW_SETTITLEBARCOLOR
  1141. SUB WINDOW_SETTITLEBARCOLOR (h%, c~&)
  1142.  
  1143. SHARED WIN() AS WIN ' window array
  1144.  
  1145. WIN(h%).TBColor = c~& '                                               set title bar color
  1146.  
  1147.  
  1148. '--------------------------------------------------------------------------------------------------------------------------------
  1149. '                                                                                                                     WINDOW_SHOW
  1150. SUB WINDOW_SHOW (h%)
  1151.  
  1152. SHARED WIN() AS WIN ' window array
  1153.  
  1154. WIN(h%).Visible = -1
  1155.  
  1156.  
  1157. '--------------------------------------------------------------------------------------------------------------------------------
  1158. '                                                                                                                     WINDOW_HIDE
  1159. SUB WINDOW_HIDE (h%)
  1160.  
  1161. SHARED WIN() AS WIN ' window array
  1162.  
  1163. WIN(h%).Visible = 0
  1164.  
  1165.  
  1166. '--------------------------------------------------------------------------------------------------------------------------------
  1167. '                                                                                                                        POINTERS
  1168. SUB POINTERS ()
  1169.  
  1170. SHARED POINTER() AS MOUSEPOINTERS
  1171.  
  1172. DIM Icon$
  1173.  
  1174. Icon$ = "b           bb          bwb         bwwb        bwwwb       bwwwwb      bwwwwwb     bwwwwwwb    "+_
  1175.         "bwwwwwwwb   bwwwwwwwwb  bwwwwwwwwwb bwwwwwwbbbbbbwwwbwwb    bwwbbwwb    bwb  bwwb   bb   bwwb   "+_
  1176.         "b     bwwb        bwwb         bwwb        bwwb         bb  "
  1177. MAKEICON 0, Icon$, 12, 21, 0, 0 ' default - 12x21 - offset 0,0
  1178. Icon$ = "    w       wbw     wbbbw   wbbbbbw wbbbbbbbwwwwwbwwww   wbw      wbw      wbw      wbw   "+_
  1179.         "   wbw      wbw      wbw      wbw      wbw   wwwwbwwwwwbbbbbbbw wbbbbbw   wbbbw     wbw       w    "
  1180. MAKEICON 1, Icon$, 9, 21, -4, -10 ' NS resize - 9x21 - offset 5,11
  1181. Icon$ = "    ww         ww       wbw         wbw     wbbw         wbbw   wbbbwwwwwwwwwwwbbbw wbbbbbbbbbbbbbbbbbbbw"+_
  1182.         " wbbbwwwwwwwwwwwbbbw   wbbw         wbbw     wbw         wbw       ww         ww    "
  1183. MAKEICON 2, Icon$, 21, 9, -10, -4 ' EW resize - 21x9 - offset 11,5
  1184. Icon$ = "        wwwwwww        wbbbbbw         wbbbbw          wbbbw         wbwbbw        wbw wbw"+_
  1185.         "       wbw   ww      wbw      ww   wbw       wbw wbw        wbbwbw         wbbbw          "+_
  1186.         "wbbbbw         wbbbbbw        wwwwwww        "
  1187. MAKEICON 3, Icon$, 15, 15, -7, -7 ' NESW resize - 15x15 - offset 8,8
  1188. Icon$ = "     bb              bwwb             bwwb             bwwb             bwwb             bwwbbb       "+_
  1189.         "    bwwbwwbbb        bwwbwwbwwbb      bwwbwwbwwbwb bbb bwwbwwbwwbwwbbwwbbwwwwwwwwbwwbbwwwbwwwwwwwwwwwb"+_
  1190.         " bwwbwwwwwwwwwwwb  bwbwwwwwwwwwwwb  bwwwwwwwwwwwwwb   bwwwwwwwwwwwwb   bwwwwwwwwwwwb     bwwwwwwwwwwb "+_
  1191.         "    bwwwwwwwwwwb      bwwwwwwwwb       bwwwwwwwwb       bbbbbbbbbb  "
  1192. MAKEICON 5, Icon$, 17, 22, -5, 0 ' pointer (hand) - 17x22 - offset 6,0
  1193. Icon$ = "wwwwwww        wbbbbbw        wbbbbw         wbbbw          wbbwbw         wbw wbw        "+_
  1194.         "ww   wbw             wbw             wbw   ww        wbw wbw         wbwbbw          wbbbw"+_
  1195.         "         wbbbbw        wbbbbbw        wwwwwww"
  1196. MAKEICON 6, Icon$, 15, 15, -7, -7 ' NWSE resize - 15x15 - offset 8,8
  1197. Icon$ = "bbbbbbbbbbbbbbbwwwwwwwwwbbbbbbbbbbbbbbb bwwwwwwwwwb  bwwwwwwwwwb  bwwbwbwbwwb  bwwwbwbwwwb "+_
  1198.         " bbwwwbwwwbb   bbwwwwwbb     bbwbwbb       bbwbb        bbwbb       bbwwwbb     bbwwbwwbb  "+_
  1199.         " bbwwwwwwwbb  bwwwwbwwwwb  bwwwbwbwwwb  bwwbwbwbwwb  bwbwbwbwbwb bbbbbbbbbbbbbbbwwwwwwwwwbbbbbbbbbbbbbbb"
  1200. MAKEICON 7, Icon$, 13, 22, -6, -10 ' wait - 13x22 - offset 7,11
  1201. Icon$ = "          w                   wbw                 wbbbw               wbbbbbw             wbbbbbbbw      "+_
  1202.         "      wwwwbwwww          ww   wbw   ww       wbw   wbw   wbw     wbbw   wbw   wbbw   wbbbwwwwwbwwwwwbbbw "+_
  1203.         "wbbbbbbbbbbbbbbbbbbbw wbbbwwwwwbwwwwwbbbw   wbbw   wbw   wbbw     wbw   wbw   wbw       ww   wbw   ww    "+_
  1204.         "      wwwwbwwww            wbbbbbbbw             wbbbbbw               wbbbw                 wbw         "+_
  1205.         "          w          "
  1206. MAKEICON 10, Icon$, 21, 21, -10, -10 ' move - 21x21 - offset 11,11
  1207. Icon$ = "        www                wbw                wbw                wbw                wbw        "+_
  1208.         "        wbw                wbw                wbw        wwwwwwwwwbwwwwwwwwwwbbbbbbbbbbbbbbbbbw"+_
  1209.         "wwwwwwwwwbwwwwwwwww        wbw                wbw                wbw                wbw        "+_
  1210.         "        wbw                wbw                wbw                www        "
  1211. MAKEICON 11, Icon$, 19, 19, -9, -9 ' crosshair - 19x19 - offset 10,10
  1212. Icon$ = "wwww wwwwwbbbwbbbwwwwwbwwww   wbw      wbw      wbw      wbw      wbw      wbw      wbw   "+_
  1213.         "   wbw      wbw      wbw      wbw      wbw   wwwwbwwwwwbbbwbbbwwwww wwww"
  1214. MAKEICON 13, Icon$, 9, 18, -4, -8 ' text - 9x18 - offset 5,9
  1215. Icon$ = "       wwwwww            wwbbbbbbww         wbbbbbbbbbbw       wbbbbwwwwbbbbw     wbbbww    wwbbbw  "+_
  1216.         " wbbbbbw      wbbbw  wbbwbbbw      wbbw wbbbwwbbbw     wbbbwwbbw  wbbbw     wbbwwbbw   wbbbw    wbbw"+_
  1217.         "wbbw    wbbbw   wbbwwbbw     wbbbw  wbbwwbbbw     wbbbwwbbbw wbbw      wbbbwbbw  wbbbw      wbbbbbw "+_
  1218.         "  wbbbww    wwbbbw     wbbbbwwwwbbbbw       wbbbbbbbbbbw         wwbbbbbbww            wwwwww       "
  1219. MAKEICON 14, Icon$, 20, 20, -9, -9 ' not-allowed - 20x20 - offset 10,10
  1220. Icon$ = "11111111111111111111121133333331144444444112113355533114455554411211335553311445555441121133555331144444441112"+_
  1221.         "11335553311444444411121133555331144555544112113355533114455554411211333333311444444441121133333331144444444112"+_
  1222.         "11113331111111111111121111111111111111111112116666666117711117711211661111111771111771121166111111177111177112"+_
  1223.         "11666666611777777771121166666661177777777112116655566111111117711211665556611111111771121166666661111111177112"+_
  1224.         "11111111111111111111122222222222222222222222"
  1225. MAKEICON -1, Icon$, 22, 22, 0, 0 ' QB64 - 22x22
  1226.  
  1227. POINTER(4) = POINTER(1)
  1228. POINTER(8) = POINTER(2)
  1229. POINTER(9) = POINTER(6)
  1230. POINTER(12) = POINTER(3)
  1231.  
  1232.  
  1233.  
  1234. '--------------------------------------------------------------------------------------------------------------------------------
  1235. '                                                                                                                        MAKEICON
  1236. SUB MAKEICON (n%, i$, w%, h%, xo%, yo%)
  1237.  
  1238. SHARED POINTER() AS MOUSEPOINTERS
  1239. SHARED QB64Icon&
  1240.  
  1241. DIM x%
  1242. DIM y%
  1243. DIM p$
  1244. DIM c%
  1245.  
  1246. IF n% = -1 THEN
  1247.     QB64Icon& = _NEWIMAGE(22, 22, 32)
  1248.     _DEST QB64Icon&
  1249.     POINTER(n%).Icon = _NEWIMAGE(w%, h%, 32)
  1250.     POINTER(n%).X = xo%
  1251.     POINTER(n%).Y = yo%
  1252.     _DEST POINTER(n%).Icon
  1253. FOR y% = 0 TO h% - 1
  1254.     FOR x% = 0 TO w% - 1
  1255.         c% = c% + 1
  1256.         p$ = MID$(i$, c%, 1)
  1257.         IF p$ = "b" THEN PSET (x%, y%), _RGB32(0, 0, 1)
  1258.         IF p$ = "w" THEN PSET (x%, y%), _RGB32(255, 255, 255)
  1259.         IF p$ = "1" THEN PSET (x%, y%), _RGB32(0, 0, 252)
  1260.         IF p$ = "2" THEN PSET (x%, y%), _RGB32(0, 0, 112)
  1261.         IF p$ = "3" THEN PSET (x%, y%), _RGB32(0, 188, 252)
  1262.         IF p$ = "4" THEN PSET (x%, y%), _RGB32(0, 124, 252)
  1263.         IF p$ = "5" THEN PSET (x%, y%), _RGB32(0, 0, 168)
  1264.         IF p$ = "6" THEN PSET (x%, y%), _RGB32(252, 188, 0)
  1265.         IF p$ = "7" THEN PSET (x%, y%), _RGB32(252, 124, 0)
  1266.     NEXT x%
  1267. NEXT y%
  1268.  
  1269.  
  1270. '--------------------------------------------------------------------------------------------------------------------------------
  1271. '                                                                                                                 CALCULATECOLORS
  1272. SUB CALCULATECOLORS (h%)
  1273.  
  1274. SHARED WIN() AS WIN
  1275.  
  1276. WIN(h%).Wred = _RED(WIN(h%).WColor) '                                                     get RGB components of window color
  1277. WIN(h%).Wgreen = _GREEN(WIN(h%).WColor)
  1278. WIN(h%).Wblue = _BLUE(WIN(h%).WColor)
  1279. WIN(h%).Lighter = _RGB32(WIN(h%).Wred * 1.5, WIN(h%).Wgreen * 1.5, WIN(h%).Wblue * 1.5) ' calculate window/border color shades
  1280. WIN(h%).Light = _RGB32(WIN(h%).Wred * 1.25, WIN(h%).Wgreen * 1.25, WIN(h%).Wblue * 1.25)
  1281. WIN(h%).Dark = _RGB32(WIN(h%).Wred / 1.25, WIN(h%).Wgreen / 1.25, WIN(h%).Wblue / 1.25)
  1282. WIN(h%).Darker = _RGB32(WIN(h%).Wred / 1.5, WIN(h%).Wgreen / 1.5, WIN(h%).Wblue / 1.5)
  1283. WIN(h%).Darkest = _RGB32(WIN(h%).Wred / 2, WIN(h%).Wgreen / 2, WIN(h%).Wblue / 2)
  1284.  
  1285.  
  1286. '--------------------------------------------------------------------------------------------------------------------------------
  1287. '                                                                                                                  MOUSEMOVEMENTY
  1288. FUNCTION MOUSEMOVEMENTY ()
  1289. '
  1290. ' returns the mouse y coordinate difference between calls
  1291. '
  1292. SHARED MOUSE AS MOUSEFLAGS
  1293.  
  1294. STATIC y% ' previous call's mouse y coordinate (saved between calls)
  1295.  
  1296. MOUSEMOVEMENTY = MOUSE.Y - y% ' calculate mouse y offset from previous call
  1297. y% = MOUSE.Y '                  save current mouse y coordinate
  1298.  
  1299.  
  1300. '--------------------------------------------------------------------------------------------------------------------------------
  1301. '                                                                                                                  MOUSEMOVEMENTX
  1302. FUNCTION MOUSEMOVEMENTX ()
  1303. '
  1304. ' returns the mouse x coordinate difference between calls
  1305. '
  1306. SHARED MOUSE AS MOUSEFLAGS
  1307.  
  1308. STATIC x% ' previous call's mouse x coordinate (saved between calls)
  1309.  
  1310. MOUSEMOVEMENTX = MOUSE.X - x% ' calculate mouse x offset from previous call
  1311. x% = MOUSE.X '                  save current mouse x coordinate
  1312.  
  1313.  
  1314.  
  1315.  
Title: Re: child windows into window of the program: a demonstration
Post by: keybone on February 19, 2020, 03:19:59 pm
I was tinkering around with GUI structures a few years back. Here is the code. It may give you some ideas for your code. You can resize the windows by clicking and holding the bottom right corner of the window, just like Windows.

Code: QB64: [Select]
  1. 'GUI 02/27/16
  2.  
  3. CONST BYWINDOW = 0
  4. CONST BYSCREEN = -1
  5. CONST ALLWINDOWS = 0
  6.  
  7. TYPE MOUSEFLAGS
  8.     OnWindow AS INTEGER '              current window pointer is hovering over
  9.     Icon AS INTEGER '                  current mouse pointer icon
  10.     X AS INTEGER '                     current desktop mouse x coordinate
  11.     Y AS INTEGER '                     current desktop mouse y coordinate
  12.     PX AS INTEGER '                    previous desktop mouse x coordinate
  13.     PY AS INTEGER '                    previous desktop mouse y coordinate
  14.     WindowX AS INTEGER '               current window mouse x coordinate
  15.     WindowY AS INTEGER '               current window mouse y coordinate
  16.     SurfaceX AS INTEGER '              current work space mouse x coordinate
  17.     SurfaceY AS INTEGER '              current work space mouse y coordinate
  18.     OnSurface AS INTEGER '      [BOOL] mouse currently hovering over surface?
  19.     OnTitlebar AS INTEGER '     [BOOL] mouse currently hovering over title bar?
  20.     OnBorder AS INTEGER '       [BOOL] mouse currently hovering over a border?
  21.     Border AS INTEGER '                border(s) mouse hovering (1-top, 2-right, 4-bottom, 8-left ... i.e. 6 = bottom right corner)
  22.     LeftClick AS INTEGER '      [BOOL] mouse left button currently pressed?
  23.     RightClick AS INTEGER '     [BOOL] mouse right button currently pressed?
  24.     Move AS INTEGER '                  window currently in the process of being moved
  25.     Resize AS INTEGER '                current window being resized
  26.     LeftReleased AS INTEGER '   [BOOL] left mouse button released?
  27.     RightReleased AS INTEGER '  [BOOL] right mouse button released?
  28.  
  29.     OnButton AS INTEGER '              current button pointer is hovering over
  30.     ButtonPressed AS INTEGER '         current button being held down
  31.     ButtonClicked AS INTEGER '         button that was clicked then released
  32.  
  33.  
  34.  
  35. TYPE WINDOWFLAGS
  36.     X AS INTEGER '                     x location of current window
  37.     Y AS INTEGER '                     y location of current window
  38.     Width AS INTEGER '                 width of current window
  39.     Height AS INTEGER '                height of current window
  40.     Surface AS LONG '            [IMG]  window surface image
  41.     SurfaceX AS INTEGER '              x location of current work space
  42.     SurfaceY AS INTEGER '              y location of current workspace
  43.     SWidth AS INTEGER '                width of current surface
  44.     SHeight AS INTEGER '               height of current surface
  45.     Focus AS INTEGER '                 the window that has focus
  46.     HasFocus AS INTEGER '       [BOOL] current window has focus?
  47.  
  48. TYPE WIN
  49.     Width AS INTEGER '                 overall window width
  50.     Height AS INTEGER '                overall window height
  51.  
  52.     OWidth AS INTEGER '                original width
  53.     OHeight AS INTEGER
  54.  
  55.     SWidth AS INTEGER '                surface width
  56.     SHeight AS INTEGER '               surface height
  57.  
  58.     SIWidth AS INTEGER '               surface image width
  59.     SIHeight AS INTEGER '              surface image height
  60.  
  61.     MinWidth AS INTEGER
  62.     MaxWidth AS INTEGER
  63.     MinHeight AS INTEGER
  64.     MaxHeight AS INTEGER
  65.  
  66.  
  67.     X AS INTEGER '                     window x location
  68.     Y AS INTEGER '                     window y location
  69.     SurfaceX AS INTEGER '              surface x location
  70.     SurfaceY AS INTEGER '              surface y location
  71.     Font AS LONG '              [FONT] window font
  72.     InUse AS INTEGER '          [BOOL] window in use?
  73.     Window AS LONG '            [IMG]  window image
  74.     Surface AS LONG '           [IMG]  surface image
  75.     BGImage AS LONG '           [IMG]  background image under window
  76.     TBFImage AS LONG '          [IMG]  title bar image when window has focus
  77.     TBNFImage AS LONG '         [IMG]  title bar image when window has lost focus
  78.     Shadow AS INTEGER '         [BOOL] shadow present
  79.     BWidth AS INTEGER '                border width
  80.     TBHeight AS INTEGER '              title bar height
  81.     WColor AS _UNSIGNED LONG '  [CLR]  window color
  82.     Wred AS INTEGER '           [CLR]  red component of Wcolor
  83.     Wgreen AS INTEGER '         [CLR]  green component of Wcolor
  84.     Wblue AS INTEGER '          [CLR]  blue component of Wcolor
  85.     TBColor AS _UNSIGNED LONG ' [CLR]  title bar color
  86.     TTColor AS _UNSIGNED LONG ' [CLR]  title text color
  87.     Title AS STRING * 128 '            window title
  88.     Visible AS INTEGER '        [BOOL] window on screen?
  89.     Focus AS INTEGER '          [BOOL] window has focus?
  90.  
  91.     'ByMethod AS INTEGER '       [BOOL] -1 = window dimensions by surface, 0 = dimensions by window
  92.  
  93.     Move AS INTEGER '           [BOOL] window currently being moved?
  94.     Resize AS INTEGER '         [BOOL] window currently being resized
  95.     Lighter AS _UNSIGNED LONG ' [CLR]  border colors
  96.     Light AS _UNSIGNED LONG '   [CLR]
  97.     Dark AS _UNSIGNED LONG '    [CLR]
  98.     Darker AS _UNSIGNED LONG '  [CLR]
  99.     Darkest AS _UNSIGNED LONG ' [CLR]
  100.     Icon AS LONG '              [IMG]  window icon
  101.     TBSolid AS INTEGER '        [BOOL] solid title bar?
  102.     Size AS INTEGER '           [BOOL] window resizable?
  103.  
  104.     CloseButton AS INTEGER '           0 = no button, >0 = button handle number
  105.     MaxButton AS INTEGER
  106.     MinButton AS INTEGER
  107.     RestoreButton AS INTEGER
  108.     SUButton AS INTEGER
  109.     SDButton AS INTEGER
  110.     SLButton AS INTEGER
  111.     SRButton AS INTEGER
  112.  
  113.     Maximized AS INTEGER '             -1 window currently maximized, 0 = normal  (use 'state' instead for max/min/normal?)
  114.     Minimized AS INTEGER '             -1 window currently minimized
  115.  
  116.     Rwidth AS INTEGER '                restore width  (when max or min - values to restore window size)
  117.     Rheight AS INTEGER '               restore height
  118.  
  119.  
  120. TYPE BUTTON
  121.     InUse AS INTEGER '          [BOOL] button in use?
  122.     X AS INTEGER
  123.     Y AS INTEGER
  124.     Height AS INTEGER
  125.     State AS INTEGER '                 state of button: -1 = pressed, 0 = normal, 1 = disabled
  126.     Normal AS LONG '            [IMG]  normal button
  127.     Pressed AS LONG '           [IMG]  pressed button
  128.     Disabled AS LONG '          [IMG]  disabled button
  129.     Window AS INTEGER '                window button belongs to
  130.     WinButton AS INTEGER '      [BOOL] indicates a button for window use only (scroll bar buttons, etc..)
  131.  
  132. TYPE MOUSEPOINTERS
  133.     Icon AS LONG '              [IMG]  mouse pointer image
  134.     X AS INTEGER '                     x offset of pointer
  135.     Y AS INTEGER '                     y offset of pointer
  136.  
  137. REDIM WIN(1) AS WIN
  138. REDIM BUT(1) AS BUTTON
  139. REDIM WinOrder%(0)
  140. DIM POINTER(15) AS MOUSEPOINTERS
  141. DIM QB64Icon&
  142. DIM WIN AS WINDOWFLAGS
  143. DIM MOUSE AS MOUSEFLAGS
  144.  
  145. DIM DeskTop&
  146.  
  147. DIM untitled%(10)
  148.  
  149.  
  150. POINTERS
  151.  
  152. WINDOW_DESKTOP 1024, 768, 0, ""
  153.  
  154.  
  155.  
  156.  
  157. 'FOR i% = 1 TO 10
  158. '    untitled%(i%) = WINDOW_NEW(320, 240)
  159. '    WINDOW_SETTITLE untitled%(i%), "Untitled-" + LTRIM$(STR$(i%))
  160. '    WIN(untitled%(i%)).TBSolid = 0
  161. '    WINDOW_MAKE untitled%(i%)
  162. '    WINDOW_SHOW untitled%(i%)
  163. '    WINDOW_PUT untitled%(i%), 140 + i% * 25, 20 + i% * 25, BYWINDOW
  164. '    WIN(untitled%(i%)).Size = -1
  165. 'NEXT i%
  166.  
  167.  
  168. untitled1% = WINDOW_NEW(640, 480)
  169. untitled2% = WINDOW_NEW(320, 240)
  170. untitled3% = WINDOW_NEW(160, 120)
  171.  
  172. WINDOW_SETTITLE untitled1%, "Untitled-1"
  173. WINDOW_SETTITLE untitled2%, "Untitled-2"
  174. WINDOW_SETTITLE untitled3%, "Untitled-3"
  175.  
  176. WIN(untitled2%).TBSolid = 0 '                    need to create library command for this
  177.  
  178.  
  179. WINDOW_MAKE untitled3%
  180. WINDOW_MAKE untitled2%
  181. WINDOW_MAKE untitled1%
  182.  
  183. WINDOW_SHOW untitled1%
  184. WINDOW_SHOW untitled2%
  185. WINDOW_SHOW untitled3%
  186.  
  187. WINDOW_PUT untitled3%, 150, 25, BYWINDOW
  188. WINDOW_PUT untitled2%, 200, 100, BYWINDOW
  189. WINDOW_PUT untitled1%, 300, 200, BYWINDOW
  190.  
  191.  
  192. WIN(untitled1%).Size = -1 '                      need to create library command for this
  193. WIN(untitled2%).Size = -1 '                      need to create library command for this
  194. WIN(untitled3%).Size = -1 '                      need to create library command for this
  195.  
  196.  
  197.     IF _MOUSEINPUT THEN WINDOW_MOUSE
  198.     WINDOW_REFRESH
  199.     LOCATE 1, 1
  200.     PRINT " Focus ------> "; WinOrder%(1)
  201.     PRINT " Mouse X ----> "; MOUSE.X
  202.     PRINT " Mouse Y ----> "; MOUSE.Y
  203.     PRINT " On Window --> "; MOUSE.OnWindow
  204.     PRINT " Window X ---> "; MOUSE.WindowX
  205.     PRINT " Window Y ---> "; MOUSE.WindowY
  206.     PRINT " On Surface -> "; MOUSE.OnSurface
  207.     PRINT " Surface X---> "; MOUSE.SurfaceX
  208.     PRINT " Surface Y --> "; MOUSE.SurfaceY
  209.     PRINT " On TitleBar > "; MOUSE.OnTitlebar
  210.     PRINT " On Border --> "; MOUSE.OnBorder
  211.     PRINT " Border -----> "; MOUSE.Border
  212.     PRINT " Left Click -> "; MOUSE.LeftClick
  213.     PRINT " Right Click > "; MOUSE.RightClick
  214.     PRINT " Moving -----> "; MOUSE.Move
  215.     PRINT " Resizing ---> "; MOUSE.Resize
  216.     PRINT " On Button --> "; MOUSE.OnButton
  217.     PRINT " Button Press> "; MOUSE.ButtonPressed
  218.     PRINT " Button Click> "; MOUSE.ButtonClicked
  219.     _DISPLAY
  220.  
  221.  
  222.  
  223.  
  224.  
  225. '--------------------------------------------------------------------------------------------------------------------------------
  226. '                                                                                                                         TBIMAGE
  227. SUB TBIMAGE (h%, f%)
  228.  
  229. ' h% = window handle
  230. ' f% = focus 1, no focus 0
  231.  
  232. SHARED WIN() AS WIN ' window array
  233. SHARED BUT() AS BUTTON
  234.  
  235. DIM c% '                  generic counter
  236. DIM Red!, Green!, Blue!
  237. DIM Redinc!, Greeninc!, Blueinc!
  238.  
  239. IF f% THEN
  240.     _DEST WIN(h%).TBFImage '                                                                draw on title bar focus image
  241.     _FONT WIN(h%).Font '                                                                    set title bar font
  242.     _PRINTMODE _KEEPBACKGROUND '                                                            font will be transparent
  243.     COLOR WIN(h%).TTColor '                                                                 set font color
  244.     CLS , WIN(h%).TBColor '                                                             yes, color title bar
  245.     IF NOT WIN(h%).TBSolid THEN
  246.         Red! = _RED(WIN(h%).TBColor) '                                                      get title bar color components
  247.         Green! = _GREEN(WIN(h%).TBColor)
  248.         Blue! = _BLUE(WIN(h%).TBColor)
  249.         Redinc! = (255 - Red!) / WIN(h%).SWidth / 2 '                                       calculate color fade values
  250.         Greeninc! = (255 - Green!) / WIN(h%).SWidth / 2
  251.         Blueinc! = (255 - Blue!) / WIN(h%).SWidth / 2
  252.     END IF
  253.     _DEST WIN(h%).TBNFImage
  254.     _FONT WIN(h%).Font
  255.     COLOR _RGB32(212, 208, 200)
  256.     CLS , _RGB32(128, 128, 128)
  257.     IF NOT WIN(h%).TBSolid THEN
  258.         Red! = 128
  259.         Green! = 128
  260.         Blue! = 128
  261.         Redinc! = 63 / WIN(h%).SWidth
  262.         Greeninc! = 63 / WIN(h%).SWidth
  263.         Blueinc! = 63 / WIN(h%).SWidth
  264.     END IF
  265. IF NOT WIN(h%).TBSolid THEN
  266.     FOR c% = 0 TO WIN(h%).SWidth - 1
  267.         LINE (c%, 0)-(c%, WIN(h%).TBHeight - 1), _RGB32(Red!, Green!, Blue!)
  268.         Red! = Red! + Redinc!
  269.         Green! = Green! + Greeninc!
  270.         Blue! = Blue! + Blueinc!
  271.     NEXT c%
  272. w% = _PRINTWIDTH("#") + 6
  273.  
  274. IF WIN(h%).CloseButton THEN w% = w% + BUT(WIN(h%).CloseButton).Width
  275. IF WIN(h%).MaxButton THEN w% = w% + BUT(WIN(h%).MaxButton).Width
  276. IF WIN(h%).MinButton THEN w% = w% + BUT(WIN(h%).MinButton).Width
  277.  
  278. mw% = WIN(h%).SWidth - (WIN(h%).TBHeight + 2) - w%
  279. t$ = RTRIM$(WIN(h%).Title)
  280. WIN(h%).MinWidth = _PRINTWIDTH(LEFT$(t$, 3) + "...") + WIN(h%).TBHeight + 2 + w%
  281. nt$ = t$
  282. WHILE _PRINTWIDTH(nt$) > mw%
  283.     t$ = LEFT$(t$, LEN(t$) - 1)
  284.     nt$ = t$ + "..."
  285. _PRINTSTRING (WIN(h%).TBHeight + 2, 4), nt$ '                         print title on title bar
  286. _PUTIMAGE (2, 1)-(WIN(h%).TBHeight - 1, WIN(h%).TBHeight - 2), WIN(h%).Icon '           place icon on title bar
  287.  
  288.  
  289. '--------------------------------------------------------------------------------------------------------------------------------
  290. '                                                                                                                          WITHIN
  291. FUNCTION WITHIN (x%, y%, x2%, y2%)
  292.  
  293. '*
  294. '* Returns true if mouse pointer within given coordinate pairs.
  295. '*
  296.  
  297. SHARED MOUSE AS MOUSEFLAGS
  298.  
  299. IF MOUSE.X >= x% THEN '              mouse pointer inside given rectangle?
  300.     IF MOUSE.X <= x2% THEN
  301.         IF MOUSE.Y >= y% THEN
  302.             IF MOUSE.Y <= y2% THEN
  303.                 WITHIN = -1 '        yes, return true
  304.             END IF
  305.         END IF
  306.     END IF
  307.  
  308.  
  309. '--------------------------------------------------------------------------------------------------------------------------------
  310. '                                                                                                                      BUTTON_PUT
  311. SUB BUTTON_PUT (b%, x%, y%, state%) ' state% needed?
  312.  
  313. SHARED WIN() AS WIN
  314. SHARED BUT() AS BUTTON
  315.  
  316. IF BUT(b%).WinButton THEN '                                                                  is button for window use only?
  317.     SELECT CASE BUT(b%).State '                                                              which state is title bar button in?
  318.         CASE -1 '                                                                            pressed state
  319.             _PUTIMAGE (BUT(b%).X, BUT(b%).Y), BUT(b%).Pressed, WIN(BUT(b%).Window).Window '  draw pressed button on window
  320.         CASE 0 '                                                                             normal (depressed) state
  321.             _PUTIMAGE (BUT(b%).X, BUT(b%).Y), BUT(b%).Normal, WIN(BUT(b%).Window).Window '   draw normal button on window
  322.         CASE 1 '                                                                             disabled state
  323.             _PUTIMAGE (BUT(b%).X, BUT(b%).Y), BUT(b%).Disabled, WIN(BUT(b%).Window).Window ' draw disabled button on window
  324.     END SELECT
  325.  
  326.     '*
  327.     '* Custom made buttons here
  328.     '*
  329.  
  330.  
  331.  
  332. '--------------------------------------------------------------------------------------------------------------------------------
  333. '                                                                                                                      BUTTON_NEW
  334. FUNCTION BUTTON_NEW (win%, w%, h%, t$, f&, c~&, t~&)
  335. '*
  336. '* win% - window button belongs to (negative value sent in means a title bar button is being created)
  337. '* w%   - width of button (ignored if title bar button is being created)
  338. '* h%   - height of button (ignored if title bar button is being created)
  339. '* t$   - text to be placed on button (if title bar button then "CLOSE", "MAXIMIZE", "MINIMIZE', and "RESTORE")
  340. '* f&   - text font (ignored if title bar button is being created)
  341. '* c~&  - button color (if 0 then window color is used)
  342. '* t~&  - text color (if 0 then balck is used)
  343. '*
  344. SHARED WIN() AS WIN
  345. SHARED BUT() AS BUTTON
  346.  
  347. DIM i% ' next available button array index
  348. DIM c% ' generic counter
  349.  
  350. i% = UBOUND(BUT) '                                                              get last button index
  351. WHILE NOT BUT(i%).InUse AND i% > 1 '                                            is button in use?
  352.     REDIM _PRESERVE BUT(i% - 1) AS BUTTON '                                     no, remove it
  353.     i% = i% - 1 '                                                               go to previous index
  354. WEND '                                                                          leave when last button still being used
  355. i% = 0 '                                                                        start at beginning
  356. c% = 1
  357. DO '                                                                            cycle through button indexes
  358.     IF NOT BUT(c%).InUse THEN '                                                 button in use?
  359.         i% = c% '                                                               no, use this index
  360.     ELSE '                                                                      yes
  361.         c% = c% + 1 '                                                           increment index counter
  362.         IF c% > UBOUND(BUT) THEN '                                              reached end of buttons?
  363.             REDIM _PRESERVE BUT(c%) AS BUTTON '                                 yes, create a new button
  364.             i% = c% '                                                           use this index
  365.         END IF
  366.     END IF
  367. LOOP UNTIL i% '                                                                 leave when available index found
  368. IF win% < 0 THEN '                                                              button belong to a title bar?
  369.     win% = -win% '                                                              yes, correct window handle
  370.     BUT(i%).WinButton = -1 '                                                    mark button as belonging to a title bar
  371. BUT(i%).Window = win% '                                                         button belongs to window (0 for desktop)
  372. BUT(i%).InUse = -1 '                                                            mark index as used
  373. BUT(i%).State = 0 '                                                             default to normal
  374. BUT(i%).X = 0 '                                                                 reset x coordinate
  375. BUT(i%).Y = 0 '                                                                 reset y coordinate
  376. IF BUT(i%).WinButton THEN '                                                     creating a title bar button?
  377.     BUT(i%).Height = WIN(win%).TBHeight - 4 '                                   calculate button height
  378.     BUT(i%).Width = INT(BUT(i%).Height * 1.14286) '                             calculate button width
  379.     IF w% THEN BUT(i%).Height = BUT(i%).Width '                                 yes, height=width
  380.     x2% = BUT(i%).Width - 1 '                                                   calculate right bottom corner button X
  381.     y2% = BUT(i%).Height - 1 '                                                  calculate right bottom corner button Y
  382.     BUT(i%).State = 0 '                                                         set button as normal (depressed)
  383.     BUT(i%).Normal = _NEWIMAGE(BUT(i%).Width, BUT(i%).Height, 32) '             create normal image holder
  384.     _DEST BUT(i%).Normal '                                                      draw on image
  385.     CLS , WIN(win%).Darkest '                                                   create common button image
  386.     LINE (0, 0)-(x2% - 1, y2% - 1), WIN(win%).Lighter, B '                      draw background
  387.     LINE (1, 1)-(x2% - 1, y2% - 1), WIN(win%).Darker, B
  388.     LINE (1, 1)-(x2% - 2, y2% - 2), WIN(win%).WColor, BF
  389.     BUT(i%).Pressed = _NEWIMAGE(BUT(i%).Width, BUT(i%).Height, 32) '            create pressed image holder
  390.     _DEST BUT(i%).Pressed '                                                     draw on image
  391.     CLS , WIN(win%).Lighter '                                                   create common button image
  392.     LINE (0, 0)-(x2% - 1, y2% - 1), WIN(win%).Darkest, B '                      draw background
  393.     LINE (1, 1)-(x2% - 1, y2% - 1), WIN(win%).WColor, B
  394.     LINE (1, 1)-(x2% - 2, y2% - 2), WIN(win%).Darker, B
  395.     LINE (2, 2)-(x2% - 1, y2% - 1), WIN(win%).WColor, BF
  396.     BUT(i%).Disabled = _NEWIMAGE(BUT(i%).Width, BUT(i%).Height, 32) '           create disabled image holder
  397.     IF NOT w% THEN '                                                            title bar button?
  398.         _DEST BUT(i%).Disabled '                                                yes, draw on image
  399.         CLS , WIN(win%).Darkest '                                               create common button image
  400.         LINE (0, 0)-(x2% - 1, y2% - 1), WIN(win%).Lighter, B '                  draw background
  401.         LINE (1, 1)-(x2% - 1, y2% - 1), WIN(win%).Darker, B
  402.         LINE (1, 1)-(x2% - 2, y2% - 2), WIN(win%).WColor, BF
  403.     END IF
  404.     SELECT CASE t$ '                                                            yes, which window button being created?
  405.         CASE "CLOSE" '                                                          close button
  406.             _DEST BUT(i%).Normal '                                              work on normal
  407.             LINE (4, 3)-(x2% - 5, y2% - 4), _RGB32(0, 0, 0) '                   draw depressed button
  408.             LINE (5, 3)-(x2% - 4, y2% - 4), _RGB32(0, 0, 0)
  409.             LINE (4, y2% - 4)-(x2% - 5, 3), _RGB32(0, 0, 0)
  410.             LINE (5, y2% - 4)-(x2% - 4, 3), _RGB32(0, 0, 0)
  411.             _DEST BUT(i%).Pressed '                                             work on pressed
  412.             LINE (5, 4)-(x2% - 4, y2% - 3), _RGB32(0, 0, 0) '                   draw pressed button
  413.             LINE (6, 4)-(x2% - 3, y2% - 3), _RGB32(0, 0, 0)
  414.             LINE (5, y2% - 3)-(x2% - 4, 4), _RGB32(0, 0, 0)
  415.             LINE (6, y2% - 3)-(x2% - 3, 4), _RGB32(0, 0, 0)
  416.             _DEST BUT(i%).Disabled '                                            work on disabled
  417.             LINE (5, y2% - 4)-(x2% - 4, 4), _RGB32(255, 255, 255) '             draw disabled button
  418.             LINE (6, y2% - 4)-(x2% - 3, 4), _RGB32(255, 255, 255)
  419.             LINE (x2% - 4, y2% - 3)-(x2% - 3, y2% - 3), _RGB32(255, 255, 255) '
  420.             LINE (4, 3)-(x2% - 5, y2% - 4), _RGB32(128, 128, 128)
  421.             LINE (5, 3)-(x2% - 4, y2% - 4), _RGB32(128, 128, 128)
  422.             LINE (4, y2% - 4)-(x2% - 5, 3), _RGB32(128, 128, 128)
  423.             LINE (5, y2% - 4)-(x2% - 4, 3), _RGB32(128, 128, 128)
  424.         CASE "MAXIMIZE" '                                                       maximize button
  425.             _DEST BUT(i%).Normal '                                              work on normal
  426.             LINE (3, 3)-(x2% - 4, y2% - 3), _RGB32(0, 0, 0), B '                draw depressed button
  427.             LINE (3, 2)-(x2% - 4, 2), _RGB32(0, 0, 0)
  428.             _DEST BUT(i%).Pressed '                                             work on pressed
  429.             LINE (4, 4)-(x2% - 3, y2% - 2), _RGB32(0, 0, 0), B '                draw pressed button
  430.             LINE (4, 3)-(x2% - 3, 3), _RGB32(0, 0, 0)
  431.             _DEST BUT(i%).Disabled '                                            work on disabled
  432.             LINE (4, 4)-(x2% - 3, y2% - 2), _RGB32(255, 255, 255), B '          draw disabled button
  433.             PSET (x2% - 3, 3), _RGB32(255, 255, 255)
  434.             LINE (3, 3)-(x2% - 4, y2% - 3), _RGB32(128, 128, 128), B
  435.             LINE (3, 2)-(x2% - 4, 2), _RGB32(128, 128, 128)
  436.         CASE "MINIMIZE" '                                                       minimize button
  437.             _DEST BUT(i%).Normal '                                              work on normal
  438.             LINE (4, y2% - 4)-(x2% - 6, y2% - 3), _RGB32(0, 0, 0), B '          draw depressed button
  439.             _DEST BUT(i%).Pressed '                                             work on pressed
  440.             LINE (5, y2% - 3)-(x2% - 5, y2% - 2), _RGB32(0, 0, 0), B '          draw pressed button
  441.             _DEST BUT(i%).Disabled '                                            work on disabled
  442.             LINE (5, y2% - 3)-(x2% - 5, y2% - 2), _RGB32(255, 255, 255), B '    draw disabled button
  443.             LINE (4, y2% - 4)-(x2% - 6, y2% - 3), _RGB32(128, 128, 128), B
  444.         CASE "RESTORE" '                                                        restore button
  445.             _DEST BUT(i%).Normal '                                              work on normal
  446.             LINE (3, 6)-(x2% - 7, y2% - 3), _RGB32(0, 0, 0), B '                draw depressed button
  447.             LINE (3, 5)-(x2% - 7, 5), _RGB32(0, 0, 0)
  448.             PSET (5, 4), _RGB32(0, 0, 0)
  449.             PSET (x2% - 6, y2% - 6), _RGB32(0, 0, 0)
  450.             LINE (5, 2)-(x2% - 5, 3), _RGB32(0, 0, 0), B
  451.             LINE (x2% - 5, 4)-(x2% - 5, y2% - 6), _RGB32(0, 0, 0)
  452.             _DEST BUT(i%).Pressed '                                             work on pressed
  453.             LINE (4, 7)-(x2% - 6, y2% - 2), _RGB32(0, 0, 0), B '                draw pressed button
  454.             LINE (4, 6)-(x2% - 6, 6), _RGB32(0, 0, 0)
  455.             PSET (6, 5), _RGB32(0, 0, 0)
  456.             PSET (x2% - 5, y2% - 5), _RGB32(0, 0, 0)
  457.             LINE (6, 3)-(x2% - 4, 4), _RGB32(0, 0, 0), B
  458.             LINE (x2% - 4, 5)-(x2% - 4, y2% - 5), _RGB32(0, 0, 0)
  459.             _DEST BUT(i%).Disabled '                                            work on disabled
  460.             LINE (4, 7)-(x2% - 6, y2% - 2), _RGB32(255, 255, 255), B '          draw disabled button
  461.             LINE (6, 4)-(x2% - 6, 4), _RGB32(255, 255, 255)
  462.             LINE (x2% - 5, 3)-(x2% - 4, y2% - 5), _RGB32(255, 255, 255), B
  463.             LINE (3, 6)-(x2% - 7, y2% - 3), _RGB32(128, 128, 128), B
  464.             LINE (3, 5)-(x2% - 7, 5), _RGB32(128, 128, 128)
  465.             PSET (5, 4), _RGB32(128, 128, 128)
  466.             PSET (x2% - 6, y2% - 6), _RGB32(128, 128, 128)
  467.             LINE (5, 2)-(x2% - 5, 3), _RGB32(128, 128, 128), B
  468.             LINE (x2% - 5, 4)-(x2% - 5, y2% - 6), _RGB32(128, 128, 128)
  469.         CASE "SCROLLUP"
  470.             _DEST BUT(i%).Normal
  471.             LINE (BUT(i%).Width \ 2, 6)-(4, y2% - 6), _RGB32(0, 0, 0)
  472.             LINE -(x2% - 4, y2% - 6), _RGB32(0, 0, 0)
  473.             LINE -(BUT(i%).Width \ 2, 6), _RGB32(0, 0, 0)
  474.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  475.             _DEST BUT(i%).Pressed
  476.             LINE (BUT(i%).Width \ 2 + 1, 7)-(5, y2% - 5), _RGB32(0, 0, 0)
  477.             LINE -(x2% - 3, y2% - 5), _RGB32(0, 0, 0)
  478.             LINE -(BUT(i%).Width \ 2 + 1, 7), _RGB32(0, 0, 0)
  479.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  480.         CASE "SCROLLDOWN"
  481.             _DEST BUT(i%).Normal
  482.             LINE (BUT(i%).Width \ 2, y2% - 6)-(4, 6), _RGB32(0, 0, 0)
  483.             LINE -(y2% - 4, 6), _RGB32(0, 0, 0)
  484.             LINE -(BUT(i%).Width \ 2, y2% - 6), _RGB32(0, 0, 0)
  485.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  486.             _DEST BUT(i%).Pressed
  487.             LINE (BUT(i%).Width \ 2 + 1, y2% - 5)-(5, 7), _RGB32(0, 0, 0)
  488.             LINE -(x2% - 3, 7), _RGB32(0, 0, 0)
  489.             LINE -(BUT(i%).Width \ 2 + 1, y2% - 5), _RGB32(0, 0, 0)
  490.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  491.         CASE "SCROLLLEFT"
  492.             _DEST BUT(i%).Normal
  493.             LINE (5, BUT(i%).Height \ 2)-(x2% - 7, 4), _RGB32(0, 0, 0)
  494.             LINE -(x2% - 7, y2% - 5), _RGB32(0, 0, 0)
  495.             LINE -(5, BUT(i%).Height \ 2), _RGB32(0, 0, 0)
  496.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  497.             _DEST BUT(i%).Pressed
  498.             LINE (6, BUT(i%).Height \ 2 + 1)-(x2% - 6, 5), _RGB32(0, 0, 0)
  499.             LINE -(x2% - 6, y2% - 4), _RGB32(0, 0, 0)
  500.             LINE -(6, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0)
  501.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  502.         CASE "SCROLLRIGHT"
  503.             _DEST BUT(i%).Normal
  504.             LINE (x2% - 6, BUT(i%).Height \ 2)-(6, 4), _RGB32(0, 0, 0)
  505.             LINE -(6, y2% - 5), _RGB32(0, 0, 0)
  506.             LINE -(x2% - 6, BUT(i%).Height \ 2), _RGB32(0, 0, 0)
  507.             PAINT (BUT(i%).Width \ 2, BUT(i%).Height \ 2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  508.             _DEST BUT(i%).Pressed
  509.             LINE (x2% - 5, BUT(i%).Height \ 2 + 1)-(7, 5), _RGB32(0, 0, 0)
  510.             LINE -(7, y2% - 4), _RGB32(0, 0, 0)
  511.             LINE -(x2% - 5, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0)
  512.             PAINT (BUT(i%).Width \ 2 + 1, BUT(i%).Height \ 2 + 1), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  513.     END SELECT
  514.  
  515.     '*
  516.     '* custom made buttons here
  517.     '*
  518.  
  519.  
  520. BUTTON_NEW = i%
  521.  
  522.  
  523. '--------------------------------------------------------------------------------------------------------------------------------
  524. '                                                                                                                    WINDOW_MOUSE
  525. SUB WINDOW_MOUSE ()
  526. '
  527. ' work in progress (only called when there has been mouse activity)
  528. '
  529. SHARED WIN() AS WIN
  530. SHARED WinOrder%()
  531. SHARED WIN AS WINDOWFLAGS
  532. SHARED MOUSE AS MOUSEFLAGS
  533. SHARED BUT() AS BUTTON
  534.  
  535. DIM c% ' current window being checked for mouse hover
  536. DIM o% ' order of windows
  537. DIM x% ' x offset movement of mouse
  538. DIM y% ' y offset movement of mouse
  539. DIM tx%
  540. DIM ty%
  541.  
  542. MOUSE.PX = MOUSE.X '                                                                         save last mouse x position
  543. MOUSE.PY = MOUSE.Y '                                                                         save last mouse y position
  544. WHILE _MOUSEINPUT: WEND '                                                                    get latest mouse status
  545. MOUSE.X = _MOUSEX '                                                                          set desktop x coordinate flag
  546. MOUSE.Y = _MOUSEY '                                                                          set desktop y coordinate flag
  547. MOUSE.LeftClick = _MOUSEBUTTON(1) '                                                          set left mouse button status
  548. MOUSE.RightClick = _MOUSEBUTTON(2) '                                                         set right mouse button status
  549. IF NOT MOUSE.LeftClick THEN
  550.     MOUSE.LeftReleased = -1 '                                                                left mouse button has been released?
  551.     WIN(MOUSE.Move).Move = 0 '                                                               yes, window no longer being moved
  552.     MOUSE.Move = 0 '                                                                         end window movement
  553.     WIN(MOUSE.Resize).Resize = 0 '                                                           window no longer being resized
  554.     MOUSE.Resize = 0 '                                                                       end window resizing
  555.     MOUSE.Icon = 0 '                                                                         mouse pointer to default
  556.     IF MOUSE.ButtonPressed THEN '                                                            was a button being held down?
  557.         MOUSE.ButtonClicked = MOUSE.ButtonPressed '                                          yes, this button has now been clicked
  558.         MOUSE.ButtonPressed = 0 '                                                            button no longer being held down
  559.         BUT(MOUSE.ButtonClicked).State = 0 '                                                 set button state back to normal
  560.     END IF
  561.     IF MOUSE.Move THEN '                                                                     window currently being moved?
  562.         WINDOW_PUT MOUSE.move, WIN(MOUSE.move).X + MOUSEMOVEMENTX,_
  563.                               WIN(MOUSE.move).Y + MOUSEMOVEMENTY,_
  564.                               BYWINDOW '                                                     yes, update window position
  565.     ELSEIF MOUSE.Resize THEN '                                                               window currently being resized?
  566.         x% = MOUSEMOVEMENTX '                                                                yes, get change in x position
  567.         y% = MOUSEMOVEMENTY '                                                                get change in y position
  568.         IF MOUSE.Border AND 1 THEN '                                                         mouse on top border?
  569.             ty% = WIN(MOUSE.Resize).Height - y% '                                            yes, calculate possible y value
  570.             IF ty% >= WIN(MOUSE.Resize).MinHeight AND ty% <= WIN(MOUSE.Resize).MaxHeight THEN ' outside limits?
  571.                 WIN(MOUSE.Resize).Y = WIN(MOUSE.Resize).Y + y% '                             no, adjust window y location
  572.                 WIN(MOUSE.Resize).Height = ty% '                                             adjust overall window height
  573.  
  574.                 WIN(MOUSE.Resize).SHeight = WIN(MOUSE.Resize).SHeight - y% '                 adjust window screen height
  575.  
  576.             ELSE '                                                                           yes, minimum reached
  577.                 _MOUSEMOVE MOUSE.X, MOUSE.PY '                                               force pointer back       (not working correctly in GL)
  578.                 MOUSE.Y = MOUSE.PY '                                                         update mouse y position
  579.                 MOUSE.PY = MOUSEMOVEMENTY '                                                  seed new y offset position
  580.             END IF
  581.         ELSEIF MOUSE.Border AND 4 THEN '                                                     no, mouse on bottom border?
  582.             ty% = WIN(MOUSE.Resize).Height + y% '                                            calculate possible y value
  583.             IF ty% >= WIN(MOUSE.Resize).MinHeight AND ty% <= WIN(MOUSE.Resize).MaxHeight THEN ' outside limits?
  584.                 WIN(MOUSE.Resize).Height = ty% '                                             no, adjust overall window height
  585.  
  586.                 WIN(MOUSE.Resize).SHeight = WIN(MOUSE.Resize).SHeight + y% '                 adjust window screen height
  587.  
  588.             ELSE '                                                                           yes, minimum reached
  589.                 _MOUSEMOVE MOUSE.X, MOUSE.PY '                                               force pointer back       (not working correclty in GL)
  590.                 MOUSE.Y = MOUSE.PY '                                                         update mouse y position
  591.                 MOUSE.PY = MOUSEMOVEMENTY '                                                  seed new y offset position
  592.             END IF
  593.         END IF
  594.         IF MOUSE.Border AND 2 THEN '                                                         mouse on right border?
  595.             tx% = WIN(MOUSE.Resize).Width + x% '                                             yes, calculate possible x value
  596.             IF tx% >= WIN(MOUSE.Resize).MinWidth AND tx% <= WIN(MOUSE.Resize).MaxWidth THEN ' outside limits?
  597.                 WIN(MOUSE.Resize).Width = tx% '                                              no, adjust overall window width
  598.  
  599.                 WIN(MOUSE.Resize).SWidth = WIN(MOUSE.Resize).SWidth + x% '                   adjust window screen width
  600.  
  601.             ELSE '                                                                           yes, minimum reached
  602.                 _MOUSEMOVE MOUSE.PX, MOUSE.Y '                                               force pointer back       (not working correclty in GL)
  603.                 MOUSE.X = MOUSE.PX '                                                         update mouse x position
  604.                 MOUSE.PX = MOUSEMOVEMENTX '                                                  seed new x offset position
  605.             END IF
  606.         ELSEIF MOUSE.Border AND 8 THEN '                                                     no, mouse on left border?
  607.             tx% = WIN(MOUSE.Resize).Width - x% '                                             calculate possible x value
  608.             IF tx% >= WIN(MOUSE.Resize).MinWidth AND tx% <= WIN(MOUSE.Resize).MaxWidth THEN ' outside limits?
  609.                 WIN(MOUSE.Resize).X = WIN(MOUSE.Resize).X + x% '                             no, adjust window x location
  610.                 WIN(MOUSE.Resize).Width = tx% '                                              adjust overall window width
  611.  
  612.                 WIN(MOUSE.Resize).SWidth = WIN(MOUSE.Resize).SWidth - x% '                   adjust window screen width
  613.  
  614.             ELSE '                                                                           yes, minimum reached
  615.                 _MOUSEMOVE MOUSE.PX, MOUSE.Y '                                               force pointer back       (not working correctly in GL)
  616.                 MOUSE.X = MOUSE.PX '                                                         update mouse x position
  617.                 MOUSE.PX = MOUSEMOVEMENTX '                                                  seed new x offset position
  618.             END IF
  619.         END IF
  620.         WINDOW_MAKE MOUSE.Resize '                                                           redraw window
  621.     ELSE
  622.         MOUSE.WindowX = MOUSE.X - WIN(MOUSE.OnWindow).X '                                    set window x coordinate flag
  623.         MOUSE.WindowY = MOUSE.Y - WIN(MOUSE.OnWindow).Y '                                    set window y coordinate flag
  624.         MOUSE.SurfaceX = MOUSE.WindowX - WIN(MOUSE.OnWindow).SurfaceX '                        yes, set work space x flag
  625.         MOUSE.SurfaceY = MOUSE.WindowY - WIN(MOUSE.OnWindow).SurfaceY '                        set work space y flag
  626.     END IF
  627.  
  628. IF NOT MOUSE.LeftReleased THEN EXIT SUB '                                                    don't interact if left button being held down
  629.  
  630. WIN.X = 0 '                                                                                  reset window flags
  631. WIN.Y = 0
  632. WIN.Width = 0
  633. WIN.Height = 0
  634. WIN.Surface = 0
  635. WIN.SurfaceX = 0
  636. WIN.SurfaceY = 0
  637. WIN.SWidth = 0
  638. WIN.SHeight = 0
  639. WIN.HasFocus = 0
  640. MOUSE.Icon = 0
  641. MOUSE.OnWindow = 0 '                                                                         reset remaining mouse flags
  642. MOUSE.WindowX = 0
  643. MOUSE.WindowY = 0
  644. MOUSE.OnSurface = 0
  645. MOUSE.SurfaceX = 0
  646. MOUSE.SurfaceY = 0
  647. MOUSE.OnTitlebar = 0
  648. MOUSE.OnBorder = 0
  649. MOUSE.Border = 0
  650. MOUSE.OnButton = 0
  651. DO '                                                                                         loop through window order array
  652.     c% = c% + 1 '                                                                            increment array index
  653.     o% = WinOrder%(c%) '                                                                     next window to check
  654.     IF WIN(o%).Visible THEN '                                                                is window visible on screen?
  655.         IF WITHIN(WIN(o%).X,_
  656.                   WIN(o%).Y,_
  657.                   WIN(o%).X + WIN(o%).Width - 1,_
  658.                   WIN(o%).Y + WIN(o%).Height - 1) THEN '                                     yes, mouse within window coordinates?
  659.             MOUSE.OnWindow = o% '                                                            yes, set pointer flag to hovered window
  660.             MOUSE.WindowX = MOUSE.X - WIN(o%).X '                                            set window x coordinate flag
  661.             MOUSE.WindowY = MOUSE.Y - WIN(o%).Y '                                            set window y coordinate flag
  662.  
  663.             WIN.X = WIN(o%).X
  664.             WIN.Y = WIN(o%).Y
  665.             WIN.Width = WIN(o%).Width '                                                      set window width flag
  666.             WIN.Height = WIN(o%).Height '                                                    set window height flag
  667.             WIN.Surface = WIN(o%).Surface
  668.             WIN.SurfaceX = WIN(o%).SurfaceX
  669.             WIN.SurfaceY = WIN(o%).SurfaceY
  670.             WIN.SWidth = WIN(o%).SWidth '                                                    set window work space width flag
  671.             WIN.SHeight = WIN(o%).SHeight '                                                  set window work space height flag
  672.             WIN.HasFocus = WIN(o%).Focus
  673.  
  674.             IF WITHIN(WIN(o%).X + WIN(o%).SurfaceX,_
  675.                       WIN(o%).Y + WIN(o%).SurfaceY,_
  676.                       WIN(o%).X + WIN(o%).SurfaceX + WIN(o%).SWidth - 1,_
  677.                       WIN(o%).Y + WIN(o%).SurfaceY + WIN(o%).SHeight - 1) THEN '              mouse within screen coordinates?
  678.                 MOUSE.SurfaceX = MOUSE.WindowX - WIN(o%).SurfaceX '                            yes, set screen x flag
  679.                 MOUSE.SurfaceY = MOUSE.WindowY - WIN(o%).SurfaceY '                            set screen y flag
  680.                 MOUSE.OnSurface = -1 '                                                        set screen flag
  681.             ELSEIF WITHIN(WIN(o%).X + WIN(o%).SurfaceX,_
  682.                           WIN(o%).Y + WIN(o%).BWidth,_
  683.                           WIN(o%).X + WIN(o%).SurfaceX + WIN(o%).SWidth - 1,_
  684.                           WIN(o%).Y + WIN(o%).BWidth + WIN(o%).TBHeight - 1) THEN '          no, mouse within title bar?
  685.                 IF WIN(o%).CloseButton THEN '                                                yes, does this window have a close button?
  686.                     IF WITHIN(WIN(o%).X + BUT(WIN(o%).CloseButton).X,_
  687.                               WIN(o%).Y + BUT(WIN(o%).CloseButton).Y,_
  688.                               WIN(o%).X + BUT(WIN(o%).CloseButton).X + BUT(WIN(o%).CloseButton).Width - 1,_
  689.                               WIN(o%).Y + BUT(WIN(o%).CloseButton).Y + BUT(WIN(o%).CloseButton).Height - 1) THEN ' yes, on button?
  690.                         MOUSE.OnButton = WIN(o%).CloseButton '                               yes, set flag
  691.                     END IF
  692.                 END IF
  693.                 IF WIN(o%).MaxButton THEN '                                                  does this window have a maximize button?
  694.                     IF WITHIN(WIN(o%).X + BUT(WIN(o%).MaxButton).X,_
  695.                               WIN(o%).Y + BUT(WIN(o%).MaxButton).Y,_
  696.                               WIN(o%).X + BUT(WIN(o%).MaxButton).X + BUT(WIN(o%).MaxButton).Width - 1,_
  697.                               WIN(o%).Y + BUT(WIN(o%).MaxButton).Y + BUT(WIN(o%).MaxButton).Height - 1) THEN ' yes, on button?
  698.                         MOUSE.OnButton = WIN(o%).MaxButton '                                 yes, set flag
  699.                     END IF
  700.                 END IF
  701.                 IF WIN(o%).MinButton THEN '                                                  does this window have a minimize button?
  702.                     IF WITHIN(WIN(o%).X + BUT(WIN(o%).MinButton).X,_
  703.                               WIN(o%).Y + BUT(WIN(o%).MinButton).Y,_
  704.                               WIN(o%).X + BUT(WIN(o%).MinButton).X + BUT(WIN(o%).MinButton).Width - 1,_
  705.                               WIN(o%).Y + BUT(WIN(o%).MinButton).Y + BUT(WIN(o%).MinButton).Height - 1) THEN ' yes, on button?
  706.                         MOUSE.OnButton = WIN(o%).MinButton '                                 yes, set flag
  707.                     END IF
  708.                 END IF
  709.                 IF MOUSE.OnButton = 0 THEN MOUSE.OnTitlebar = -1 '                           if not on button then must be on title bar
  710.             END IF
  711.             IF WIN(o%).Size THEN '                                                           is window resizable?
  712.                 IF MOUSE.OnSurface + MOUSE.OnTitlebar + MOUSE.OnButton = 0 THEN '             yes, mouse on anything?
  713.                     MOUSE.OnBorder = -1 '                                                    no, mouse must be on a border
  714.                     IF MOUSE.Y <= WIN(o%).Y + WIN(o%).BWidth - 1 THEN '                      on top border?
  715.                         MOUSE.Border = 1 '                                                   yes, set border value
  716.                     ELSEIF MOUSE.Y >= WIN(o%).Y + WIN(o%).Height - WIN(o%).BWidth - 1 THEN ' no, on bottom border?
  717.                         MOUSE.Border = MOUSE.Border + 4 '                                    yes, add border value
  718.                     END IF
  719.                     IF MOUSE.X >= WIN(o%).X + WIN(o%).Width - WIN(o%).BWidth - 1 THEN '      on right border?
  720.                         MOUSE.Border = MOUSE.Border + 2 '                                    yes, add border value
  721.                     ELSEIF MOUSE.X <= WIN(o%).X + WIN(o%).BWidth - 1 THEN '                  no, on left border?
  722.                         MOUSE.Border = MOUSE.Border + 8 '                                    yes, add border value
  723.                     END IF
  724.                     MOUSE.Icon = MOUSE.Border '                                              mouse icon to resize
  725.                 END IF
  726.             END IF
  727.         END IF
  728.     END IF
  729. LOOP UNTIL MOUSE.OnWindow OR c% = UBOUND(WinOrder%) '                                        leave when hovering or entire array scanned
  730. IF MOUSE.LeftClick THEN MOUSE.LeftReleased = 0 '                                             left mouse button currently held down
  731. IF MOUSE.OnWindow AND MOUSE.LeftClick THEN '                                                 is pointer on a window and left button pressed?
  732.     WINDOW_SETFOCUS MOUSE.OnWindow '                                                         yes, this window now has focus
  733.     c% = MOUSEMOVEMENTX '                                                                    seed mouse x offset function
  734.     c% = MOUSEMOVEMENTY '                                                                    seed mouse y offset function
  735.     IF MOUSE.OnTitlebar AND MOUSE.Move = 0 THEN '                                            is pointer on title bar and window not moving?
  736.         MOUSE.Move = MOUSE.OnWindow '                                                        yes, this window can now be moved
  737.         WIN(MOUSE.Move).Move = -1 '                                                          set window state to moving
  738.     ELSEIF MOUSE.OnBorder AND MOUSE.Resize = 0 THEN '                                        is mouse on border and not resizing?
  739.         MOUSE.Resize = MOUSE.OnWindow '                                                      yes, this window can now be resized
  740.         WIN(MOUSE.Resize).Resize = -1 '                                                      set window state to resizing
  741.     ELSEIF MOUSE.OnButton THEN '                                                             pointer on button?
  742.         MOUSE.ButtonPressed = MOUSE.OnButton '                                               yes, button is currently being pressed
  743.         BUT(MOUSE.ButtonPressed).State = -1 '                                                set button state to pressed
  744.     END IF
  745.  
  746.  
  747. '--------------------------------------------------------------------------------------------------------------------------------
  748. '                                                                                                                 WINDOW_SETFOCUS
  749. SUB WINDOW_SETFOCUS (h%)
  750. '
  751. ' h% = handle of window to set focus ******************** NEEDS FIXED for only 1 window
  752. '
  753. SHARED WIN() AS WIN
  754. SHARED WinOrder%()
  755.  
  756. DIM c%
  757. DIM o%
  758.  
  759. IF h% < 1 THEN EXIT SUB '                                                       leave if no window selected
  760. IF WIN(h%).Focus THEN EXIT SUB '                                                leave if window already in focus
  761. IF NOT WIN(h%).Visible THEN EXIT SUB '                                          leave if window is not on screen
  762. DO '                                                                            loop through window order array
  763.     c% = c% + 1 '                                                               increment array index
  764. LOOP UNTIL h% = WinOrder%(c%) OR c% = UBOUND(WinOrder%) '                       leave if window found or end of array reached
  765. IF c% = UBOUND(WinOrder%) AND WinOrder%(c%) <> h% THEN EXIT SUB '               window does not exist, leave subroutine
  766. FOR o% = c% - 1 TO 1 STEP -1 '                                                  cycle through array
  767.     WinOrder%(o% + 1) = WinOrder%(o%) '                                         move windows above h% down one
  768. NEXT o%
  769. WinOrder%(1) = h% '                                                             make this window the new focus
  770. c% = WinOrder%(2)
  771. WIN(h%).Focus = -1 '                                                            this window now has focus
  772.  
  773. _PUTIMAGE (WIN(h%).BWidth, WIN(h%).BWidth), WIN(h%).TBFImage, WIN(h%).Window '  place focused title bar image on window
  774.  
  775. WIN(WinOrder%(2)).Focus = 0 '                                                   previous window lost focus
  776.  
  777. _PUTIMAGE (WIN(c%).BWidth, WIN(c%).BWidth), WIN(c%).TBNFImage, WIN(c%).Window ' unfocused
  778.  
  779.  
  780. '--------------------------------------------------------------------------------------------------------------------------------
  781. '                                                                                                                  WINDOW_DESKTOP
  782. SUB WINDOW_DESKTOP (w%, h%, c~&, i$)
  783. '
  784. ' w%  = desktop width  (0 for default 640 or to use optional desktop image width)
  785. ' h%  = desktop height (0 for default 480 or to use optional desktop image height)
  786. ' c~& = desktop color  (0 for none)
  787. ' i$  = desktop image  (null for none)
  788. '
  789. ' If width and height are supplied then desktop is created with those dimensions and optional desktop image stretched across
  790. '
  791. SHARED DeskTop&
  792.  
  793. DIM Back& ' desktop background image
  794.  
  795. IF w% <> 0 AND h% <> 0 THEN '                                 dimensions supplied?
  796.     DeskTop& = _NEWIMAGE(w%, h%, 32) '                        yes, create desktop screen with dimensions
  797.     IF _FILEEXISTS(i$) THEN '                                 does background image exist?
  798.         Back& = _LOADIMAGE(i$, 32) '                          yes, load background image
  799.         _PUTIMAGE , Back&, DeskTop& '                         put background image on desktop screen
  800.         _FREEIMAGE Back& '                                    background image no longer needed
  801.     ELSE '                                                    no, background image does not exist
  802.         _DEST DeskTop& '                                      draw on desktop screen
  803.         IF c~& <> 0 THEN CLS , c~& ELSE CLS '                 color desktop background
  804.     END IF
  805. ELSE '                                                        no dimensions supplied
  806.     IF _FILEEXISTS(i$) THEN '                                 does background image exist?
  807.         DeskTop& = _LOADIMAGE(i$, 32) '                       yes, use this as the desktop
  808.     ELSE '                                                    no, background image does not exist
  809.         DeskTop& = _NEWIMAGE(640, 480, 32) '                  create default 640x480 desktop screen
  810.         _DEST DeskTop& '                                      draw on desktop screen
  811.         IF c~& <> 0 THEN CLS , c~& ELSE CLS '                 color desktop background
  812.     END IF
  813. SCREEN _NEWIMAGE(_WIDTH(DeskTop&), _HEIGHT(DeskTop&), 32) '   make main screen that matches desktop dimensions
  814. CLS '                                                         clear screen (remove transparency)
  815. _SCREENMOVE _MIDDLE '                                         move screen to the center of the programmer's desktop
  816.  
  817.  
  818. '--------------------------------------------------------------------------------------------------------------------------------
  819. '                                                                                                                  WINDOW_REFRESH
  820. SUB WINDOW_REFRESH ()
  821.  
  822. SHARED WIN() AS WIN ' window array
  823. SHARED BUT() AS BUTTON
  824. SHARED DeskTop&
  825. SHARED WinOrder%()
  826. SHARED POINTER() AS MOUSEPOINTERS
  827. SHARED MOUSE AS MOUSEFLAGS
  828.  
  829. DIM o%
  830. DIM h%
  831.  
  832. IF DeskTop& THEN _PUTIMAGE (0, 0), DeskTop& '                                               place background image if exist
  833. FOR o% = UBOUND(WinOrder%) TO 1 STEP -1 '                                                   cycle through window order eversed
  834.     h% = WinOrder%(o%) '                                                                    get next window handle
  835.     IF WIN(h%).Visible THEN '                                                               is this window visible?
  836.  
  837.         IF WIN(h%).CloseButton THEN BUTTON_PUT WIN(h%).CloseButton, 0, 0, 0 '               draw close button if exist
  838.         IF WIN(h%).MaxButton THEN BUTTON_PUT WIN(h%).MaxButton, 0, 0, 0 '                   draw maximize button if exist
  839.         IF WIN(h%).MinButton THEN BUTTON_PUT WIN(h%).MinButton, 0, 0, 0 '                   draw minimize button if exist
  840.  
  841.         _PUTIMAGE (WIN(h%).X, WIN(h%).Y), WIN(h%).Window '                                  place window onto desktop
  842.     END IF
  843. NEXT o%
  844. _PUTIMAGE (MOUSE.X + POINTER(MOUSE.Icon).X, MOUSE.Y + POINTER(MOUSE.Icon).Y), POINTER(MOUSE.Icon).Icon ' place mouse pointer
  845.  
  846.  
  847. '--------------------------------------------------------------------------------------------------------------------------------
  848. '                                                                                                                      WINDOW_PUT
  849. SUB WINDOW_PUT (h%, x%, y%, m%)
  850. '
  851. ' h% - handle of window to move
  852. ' x% - new window x coordinate
  853. ' y% - new window y coordinate
  854. ' m% - method of move (by work space origin coordinates (BYSCREEN) or by entire window origin coordinates (BYWINDOW))
  855. '
  856. SHARED WIN() AS WIN ' window array
  857.  
  858. IF m% THEN '                                                BYSCREEN
  859.     WIN(h%).X = x% - WIN(h%).BWidth
  860.     WIN(h%).Y = y% - WIN(h%).BWidth - WIN(h%).TBHeight
  861. ELSE '                                                      BYWINDOW
  862.     WIN(h%).X = x%
  863.     WIN(h%).Y = y%
  864.  
  865. 'IF WIN(h%).Visible THEN WINDOW_SETFOCUS h% ' *************************************** focus routine needs fixing for only 1 window
  866.  
  867.  
  868. '--------------------------------------------------------------------------------------------------------------------------------
  869. '                                                                                                                     WINDOW_MAKE
  870. SUB WINDOW_MAKE (h%)
  871. '
  872. ' h% - handle of window to create
  873. '
  874. SHARED WIN() AS WIN ' window array
  875. SHARED MOUSE AS MOUSEFLAGS
  876. SHARED BUT() AS BUTTON '             needed?
  877.  
  878. DIM p&(1)
  879. DIM c% '                  generic counter
  880. DIM Red!, Green!, Blue!
  881. DIM Redinc!, Greeninc!, Blueinc!
  882. DIM x%, y%
  883.  
  884. DIM CurrentDest&
  885.  
  886. p&(0) = 43690 '                                                                             scroll bar background pattern 1
  887. p&(1) = 21845 '                                                                             scroll bar background pattern 2
  888.  
  889. CurrentDest& = _DEST '                                                                      remember calling destination
  890.  
  891. IF WIN(h%).Resize THEN '                                                                    window being resized?
  892.     _FREEIMAGE WIN(h%).Window '                                                             remove window image from RAM
  893.     IF (MOUSE.Border AND 2) OR (MOUSE.Border AND 8) THEN '                                  resizing right or left border?
  894.         _FREEIMAGE WIN(h%).TBFImage '                                                       yes, remove title bar focus image
  895.         _FREEIMAGE WIN(h%).TBNFImage '                                                      remove title bar no focus image
  896.     END IF
  897. ELSE '                                                                                      no, window being created
  898.     CALCULATECOLORS h% '                                                                    calculate window color shades
  899.     WIN(h%).TBHeight = _FONTHEIGHT(WIN(h%).Font) + 8 '                                      calculate title bar height
  900.     WIN(h%).Width = WIN(h%).SWidth + WIN(h%).BWidth * 2 '                                   yes, calculate window width
  901.     WIN(h%).Height = WIN(h%).SHeight + WIN(h%).BWidth * 2 + WIN(h%).TBHeight + 1 '          calculate window height
  902.     WIN(h%).OWidth = WIN(h%).Width
  903.     WIN(h%).OHeight = WIN(h%).Height
  904.     WIN(h%).MaxWidth = WIN(h%).OWidth '                                                     save maximim width of window
  905.     WIN(h%).MaxHeight = WIN(h%).OHeight '                                                   save maximim height of window
  906.     WIN(h%).SurfaceX = WIN(h%).BWidth '                                                      calculate screen x location
  907.     WIN(h%).SurfaceY = WIN(h%).BWidth + WIN(h%).TBHeight '                                   calculate screen y location
  908.  
  909.  
  910.     WIN(h%).CloseButton = BUTTON_NEW(-h%, 0, 0, "CLOSE", 0, 0, 0) '                         create close title bar button
  911.     WIN(h%).MaxButton = BUTTON_NEW(-h%, 0, 0, "MAXIMIZE", 0, 0, 0) '                        create maximize title bar button
  912.     WIN(h%).MinButton = BUTTON_NEW(-h%, 0, 0, "MINIMIZE", 0, 0, 0) '                        create minimize title bar button
  913.     WIN(h%).RestoreButton = BUTTON_NEW(-h%, 0, 0, "RESTORE", 0, 0, 0) '                     create restore title bar button
  914.     WIN(h%).SUButton = BUTTON_NEW(-h%, 1, 0, "SCROLLUP", 0, 0, 0) '                         create scroll bar up button
  915.     WIN(h%).SDButton = BUTTON_NEW(-h%, 1, 0, "SCROLLDOWN", 0, 0, 0) '                       create scroll bar down button
  916.     WIN(h%).SLButton = BUTTON_NEW(-h%, 1, 0, "SCROLLLEFT", 0, 0, 0) '                       create scroll bar left button
  917.     WIN(h%).SRButton = BUTTON_NEW(-h%, 1, 0, "SCROLLRIGHT", 0, 0, 0) '                      create scroll bar right button
  918.     WIN(h%).MinHeight = WIN(h%).TBHeight + WIN(h%).BWidth * 2 + BUT(WIN(h%).SUButton).Height * 4 ' calculate min window height
  919.  
  920.     WIN(h%).TBFImage = _NEWIMAGE(WIN(h%).SWidth, WIN(h%).TBHeight, 32) '                    create title bar with focus
  921.     WIN(h%).TBNFImage = _COPYIMAGE(WIN(h%).TBFImage) '                                      create title bar without focus
  922.     WIN(h%).Surface = _NEWIMAGE(WIN(h%).SWidth, WIN(h%).SHeight, 32) '                       create screen image container
  923.  
  924.  
  925.     BUT(WIN(h%).CloseButton).Y = WIN(h%).BWidth + 2 '                                       close button Y location
  926.     BUT(WIN(h%).MaxButton).Y = WIN(h%).BWidth + 2 '                                         maximize buttun Y location
  927.     BUT(WIN(h%).MinButton).Y = WIN(h%).BWidth + 2 '                                         minimize button Y location
  928.     BUT(WIN(h%).RestoreButton).Y = WIN(h%).BWidth + 2 '                                     restore button Y location
  929.     BUT(WIN(h%).SUButton).Y = WIN(h%).BWidth + WIN(h%).TBHeight + 1 '                       scroll up button Y location
  930.     BUT(WIN(h%).SLButton).X = WIN(h%).BWidth '                                              scroll left button X location
  931.  
  932.  
  933. WIN(h%).Window = _NEWIMAGE(WIN(h%).Width, WIN(h%).Height, 32) '                             create window image container
  934.  
  935.  
  936. BUT(WIN(h%).CloseButton).X = WIN(h%).Width - WIN(h%).BWidth - BUT(WIN(h%).CloseButton).Width - 2 ' close button X location
  937. BUT(WIN(h%).MaxButton).X = BUT(WIN(h%).CloseButton).X - BUT(WIN(h%).MaxButton).Width - 2 '  maximize button X location
  938. BUT(WIN(h%).MinButton).X = BUT(WIN(h%).MaxButton).X - BUT(WIN(h%).MinButton).Width '        minimize button X location
  939. BUT(WIN(h%).RestoreButton).X = BUT(WIN(h%).MaxButton).X '                                   restore button X location
  940.  
  941.  
  942. BUT(WIN(h%).SUButton).X = BUT(WIN(h%).CloseButton).X '                                      scroll up buttom X location
  943. BUT(WIN(h%).SDButton).X = BUT(WIN(h%).CloseButton).X '                                      scroll down button X location
  944. BUT(WIN(h%).SRButton).X = BUT(WIN(h%).CloseButton).X '                                      scroll right button X location
  945. BUT(WIN(h%).SDButton).Y = WIN(h%).Height - WIN(h%).BWidth - BUT(WIN(h%).SDButton).Height '  scroll down button Y location
  946. BUT(WIN(h%).SLButton).Y = WIN(h%).Height - WIN(h%).BWidth - BUT(WIN(h%).SDButton).Height '  scroll left button Y location
  947. BUT(WIN(h%).SRButton).Y = BUT(WIN(h%).SLButton).Y '                                         scroll left button X location
  948.  
  949.  
  950. IF NOT (WIN(h%).Resize AND ((MOUSE.Border = 1) OR (MOUSE.Border = 4))) THEN '               resizing right or left border?
  951.     WIN(h%).TBFImage = _NEWIMAGE(WIN(h%).SWidth, WIN(h%).TBHeight, 32) '                    yes, create title bar with focus
  952.     WIN(h%).TBNFImage = _COPYIMAGE(WIN(h%).TBFImage) '                                      create title bar without focus
  953.     TBIMAGE h%, 0 '                                                                         draw focused image
  954.     TBIMAGE h%, 1 '                                                                         draw unfocused image
  955.  
  956.  
  957. _DEST WIN(h%).Window '                                                                      draw on window image
  958. CLS , WIN(h%).Lighter '                                                                     clear window image
  959. IF WIN(h%).Focus THEN '                                                             does this window have focus?
  960.     _PUTIMAGE (WIN(h%).BWidth, WIN(h%).BWidth), WIN(h%).TBFImage, WIN(h%).Window '  yes, draw focused title bar
  961. ELSE '                                                                              no
  962.     _PUTIMAGE (WIN(h%).BWidth, WIN(h%).BWidth), WIN(h%).TBNFImage, WIN(h%).Window ' draw unfocused title bar
  963.  
  964.  
  965.  
  966.  
  967.  
  968. IF WIN(h%).SWidth < WIN(h%).SIWidth THEN
  969.  
  970.     BUT(WIN(h%).SDButton).Y = BUT(WIN(h%).SDButton).Y - BUT(WIN(h%).SDButton).Height '      yes, adjust scroll down button Y
  971.  
  972.     LINE (BUT(WIN(h%).SLButton).X + BUT(WIN(h%).SLButton).Width - 1, BUT(WIN(h%).SLButton).Y)-(BUT(WIN(h%).SRButton).X, BUT(WIN(h%).SRButton).Y + BUT(WIN(h%).SRButton).Height - 1), _RGB32(255, 255, 255), BF
  973.     FOR y% = BUT(WIN(h%).SLButton).Y TO BUT(WIN(h%).SLButton).Y + BUT(WIN(h%).SLButton).Height - 1
  974.         LINE (BUT(WIN(h%).SLButton).X + BUT(WIN(h%).SLButton).Width - 1, y%)-(BUT(WIN(h%).SRButton).X, y%), _RGB32(212, 208, 200), , p&(y% AND 1) ' alternate odd/even pattern
  975.     NEXT y%
  976.     BUTTON_PUT WIN(h%).SLButton, 0, 0, 0
  977.     BUTTON_PUT WIN(h%).SRButton, 0, 0, 0
  978.  
  979. IF WIN(h%).SHeight < WIN(h%).SIHeight THEN
  980.  
  981.     BUT(WIN(h%).SRButton).X = BUT(WIN(h%).SRButton).X - BUT(WIN(h%).SRButton).Width '       yes, adjust scroll right button X
  982.  
  983.     LINE (BUT(WIN(h%).SUButton).X, BUT(WIN(h%).SUButton).Y + BUT(WIN(h%).SUButton).Height)-(BUT(WIN(h%).SDButton).X + BUT(WIN(h%).SDButton).Width - 1, BUT(WIN(h%).SDButton).Y), _RGB32(255, 255, 255), BF
  984.     FOR x% = BUT(WIN(h%).SUButton).X TO BUT(WIN(h%).SUButton).X + BUT(WIN(h%).SUButton).Width - 1
  985.         LINE (x%, BUT(WIN(h%).SUButton).Y + BUT(WIN(h%).SUButton).Height)-(x%, BUT(WIN(h%).SDButton).Y), _RGB32(212, 208, 200), , p&(x% AND 1)
  986.     NEXT x%
  987.     BUTTON_PUT WIN(h%).SUButton, 0, 0, 0
  988.     BUTTON_PUT WIN(h%).SDButton, 0, 0, 0
  989.  
  990.  
  991.  
  992. '**
  993. '** Calculate where screen needs to sit inside viewport
  994. '**
  995. '** place window at viewport
  996. '**
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003. IF WIN(h%).BWidth THEN '                                                                    draw a border?
  1004.     IF WIN(h%).BWidth = 1 THEN '                                                            yes, 1 pixel border?
  1005.         LINE (WIN(h%).Width - 1, 0)-(WIN(h%).Width - 1, WIN(h%).Height - 1), WIN(h%).Dark ' yes, draw border
  1006.         LINE -(0, WIN(h%).Height - 1), WIN(h%).Dark
  1007.     END IF
  1008.     IF WIN(h%).BWidth = 2 THEN '                                                            2 pixel border?
  1009.         LINE (0, 0)-(WIN(h%).Width - 1, WIN(h%).Height - 1), WIN(h%).Dark, B '              yes, draw bottom and right border
  1010.         LINE (0, 0)-(WIN(h%).Width - 2, WIN(h%).Height - 2), WIN(h%).Light, B '             draw top and left border
  1011.     END IF
  1012.     IF WIN(h%).BWidth > 2 THEN '                                                            more than 2 pixel border?
  1013.         LINE (0, 0)-(WIN(h%).Width - 1, WIN(h%).Height - 1), WIN(h%).Darker, B '            yes, draw bottom and right border
  1014.         LINE (0, 0)-(WIN(h%).Width - 2, WIN(h%).Height - 2), WIN(h%).Lighter, B '           draw top and left border
  1015.         LINE (1, 1)-(WIN(h%).Width - 2, WIN(h%).Height - 2), WIN(h%).Dark, B '              draw bottom and right middle border
  1016.         LINE (1, 1)-(WIN(h%).Width - 3, WIN(h%).Height - 3), WIN(h%).Light, B '             draw top and left middle border
  1017.         LINE (2, 2)-(WIN(h%).Width - 3, WIN(h%).Height - 3), WIN(h%).WColor, B
  1018.     END IF
  1019.     IF WIN(h%).BWidth > 3 THEN '                                                            more than 3 pixel border?
  1020.         LINE (WIN(h%).BWidth - 1, WIN(h%).BWidth - 1)-(WIN(h%).Width - WIN(h%).BWidth, WIN(h%).Height - WIN(h%).BWidth), WIN(h%).Light, B
  1021.         LINE (WIN(h%).BWidth - 1, WIN(h%).BWidth - 1)-(WIN(h%).Width - WIN(h%).BWidth - 1, WIN(h%).Height - WIN(h%).BWidth - 1), WIN(h%).Dark, B
  1022.     END IF
  1023.  
  1024.     LINE (WIN(h%).BWidth, WIN(h%).BWidth + WIN(h%).TBHeight)-(WIN(h%).Width - WIN(h%).BWidth - 1, WIN(h%).BWidth + WIN(h%).TBHeight), _RGB32(0, 0, 0)
  1025.  
  1026.  
  1027.  
  1028. _DEST CurrentDest&
  1029.  
  1030.  
  1031. '--------------------------------------------------------------------------------------------------------------------------------
  1032. '                                                                                                                      WINDOW_NEW
  1033. FUNCTION WINDOW_NEW (w%, h%)
  1034. '
  1035. ' w% = width of window work space
  1036. ' h% = height of window work space
  1037. '
  1038. ' returns = integer handle number to reference window with
  1039. '
  1040. SHARED WIN() AS WIN ' window array
  1041. SHARED WinOrder%()
  1042. SHARED QB64Icon&
  1043.  
  1044. DIM i% ' next available window array index
  1045. DIM c% ' generic counter
  1046.  
  1047. i% = UBOUND(WIN) '                                 get last window index
  1048. WHILE NOT WIN(i%).InUse AND i% > 1 '               is window in use?
  1049.     REDIM _PRESERVE WIN(i% - 1) AS WIN '           no, remove it
  1050.     i% = i% - 1 '                                  go to previous index
  1051. i% = 0 '                                           start at beginning
  1052. c% = 1
  1053. DO '                                               cycle through window indexes
  1054.     IF NOT WIN(c%).InUse THEN '                    window is use?
  1055.         i% = c% '                                  no, use this index
  1056.     ELSE '                                         yes
  1057.         c% = c% + 1 '                              increment index counter
  1058.         IF c% > UBOUND(WIN) THEN '                 reached end of windows?
  1059.             REDIM _PRESERVE WIN(c%) AS WIN '       yes, create a new window
  1060.             i% = c% '                              use this index
  1061.         END IF
  1062.     END IF
  1063. LOOP UNTIL i% '                                    leave when available index found
  1064. WIN(i%).InUse = -1 '                               mark index as used
  1065. WIN(i%).Visible = 0 '                              set window invisible
  1066.  
  1067. WIN(i%).SIWidth = w% '                             set screen image width
  1068. WIN(i%).SIHeight = h% '                            set screen image height
  1069. WIN(i%).SWidth = w% '                              set window screen width
  1070. WIN(i%).SHeight = h% '                             set window screen  height
  1071.  
  1072. WIN(i%).X = 0 '                                    set window x location
  1073. WIN(i%).Y = 0 '                                    set window y location
  1074. WIN(i%).BWidth = 3 '                               set border width
  1075. WIN(i%).Font = _FONT
  1076. WIN(i%).Title = ""
  1077. WIN(i%).Icon = QB64Icon&
  1078. WIN(i%).WColor = _RGB32(212, 208, 200) '           set window color
  1079. WIN(i%).TBColor = _RGB32(10, 40, 100) '            set title bar color
  1080. WIN(i%).TTColor = _RGB32(255, 255, 255) '          set title bar text color
  1081. WIN(i%).TBSolid = -1
  1082. WIN(i%).Shadow = 0 '                               set window shadow (off)
  1083. WIN(i%).Focus = 0 '                                set window without focus
  1084. WIN(i%).Move = 0
  1085. WIN(i%).Resize = 0
  1086. WIN(i%).Size = 0
  1087. WIN(i%).CloseButton = 0
  1088. WIN(i%).MaxButton = 0
  1089. WIN(i%).MinButton = 0
  1090. WIN(i%).RestoreButton = 0
  1091. WIN(i%).SUButton = 0
  1092. WIN(i%).SDButton = 0
  1093. WIN(i%).SLButton = 0
  1094. WIN(i%).SRButton = 0
  1095. WIN(i%).Maximized = 0
  1096. WIN(i%).Minimized = 0
  1097. REDIM _PRESERVE WinOrder%(UBOUND(WinOrder%) + 1) ' increase window order array
  1098. WinOrder%(UBOUND(WinOrder%)) = i% '                add window to order array
  1099. WINDOW_NEW = i% '                                  return window handle
  1100.  
  1101.  
  1102.  
  1103. '--------------------------------------------------------------------------------------------------------------------------------
  1104. '                                                                                                                 WINDOW_SETTITLE
  1105. SUB WINDOW_SETTITLE (h%, t$)
  1106.  
  1107. SHARED WIN() AS WIN ' window array
  1108.  
  1109. WIN(h%).Title = t$ '                                                               set title of window
  1110.  
  1111.  
  1112. '--------------------------------------------------------------------------------------------------------------------------------
  1113. '                                                                                                                  WINDOW_SETFONT
  1114. SUB WINDOW_SETFONT (h%, f&)
  1115.  
  1116. SHARED WIN() AS WIN ' window array
  1117.  
  1118. WIN(h%).Font = f& '                                                                set window font
  1119.  
  1120.  
  1121. '--------------------------------------------------------------------------------------------------------------------------------
  1122. '                                                                                                                WINDOW_SETBORDER
  1123. SUB WINDOW_SETBORDER (h%, w%)
  1124.  
  1125. SHARED WIN() AS WIN ' window array
  1126.  
  1127. WIN(h%).BWidth = w%
  1128.  
  1129.  
  1130. '--------------------------------------------------------------------------------------------------------------------------------
  1131. '                                                                                                                 WINDOW_SETCOLOR
  1132. SUB WINDOW_SETCOLOR (h%, c~&)
  1133.  
  1134. SHARED WIN() AS WIN ' window array
  1135.  
  1136. WIN(h%).WColor = c~& '                                              set window color
  1137.  
  1138.  
  1139. '--------------------------------------------------------------------------------------------------------------------------------
  1140. '                                                                                                         WINDOW_SETTITLEBARCOLOR
  1141. SUB WINDOW_SETTITLEBARCOLOR (h%, c~&)
  1142.  
  1143. SHARED WIN() AS WIN ' window array
  1144.  
  1145. WIN(h%).TBColor = c~& '                                               set title bar color
  1146.  
  1147.  
  1148. '--------------------------------------------------------------------------------------------------------------------------------
  1149. '                                                                                                                     WINDOW_SHOW
  1150. SUB WINDOW_SHOW (h%)
  1151.  
  1152. SHARED WIN() AS WIN ' window array
  1153.  
  1154. WIN(h%).Visible = -1
  1155.  
  1156.  
  1157. '--------------------------------------------------------------------------------------------------------------------------------
  1158. '                                                                                                                     WINDOW_HIDE
  1159. SUB WINDOW_HIDE (h%)
  1160.  
  1161. SHARED WIN() AS WIN ' window array
  1162.  
  1163. WIN(h%).Visible = 0
  1164.  
  1165.  
  1166. '--------------------------------------------------------------------------------------------------------------------------------
  1167. '                                                                                                                        POINTERS
  1168. SUB POINTERS ()
  1169.  
  1170. SHARED POINTER() AS MOUSEPOINTERS
  1171.  
  1172. DIM Icon$
  1173.  
  1174. Icon$ = "b           bb          bwb         bwwb        bwwwb       bwwwwb      bwwwwwb     bwwwwwwb    "+_
  1175.         "bwwwwwwwb   bwwwwwwwwb  bwwwwwwwwwb bwwwwwwbbbbbbwwwbwwb    bwwbbwwb    bwb  bwwb   bb   bwwb   "+_
  1176.         "b     bwwb        bwwb         bwwb        bwwb         bb  "
  1177. MAKEICON 0, Icon$, 12, 21, 0, 0 ' default - 12x21 - offset 0,0
  1178. Icon$ = "    w       wbw     wbbbw   wbbbbbw wbbbbbbbwwwwwbwwww   wbw      wbw      wbw      wbw   "+_
  1179.         "   wbw      wbw      wbw      wbw      wbw   wwwwbwwwwwbbbbbbbw wbbbbbw   wbbbw     wbw       w    "
  1180. MAKEICON 1, Icon$, 9, 21, -4, -10 ' NS resize - 9x21 - offset 5,11
  1181. Icon$ = "    ww         ww       wbw         wbw     wbbw         wbbw   wbbbwwwwwwwwwwwbbbw wbbbbbbbbbbbbbbbbbbbw"+_
  1182.         " wbbbwwwwwwwwwwwbbbw   wbbw         wbbw     wbw         wbw       ww         ww    "
  1183. MAKEICON 2, Icon$, 21, 9, -10, -4 ' EW resize - 21x9 - offset 11,5
  1184. Icon$ = "        wwwwwww        wbbbbbw         wbbbbw          wbbbw         wbwbbw        wbw wbw"+_
  1185.         "       wbw   ww      wbw      ww   wbw       wbw wbw        wbbwbw         wbbbw          "+_
  1186.         "wbbbbw         wbbbbbw        wwwwwww        "
  1187. MAKEICON 3, Icon$, 15, 15, -7, -7 ' NESW resize - 15x15 - offset 8,8
  1188. Icon$ = "     bb              bwwb             bwwb             bwwb             bwwb             bwwbbb       "+_
  1189.         "    bwwbwwbbb        bwwbwwbwwbb      bwwbwwbwwbwb bbb bwwbwwbwwbwwbbwwbbwwwwwwwwbwwbbwwwbwwwwwwwwwwwb"+_
  1190.         " bwwbwwwwwwwwwwwb  bwbwwwwwwwwwwwb  bwwwwwwwwwwwwwb   bwwwwwwwwwwwwb   bwwwwwwwwwwwb     bwwwwwwwwwwb "+_
  1191.         "    bwwwwwwwwwwb      bwwwwwwwwb       bwwwwwwwwb       bbbbbbbbbb  "
  1192. MAKEICON 5, Icon$, 17, 22, -5, 0 ' pointer (hand) - 17x22 - offset 6,0
  1193. Icon$ = "wwwwwww        wbbbbbw        wbbbbw         wbbbw          wbbwbw         wbw wbw        "+_
  1194.         "ww   wbw             wbw             wbw   ww        wbw wbw         wbwbbw          wbbbw"+_
  1195.         "         wbbbbw        wbbbbbw        wwwwwww"
  1196. MAKEICON 6, Icon$, 15, 15, -7, -7 ' NWSE resize - 15x15 - offset 8,8
  1197. Icon$ = "bbbbbbbbbbbbbbbwwwwwwwwwbbbbbbbbbbbbbbb bwwwwwwwwwb  bwwwwwwwwwb  bwwbwbwbwwb  bwwwbwbwwwb "+_
  1198.         " bbwwwbwwwbb   bbwwwwwbb     bbwbwbb       bbwbb        bbwbb       bbwwwbb     bbwwbwwbb  "+_
  1199.         " bbwwwwwwwbb  bwwwwbwwwwb  bwwwbwbwwwb  bwwbwbwbwwb  bwbwbwbwbwb bbbbbbbbbbbbbbbwwwwwwwwwbbbbbbbbbbbbbbb"
  1200. MAKEICON 7, Icon$, 13, 22, -6, -10 ' wait - 13x22 - offset 7,11
  1201. Icon$ = "          w                   wbw                 wbbbw               wbbbbbw             wbbbbbbbw      "+_
  1202.         "      wwwwbwwww          ww   wbw   ww       wbw   wbw   wbw     wbbw   wbw   wbbw   wbbbwwwwwbwwwwwbbbw "+_
  1203.         "wbbbbbbbbbbbbbbbbbbbw wbbbwwwwwbwwwwwbbbw   wbbw   wbw   wbbw     wbw   wbw   wbw       ww   wbw   ww    "+_
  1204.         "      wwwwbwwww            wbbbbbbbw             wbbbbbw               wbbbw                 wbw         "+_
  1205.         "          w          "
  1206. MAKEICON 10, Icon$, 21, 21, -10, -10 ' move - 21x21 - offset 11,11
  1207. Icon$ = "        www                wbw                wbw                wbw                wbw        "+_
  1208.         "        wbw                wbw                wbw        wwwwwwwwwbwwwwwwwwwwbbbbbbbbbbbbbbbbbw"+_
  1209.         "wwwwwwwwwbwwwwwwwww        wbw                wbw                wbw                wbw        "+_
  1210.         "        wbw                wbw                wbw                www        "
  1211. MAKEICON 11, Icon$, 19, 19, -9, -9 ' crosshair - 19x19 - offset 10,10
  1212. Icon$ = "wwww wwwwwbbbwbbbwwwwwbwwww   wbw      wbw      wbw      wbw      wbw      wbw      wbw   "+_
  1213.         "   wbw      wbw      wbw      wbw      wbw   wwwwbwwwwwbbbwbbbwwwww wwww"
  1214. MAKEICON 13, Icon$, 9, 18, -4, -8 ' text - 9x18 - offset 5,9
  1215. Icon$ = "       wwwwww            wwbbbbbbww         wbbbbbbbbbbw       wbbbbwwwwbbbbw     wbbbww    wwbbbw  "+_
  1216.         " wbbbbbw      wbbbw  wbbwbbbw      wbbw wbbbwwbbbw     wbbbwwbbw  wbbbw     wbbwwbbw   wbbbw    wbbw"+_
  1217.         "wbbw    wbbbw   wbbwwbbw     wbbbw  wbbwwbbbw     wbbbwwbbbw wbbw      wbbbwbbw  wbbbw      wbbbbbw "+_
  1218.         "  wbbbww    wwbbbw     wbbbbwwwwbbbbw       wbbbbbbbbbbw         wwbbbbbbww            wwwwww       "
  1219. MAKEICON 14, Icon$, 20, 20, -9, -9 ' not-allowed - 20x20 - offset 10,10
  1220. Icon$ = "11111111111111111111121133333331144444444112113355533114455554411211335553311445555441121133555331144444441112"+_
  1221.         "11335553311444444411121133555331144555544112113355533114455554411211333333311444444441121133333331144444444112"+_
  1222.         "11113331111111111111121111111111111111111112116666666117711117711211661111111771111771121166111111177111177112"+_
  1223.         "11666666611777777771121166666661177777777112116655566111111117711211665556611111111771121166666661111111177112"+_
  1224.         "11111111111111111111122222222222222222222222"
  1225. MAKEICON -1, Icon$, 22, 22, 0, 0 ' QB64 - 22x22
  1226.  
  1227. POINTER(4) = POINTER(1)
  1228. POINTER(8) = POINTER(2)
  1229. POINTER(9) = POINTER(6)
  1230. POINTER(12) = POINTER(3)
  1231.  
  1232.  
  1233.  
  1234. '--------------------------------------------------------------------------------------------------------------------------------
  1235. '                                                                                                                        MAKEICON
  1236. SUB MAKEICON (n%, i$, w%, h%, xo%, yo%)
  1237.  
  1238. SHARED POINTER() AS MOUSEPOINTERS
  1239. SHARED QB64Icon&
  1240.  
  1241. DIM x%
  1242. DIM y%
  1243. DIM p$
  1244. DIM c%
  1245.  
  1246. IF n% = -1 THEN
  1247.     QB64Icon& = _NEWIMAGE(22, 22, 32)
  1248.     _DEST QB64Icon&
  1249.     POINTER(n%).Icon = _NEWIMAGE(w%, h%, 32)
  1250.     POINTER(n%).X = xo%
  1251.     POINTER(n%).Y = yo%
  1252.     _DEST POINTER(n%).Icon
  1253. FOR y% = 0 TO h% - 1
  1254.     FOR x% = 0 TO w% - 1
  1255.         c% = c% + 1
  1256.         p$ = MID$(i$, c%, 1)
  1257.         IF p$ = "b" THEN PSET (x%, y%), _RGB32(0, 0, 1)
  1258.         IF p$ = "w" THEN PSET (x%, y%), _RGB32(255, 255, 255)
  1259.         IF p$ = "1" THEN PSET (x%, y%), _RGB32(0, 0, 252)
  1260.         IF p$ = "2" THEN PSET (x%, y%), _RGB32(0, 0, 112)
  1261.         IF p$ = "3" THEN PSET (x%, y%), _RGB32(0, 188, 252)
  1262.         IF p$ = "4" THEN PSET (x%, y%), _RGB32(0, 124, 252)
  1263.         IF p$ = "5" THEN PSET (x%, y%), _RGB32(0, 0, 168)
  1264.         IF p$ = "6" THEN PSET (x%, y%), _RGB32(252, 188, 0)
  1265.         IF p$ = "7" THEN PSET (x%, y%), _RGB32(252, 124, 0)
  1266.     NEXT x%
  1267. NEXT y%
  1268.  
  1269.  
  1270. '--------------------------------------------------------------------------------------------------------------------------------
  1271. '                                                                                                                 CALCULATECOLORS
  1272. SUB CALCULATECOLORS (h%)
  1273.  
  1274. SHARED WIN() AS WIN
  1275.  
  1276. WIN(h%).Wred = _RED(WIN(h%).WColor) '                                                     get RGB components of window color
  1277. WIN(h%).Wgreen = _GREEN(WIN(h%).WColor)
  1278. WIN(h%).Wblue = _BLUE(WIN(h%).WColor)
  1279. WIN(h%).Lighter = _RGB32(WIN(h%).Wred * 1.5, WIN(h%).Wgreen * 1.5, WIN(h%).Wblue * 1.5) ' calculate window/border color shades
  1280. WIN(h%).Light = _RGB32(WIN(h%).Wred * 1.25, WIN(h%).Wgreen * 1.25, WIN(h%).Wblue * 1.25)
  1281. WIN(h%).Dark = _RGB32(WIN(h%).Wred / 1.25, WIN(h%).Wgreen / 1.25, WIN(h%).Wblue / 1.25)
  1282. WIN(h%).Darker = _RGB32(WIN(h%).Wred / 1.5, WIN(h%).Wgreen / 1.5, WIN(h%).Wblue / 1.5)
  1283. WIN(h%).Darkest = _RGB32(WIN(h%).Wred / 2, WIN(h%).Wgreen / 2, WIN(h%).Wblue / 2)
  1284.  
  1285.  
  1286. '--------------------------------------------------------------------------------------------------------------------------------
  1287. '                                                                                                                  MOUSEMOVEMENTY
  1288. FUNCTION MOUSEMOVEMENTY ()
  1289. '
  1290. ' returns the mouse y coordinate difference between calls
  1291. '
  1292. SHARED MOUSE AS MOUSEFLAGS
  1293.  
  1294. STATIC y% ' previous call's mouse y coordinate (saved between calls)
  1295.  
  1296. MOUSEMOVEMENTY = MOUSE.Y - y% ' calculate mouse y offset from previous call
  1297. y% = MOUSE.Y '                  save current mouse y coordinate
  1298.  
  1299.  
  1300. '--------------------------------------------------------------------------------------------------------------------------------
  1301. '                                                                                                                  MOUSEMOVEMENTX
  1302. FUNCTION MOUSEMOVEMENTX ()
  1303. '
  1304. ' returns the mouse x coordinate difference between calls
  1305. '
  1306. SHARED MOUSE AS MOUSEFLAGS
  1307.  
  1308. STATIC x% ' previous call's mouse x coordinate (saved between calls)
  1309.  
  1310. MOUSEMOVEMENTX = MOUSE.X - x% ' calculate mouse x offset from previous call
  1311. x% = MOUSE.X '                  save current mouse x coordinate
  1312.  
  1313.  
  1314.  
  1315.  

I remember that thing, awesome! Thanks for posting it again. :-)
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 19, 2020, 07:14:08 pm
Thanks Terry for your code!

Surely there is so much to study and understand to port in some other system!

PS Do you think that I need just to oversize my demonstration from about 560 lines to your about 1300 lines of code to get your wonderful results? Or do you think that I need to develop more and better skills to project and in second time to code applications?
It is always fine to see your works!
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 19, 2020, 07:22:00 pm
Hi Bplus
about
Quote
but when I click either white box it seems totally random whether they decide to do the white outline for resizing
it is a less precision managment of data.... if you see in the code there are some cases that are no managed: ie the distance between mouse pointer and original border of window in resizing, another is when the user try to reduce the dimension of the window under the minimum setting, in that case the no managment of the data let flickering the white border or move window in the direction of the movement of the mouse pointer...
Going on with the development of this demonstration these issues can be solved. So the displaying data into the windows.
Thanks for more feedback.
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on February 19, 2020, 07:38:10 pm
Hi TempodiBasic,

It is my understanding to resize a window in your code:
1) Click top right box and that activates the 2 white resize boxes
2) Click one of those and that tells your code which corner is anchor and which corner will be moved, this activatees the dashed outline border
3) then you mouse down and drag that box to desired position and release.

or am I operating under the wrong directions?



Hi Terry,

As keybone says "awesome!" I have a question about the resizing, when making a new window instance, is there some limit put on how big the window can be made? I ask because the smallest window in your demo doesn't allow getting bigger but is willing to get smaller easy enough.




These are very ambitious projects! Don't worry TempodiBasic, Terry has 1300 lines and no code yet for clicking a button action ;-)) I imagine with this sort of project you never get the feeling you are finished. :) Except for Fellippe of course. ;-))
Title: Re: child windows into window of the program: a demonstration
Post by: TerryRitchie on February 19, 2020, 07:57:32 pm
Thanks Terry for your code!

Surely there is so much to study and understand to port in some other system!

PS Do you think that I need just to oversize my demonstration from about 560 lines to your about 1300 lines of code to get your wonderful results? Or do you think that I need to develop more and better skills to project and in second time to code applications?
It is always fine to see your works!

Tempo, I tinkered with GUI systems for a few years and came to this conclusion: They are damned difficult to design. The code I posted here was the closest I ever got to making a GUI similar to Windows within QB64. As much as I loathe OOP programming I believe that is the kind of language needed to write an effective GUI. Don't get me wrong, I'm sure it can be done in a functional language such as QB64 (Galleon made a demo that simply blew me away, I have since lost it) but I simply don't have the time nor patience to correctly lay out the means to do so.

Don't give up trying though Tempo. When I first learned of QB64 back in 2010 my coding was MUCH less proficient than yours. I just kept playing, tinkering, and plugging away.
Title: Re: child windows into window of the program: a demonstration
Post by: TerryRitchie on February 19, 2020, 08:12:32 pm
Hi Terry,

As keybone says "awesome!" I have a question about the resizing, when making a new window instance, is there some limit put on how big the window can be made? I ask because the smallest window in your demo doesn't allow getting bigger but is willing to get smaller easy enough.

I have not played with this code in over 4 years. I would need to go back through the code and read my comments to get a feel for it again.
Title: Re: child windows into window of the program: a demonstration
Post by: TerryRitchie on February 19, 2020, 08:14:56 pm
Would anyone happen to have the GUI demo Galleon posted on [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] back around 2012?
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 19, 2020, 08:18:22 pm
@Bplus
so
Quote
It is my understanding to resize a window in your code:
1) Click top right box and that activates the 2 white resize boxes
2) Click one of those and that tells your code which corner is anchor and which corner will be moved, this activatees the dashed outline border
these 2 steps are ok (dashed lines are added only to give more feedback to user, each anchor has its dashed line)
after got dashed line you must
3) move the pointer of mouse without any mouse button pressed (like mouse was locked in dragging mode)
4) left click another time to escape from this situation of dragging anchor without any mouse button pressed
now you get the new dimensioned window.


@Terry
Thanks
and thanks for this http://qb64sourcecode.com/ (http://qb64sourcecode.com/)
Title: Re: child windows into window of the program: a demonstration
Post by: TerryRitchie on February 19, 2020, 09:12:01 pm

and thanks for this http://qb64sourcecode.com/ (http://qb64sourcecode.com/)

I never did finish the last 4 lessons on that site. When the school I was working for forced me to start teaching Python I never found the time to finish.

I'm glad you like it and you are welcome. I've had quite a few people tell me that it helped them get a start in QB64.
Title: Re: child windows into window of the program: a demonstration
Post by: bplus on February 19, 2020, 09:34:59 pm
@Bplus
sothese 2 steps are ok (dashed lines are added only to give more feedback to user, each anchor has its dashed line)
after got dashed line you must
3) move the pointer of mouse without any mouse button pressed (like mouse was locked in dragging mode)
4) left click another time to escape from this situation of dragging anchor without any mouse button pressed
now you get the new dimensioned window.

...

Ah... It does work better, when I click the white box and if it does not respond, it usually responds with a 2nd try after I click the interior of box. I am in such a habit of mouse down and drag to resize, it's hard to test a different way.

Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 20, 2020, 08:38:17 am
Hi

@Keybone
I have tried my code in QB64 1.3 in Lubuntu 16.4 and I have had your same experience!
I don't know why the click is not detected in the little white boxes.... the same code works on Windows 10.

Please try this
1. go in the code to the line 334 of the code
Code: QB64: [Select]
  1.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN  'this one line
  2.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  3.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  4.                             END IF
and cancel the second condition of the IF, you'll find the resizing but with the issue to not be able to choose the bottomright white square.

Please gimme feedback when you can do it.

@Bplus
thanks, this is a problem of bad communication from me...

@QB64 coders
who can give me feedback on MacOs?
Thanks
Title: Re: child windows into window of the program: a demonstration
Post by: keybone on February 20, 2020, 01:21:08 pm
Hi

@Keybone
I have tried my code in QB64 1.3 in Lubuntu 16.4 and I have had your same experience!
I don't know why the click is not detected in the little white boxes.... the same code works on Windows 10.

Please try this
1. go in the code to the line 334 of the code
Code: QB64: [Select]
  1.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN  'this one line
  2.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  3.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  4.                             END IF
and cancel the second condition of the IF, you'll find the resizing but with the issue to not be able to choose the bottomright white square.

Please gimme feedback when you can do it.

@Bplus
thanks, this is a problem of bad communication from me...

@QB64 coders
who can give me feedback on MacOs?
Thanks

Yeah thats kind odd that it works on windows and not linux.
I have no idea why it's not working. Maybe you need to simplify your mouse input routines.
Other than the mouse not working properly, it looks pretty decent.

I'm going to say though that the way this window manager works is pretty unstandard.
It is very different from how it would be expected to work compared to others.

For example the minimize button restores the window from maximized, and the close button minimizes it.
You might want to rethink it a little bit, but not saying its bad or anything, just different. :-)
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on February 21, 2020, 04:35:39 pm
@keybone

I'm thinking that the only difference between the executable compiled in Windows 10 and that compiled in Lubuntu 16.04 is QB64 !
Yes  the translator from QB to C++ to compile with GCC.
So about this
Quote
Yeah thats kind odd that it works on windows and not linux.
I have no idea why it's not working. Maybe you need to simplify your mouse input routines.
I think that the same QB64 code is translated into 2 different ways in the 2 different OSes.
in fact if you cut out 
Code: QB64: [Select]
  1.      AND _MOUSEBUTTON(1)
  from line
 
Code: QB64: [Select]
  1.                      IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN  'this one line
the code works with the original glicth that you can use only the leftest white square of the resizing tool.

about
Quote
For example the minimize button restores the window from maximized, and the close button minimizes it.
You might want to rethink it a little bit, but not saying its bad or anything, just different. :-)

yes the will to build something just different is behind this demonstration...
1. the X to close to the minimum size (the only bar of window) 
2. the maximize button not switching between maximize and restore to normal size
3. the dotted square for resize the window

I agree that the button to restore the area of the window brings a picture that is not intuitive! I'll change this picture with another more clear.

About resizing routine: it is a choice to not use the continue state of left button of mouse down as signal to resize but to use a lock system that can be disactivated clicking outer of the shape of resizing.

Thanks for your feedbacks


Good hearing
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on April 18, 2020, 06:22:47 am
Hy guys
just a little feedback

I have found as to fix the issue on Linux!
it seems that the translation in C++ on Linux's ship makes faster the execution of code...
so if you put a delay not littler than .1 you got the code working well

Code: QB64: [Select]
  1. _DELAY 0.1

under the .1 ( as .08 .05 .02)  the issue comes back!
What fine thing....

As i can recover the rest of fixing I'll post the code with no scattering of window resized and a demo of a module with input in a window and output into another.
Thanks to read
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on May 08, 2020, 04:30:07 am
Hi guys
here a first fixed version of wchild demonstration with its original method for  get resizing, fullscreen, fullwindow and normalwindow child windows into a main window program.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Here the code 

Code: QB64: [Select]
  1. ' HELP:
  2. ' click by left button of mouse on the title bar and drag and drop to move a child window
  3. ' click by left button of mouse on the leftest button on the title bar of a child window to resize window
  4. '   and then click on one of two white squares  and when white border  of window is changed
  5. '   move mouse and the border follow pointerofmouse resizing window.
  6. '   To stop resizing and fix the new dimensions click again on white square
  7. ' click by left button of mouse on the rightest button on the title bar  of window to minimize window to its title bar
  8. ' click by left button of mouse on the second rightest button on the title bar  to maximize window occupying the whole main window
  9. '      in fullscreen mode you get the fullscreen area with wchild choosen
  10. ' click by left button of mouse on the third rightest button on the title bar  to restore the window from minimized_to_bar  to previous status Normal or Maximized
  11. ' click by third (wheel) button of mouse to pass from fullscreen to window status of main window of the program
  12. ' click by second (right) button of mouse to pass from window to fullscreen status of main window of the program
  13.  
  14.  
  15.  
  16. ' settings-------------------------------------------------------
  17. SCREEN _NEWIMAGE(800, 600, 32)
  18. _TITLE "Child windows"
  19. ' the CONST with colors is better to declare after screen definition
  20. ' also if _RGBA32 is indipendent form screen definition
  21. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  22. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  23. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  24.  
  25. ' these constants have the role of commands to execute from windows' engine
  26. CONST Minim = 10, Maxim = 20, Closed = 100
  27. CONST wMin = 5, aNull = 0, aQuit = 9999
  28. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  29. CONST cResize = 700, LResize = 710, RResize = 720, StopResize = 730
  30. ' these constants are universal
  31. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  32.  
  33. _FULLSCREEN ' app starts at fullscreen state
  34. RANDOMIZE TIMER ' to support randomizing
  35.  
  36. 'dataset  -----------------------------------------------
  37. ' components' type
  38. REM here declaration for components used into wchild
  39. REM  for large components you can use an $include file
  40.  
  41. ' window's type
  42. TYPE wChild
  43.     X AS INTEGER ' x of window
  44.     Y AS INTEGER 'y of window
  45.     WIDTH AS INTEGER ' width of window
  46.     Height AS INTEGER 'height of window
  47.     Zorder AS INTEGER 'order along z axis 1 = on top , lower value = at bottom
  48.     Status AS INTEGER 'status maximized/fullscreen, minimized/normal or StatusBar/Closed
  49.     COLOR AS _UNSIGNED LONG ' color of background of window
  50.     Name AS STRING
  51.  
  52. ' 2 arrays one for windows and one for operation with windows
  53. ' like to manage temporary data or store original data
  54. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  55. DIM Action AS INTEGER ' flag of actions for engine
  56.  
  57.  
  58. InitWin ' it creates some windows
  59.  
  60.  
  61.  
  62. ' main loop -----------------------------------------------
  63.  
  64.     ' set the main window's background
  65.     CLS , Orange
  66.     ' reset the flag of engine
  67.     Action = aNull
  68.  
  69.     DrawAllWin ' output windows in Zorder
  70.     GetInput Action ' this SUB takes keyboard and mouse input from user and translate it as engine's command
  71.     DoAction Action ' it executes command of getinput
  72.     _DISPLAY ' retracing the video
  73.     _LIMIT 30 'fps 30
  74.  
  75. ' SUBs and FUNCTIONs --------------------------------------
  76.  
  77.  
  78. SUB InitWin ' it creates  windows and save their data in oldW
  79.     SHARED Windows() AS wChild, OldW() AS wChild
  80.     DIM a AS INTEGER
  81.  
  82.     Windows(1).X = 1
  83.     Windows(1).Y = 1
  84.     Windows(1).WIDTH = 300
  85.     Windows(1).Height = 400
  86.     Windows(1).Zorder = 1
  87.     Windows(1).Status = Minim
  88.     Windows(1).COLOR = Blu
  89.     Windows(1).Name = "Blu"
  90.  
  91.     Windows(2).X = 100
  92.     Windows(2).Y = 1
  93.     Windows(2).WIDTH = 300
  94.     Windows(2).Height = 400
  95.     Windows(2).Zorder = 2
  96.     Windows(2).Status = Minim
  97.     Windows(2).COLOR = Yellow
  98.     Windows(2).Name = "Yellow"
  99.  
  100.     Windows(3).X = 200
  101.     Windows(3).Y = 1
  102.     Windows(3).WIDTH = 300
  103.     Windows(3).Height = 400
  104.     Windows(3).Zorder = 3
  105.     Windows(3).Status = Minim
  106.     Windows(3).COLOR = Green
  107.     Windows(3).Name = "Green"
  108.  
  109.     Windows(4).X = 300
  110.     Windows(4).Y = 1
  111.     Windows(4).WIDTH = 300
  112.     Windows(4).Height = 400
  113.     Windows(4).Zorder = 4
  114.     Windows(4).Status = Minim
  115.     Windows(4).COLOR = Red
  116.     Windows(4).Name = "Red"
  117.     Windows(5).X = 400
  118.     Windows(5).Y = 1
  119.     Windows(5).WIDTH = 300
  120.     Windows(5).Height = 400
  121.     Windows(5).Zorder = 5
  122.     Windows(5).Status = Minim
  123.     Windows(5).COLOR = Cyan
  124.     Windows(5).Name = "Cyan"
  125.  
  126.     FOR a = 1 TO wMin STEP 1
  127.         AdjournWin a 'it stores informations of  windows into OldW
  128.     NEXT a
  129.  
  130. SUB RestoreWin (a AS INTEGER) ' it restores data of a windows from OldW
  131.     SHARED Windows() AS wChild, OldW() AS wChild
  132.  
  133.     Windows(a).X = OldW(a).X
  134.     Windows(a).Y = OldW(a).Y
  135.     Windows(a).WIDTH = OldW(a).WIDTH
  136.     Windows(a).Height = OldW(a).Height
  137.     Windows(a).Zorder = OldW(a).Zorder
  138.     Windows(a).COLOR = OldW(a).COLOR
  139.  
  140. SUB AdjournWin (a AS INTEGER) 'it saves data of a window into OldW
  141.     SHARED Windows() AS wChild, OldW() AS wChild
  142.  
  143.     OldW(a).X = Windows(a).X
  144.     OldW(a).Y = Windows(a).Y
  145.     OldW(a).WIDTH = Windows(a).WIDTH
  146.     OldW(a).Height = Windows(a).Height
  147.     OldW(a).Zorder = Windows(a).Zorder
  148.     OldW(a).COLOR = Windows(a).COLOR
  149.  
  150. SUB DrawAllWin ' it draws all windows starting from bottom of Zorder stack
  151.     SHARED Windows() AS wChild ' here parameters of wchild and components
  152.     DIM Finished AS INTEGER 'target to draw
  153.     DIM a AS INTEGER ' counter of FOR
  154.     Finished = wMin ' it starts from the bottom of Zorder
  155.     DO
  156.         FOR a = 1 TO wMin 'for all windows created (wMin)
  157.             IF Windows(a).Zorder = Finished THEN ' if the window is that we are searching
  158.                 DrawWindow Windows(a), a 'we draw window
  159.                 Finished = Finished - 1 'we decrease the pointer from bottom to up until the first window
  160.                 EXIT FOR ' next window
  161.             END IF
  162.         NEXT a
  163.     LOOP UNTIL Finished = 0
  164.  
  165. SUB Focus (Index AS INTEGER) ' it puts a windows at top of Zorder and the previous top window to the bottom
  166.     SHARED Windows() AS wChild
  167.     DIM b AS INTEGER
  168.     FOR b = 1 TO wMin
  169.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  170.     NEXT b
  171.     ' here it changes the position between the new Ontpo window and the last Ontop Window
  172.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  173.     DrawAllWin
  174.  
  175.  
  176. SUB DoAction (Act AS INTEGER) ' it is the engine of the manager of windows
  177.     SHARED Windows() AS wChild, OldW() AS wChild
  178.     ' engine's variables
  179.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  180.  
  181.     ' mouse's variables
  182.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  183.     ' it executes Act's content
  184.     SELECT CASE Act
  185.         CASE aQuit
  186.             END
  187.  
  188.         CASE Maxim
  189.             _FULLSCREEN
  190.  
  191.         CASE Minim
  192.             _FULLSCREEN _OFF
  193.  
  194.         CASE mLeft ' Left Click of mouse
  195.             mX = _MOUSEX ' we store the actual X and Y of mouse
  196.             mY = _MOUSEY
  197.  
  198.             ' search where and what mouse has touched by leftclick
  199.             OldA = 0
  200.             OldActio = 0
  201.             FOR a = 1 TO wMin ' windows(0) is out of action
  202.                 Actio = IsInWindow(mX, mY, Windows(a)) ' what window on the top of stack is interacting with mouse
  203.                 IF Actio THEN
  204.                     IF OldA <= 0 THEN ' if no previous window has interact with mouse
  205.                         OldA = a 'we memorize action and index of window
  206.                         OldActio = Actio
  207.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN ' if actual window has a Zorder less the previouse
  208.                         OldA = a ' we memorize action and  index of window
  209.                         OldActio = Actio
  210.                     END IF
  211.                 END IF
  212.             NEXT a
  213.             IF a > OldA THEN
  214.                 a = OldA ' restore the last windows interacting
  215.                 Actio = OldActio
  216.             END IF
  217.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB ' no action out of SUB
  218.  
  219.  
  220.             Focus a 'set zorder on the (a) window that gets the input
  221.  
  222.  
  223.             SELECT CASE Actio
  224.                 CASE cMinim
  225.                     ' here restore to  standard (bar + area of window) status of child window
  226.                     IF Windows(a).Status = Closed + Maxim THEN
  227.                         ' if windows is a closed maximized window
  228.                         ' we restore its status of maximized
  229.                         Windows(a).Status = Maxim
  230.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  231.                         ' if windows is a closed minimized window
  232.                         ' we restore its status of minimized
  233.                         Windows(a).Status = Minim
  234.                     ELSEIF Windows(a).Status = Maxim THEN
  235.                         ' if is a window maximized it gets back all info setting
  236.                         ' we restore its status of minimized
  237.                         RestoreWin a
  238.                         Windows(a).Status = Minim
  239.                     END IF
  240.  
  241.  
  242.                 CASE cMaxim
  243.                     ' here convert the window to full size of main window of the program
  244.                     ' OR gives 1 if both parameter are true or al last one is true
  245.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  246.                         ' it acts if windows if not still maximized
  247.                         ' it is minimized window opened or closed
  248.                         ' memorize window's data when it is not maximized
  249.                         '                        IF Windows(a).Width < _WIDTH THEN
  250.                         AdjournWin a
  251.                         ' it sets maximized status
  252.                         Windows(a).WIDTH = _WIDTH
  253.                         Windows(a).Height = _HEIGHT
  254.                         Windows(a).X = 1
  255.                         Windows(a).Y = 1
  256.                         ' change status
  257.                         Windows(a).Status = Maxim
  258.                     END IF
  259.  
  260.                 CASE cClosed
  261.                     ' here minimize the child window to its window bar
  262.                     IF NOT Windows(a).Status > Closed THEN
  263.                         Windows(a).Status = Windows(a).Status + Closed
  264.                     END IF
  265.  
  266.                 CASE Dragging
  267.                     ' dragging is possible for all status of windows
  268.                     '
  269.                     ' if minimized or Closed and minimized window we save data info
  270.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  271.                     ' it sets variables for dragging
  272.                     OldW(0).X = Windows(a).X
  273.                     OldW(0).Y = Windows(a).Y
  274.                     OldW(0).WIDTH = Windows(a).WIDTH
  275.                     OldW(0).Height = Windows(a).Height
  276.  
  277.                     OmX = _MOUSEX - OldW(0).X ' we store actual value of X and Y of mouse
  278.                     OmY = _MOUSEY - OldW(0).Y
  279.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  280.                     DO WHILE _MOUSEBUTTON(1) ' while left mouse is pressed down
  281.                         IF _MOUSEINPUT THEN ' if there is a mouseinput
  282.                             CLS , Orange 'reset background
  283.  
  284.                             OldW(0).X = (_MOUSEX - OmX) 'it adjourns window X and Y
  285.                             OldW(0).Y = (_MOUSEY - OmY)
  286.                             DrawAllWin ' it shows all windows
  287.                             dragWindow OldW(0) ' it shows white skeleton of window
  288.                         END IF
  289.                     LOOP
  290.                     ' new position of window
  291.                     Windows(a).X = OldW(0).X
  292.                     Windows(a).Y = OldW(0).Y
  293.                     OldW(a).X = Windows(a).X
  294.                     OldW(a).Y = Windows(a).Y
  295.  
  296.                 CASE Focusing
  297.                     Focus a ' it puts at the top of stack of windows
  298.  
  299.                 CASE cResize
  300.                     ' resizing is possible only for minimized opened child windows
  301.                     IF Windows(a).Status = Minim THEN
  302.                         Windows(a).Status = cResize
  303.                         DO WHILE _MOUSEBUTTON(1) OR _MOUSEINPUT: LOOP ' it waits if there is a mouse input
  304.                         DO WHILE Windows(a).Status = cResize ' while window is in resize mode
  305.                             CLS , Orange ' it redraws background of main window
  306.                             DrawAllWin ' it draws all mouse  windows
  307.                             ShowDimension Windows(a), 0
  308.  
  309.                             ' if mouse move or left mouse button is down
  310.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN
  311.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  312.                                 _DELAY 0.1 ' <---- this fixs Linus issue
  313.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  314.                             END IF
  315.                             _DISPLAY
  316.                         LOOP
  317.                     END IF
  318.  
  319.             END SELECT
  320.         CASE ELSE
  321.     END SELECT
  322.  
  323. SUB IsResizing (Win AS wChild, mX AS INTEGER, mY AS INTEGER) ' this resize window by mouse
  324.     SHARED Windows() AS wChild, OldW() AS wChild
  325.     DIM Actio AS INTEGER, OldmX AS INTEGER, OldmY AS INTEGER
  326.     Actio = 0
  327.     'if mouse X is in the X range of the window
  328.     IF IsInTheRange%(mX, Win.X, Win.X + Win.WIDTH) THEN
  329.         ' if mouse Y is in the y range of the window
  330.         IF IsInTheRange%(mY, Win.Y, Win.Y + Win.Height) THEN
  331.             ' do nothing if it is in the range of window
  332.         ELSE
  333.             ' user click out of area  of window to resize
  334.             Actio = StopResize
  335.         END IF
  336.     ELSE
  337.         ' user click out of area  of window to resize
  338.         Actio = StopResize
  339.     END IF
  340.  
  341.  
  342.  
  343.  
  344.     ' if mouse X is in the x range  of the leftest button on the window's bar
  345.     IF IsInTheRange%(mX, Win.X, Win.X + 10) THEN
  346.         ' if mouse Y is in the y range of the window's bar
  347.         IF IsInTheRange%(mY, Win.Y, Win.Y + 10) THEN
  348.             ' user click on lefttop square to resize
  349.             Actio = LResize
  350.         END IF
  351.     END IF
  352.     ' if mouse X is in the range of rightest button of window's bar
  353.     IF IsInTheRange%(mX, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  354.         ' if mouse Y is in the y range of the bottom of window
  355.         IF IsInTheRange%(mY, Win.Y + Win.Height - 10, Win.Y + Win.Height) THEN
  356.             ' user click on the rightbottom square to resize
  357.             Actio = RResize
  358.         END IF
  359.     END IF
  360.  
  361.     IF Actio = 0 THEN
  362.         ' no action done
  363.     ELSEIF Actio = LResize THEN
  364.         ' choosen LeftTop buttom to resize
  365.         OldW(0).X = Win.X
  366.         OldW(0).Y = Win.Y
  367.         OldW(0).WIDTH = Win.WIDTH
  368.         OldW(0).Height = Win.Height
  369.         OldmX = _MOUSEX
  370.         OldmY = _MOUSEY
  371.         DO WHILE Actio = LResize
  372.             IF _MOUSEINPUT THEN ' if mouse moves it adapts the dimension to the minimun default value for X and Y
  373.                 IF (OldW(0).X + OldW(0).WIDTH - OldmX) >= 70 THEN OldW(0).WIDTH = OldW(0).X + OldW(0).WIDTH - OldmX ELSE OldW(0).WIDTH = 70: OldW(0).X = Win.X + Win.WIDTH - 70: OldmX = OldW(0).X
  374.                 IF (OldW(0).Y + OldW(0).Height - OldmY) >= 30 THEN OldW(0).Height = OldW(0).Y + OldW(0).Height - OldmY ELSE OldW(0).Height = 30: OldW(0).Y = Win.Y + Win.Height - 30: OldmY = OldW(0).Y
  375.                 CLS , Orange
  376.                 DrawAllWin
  377.                 ShowDimension OldW(0), Actio
  378.                 OldW(0).X = OldmX ' it stores new Oldmx and OldmY
  379.                 OldW(0).Y = OldmY
  380.  
  381.                 OldmX = _MOUSEX
  382.                 OldmY = _MOUSEY
  383.             ELSE
  384.                 IF _MOUSEBUTTON(1) THEN Actio = 0 ' a second leftclick stops the resize action
  385.             END IF
  386.         LOOP
  387.         Win.X = OldW(0).X 'the new dimension of windows are stored
  388.         Win.Y = OldW(0).Y
  389.         Win.WIDTH = OldW(0).WIDTH
  390.         Win.Height = OldW(0).Height
  391.  
  392.  
  393.     ELSEIF Actio = RResize THEN
  394.         ' choosen bottomright square
  395.         OldW(0).X = Win.X ' it gets the window dimensions
  396.         OldW(0).Y = Win.Y
  397.         OldW(0).WIDTH = Win.WIDTH
  398.         OldW(0).Height = Win.Height
  399.         OldmX = _MOUSEX 'actual mouse X and Y
  400.         OldmY = _MOUSEY
  401.         DO WHILE Actio = RResize ' while is active resize from right
  402.             IF _MOUSEINPUT THEN ' if mouse moves it adapts the dimension of window to mouse position
  403.                 IF OldmX - OldW(0).X >= 70 THEN OldW(0).WIDTH = OldmX - OldW(0).X
  404.                 IF OldmY - OldW(0).Y >= 30 THEN OldW(0).Height = OldmY - OldW(0).Y
  405.                 CLS , Orange
  406.                 DrawAllWin
  407.                 ShowDimension OldW(0), Actio
  408.                 OldmX = _MOUSEX
  409.                 OldmY = _MOUSEY
  410.             ELSE
  411.                 IF _MOUSEBUTTON(1) THEN Actio = 0 ' il mouse leftclick it stops resize
  412.             END IF
  413.         LOOP
  414.         Win.X = OldW(0).X 'it adjusts the dimensions of window to the new status
  415.         Win.Y = OldW(0).Y
  416.         Win.WIDTH = OldW(0).WIDTH
  417.         Win.Height = OldW(0).Height
  418.  
  419.     ELSEIF Actio = StopResize THEN
  420.         ' click out of window to stop resize action
  421.         Win.Status = Minim
  422.     END IF
  423.  
  424. SUB ShowDimension (win AS wChild, Actio AS INTEGER) ' it shows skeleton of window with 2 buttons for dimensioning
  425.     IF win.Status = cResize AND Actio = 0 THEN
  426.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B ' windows size
  427.     ELSEIF Actio = LResize THEN
  428.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 45 ' windows size
  429.     ELSEIF Actio = RResize THEN
  430.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 200 ' windows size
  431.     END IF
  432.     LINE (win.X, win.Y)-(win.X + 10, win.Y + 10), White, BF 'button for resizing window
  433.     LINE (win.X + win.WIDTH - 10, win.Y + win.Height - 10)-(win.X + win.WIDTH, win.Y + win.Height), White, BF 'button for resizing window
  434.     _DISPLAY
  435.  
  436. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild) 'it searches if mouse is in window passed as Win
  437.     IsInWindow = mFalse
  438.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  439.         ' if window is closed to its bar it cannot get focus on the window area
  440.         IF IsInTheRange%(X, Win.X, Win.X + Win.WIDTH) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  441.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  442.         ' if it is the window bar area
  443.         IF IsInTheRange%(X, Win.X + 10, Win.X + Win.WIDTH - 31) THEN
  444.             ' if it is to the left of buttons on the bar
  445.             IsInWindow = Dragging
  446.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 30, Win.X + Win.WIDTH - 21) THEN
  447.             ' if it is on the leftest button on the bar
  448.             IsInWindow = cMinim ' icon minimize--> restore to child default
  449.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 20, Win.X + Win.WIDTH - 11) THEN
  450.             ' if it is on the middle button on the bar
  451.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  452.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  453.             ' if is on the rightest button on the bar
  454.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  455.         ELSEIF IsInTheRange%(X, Win.X, Win.X + 10) THEN ' if is on the left side of bar on Resize button
  456.             IsInWindow = cResize
  457.         END IF
  458.     END IF
  459.  
  460. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER) ' it tests if What is between Min and Max
  461.     IF Min > Max THEN SWAP Min, Max
  462.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  463.  
  464. SUB dragWindow (Win AS wChild) ' this draw the white skeleton of a window
  465.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), White, B ' windows size
  466.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), White, BF 'title bar for dragging window
  467.     _DISPLAY
  468.  
  469. SUB wClosed (Win AS wChild) 'title bar button for show only title bar of window
  470.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF
  471.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Black, B
  472.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 3)-(Win.X + Win.WIDTH - 3, Win.Y + 7), Black
  473.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 7)-(Win.X + Win.WIDTH - 3, Win.Y + 3), Black
  474.  
  475. SUB wMaxim (win AS wChild) 'title bar  button for maximize to the whole main window
  476.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Pink, BF
  477.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Black, B
  478.     LINE (win.X + win.WIDTH - 17, win.Y + 3)-(win.X + win.WIDTH - 13, win.Y + 7), Black, B
  479.  
  480. SUB wMinim (Win AS wChild) 'title bar button for restore to original dimensions
  481.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Pink, BF
  482.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Black, B
  483.     LINE (Win.X + Win.WIDTH - 27, Win.Y + 3)-(Win.X + Win.WIDTH - 23, Win.Y + 4), Black, BF
  484.     LINE (Win.X + Win.WIDTH - 27, Win.Y + 3)-(Win.X + Win.WIDTH - 23, Win.Y + 7), Black, B , &B1010101010101010
  485.  
  486. SUB wResize (Win AS wChild) 'title bar button for resize  dimensions of window
  487.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Pink, BF
  488.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Black, B
  489.     LINE (Win.X + 2, Win.Y + 2)-(Win.X + 7, Win.Y + 7), Black, B , &B1010101010101010
  490.  
  491. SUB DrawWindow (Win AS wChild, a AS INTEGER) ' it draws a window aspect following its status
  492.  
  493.     ' the window
  494.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  495.         LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Win.COLOR, BF
  496.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  497.         LINE (Win.X + Win.WIDTH, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  498.     END IF
  499.     ' the title bar
  500.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF 'title bar for dragging window
  501.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.WIDTH, Win.Y + 10), Black
  502.     wMinim Win
  503.     wMaxim Win
  504.     wClosed Win
  505.     wResize Win
  506.  
  507.     ' the content of the window
  508.     REM here the draw routine of components
  509.  
  510.  
  511.  
  512. SUB GetInput (Act AS INTEGER) ' manager of input by keyboard & mouse
  513.     DIM mInput AS INTEGER ' flag of commands of mouse
  514.  
  515.  
  516.     ' keyboard input
  517.     a$ = INKEY$
  518.     IF a$ = CHR$(27) THEN Act = aQuit 'keyboard's command in feedback by Act
  519.  
  520.     'mouse input
  521.     mInput = mFalse
  522.     IF _MOUSEINPUT THEN mInput = mTrue
  523.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  524.     LOOP
  525.     IF mInput THEN ' here flag of mouse gets the command's values
  526.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  527.             mInput = mLR
  528.         ELSEIF _MOUSEBUTTON(1) THEN
  529.             mInput = mLeft
  530.         ELSEIF _MOUSEBUTTON(2) THEN
  531.             mInput = mRight
  532.         ELSEIF _MOUSEBUTTON(3) THEN
  533.             mInput = mMiddle
  534.         END IF
  535.     END IF
  536.     'mouse's command in feedback by Act
  537.     IF mInput = mLR THEN
  538.         Act = aQuit
  539.     ELSEIF mInput = mMiddle THEN
  540.         Act = Minim
  541.     ELSEIF mInput = mRight THEN
  542.         Act = Maxim
  543.     ELSEIF mInput = mLeft THEN
  544.         Act = mInput
  545.     END IF
  546.  
  547.  
  548.  
Title: Re: child windows into window of the program: a demonstration
Post by: TempodiBasic on May 11, 2020, 03:27:50 pm
Hi
it is just an update to show how to manage a content of child windows.
Here there is a simple label into windows... coming soon a BMI database for people

Code: QB64: [Select]
  1. ' 2020 04 18  Fixed Linux issue about selection of resizing white buttons
  2.  
  3. ' 2020 04 03  creating label as component of window (label is from 1 to 100 characters on one line)
  4. '             to be visible in a window it is printed only for the inner width of window
  5.  
  6. ' 2020 03 25  fixing  window undraggable if it has been put lefter  to
  7. ' the left border of main window
  8.  
  9. ' 2020 02 17  fixing resize from left bug with scattering of window resized
  10.  
  11. ' 2020 02 12  with the power of the second array we implement the feature
  12. '             of resizable of child window
  13.  
  14. ' 2020 02 09  with the power of the second array we implement a different
  15. '             child windows' system:
  16. '             all child windows can be Closed to window's bar
  17. '             all child windows can be dragged on the screen
  18.  
  19. ' 2020 02 08  using a second array we store windows information indipendently so
  20. '             now each window can be modified and restored
  21.  
  22.  
  23. ' 2020 02 06  after dragging or maximize a window, restoring it we gives
  24. '             to it the last value used in windows(0) so the info of the last
  25. '             window that is dragged or maximize when we use Minimize button on
  26. '             another child window
  27. '             the fix can be got using a shadow array that stores windows informations
  28. '             or windows(0) as the child window that takes the information of the
  29. '             child window that must be acted (Minimize, Maximize and Closed)
  30. '             and we use it as template to make graphic output
  31.  
  32. ' 2020 02 05 fixed a minor bug on mouse click events
  33. '            activated events Maxim Minim and Closed
  34.  
  35.  
  36. ' 2020 02 03 increasing the windows managed and close initialization to SUB
  37. '            removed vMax SHARED variable
  38. '            added 3 buttons on the rightest site of the bar of the child window
  39. '            SUB wClosed, wMaxim, wMinim
  40. '            In this version the user can maximize one child window to the application window
  41. '            In the status of Maxim the child window has the focus and can be only
  42. '            reduced to status Minim, it cannot be dragging or Closed to bar of window
  43.  
  44.  
  45. ' 2020 01 30 fixed bug on focusing a child window
  46. '
  47.  
  48. ' 2020 01 25  A program with child windows into it
  49. ' we need a system to manage multiple windows
  50. ' and a system to manage input/output
  51. ' and a system to make graphic report
  52.  
  53.  
  54. ' settings-------------------------------------------------------
  55. SCREEN _NEWIMAGE(800, 600, 32)
  56. _TITLE "Child windows"
  57. ' the CONST with colors is better to declare after screen definition
  58. ' also if _RGBA32 is indipendent form screen definition
  59. CONST Black = _RGBA32(0, 0, 0, 255), White = _RGBA32(255, 255, 255, 255), Red = _RGBA32(200, 0, 0, 255)
  60. CONST Green = _RGBA32(0, 200, 0, 255), Blu = _RGBA32(0, 0, 200, 255), Yellow = _RGBA32(200, 200, 20, 255)
  61. CONST Cyan = _RGBA32(20, 140, 230, 255), Orange = _RGBA32(200, 100, 20, 255), Pink = _RGBA32(227, 80, 120, 255)
  62.  
  63. ' these constants have the role of commands to execute from windows' engine
  64. CONST Minim = 10, Maxim = 20, Closed = 100
  65. CONST wMin = 5, aNull = 0, aQuit = 9999
  66. CONST Dragging = 300, Focusing = 200, cMinim = 400, cMaxim = 500, cClosed = 600
  67. CONST cResize = 700, LResize = 710, RResize = 720, StopResize = 730
  68. ' these constants are universal
  69. CONST mTrue = 1, mFalse = 0, mLeft = 2, mRight = 3, mMiddle = 4, mLR = 5
  70.  
  71. _FULLSCREEN ' app starts at fullscreen state
  72. RANDOMIZE TIMER ' to support randomizing
  73.  
  74. 'dataset  -----------------------------------------------
  75. ' components type
  76. TYPE Label
  77.     X AS INTEGER ' x relative to x of parent window
  78.     Y AS INTEGER ' y relative to y of parent window
  79.     Parent AS STRING ' the name of window   if=" Desktop" it is the main window
  80.     Lenght AS INTEGER ' lenght of label
  81.     Caption AS STRING ' the text of label
  82.     Color AS _UNSIGNED LONG ' foreground color of text of label
  83.     font AS LONG ' it is handle of font
  84.  
  85. ' window's type
  86. TYPE wChild
  87.     X AS INTEGER ' x of window
  88.     Y AS INTEGER 'y of window
  89.     WIDTH AS INTEGER ' width of window
  90.     Height AS INTEGER 'height of window
  91.     Zorder AS INTEGER 'order along z axis 1 = on top , lower value = at bottom
  92.     Status AS INTEGER 'status maximized/fullscreen, minimized/normal or StatusBar/Closed
  93.     COLOR AS _UNSIGNED LONG ' color of background of window
  94.     Name AS STRING
  95. ' 2 arrays one for windows and one for operation with windows
  96. ' like to manage temporary data or store original data
  97. REDIM Windows(1 TO wMin) AS wChild, OldW(0 TO wMin) AS wChild
  98. DIM L(1 TO wMin) AS Label
  99. DIM Action AS INTEGER ' flag of actions for engine
  100.  
  101.  
  102. InitWin ' it creates some windows
  103. InitLabel L(), Windows()
  104.  
  105.  
  106.  
  107.  
  108. ' main loop -----------------------------------------------
  109.  
  110.     ' set the main window's background
  111.     CLS , Orange
  112.     ' reset the flag of engine
  113.     Action = aNull
  114.  
  115.     DrawAllWin ' output windows in Zorder
  116.     GetInput Action ' this SUB takes keyboard and mouse input from user and translate it as engine's command
  117.     DoAction Action ' it executes command of getinput
  118.     _DISPLAY ' retracing the video
  119.     _LIMIT 30 'fps 30
  120.  
  121. ' SUBs and FUNCTIONs --------------------------------------
  122. SUB ShowString (L AS Label, Win AS wChild)
  123.     IF Win.Status <> Minim AND Win.Status <> Maxim THEN EXIT SUB
  124.     DIM VisibleString AS STRING, NumChar AS INTEGER
  125.     IF _FONTHEIGHT(L.font) + L.Y >= Win.Height THEN EXIT SUB
  126.     IF L.Lenght + L.X >= Win.WIDTH THEN
  127.         NumChar = CINT((Win.WIDTH - L.X - 4) / _FONTWIDTH)
  128.         VisibleString = LEFT$(L.Caption, NumChar)
  129.     ELSE
  130.         VisibleString = L.Caption
  131.     END IF
  132.     COLOR L.Color, Win.COLOR
  133.     _PRINTSTRING (L.X + Win.X, L.Y + Win.Y + 10), VisibleString
  134.  
  135. SUB InitLabel (L() AS Label, win() AS wChild)
  136.     FOR a% = 1 TO wMin
  137.         L(a%).X = 3 + (RND * (win(a%).Height / 2) - 10)
  138.         L(a%).Y = 4 + (RND * (win(a%).WIDTH / 2) - 10)
  139.         L(a%).Parent = win(a%).Name
  140.         L(a%).Caption = "This is a demonstration of output"
  141.         L(a%).Color = _RGBA32(133, 39, 177, 255)
  142.         L(a%).font = _LOADFONT("cour.ttf", 12, "monospace")
  143.         IF L(a%).font <= 0 THEN PRINT "error loading font ": SLEEP
  144.         L(a%).Lenght = LEN(L(a%).Caption) * _FONTWIDTH
  145.     NEXT a%
  146.  
  147. SUB InitWin ' it creates  windows and save their data in oldW
  148.     SHARED Windows() AS wChild, OldW() AS wChild
  149.     DIM a AS INTEGER
  150.  
  151.     Windows(1).X = 1
  152.     Windows(1).Y = 1
  153.     Windows(1).WIDTH = 300
  154.     Windows(1).Height = 400
  155.     Windows(1).Zorder = 1
  156.     Windows(1).Status = Minim
  157.     Windows(1).COLOR = Blu
  158.     Windows(1).Name = "Blu"
  159.  
  160.     Windows(2).X = 100
  161.     Windows(2).Y = 1
  162.     Windows(2).WIDTH = 300
  163.     Windows(2).Height = 400
  164.     Windows(2).Zorder = 2
  165.     Windows(2).Status = Minim
  166.     Windows(2).COLOR = Yellow
  167.     Windows(2).Name = "Yellow"
  168.  
  169.     Windows(3).X = 200
  170.     Windows(3).Y = 1
  171.     Windows(3).WIDTH = 300
  172.     Windows(3).Height = 400
  173.     Windows(3).Zorder = 3
  174.     Windows(3).Status = Minim
  175.     Windows(3).COLOR = Green
  176.     Windows(3).Name = "Green"
  177.  
  178.     Windows(4).X = 300
  179.     Windows(4).Y = 1
  180.     Windows(4).WIDTH = 300
  181.     Windows(4).Height = 400
  182.     Windows(4).Zorder = 4
  183.     Windows(4).Status = Minim
  184.     Windows(4).COLOR = Red
  185.     Windows(4).Name = "Red"
  186.     Windows(5).X = 400
  187.     Windows(5).Y = 1
  188.     Windows(5).WIDTH = 300
  189.     Windows(5).Height = 400
  190.     Windows(5).Zorder = 5
  191.     Windows(5).Status = Minim
  192.     Windows(5).COLOR = Cyan
  193.     Windows(5).Name = "Cyan"
  194.  
  195.     FOR a = 1 TO wMin STEP 1
  196.         AdjournWin a 'it stores informations of  windows into OldW
  197.     NEXT a
  198.  
  199. SUB RestoreWin (a AS INTEGER) ' it restores data of a windows from OldW
  200.     SHARED Windows() AS wChild, OldW() AS wChild
  201.  
  202.     Windows(a).X = OldW(a).X
  203.     Windows(a).Y = OldW(a).Y
  204.     Windows(a).WIDTH = OldW(a).WIDTH
  205.     Windows(a).Height = OldW(a).Height
  206.     Windows(a).Zorder = OldW(a).Zorder
  207.     Windows(a).COLOR = OldW(a).COLOR
  208.  
  209. SUB AdjournWin (a AS INTEGER) 'it saves data of a window into OldW
  210.     SHARED Windows() AS wChild, OldW() AS wChild
  211.  
  212.     OldW(a).X = Windows(a).X
  213.     OldW(a).Y = Windows(a).Y
  214.     OldW(a).WIDTH = Windows(a).WIDTH
  215.     OldW(a).Height = Windows(a).Height
  216.     OldW(a).Zorder = Windows(a).Zorder
  217.     OldW(a).COLOR = Windows(a).COLOR
  218.  
  219. SUB DrawAllWin ' it draws all windows starting from bottom of Zorder stack
  220.     SHARED Windows() AS wChild, L AS Label
  221.     DIM Finished AS INTEGER 'target to draw
  222.     DIM a AS INTEGER ' counter of FOR
  223.     Finished = wMin ' it starts from the bottom of Zorder
  224.     DO
  225.         FOR a = 1 TO wMin 'for all windows created (wMin)
  226.             IF Windows(a).Zorder = Finished THEN ' if the window is that we are searching
  227.                 DrawWindow Windows(a), a 'we draw window
  228.                 Finished = Finished - 1 'we decrease the pointer from bottom to up until the first window
  229.                 EXIT FOR ' next window
  230.             END IF
  231.         NEXT a
  232.     LOOP UNTIL Finished = 0
  233.  
  234. SUB Focus (Index AS INTEGER) ' it puts a windows at top of Zorder and the previous top window to the bottom
  235.     SHARED Windows() AS wChild
  236.     DIM b AS INTEGER
  237.     FOR b = 1 TO wMin
  238.         IF Windows(b).Zorder = 1 THEN EXIT FOR
  239.     NEXT b
  240.     ' here it changes the position between the new Ontpo window and the last Ontop Window
  241.     IF Index <> b THEN SWAP Windows(Index).Zorder, Windows(b).Zorder
  242.     DrawAllWin
  243.  
  244.  
  245. SUB DoAction (Act AS INTEGER) ' it is the engine of the manager of windows
  246.     SHARED Windows() AS wChild, OldW() AS wChild
  247.     ' engine's variables
  248.     DIM a AS INTEGER, Actio AS INTEGER, OldA AS INTEGER, OldActio AS INTEGER
  249.  
  250.     ' mouse's variables
  251.     DIM mX AS INTEGER, mY AS INTEGER, OmX AS INTEGER, OmY AS INTEGER
  252.     ' it executes Act's content
  253.     SELECT CASE Act
  254.         CASE aQuit
  255.             END
  256.  
  257.         CASE Maxim
  258.             _FULLSCREEN
  259.  
  260.         CASE Minim
  261.             _FULLSCREEN _OFF
  262.  
  263.         CASE mLeft ' Left Click of mouse
  264.             mX = _MOUSEX ' we store the actual X and Y of mouse
  265.             mY = _MOUSEY
  266.  
  267.             ' search where and what mouse has touched by leftclick
  268.             OldA = 0
  269.             OldActio = 0
  270.             FOR a = 1 TO wMin ' windows(0) is out of action
  271.                 Actio = IsInWindow(mX, mY, Windows(a)) ' what window on the top of stack is interacting with mouse
  272.                 IF Actio THEN
  273.                     IF OldA <= 0 THEN ' if no previous window has interact with mouse
  274.                         OldA = a 'we memorize action and index of window
  275.                         OldActio = Actio
  276.                     ELSEIF Windows(a).Zorder < Windows(OldA).Zorder THEN ' if actual window has a Zorder less the previouse
  277.                         OldA = a ' we memorize action and  index of window
  278.                         OldActio = Actio
  279.                     END IF
  280.                 END IF
  281.             NEXT a
  282.             IF a > OldA THEN
  283.                 a = OldA ' restore the last windows interacting
  284.                 Actio = OldActio
  285.             END IF
  286.             IF OldA = 0 OR OldActio = 0 THEN EXIT SUB ' no action out of SUB
  287.  
  288.  
  289.             Focus a 'set zorder on the (a) window that gets the input
  290.  
  291.  
  292.             SELECT CASE Actio
  293.                 CASE cMinim
  294.                     ' here restore to  standard (bar + area of window) status of child window
  295.                     IF Windows(a).Status = Closed + Maxim THEN
  296.                         ' if windows is a closed maximized window
  297.                         ' we restore its status of maximized
  298.                         Windows(a).Status = Maxim
  299.                     ELSEIF Windows(a).Status = Closed + Minim THEN
  300.                         ' if windows is a closed minimized window
  301.                         ' we restore its status of minimized
  302.                         Windows(a).Status = Minim
  303.                     ELSEIF Windows(a).Status = Maxim THEN
  304.                         ' if is a window maximized it gets back all info setting
  305.                         ' we restore its status of minimized
  306.                         RestoreWin a
  307.                         Windows(a).Status = Minim
  308.                     END IF
  309.  
  310.  
  311.                 CASE cMaxim
  312.                     ' here convert the window to full size of main window of the program
  313.                     ' OR gives 1 if both parameter are true or al last one is true
  314.                     IF (Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim) THEN
  315.                         ' it acts if windows if not still maximized
  316.                         ' it is minimized window opened or closed
  317.                         ' memorize window's data when it is not maximized
  318.                         '                        IF Windows(a).Width < _WIDTH THEN
  319.                         AdjournWin a
  320.                         ' it sets maximized status
  321.                         Windows(a).WIDTH = _WIDTH
  322.                         Windows(a).Height = _HEIGHT
  323.                         Windows(a).X = 1
  324.                         Windows(a).Y = 1
  325.                         ' change status
  326.                         Windows(a).Status = Maxim
  327.                     END IF
  328.  
  329.                 CASE cClosed
  330.                     ' here minimize the child window to its window bar
  331.                     IF NOT Windows(a).Status > Closed THEN
  332.                         Windows(a).Status = Windows(a).Status + Closed
  333.                     END IF
  334.  
  335.                 CASE Dragging
  336.                     ' dragging is possible for all status of windows
  337.                     '
  338.                     ' if minimized or Closed and minimized window we save data info
  339.                     IF Windows(a).Status = Minim OR Windows(a).Status = Closed + Minim THEN AdjournWin a
  340.                     ' it sets variables for dragging
  341.                     OldW(0).X = Windows(a).X
  342.                     OldW(0).Y = Windows(a).Y
  343.                     OldW(0).WIDTH = Windows(a).WIDTH
  344.                     OldW(0).Height = Windows(a).Height
  345.  
  346.                     OmX = _MOUSEX - OldW(0).X ' we store actual value of X and Y of mouse
  347.                     OmY = _MOUSEY - OldW(0).Y
  348.                     DO WHILE _MOUSEINPUT: LOOP ' just clear mouse buffer
  349.                     DO WHILE _MOUSEBUTTON(1) ' while left mouse is pressed down
  350.                         IF _MOUSEINPUT THEN ' if there is a mouseinput
  351.                             CLS , Orange 'reset background
  352.  
  353.                             OldW(0).X = (_MOUSEX - OmX) 'it adjourns window X and Y
  354.                             OldW(0).Y = (_MOUSEY - OmY)
  355.                             DrawAllWin ' it shows all windows
  356.                             dragWindow OldW(0) ' it shows white skeleton of window
  357.                         END IF
  358.                     LOOP
  359.                     ' new position of window
  360.                     Windows(a).X = OldW(0).X
  361.                     Windows(a).Y = OldW(0).Y
  362.                     OldW(a).X = Windows(a).X
  363.                     OldW(a).Y = Windows(a).Y
  364.  
  365.                 CASE Focusing
  366.                     Focus a ' it puts at the top of stack of windows
  367.  
  368.                 CASE cResize
  369.                     ' resizing is possible only for minimized opened child windows
  370.                     IF Windows(a).Status = Minim THEN
  371.                         Windows(a).Status = cResize
  372.                         DO WHILE _MOUSEBUTTON(1) OR _MOUSEINPUT: LOOP ' it waits if there is a mouse input
  373.                         DO WHILE Windows(a).Status = cResize ' while window is in resize mode
  374.                             CLS , Orange ' it redraws background of main window
  375.                             DrawAllWin ' it draws all mouse  windows
  376.                             ShowDimension Windows(a), 0
  377.  
  378.                             ' if mouse move or left mouse button is down
  379.                             IF _MOUSEINPUT AND _MOUSEBUTTON(1) THEN
  380.                                 DO WHILE _MOUSEINPUT: LOOP ' clear mouse buffer
  381.                                 _DELAY 0.1 ' this fixs Linus issue
  382.                                 IsResizing Windows(a), _MOUSEX, _MOUSEY
  383.                             END IF
  384.                             _DISPLAY
  385.                         LOOP
  386.                     END IF
  387.  
  388.             END SELECT
  389.         CASE ELSE
  390.     END SELECT
  391.  
  392. SUB IsResizing (Win AS wChild, mX AS INTEGER, mY AS INTEGER) ' this resize window by mouse
  393.     SHARED Windows() AS wChild, OldW() AS wChild
  394.     DIM Actio AS INTEGER, OldmX AS INTEGER, OldmY AS INTEGER
  395.     Actio = 0
  396.     'if mouse X is in the X range of the window
  397.     IF IsInTheRange%(mX, Win.X, Win.X + Win.WIDTH) THEN
  398.         ' if mouse Y is in the y range of the window
  399.         IF IsInTheRange%(mY, Win.Y, Win.Y + Win.Height) THEN
  400.             ' do nothing if it is in the range of window
  401.         ELSE
  402.             ' user click out of area  of window to resize
  403.             Actio = StopResize
  404.         END IF
  405.     ELSE
  406.         ' user click out of area  of window to resize
  407.         Actio = StopResize
  408.     END IF
  409.  
  410.  
  411.  
  412.  
  413.     ' if mouse X is in the x range  of the leftest button on the window's bar
  414.     IF IsInTheRange%(mX, Win.X, Win.X + 10) THEN
  415.         ' if mouse Y is in the y range of the window's bar
  416.         IF IsInTheRange%(mY, Win.Y, Win.Y + 10) THEN
  417.             ' user click on lefttop square to resize
  418.             Actio = LResize
  419.         END IF
  420.     END IF
  421.     ' if mouse X is in the range of rightest button of window's bar
  422.     IF IsInTheRange%(mX, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  423.         ' if mouse Y is in the y range of the bottom of window
  424.         IF IsInTheRange%(mY, Win.Y + Win.Height - 10, Win.Y + Win.Height) THEN
  425.             ' user click on the rightbottom square to resize
  426.             Actio = RResize
  427.         END IF
  428.     END IF
  429.  
  430.     IF Actio = 0 THEN
  431.         ' no action done
  432.     ELSEIF Actio = LResize THEN
  433.         ' choosen LeftTop buttom to resize
  434.         OldW(0).X = Win.X
  435.         OldW(0).Y = Win.Y
  436.         OldW(0).WIDTH = Win.WIDTH
  437.         OldW(0).Height = Win.Height
  438.         OldmX = _MOUSEX
  439.         OldmY = _MOUSEY
  440.         DO WHILE Actio = LResize
  441.             IF _MOUSEINPUT THEN ' if mouse moves it adapts the dimension to the minimun default value for X and Y
  442.                 IF (OldW(0).X + OldW(0).WIDTH - OldmX) >= 70 THEN OldW(0).WIDTH = OldW(0).X + OldW(0).WIDTH - OldmX ELSE OldW(0).WIDTH = 70: OldW(0).X = Win.X + Win.WIDTH - 70: OldmX = OldW(0).X
  443.                 IF (OldW(0).Y + OldW(0).Height - OldmY) >= 30 THEN OldW(0).Height = OldW(0).Y + OldW(0).Height - OldmY ELSE OldW(0).Height = 30: OldW(0).Y = Win.Y + Win.Height - 30: OldmY = OldW(0).Y
  444.                 CLS , Orange
  445.                 DrawAllWin
  446.                 ShowDimension OldW(0), Actio
  447.                 OldW(0).X = OldmX ' it stores new Oldmx and OldmY
  448.                 OldW(0).Y = OldmY
  449.  
  450.                 OldmX = _MOUSEX
  451.                 OldmY = _MOUSEY
  452.             ELSE
  453.                 IF _MOUSEBUTTON(1) THEN Actio = 0 ' a second leftclick stops the resize action
  454.             END IF
  455.         LOOP
  456.         Win.X = OldW(0).X 'the new dimension of windows are stored
  457.         Win.Y = OldW(0).Y
  458.         Win.WIDTH = OldW(0).WIDTH
  459.         Win.Height = OldW(0).Height
  460.  
  461.  
  462.     ELSEIF Actio = RResize THEN
  463.         ' choosen bottomright square
  464.         OldW(0).X = Win.X ' it gets the window dimensions
  465.         OldW(0).Y = Win.Y
  466.         OldW(0).WIDTH = Win.WIDTH
  467.         OldW(0).Height = Win.Height
  468.         OldmX = _MOUSEX 'actual mouse X and Y
  469.         OldmY = _MOUSEY
  470.         DO WHILE Actio = RResize ' while is active resize from right
  471.             IF _MOUSEINPUT THEN ' if mouse moves it adapts the dimension of window to mouse position
  472.                 IF OldmX - OldW(0).X >= 70 THEN OldW(0).WIDTH = OldmX - OldW(0).X
  473.                 IF OldmY - OldW(0).Y >= 30 THEN OldW(0).Height = OldmY - OldW(0).Y
  474.                 CLS , Orange
  475.                 DrawAllWin
  476.                 ShowDimension OldW(0), Actio
  477.                 OldmX = _MOUSEX
  478.                 OldmY = _MOUSEY
  479.             ELSE
  480.                 IF _MOUSEBUTTON(1) THEN Actio = 0 ' il mouse leftclick it stops resize
  481.             END IF
  482.         LOOP
  483.         Win.X = OldW(0).X 'it adjusts the dimensions of window to the new status
  484.         Win.Y = OldW(0).Y
  485.         Win.WIDTH = OldW(0).WIDTH
  486.         Win.Height = OldW(0).Height
  487.  
  488.     ELSEIF Actio = StopResize THEN
  489.         ' click out of window to stop resize action
  490.         Win.Status = Minim
  491.     END IF
  492.  
  493. SUB ShowDimension (win AS wChild, Actio AS INTEGER) ' it shows skeleton of window with 2 buttons for dimensioning
  494.     IF win.Status = cResize AND Actio = 0 THEN
  495.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B ' windows size
  496.     ELSEIF Actio = LResize THEN
  497.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 45 ' windows size
  498.     ELSEIF Actio = RResize THEN
  499.         LINE (win.X, win.Y)-(win.X + win.WIDTH, win.Y + win.Height), White, B , 200 ' windows size
  500.     END IF
  501.     LINE (win.X, win.Y)-(win.X + 10, win.Y + 10), White, BF 'button for resizing window
  502.     LINE (win.X + win.WIDTH - 10, win.Y + win.Height - 10)-(win.X + win.WIDTH, win.Y + win.Height), White, BF 'button for resizing window
  503.     _DISPLAY
  504.  
  505. FUNCTION IsInWindow (X AS INTEGER, Y AS INTEGER, Win AS wChild) 'it searches if mouse is in window passed as Win
  506.     IsInWindow = mFalse
  507.     IF IsInTheRange%(Y, Win.Y + 11, Win.Y + Win.Height) = mTrue THEN
  508.         ' if window is closed to its bar it cannot get focus on the window area
  509.         IF IsInTheRange%(X, Win.X, Win.X + Win.WIDTH) AND (Win.Status < Closed) THEN IsInWindow = Focusing
  510.     ELSEIF IsInTheRange%(Y, Win.Y, Win.Y + 10) = mTrue THEN
  511.         ' if it is the window bar area
  512.         IF IsInTheRange%(X, Win.X + 10, Win.X + Win.WIDTH - 31) THEN
  513.             ' if it is to the left of buttons on the bar
  514.             IsInWindow = Dragging
  515.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 30, Win.X + Win.WIDTH - 21) THEN
  516.             ' if it is on the leftest button on the bar
  517.             IsInWindow = cMinim ' icon minimize--> restore to child default
  518.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 20, Win.X + Win.WIDTH - 11) THEN
  519.             ' if it is on the middle button on the bar
  520.             IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
  521.         ELSEIF IsInTheRange%(X, Win.X + Win.WIDTH - 10, Win.X + Win.WIDTH) THEN
  522.             ' if is on the rightest button on the bar
  523.             IsInWindow = cClosed ' icon close-->reduce to the  bar of child window
  524.         ELSEIF IsInTheRange%(X, Win.X, Win.X + 10) THEN ' if is on the left side of bar on Resize button
  525.             IsInWindow = cResize
  526.         END IF
  527.     END IF
  528.  
  529. FUNCTION IsInTheRange% (What AS INTEGER, Min AS INTEGER, Max AS INTEGER) ' it tests if What is between Min and Max
  530.     IF Min > Max THEN SWAP Min, Max
  531.     IF What > Min AND What < Max THEN IsInTheRange% = mTrue ELSE IsInTheRange% = mFalse
  532.  
  533. SUB dragWindow (Win AS wChild) ' this draw the white skeleton of a window
  534.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), White, B ' windows size
  535.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), White, BF 'title bar for dragging window
  536.     _DISPLAY
  537.  
  538. SUB wClosed (Win AS wChild) 'title bar button for show only title bar of window
  539.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF
  540.     LINE (Win.X + Win.WIDTH - 10, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Black, B
  541.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 3)-(Win.X + Win.WIDTH - 3, Win.Y + 7), Black
  542.     LINE (Win.X + Win.WIDTH - 7, Win.Y + 7)-(Win.X + Win.WIDTH - 3, Win.Y + 3), Black
  543.  
  544. SUB wMaxim (win AS wChild) 'title bar  button for maximize to the whole main window
  545.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Pink, BF
  546.     LINE (win.X + win.WIDTH - 20, win.Y)-(win.X + win.WIDTH - 10, win.Y + 10), Black, B
  547.     LINE (win.X + win.WIDTH - 17, win.Y + 3)-(win.X + win.WIDTH - 13, win.Y + 7), Black, B
  548.  
  549. SUB wMinim (Win AS wChild) 'title bar button for restore to original dimensions
  550.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Pink, BF
  551.     LINE (Win.X + Win.WIDTH - 30, Win.Y)-(Win.X + Win.WIDTH - 20, Win.Y + 10), Black, B
  552.     LINE (Win.X + Win.WIDTH - 27, Win.Y + 3)-(Win.X + Win.WIDTH - 23, Win.Y + 4), Black, BF
  553.     LINE (Win.X + Win.WIDTH - 27, Win.Y + 3)-(Win.X + Win.WIDTH - 23, Win.Y + 7), Black, B , &B1010101010101010
  554.  
  555. SUB wResize (Win AS wChild) 'title bar button for resize  dimensions of window
  556.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Pink, BF
  557.     LINE (Win.X, Win.Y)-(Win.X + 10, Win.Y + 10), Black, B
  558.     LINE (Win.X + 2, Win.Y + 2)-(Win.X + 7, Win.Y + 7), Black, B , &B1010101010101010
  559.  
  560. SUB DrawWindow (Win AS wChild, a AS INTEGER) ' it draws a window aspect following its status
  561.     SHARED L() AS Label
  562.     ' the window
  563.     IF Win.Status = Minim OR Win.Status = Maxim THEN
  564.         LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Win.COLOR, BF
  565.         LINE (Win.X, Win.Y + Win.Height)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  566.         LINE (Win.X + Win.WIDTH, Win.Y)-(Win.X + Win.WIDTH, Win.Y + Win.Height), Black
  567.     END IF
  568.     ' the title bar
  569.     LINE (Win.X, Win.Y)-(Win.X + Win.WIDTH, Win.Y + 10), Pink, BF 'title bar for dragging window
  570.     LINE (Win.X, Win.Y + 10)-(Win.X + Win.WIDTH, Win.Y + 10), Black
  571.     wMinim Win
  572.     wMaxim Win
  573.     wClosed Win
  574.     wResize Win
  575.  
  576.     ' the content of the window
  577.     IF Win.Name = L(a).Parent THEN ShowString L(a), Win
  578.  
  579.  
  580.  
  581. SUB GetInput (Act AS INTEGER) ' manager of input by keyboard & mouse
  582.     DIM mInput AS INTEGER ' flag of commands of mouse
  583.  
  584.  
  585.     ' keyboard input
  586.     a$ = INKEY$
  587.     IF a$ = CHR$(27) THEN Act = aQuit 'keyboard's command in feedback by Act
  588.  
  589.     'mouse input
  590.     mInput = mFalse
  591.     IF _MOUSEINPUT THEN mInput = mTrue
  592.     DO WHILE _MOUSEINPUT 'clear buffer of mouse
  593.     LOOP
  594.     IF mInput THEN ' here flag of mouse gets the command's values
  595.         IF _MOUSEBUTTON(1) AND _MOUSEBUTTON(2) THEN
  596.             mInput = mLR
  597.         ELSEIF _MOUSEBUTTON(1) THEN
  598.             mInput = mLeft
  599.         ELSEIF _MOUSEBUTTON(2) THEN
  600.             mInput = mRight
  601.         ELSEIF _MOUSEBUTTON(3) THEN
  602.             mInput = mMiddle
  603.         END IF
  604.     END IF
  605.     'mouse's command in feedback by Act
  606.     IF mInput = mLR THEN
  607.         Act = aQuit
  608.     ELSEIF mInput = mMiddle THEN
  609.         Act = Minim
  610.     ELSEIF mInput = mRight THEN
  611.         Act = Maxim
  612.     ELSEIF mInput = mLeft THEN
  613.         Act = mInput
  614.     END IF
  615.  

Thanks to try