Author Topic: child windows into window of the program: a demonstration  (Read 10073 times)

0 Members and 1 Guest are viewing this topic.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #15 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 :-)
I am from a Kazakhstan, we follow the hawk.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #16 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.

 
wchild demo help.jpg

Programming isn't difficult, only it's  consuming time and coffee

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #17 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.

 
wchild demo help.jpg


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.
I am from a Kazakhstan, we follow the hawk.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #18 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
« Last Edit: February 16, 2020, 11:44:03 am by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #19 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.
I am from a Kazakhstan, we follow the hawk.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #20 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #21 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.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #22 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
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #23 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.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #24 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.  
« Last Edit: February 19, 2020, 10:07:33 pm by odin »
In order to understand recursion, one must first understand recursion.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #25 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. :-)
« Last Edit: February 19, 2020, 10:07:21 pm by odin »
I am from a Kazakhstan, we follow the hawk.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #26 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!
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #27 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.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #28 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. ;-))
« Last Edit: February 19, 2020, 07:39:35 pm by bplus »

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #29 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.
« Last Edit: February 19, 2020, 07:59:15 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.