' 2020 04 18 Fixed Linux issue about selection of resizing white buttons
' 2020 04 03 creating label as component of window (label is from 1 to 100 characters on one line)
' to be visible in a window it is printed only for the inner width of window
' 2020 03 25 fixing window undraggable if it has been put lefter to
' the left border of main window
' 2020 02 17 fixing resize from left bug with scattering of window resized
' 2020 02 12 with the power of the second array we implement the feature
' of resizable of child window
' 2020 02 09 with the power of the second array we implement a different
' child windows' system:
' all child windows can be Closed to window's bar
' all child windows can be dragged on the screen
' 2020 02 08 using a second array we store windows information indipendently so
' now each window can be modified and restored
' 2020 02 06 after dragging or maximize a window, restoring it we gives
' to it the last value used in windows(0) so the info of the last
' window that is dragged or maximize when we use Minimize button on
' another child window
' the fix can be got using a shadow array that stores windows informations
' or windows(0) as the child window that takes the information of the
' child window that must be acted (Minimize, Maximize and Closed)
' and we use it as template to make graphic output
' 2020 02 05 fixed a minor bug on mouse click events
' activated events Maxim Minim and Closed
' 2020 02 03 increasing the windows managed and close initialization to SUB
' removed vMax SHARED variable
' added 3 buttons on the rightest site of the bar of the child window
' SUB wClosed, wMaxim, wMinim
' In this version the user can maximize one child window to the application window
' In the status of Maxim the child window has the focus and can be only
' reduced to status Minim, it cannot be dragging or Closed to bar of window
' 2020 01 30 fixed bug on focusing a child window
'
' 2020 01 25 A program with child windows into it
' we need a system to manage multiple windows
' and a system to manage input/output
' and a system to make graphic report
' settings-------------------------------------------------------
' the CONST with colors is better to declare after screen definition
' also if _RGBA32 is indipendent form screen definition
CONST Black
= _RGBA32(0, 0, 0, 255), White
= _RGBA32(255, 255, 255, 255), Red
= _RGBA32(200, 0, 0, 255) CONST Green
= _RGBA32(0, 200, 0, 255), Blu
= _RGBA32(0, 0, 200, 255), Yellow
= _RGBA32(200, 200, 20, 255) CONST Cyan
= _RGBA32(20, 140, 230, 255), Orange
= _RGBA32(200, 100, 20, 255), Pink
= _RGBA32(227, 80, 120, 255)
' these constants have the role of commands to execute from windows' engine
CONST Minim
= 10, Maxim
= 20, Closed
= 100 CONST wMin
= 5, aNull
= 0, aQuit
= 9999 CONST Dragging
= 300, Focusing
= 200, cMinim
= 400, cMaxim
= 500, cClosed
= 600 CONST cResize
= 700, LResize
= 710, RResize
= 720, StopResize
= 730 ' these constants are universal
CONST mTrue
= 1, mFalse
= 0, mLeft
= 2, mRight
= 3, mMiddle
= 4, mLR
= 5
'dataset -----------------------------------------------
' components type
X
AS INTEGER ' x relative to x of parent window Y
AS INTEGER ' y relative to y of parent window Parent
AS STRING ' the name of window if=" Desktop" it is the main window font
AS LONG ' it is handle of font
' window's type
Zorder
AS INTEGER 'order along z axis 1 = on top , lower value = at bottom Status
AS INTEGER 'status maximized/fullscreen, minimized/normal or StatusBar/Closed' 2 arrays one for windows and one for operation with windows
' like to manage temporary data or store original data
InitWin ' it creates some windows
InitLabel L(), Windows()
' main loop -----------------------------------------------
' set the main window's background
' reset the flag of engine
Action = aNull
DrawAllWin ' output windows in Zorder
GetInput Action ' this SUB takes keyboard and mouse input from user and translate it as engine's command
DoAction Action ' it executes command of getinput
' SUBs and FUNCTIONs --------------------------------------
SUB ShowString
(L
AS Label
, Win
AS wChild
) VisibleString
= LEFT$(L.Caption
, NumChar
) VisibleString = L.Caption
SUB InitLabel
(L
() AS Label
, win
() AS wChild
) L
(a%
).X
= 3 + (RND * (win
(a%
).Height
/ 2) - 10) L
(a%
).Y
= 4 + (RND * (win
(a%
).
WIDTH / 2) - 10) L
(a%
).Parent
= win
(a%
).
Name L(a%).Caption = "This is a demonstration of output"
L
(a%
).font
= _LOADFONT("cour.ttf", 12, "monospace")
SUB InitWin
' it creates windows and save their data in oldW
Windows(1).X = 1
Windows(1).Y = 1
Windows(1).Height = 400
Windows(1).Zorder = 1
Windows(1).Status = Minim
Windows(2).X = 100
Windows(2).Y = 1
Windows(2).Height = 400
Windows(2).Zorder = 2
Windows(2).Status = Minim
Windows
(2).
COLOR = Yellow
Windows
(2).
Name = "Yellow"
Windows(3).X = 200
Windows(3).Y = 1
Windows(3).Height = 400
Windows(3).Zorder = 3
Windows(3).Status = Minim
Windows
(3).
Name = "Green"
Windows(4).X = 300
Windows(4).Y = 1
Windows(4).Height = 400
Windows(4).Zorder = 4
Windows(4).Status = Minim
Windows(5).X = 400
Windows(5).Y = 1
Windows(5).Height = 400
Windows(5).Zorder = 5
Windows(5).Status = Minim
AdjournWin a 'it stores informations of windows into OldW
SUB RestoreWin
(a
AS INTEGER) ' it restores data of a windows from OldW
Windows(a).X = OldW(a).X
Windows(a).Y = OldW(a).Y
Windows(a).Height = OldW(a).Height
Windows(a).Zorder = OldW(a).Zorder
SUB AdjournWin
(a
AS INTEGER) 'it saves data of a window into OldW
OldW(a).X = Windows(a).X
OldW(a).Y = Windows(a).Y
OldW(a).Height = Windows(a).Height
OldW(a).Zorder = Windows(a).Zorder
SUB DrawAllWin
' it draws all windows starting from bottom of Zorder stack Finished = wMin ' it starts from the bottom of Zorder
FOR a
= 1 TO wMin
'for all windows created (wMin) IF Windows
(a
).Zorder
= Finished
THEN ' if the window is that we are searching DrawWindow Windows(a), a 'we draw window
Finished = Finished - 1 'we decrease the pointer from bottom to up until the first window
SUB Focus
(Index
AS INTEGER) ' it puts a windows at top of Zorder and the previous top window to the bottom ' here it changes the position between the new Ontpo window and the last Ontop Window
IF Index
<> b
THEN SWAP Windows
(Index
).Zorder
, Windows
(b
).Zorder
DrawAllWin
SUB DoAction
(Act
AS INTEGER) ' it is the engine of the manager of windows ' engine's variables
' mouse's variables
' it executes Act's content
CASE mLeft
' Left Click of mouse mX
= _MOUSEX ' we store the actual X and Y of mouse
' search where and what mouse has touched by leftclick
OldA = 0
OldActio = 0
FOR a
= 1 TO wMin
' windows(0) is out of action Actio = IsInWindow(mX, mY, Windows(a)) ' what window on the top of stack is interacting with mouse
IF OldA
<= 0 THEN ' if no previous window has interact with mouse OldA = a 'we memorize action and index of window
OldActio = Actio
ELSEIF Windows
(a
).Zorder
< Windows
(OldA
).Zorder
THEN ' if actual window has a Zorder less the previouse OldA = a ' we memorize action and index of window
OldActio = Actio
a = OldA ' restore the last windows interacting
Actio = OldActio
Focus a 'set zorder on the (a) window that gets the input
' here restore to standard (bar + area of window) status of child window
IF Windows
(a
).Status
= Closed
+ Maxim
THEN ' if windows is a closed maximized window
' we restore its status of maximized
Windows(a).Status = Maxim
' if windows is a closed minimized window
' we restore its status of minimized
Windows(a).Status = Minim
' if is a window maximized it gets back all info setting
' we restore its status of minimized
RestoreWin a
Windows(a).Status = Minim
' here convert the window to full size of main window of the program
' OR gives 1 if both parameter are true or al last one is true
IF (Windows
(a
).Status
= Minim
OR Windows
(a
).Status
= Closed
+ Minim
) THEN ' it acts if windows if not still maximized
' it is minimized window opened or closed
' memorize window's data when it is not maximized
' IF Windows(a).Width < _WIDTH THEN
AdjournWin a
' it sets maximized status
Windows(a).X = 1
Windows(a).Y = 1
' change status
Windows(a).Status = Maxim
' here minimize the child window to its window bar
Windows(a).Status = Windows(a).Status + Closed
' dragging is possible for all status of windows
'
' if minimized or Closed and minimized window we save data info
IF Windows
(a
).Status
= Minim
OR Windows
(a
).Status
= Closed
+ Minim
THEN AdjournWin a
' it sets variables for dragging
OldW(0).X = Windows(a).X
OldW(0).Y = Windows(a).Y
OldW(0).Height = Windows(a).Height
OmX
= _MOUSEX - OldW
(0).X
' we store actual value of X and Y of mouse CLS , Orange
'reset background
OldW
(0).X
= (_MOUSEX - OmX
) 'it adjourns window X and Y DrawAllWin ' it shows all windows
dragWindow OldW(0) ' it shows white skeleton of window
' new position of window
Windows(a).X = OldW(0).X
Windows(a).Y = OldW(0).Y
OldW(a).X = Windows(a).X
OldW(a).Y = Windows(a).Y
Focus a ' it puts at the top of stack of windows
' resizing is possible only for minimized opened child windows
IF Windows
(a
).Status
= Minim
THEN Windows(a).Status = cResize
DO WHILE Windows
(a
).Status
= cResize
' while window is in resize mode CLS , Orange
' it redraws background of main window DrawAllWin ' it draws all mouse windows
ShowDimension Windows(a), 0
' if mouse move or left mouse button is down
_DELAY 0.1 ' this fixs Linus issue
Actio = 0
'if mouse X is in the X range of the window
' if mouse Y is in the y range of the window
IF IsInTheRange%
(mY
, Win.Y
, Win.Y
+ Win.Height
) THEN ' do nothing if it is in the range of window
' user click out of area of window to resize
Actio = StopResize
' user click out of area of window to resize
Actio = StopResize
' if mouse X is in the x range of the leftest button on the window's bar
IF IsInTheRange%
(mX
, Win.X
, Win.X
+ 10) THEN ' if mouse Y is in the y range of the window's bar
IF IsInTheRange%
(mY
, Win.Y
, Win.Y
+ 10) THEN ' user click on lefttop square to resize
Actio = LResize
' if mouse X is in the range of rightest button of window's bar
' if mouse Y is in the y range of the bottom of window
IF IsInTheRange%
(mY
, Win.Y
+ Win.Height
- 10, Win.Y
+ Win.Height
) THEN ' user click on the rightbottom square to resize
Actio = RResize
' no action done
' choosen LeftTop buttom to resize
OldW(0).X = Win.X
OldW(0).Y = Win.Y
OldW(0).Height = Win.Height
IF _MOUSEINPUT THEN ' if mouse moves it adapts the dimension to the minimun default value for X and Y 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
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
DrawAllWin
ShowDimension OldW(0), Actio
OldW(0).X = OldmX ' it stores new Oldmx and OldmY
OldW(0).Y = OldmY
Win.X = OldW(0).X 'the new dimension of windows are stored
Win.Y = OldW(0).Y
Win.Height = OldW(0).Height
' choosen bottomright square
OldW(0).X = Win.X ' it gets the window dimensions
OldW(0).Y = Win.Y
OldW(0).Height = Win.Height
OldmX
= _MOUSEX 'actual mouse X and Y DO WHILE Actio
= RResize
' while is active resize from right IF _MOUSEINPUT THEN ' if mouse moves it adapts the dimension of window to mouse position IF OldmX
- OldW
(0).X
>= 70 THEN OldW
(0).
WIDTH = OldmX
- OldW
(0).X
IF OldmY
- OldW
(0).Y
>= 30 THEN OldW
(0).Height
= OldmY
- OldW
(0).Y
DrawAllWin
ShowDimension OldW(0), Actio
Win.X = OldW(0).X 'it adjusts the dimensions of window to the new status
Win.Y = OldW(0).Y
Win.Height = OldW(0).Height
' click out of window to stop resize action
Win.Status = Minim
SUB ShowDimension
(win
AS wChild
, Actio
AS INTEGER) ' it shows skeleton of window with 2 buttons for dimensioning LINE (win.X
, win.Y
)-(win.X
+ win.
WIDTH, win.Y
+ win.Height
), White
, B
' windows size LINE (win.X
, win.Y
)-(win.X
+ win.
WIDTH, win.Y
+ win.Height
), White
, B
, 45 ' windows size LINE (win.X
, win.Y
)-(win.X
+ win.
WIDTH, win.Y
+ win.Height
), White
, B
, 200 ' windows size LINE (win.X
, win.Y
)-(win.X
+ 10, win.Y
+ 10), White
, BF
'button for resizing window 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
IsInWindow = mFalse
IF IsInTheRange%
(Y
, Win.Y
+ 11, Win.Y
+ Win.Height
) = mTrue
THEN ' if window is closed to its bar it cannot get focus on the window area
IF IsInTheRange%
(X
, Win.X
, Win.X
+ Win.
WIDTH) AND (Win.Status
< Closed
) THEN IsInWindow
= Focusing
ELSEIF IsInTheRange%
(Y
, Win.Y
, Win.Y
+ 10) = mTrue
THEN ' if it is the window bar area
IF IsInTheRange%
(X
, Win.X
+ 10, Win.X
+ Win.
WIDTH - 31) THEN ' if it is to the left of buttons on the bar
IsInWindow = Dragging
' if it is on the leftest button on the bar
IsInWindow = cMinim ' icon minimize--> restore to child default
' if it is on the middle button on the bar
IsInWindow = cMaxim ' icon maximize--> expand to fullscreen
' if is on the rightest button on the bar
IsInWindow = cClosed ' icon close-->reduce to the bar of child window
ELSEIF IsInTheRange%
(X
, Win.X
, Win.X
+ 10) THEN ' if is on the left side of bar on Resize button IsInWindow = cResize
IF What
> Min
AND What
< Max
THEN IsInTheRange%
= mTrue
ELSE IsInTheRange%
= mFalse
SUB dragWindow
(Win
AS wChild
) ' this draw the white skeleton of a window LINE (Win.X
, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ Win.Height
), White
, B
' windows size LINE (Win.X
, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ 10), White
, BF
'title bar for dragging window
SUB wClosed
(Win
AS wChild
) 'title bar button for show only title bar of window LINE (Win.X
+ Win.
WIDTH - 10, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ 10), Pink
, BF
LINE (Win.X
+ Win.
WIDTH - 10, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ 10), Black
, B
LINE (Win.X
+ Win.
WIDTH - 7, Win.Y
+ 3)-(Win.X
+ Win.
WIDTH - 3, Win.Y
+ 7), Black
LINE (Win.X
+ Win.
WIDTH - 7, Win.Y
+ 7)-(Win.X
+ Win.
WIDTH - 3, Win.Y
+ 3), Black
SUB wMaxim
(win
AS wChild
) 'title bar button for maximize to the whole main window LINE (win.X
+ win.
WIDTH - 20, win.Y
)-(win.X
+ win.
WIDTH - 10, win.Y
+ 10), Pink
, BF
LINE (win.X
+ win.
WIDTH - 20, win.Y
)-(win.X
+ win.
WIDTH - 10, win.Y
+ 10), Black
, B
LINE (win.X
+ win.
WIDTH - 17, win.Y
+ 3)-(win.X
+ win.
WIDTH - 13, win.Y
+ 7), Black
, B
SUB wMinim
(Win
AS wChild
) 'title bar button for restore to original dimensions LINE (Win.X
+ Win.
WIDTH - 30, Win.Y
)-(Win.X
+ Win.
WIDTH - 20, Win.Y
+ 10), Pink
, BF
LINE (Win.X
+ Win.
WIDTH - 30, Win.Y
)-(Win.X
+ Win.
WIDTH - 20, Win.Y
+ 10), Black
, B
LINE (Win.X
+ Win.
WIDTH - 27, Win.Y
+ 3)-(Win.X
+ Win.
WIDTH - 23, Win.Y
+ 4), Black
, BF
LINE (Win.X
+ Win.
WIDTH - 27, Win.Y
+ 3)-(Win.X
+ Win.
WIDTH - 23, Win.Y
+ 7), Black
, B
, &B1010101010101010
SUB wResize
(Win
AS wChild
) 'title bar button for resize dimensions of window LINE (Win.X
, Win.Y
)-(Win.X
+ 10, Win.Y
+ 10), Pink
, BF
LINE (Win.X
, Win.Y
)-(Win.X
+ 10, Win.Y
+ 10), Black
, B
LINE (Win.X
+ 2, Win.Y
+ 2)-(Win.X
+ 7, Win.Y
+ 7), Black
, B
, &B1010101010101010
SUB DrawWindow
(Win
AS wChild
, a
AS INTEGER) ' it draws a window aspect following its status ' the window
IF Win.Status
= Minim
OR Win.Status
= Maxim
THEN LINE (Win.X
, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ Win.Height
), Win.
COLOR, BF
LINE (Win.X
, Win.Y
+ Win.Height
)-(Win.X
+ Win.
WIDTH, Win.Y
+ Win.Height
), Black
LINE (Win.X
+ Win.
WIDTH, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ Win.Height
), Black
' the title bar
LINE (Win.X
, Win.Y
)-(Win.X
+ Win.
WIDTH, Win.Y
+ 10), Pink
, BF
'title bar for dragging window LINE (Win.X
, Win.Y
+ 10)-(Win.X
+ Win.
WIDTH, Win.Y
+ 10), Black
wMinim Win
wMaxim Win
wClosed Win
wResize Win
' the content of the window
IF Win.
Name = L
(a
).Parent
THEN ShowString L
(a
), Win
SUB GetInput
(Act
AS INTEGER) ' manager of input by keyboard & mouse
' keyboard input
IF a$
= CHR$(27) THEN Act
= aQuit
'keyboard's command in feedback by Act
'mouse input
mInput = mFalse
IF mInput
THEN ' here flag of mouse gets the command's values mInput = mLR
mInput = mLeft
mInput = mRight
mInput = mMiddle
'mouse's command in feedback by Act
Act = aQuit
Act = Minim
Act = Maxim
Act = mInput