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

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #30 on: February 19, 2020, 08:12:32 pm »
Hi Terry,

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

I have not played with this code in over 4 years. I would need to go back through the code and read my comments to get a feel for it again.
In order to understand recursion, one must first understand recursion.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #31 on: February 19, 2020, 08:14:56 pm »
Would anyone happen to have the GUI demo Galleon posted on [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] back around 2012?
In order to understand recursion, one must first understand recursion.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #32 on: February 19, 2020, 08:18:22 pm »
@Bplus
so
Quote
It is my understanding to resize a window in your code:
1) Click top right box and that activates the 2 white resize boxes
2) Click one of those and that tells your code which corner is anchor and which corner will be moved, this activatees the dashed outline border
these 2 steps are ok (dashed lines are added only to give more feedback to user, each anchor has its dashed line)
after got dashed line you must
3) move the pointer of mouse without any mouse button pressed (like mouse was locked in dragging mode)
4) left click another time to escape from this situation of dragging anchor without any mouse button pressed
now you get the new dimensioned window.


@Terry
Thanks
and thanks for this http://qb64sourcecode.com/
Programming isn't difficult, only it's  consuming time and coffee

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #33 on: February 19, 2020, 09:12:01 pm »

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

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

I'm glad you like it and you are welcome. I've had quite a few people tell me that it helped them get a start in QB64.
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #34 on: February 19, 2020, 09:34:59 pm »
@Bplus
sothese 2 steps are ok (dashed lines are added only to give more feedback to user, each anchor has its dashed line)
after got dashed line you must
3) move the pointer of mouse without any mouse button pressed (like mouse was locked in dragging mode)
4) left click another time to escape from this situation of dragging anchor without any mouse button pressed
now you get the new dimensioned window.

...

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

« Last Edit: February 20, 2020, 12:14:40 am by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: child windows into window of the program: a demonstration
« Reply #35 on: February 20, 2020, 08:38:17 am »
Hi

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

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

Please gimme feedback when you can do it.

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

@QB64 coders
who can give me feedback on MacOs?
Thanks
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 #36 on: February 20, 2020, 01:21:08 pm »
Hi

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

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

Please gimme feedback when you can do it.

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

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

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

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

For example the minimize button restores the window from maximized, and the close button minimizes it.
You might want to rethink it a little bit, but not saying its bad or anything, just different. :-)
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 #37 on: February 21, 2020, 04:35:39 pm »
@keybone

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

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

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

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

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

Thanks for your feedbacks


Good hearing
« Last Edit: February 21, 2020, 04:40:33 pm by TempodiBasic »
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 #38 on: April 18, 2020, 06:22:47 am »
Hy guys
just a little feedback

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

Code: QB64: [Select]
  1. _DELAY 0.1

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

As i can recover the rest of fixing I'll post the code with no scattering of window resized and a demo of a module with input in a window and output into another.
Thanks to read
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 #39 on: May 08, 2020, 04:30:07 am »
Hi guys
here a first fixed version of wchild demonstration with its original method for  get resizing, fullscreen, fullwindow and normalwindow child windows into a main window program.

 
Wchild demo  Fullscreen.jpg


 
Wchild demo Windowed.jpg


Here the code 

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

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

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