Let's develop OpenWinDOS

DOS specific questions.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Let's develop OpenWinDOS

Post by demosthenesk »

i have started to develop a GUI for DOS and its name is OpenWinDOS

whoever wants to contribute is welcome...

https://github.com/demosthenesk/OpenWinDOS

For now i was based on Paul Doe discord code as an example and i am developing the window.bi

Here is the starting code:

window.bi

Code: Select all

#define TBH 20   'titlebar height
#define MINWH 80 'min width/height
Type hWindow
    As UInteger id				'id of window
    As Integer x, y, w, h		'x,y,width,heigt
    As UInteger c				'c as color
    As String title				'title as string
    Declare Constructor()
    Declare Constructor(As UInteger, As Integer, As Integer, As Integer, As Integer, As String, As Integer)
    Declare Sub redraw()
End Type

Constructor hWindow()
End Constructor

Constructor hWindow(id As UInteger, x As Integer, y As Integer, w As Integer, h As Integer, t As String, c As Integer)
  This.id = id
  This.x = x
  This.y = y
  This.w = w
  This.h = h
  This.title = t
  This.c = c
  redraw()
End Constructor

Sub hWindow.redraw()
    Line(x,y)-(x+w,y+h),&hffffff,BF    'frame
    Line(x+w-10,y+h-10)-(x+w,y+h),0,BF 'angle
    Line(x+4,y+TBH)-(x+w-4,y+h-4),c,BF 'box
    Draw String(x+4,y+8),title
End Sub
main.bas

Code: Select all

#include "window.bi"
#define MAXW 800 'max desktop width
#define MAXH 600 'max desktop height

Dim Shared iWindowPopulation As UInteger = 0	'holds the number of created windows
Dim Shared pWindows() As hWindow Ptr			'array of ptr windows

Declare Sub Init()
Declare Sub NewWindow(id As UInteger, x As Integer, y As Integer, w As Integer, h As Integer, title As String, c As Integer)
Declare Sub MAINLOOP()
Declare Sub RePaint()

Sub Init()
	ScreenRes MAXW, MAXH, 32, 2
	ScreenSet( 0, 1 )
	Color RGB(0, 0, 0), RGB(15, 120, 180)
	Cls
	
	NewWindow(1, 10, 10, 200, 140, "Window 1", &h9e9e9e)
	NewWindow(2, 40, 40, 200, 140, "Window 2", &h9e9e9e)
	NewWindow(3, 80, 80, 200, 140, "Window 3", &h9e9e9e)
	NewWindow(4, 120, 120, 200, 140, "Window 4", &h9e9e9e)
	NewWindow(5, 160, 160, 200, 140, "Window 5", &h9e9e9e)

End Sub

Sub NewWindow(id As UInteger, x As Integer, y As Integer, w As Integer, h As Integer, title As String, c As Integer) '...'
	'new window
	iWindowPopulation += 1
	ReDim Preserve pWindows(1 To iWindowPopulation)
	pWindows(iWindowPopulation) = New hWindow(id, x, y, w, h, title, c)
End Sub

Sub MAINLOOP()

Dim As Integer mx, my, mb, x1, y1


Do
    GetMouse mx,my,,mb
    x1 = mx
    y1 = my
    If mb = 1 Then
        For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
            If (mx > pWindows(i)->x And mx < pWindows(i)->x + pWindows(i)->w) And (my > pWindows(i)->y And my < pWindows(i)->y + pWindows(i)->h) Then
				If i = 1 And UBound(pWindows) > 1 Then
					Swap pWindows(1), pWindows(UBound(pWindows))
				End If
				
				If i > 1 Then
                	For m As Integer = LBound(pWindows) To UBound(pWindows) Step 1
                		If m + 1 > UBound(pWindows) Then Exit For
                		Swap pWindows(m), pWindows(UBound(pWindows))
                	Next
				End If
				
                If i < UBound(pWindows) Then RePaint()
                
                If mx > (pWindows(UBound(pWindows))->x + pWindows(UBound(pWindows))->w - 10) And my > (pWindows(UBound(pWindows))->y + pWindows(UBound(pWindows))->h - 10) Then
                    Do
                        GetMouse mx,my,,mb
                        pWindows(UBound(pWindows))->w += mx - x1
                        pWindows(UBound(pWindows))->h += my - y1
                        x1 = mx
                        y1 = my
                        If pWindows(UBound(pWindows))->w < MINWH Then  pWindows(UBound(pWindows))->w = MINWH
                        If pWindows(UBound(pWindows))->h < MINWH Then  pWindows(UBound(pWindows))->h = MINWH
                        If pWindows(UBound(pWindows))->w >= MAXW Then  pWindows(UBound(pWindows))->w = MAXW
                        If pWindows(UBound(pWindows))->h >= MAXH Then  pWindows(UBound(pWindows))->h = MAXH
                        RePaint()
                    Loop Until mb = 0
                ElseIf my < (pWindows(UBound(pWindows))->y + TBH) Then
                    Do
                        GetMouse mx,my,,mb
                        pWindows(UBound(pWindows))->x += mx - x1
                        pWindows(UBound(pWindows))->y += my - y1
                        x1 = mx
                        y1 = my
                        RePaint()
                    Loop Until mb = 0
                End If
                Exit For
            End If
        Next i
    End If
    
    RePaint()
    
    Sleep( 1, 1 )
Loop Until MultiKey(&h01) 'loop until ESC pressed

End Sub

Sub RePaint()
	Cls
	For i As Integer = 1 To UBound(pWindows)
		pWindows(i)->redraw()
	Next
	Flip()
End Sub


Init()
MAINLOOP()
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

Image
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

well the code i was based it is taken from discord freebasic channel from Paul Doe but the original developer is unknown to me and to Paul Doe... :roll:

here it is the original code..

Code: Select all

#define MAXR 2   'max rect
#define MAXW 800 'max width
#define MAXH 600 'max height
#define MINWH 80 'min width/height
#define TBH 20   'titlebar height

type rect
    as integer x,y,w,h
    as uinteger c
    as string title
    declare constructor()
    declare constructor(as integer,as integer,as integer,as integer,as string,as integer)
    declare sub redraw()
end type

constructor rect()
end constructor

constructor rect(x as integer,y as integer,w as integer,h as integer,t as string,c as integer)
  this.x = x
  this.y = y
  this.w = w
  this.h = h
  this.title = t
  this.c = c
  redraw()
end constructor

sub rect.redraw()
    line(x,y)-(x+w,y+h),&hffffff,BF    'frame
    line(x+w-10,y+h-10)-(x+w,y+h),0,BF 'angle
    line(x+4,y+TBH)-(x+w-4,y+h-4),c,BF 'box
    draw string(x+4,y+8),title
end sub

dim shared as rect r(MAXR)

sub refresh()
  cls
  
  for i as integer = 0 to MAXR
     r(i).redraw()
  next
  
  flip()
end sub

screenres MAXW,MAXH,32, 2
screenSet( 0, 1 )
color 0,&h3A6EA5
cls

r(0) = rect(10,10,200,140,"Frame 1",&hff0000)
r(1) = rect(40,40,200,140,"Frame 2",&hffff00)
r(2) = rect(80,80,200,140,"Frame 3",&h0000ff)

dim as integer mx,my,mb,x1,y1

do
    getmouse mx,my,,mb
    x1 = mx
    y1 = my
    if mb = 1 then
        for i as integer = MAXR to 0 step -1
            if (mx > r(i).x and mx < r(i).x+r(i).w) and (my > r(i).y and my < r(i).y+r(i).h) then
                if i = 1 then
                    swap r(1),r(2)
                elseif i = 0 then
                    swap r(0),r(1)
                    swap r(1),r(2)
                end if
                if i < 2 then refresh()
               
                if mx > (r(2).x + r(2).w - 10) and my > (r(2).y + r(2).h - 10) then
                    do
                        getmouse mx,my,,mb
                        r(2).w += mx - x1
                        r(2).h += my - y1
                        x1 = mx
                        y1 = my
                        if r(2).w < MINWH then  r(2).w = MINWH
                        if r(2).h < MINWH then  r(2).h = MINWH
                        if r(2).w >= MAXW then  r(2).w = MAXW
                        if r(2).h >= MAXH then  r(2).h = MAXH
                        refresh()
                    loop until mb = 0
                elseif my < (r(2).y + TBH) then
                    do
                        getmouse mx,my,,mb
                        r(2).x += mx - x1
                        r(2).y += my - y1
                        x1 = mx
                        y1 = my
                        refresh()
                    loop until mb = 0
                end if
                exit for
            end if
        next i
    end if
    
    refresh()
    
    sleep( 1, 1 )
loop until multikey(1)
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

i found the source
viewtopic.php?p=239054
it is code from nimdays
thanks pal
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: Let's develop OpenWinDOS

Post by angros47 »

Have you ever heard of XFDOS? It was a project that featured a version of the FLTK GUI compiled for DOS. With the latest version of FreeBasic, I have achieved using FLTK on FreeBasic without wrappers, so perhaps it would be possible to use it from the DOS version of FreeBasic as well?
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

angros47 wrote: Sep 12, 2022 13:56 Have you ever heard of XFDOS? It was a project that featured a version of the FLTK GUI compiled for DOS. With the latest version of FreeBasic, I have achieved using FLTK on FreeBasic without wrappers, so perhaps it would be possible to use it from the DOS version of FreeBasic as well?
i will have it as alternative.
for now i want to develop all GUI from scratch. I am in a learning and fun mood developing from zero my own GUI !

Thanks!
Last edited by demosthenesk on Sep 12, 2022 17:53, edited 1 time in total.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

i have add Minimize, Maximize, Close Window buttons
i have implement the close button that closes a window

Image
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

angros47 wrote: Sep 12, 2022 13:56 Have you ever heard of XFDOS? It was a project that featured a version of the FLTK GUI compiled for DOS. With the latest version of FreeBasic, I have achieved using FLTK on FreeBasic without wrappers, so perhaps it would be possible to use it from the DOS version of FreeBasic as well?
where is your FLTK project ? At GitHub ?
angros47
Posts: 2331
Joined: Jun 21, 2005 19:04

Re: Let's develop OpenWinDOS

Post by angros47 »

Yes, this one: https://github.com/angros47/FLTK-headers-for-FreeBasic

Not tested with DOS, so let me know if you achieve anything
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

angros47 wrote: Sep 12, 2022 19:42 Yes, this one: https://github.com/angros47/FLTK-headers-for-FreeBasic

Not tested with DOS, so let me know if you achieve anything
Nice !
It would be nice if you write some EXAMPLES.bas
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

Misc optimizations, the window behavior is now stable.

window.bi

Code: Select all

#define TBH 25   'titlebar height
#define MINWH 80 'min width/height
Type hWindow
    As UInteger id				'id of window
    As Integer x, y, w, h		'x,y,width,heigt
    As UInteger c				'c as color
    As String title				'title as string
    As Boolean hasCloseButton
    As Boolean hasMinimizeButton
    As Boolean hasMaximizeButton
    Declare Constructor()
    Declare Constructor(As UInteger, As Integer, As Integer, As Integer, As Integer, As String, As UInteger)
    Declare Sub redraw()
    Declare Sub DoEvents()
    Declare Sub onCloseWindow()
    As Boolean doCloseWindow
    Declare Sub onFocusWindow()
    As Boolean doGetFocus
    Declare Sub onResizeWindow()
    As Boolean doResizeWindow
    Declare Sub onMoveWindow()
    As Boolean doMoveWindow
End Type

Constructor hWindow()
End Constructor

Constructor hWindow(id As UInteger, x As Integer, y As Integer, w As Integer, h As Integer, t As String, c As UInteger)
  This.id = id
  This.x = x
  This.y = y
  This.w = w
  This.h = h
  This.title = t
  This.c = c
  This.hasCloseButton = True
  This.hasMaximizeButton = True
  This.hasMinimizeButton = True
  This.doCloseWindow = False
  This.doGetFocus = False
  This.doResizeWindow = False
  This.doMoveWindow = False
  redraw()
End Constructor

Sub hWindow.DoEvents()
	This.onCloseWindow()
	This.onFocusWindow()
	This.onResizeWindow()
	This.onMoveWindow()
End Sub

Sub hWindow.onMoveWindow()
	Dim As Integer mx, my, mb

    GetMouse mx, my, , mb
    If mb = 1 Then
    	If mx > This.x And mx < This.x + This.w And my > This.y And my < This.y + TBH Then
    		This.doMoveWindow = True 
    	End If
    End If
End Sub

Sub hWindow.onResizeWindow()
	Dim As Integer mx, my, mb

    GetMouse mx, my, , mb
    If mb = 1 Then
    	If mx > This.x + This.w - 10 And mx < This.x + This.w And my > This.y + This.h - 10 And my < This.y + This.h Then
    		This.doResizeWindow = True 
    	End If
    End If
End Sub

Sub hWindow.onFocusWindow()
	Dim As Integer mx, my, mb

    GetMouse mx, my, , mb
    If mb = 1 Then
    	If mx > This.x And mx < This.x + This.w And my > This.y And my < This.y + This.h Then
    		This.doGetFocus = True 
    	End If
    End If
End Sub

Sub hWindow.onCloseWindow()
	Dim As Integer mx, my, mb

	GetMouse mx, my, , mb
	If mb = 1 Then
		If mx > x + w - 13 And mx < x + w - 13 + 6 And my > y + TBH / 2 - 3 And my < y + TBH Then
			'title = "Window " & id & " " & Str(mx) & " " & Str(my)
			doCloseWindow = True 
		End If
	End If
End Sub

Sub hWindow.redraw()
	Line(x, y) - (x + w, y + h), &hffffff, BF				'frame
	Line(x + w - 10, y + h - 10) - (x + w, y + h), 0, BF	'angle
	Line(x + 4, y + TBH) - (x + w - 4, y + h - 4), c, BF	'box
	Draw String(x + 4, y + 8), title						'title
	
	If This.hasCloseButton = True Then
		'close window button
		Circle (x + w - 10, (y + TBH / 2)), 6, RGB(255, 0, 0), , , , F
		Draw String(x + w - 13, y + TBH / 2 - 3), "X", RGB(255, 255, 255)
	EndIf
	
	If This.hasMinimizeButton = True Then 
		'minimize window button
		Circle (x + w - 24, (y + TBH / 2)), 6, RGB(0, 255, 0), , , , F
		Draw String(x + w - 27, y + TBH / 2 - 3), "-", RGB(255, 255, 255)
	EndIf
	
	If This.hasMaximizeButton = True Then 
		'maximize window button
		Circle (x + w - 38, (y + TBH / 2)), 6, RGB(0, 0, 255), , , , F
		Draw String(x + w - 41, y + TBH / 2 - 3), "+", RGB(255, 255, 255)
	EndIf
	
End Sub
main.bas

Code: Select all

#include "window.bi"
#define MAXW 800 'max desktop width
#define MAXH 600 'max desktop height

Dim Shared iWindowPopulation As UInteger = 0	'holds the number of created windows
Dim Shared pWindows() As hWindow Ptr			'array of ptr windows

Declare Sub Init()
Declare Sub NewWindow(id As UInteger, x As Integer, y As Integer, w As Integer, h As Integer, title As String, c As UInteger)
Declare Sub MAINLOOP()
Declare Sub DoEvents()
Declare Sub RePaint()

Declare Sub GetFocusWindow()
Declare Sub ResizeWindow()
Declare Sub MoveWindow()

Sub Init()
	ScreenRes MAXW, MAXH, 32, 2
	ScreenSet( 0, 1 )
	Color RGB(0, 0, 0), RGB(15, 120, 180)
	Cls
	
	NewWindow(1, 10, 10, 200, 140, "Window 1", &h9e9e9e) 
	NewWindow(2, 40, 40, 200, 140, "Window 2", &h9e9e9e)
	NewWindow(3, 80, 80, 200, 140, "Window 3", &h9e9e9e)
	NewWindow(4, 120, 120, 200, 140, "Window 4", &h9e9e9e)
	NewWindow(5, 160, 160, 200, 140, "Window 5", &h9e9e9e)

End Sub

Sub NewWindow(id As UInteger, x As Integer, y As Integer, w As Integer, h As Integer, title As String, c As UInteger) '...'
	'new window
	iWindowPopulation += 1
	ReDim Preserve pWindows(1 To iWindowPopulation)
	pWindows(iWindowPopulation) = New hWindow(id, x, y, w, h, title, c)
End Sub

Sub ResizeWindow() '...'
	Dim As Integer mx, my, mb, x1, y1
	RePaint()

    GetMouse mx, my, , mb
    x1 = mx
    y1 = my
    If mb = 1 Then
		For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
			If pWindows(i) = 0 Then Continue For
			If pWindows(i)->doResizeWindow = True Then
				pWindows(i)->doResizeWindow = False
                Swap pWindows(i), pWindows(UBound(pWindows))
                    Do
                        GetMouse mx,my,,mb
                        pWindows(UBound(pWindows))->w += mx - x1
                        pWindows(UBound(pWindows))->h += my - y1
                        x1 = mx
                        y1 = my
                        If pWindows(UBound(pWindows))->w < MINWH Then  pWindows(UBound(pWindows))->w = MINWH
                        If pWindows(UBound(pWindows))->h < MINWH Then  pWindows(UBound(pWindows))->h = MINWH
                        If pWindows(UBound(pWindows))->w >= MAXW Then  pWindows(UBound(pWindows))->w = MAXW
                        If pWindows(UBound(pWindows))->h >= MAXH Then  pWindows(UBound(pWindows))->h = MAXH
                        RePaint()
                    Loop Until mb = 0
				Exit For
			End If
		Next
    End If
End Sub

Sub MoveWindow() '...'
	Dim As Integer mx, my, mb, x1, y1
	RePaint()

    GetMouse mx, my, , mb
    x1 = mx
    y1 = my
    If mb = 1 Then
		For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
			If pWindows(i) = 0 Then Continue For
			If pWindows(i)->doMoveWindow = True Then
				pWindows(i)->doMoveWindow = False
                Swap pWindows(i), pWindows(UBound(pWindows))
                    Do
                        GetMouse mx,my,,mb
                        pWindows(UBound(pWindows))->x += mx - x1
                        pWindows(UBound(pWindows))->y += my - y1
                        x1 = mx
                        y1 = my
                        RePaint()
                    Loop Until mb = 0
				Exit For
			End If
		Next
    End If
End Sub

Sub GetFocusWindow() '...'
Dim As Integer mx, my, mb
	RePaint()
    GetMouse mx, my, , mb
    If mb = 1 Then
		For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
			If pWindows(i) = 0 Then Continue For
			If pWindows(i)->doGetFocus = True Then
				pWindows(i)->doGetFocus = False
                Swap pWindows(i), pWindows(UBound(pWindows))
				RePaint()
				Exit For
			End If
		Next
    End If
End Sub

Sub DoEvents()
	GetFocusWindow()
	ResizeWindow()
	MoveWindow()
	
	For i As Integer = 1 To UBound(pWindows)	'doevents of every window
		If pWindows(i) = 0 Then Continue For	'skip deleted windows
		pWindows(i)->DoEvents
		
		'if close window
		If pWindows(i)->doCloseWindow = True Then
			Delete pWindows(i)
			pWindows(i) = 0
		End If
	Next
End Sub

Sub MAINLOOP()
	Do
		DoEvents()
		Sleep( 1, 1 )
	Loop Until MultiKey(&h01) 'loop until ESC pressed

End Sub

Sub RePaint() '...'
	Cls
	For i As Integer = 1 To UBound(pWindows)
		If pWindows(i) = 0 Then Continue For
		pWindows(i)->redraw()
	Next
	Flip()
End Sub

Init()
MAINLOOP()
dodicat
Posts: 7996
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Let's develop OpenWinDOS

Post by dodicat »

You can do it all without that pointer.
I think your sleep 1,1 should be directly after flip.
But I don't have dos, I am running win 10.
And that license, you would need to live in Philadelphia to get it deciphered.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

I stayed awake all night yesterday trying to fix the overlay bug of windows...finally i did it !!!
The latest code here it is:

window.bi

Code: Select all

#define TBH 25   'titlebar height
#define MINWH 80 'min width/height

Type hWindow
    As Integer id				'id of window
    As Integer x, y, w, h		'x,y,width,heigt
    As ULong c				'c as color
    As String title				'title as string
    As Boolean hasCloseButton
    As Boolean hasMinimizeButton
    As Boolean hasMaximizeButton
    Declare Constructor()
    Declare Constructor(As Integer, As Integer, As Integer, As Integer, As Integer, As String, As ULong)
    Declare Sub redraw()
    Declare Sub DoEvents()
    Declare Sub onCloseWindow()
    As Boolean doCloseWindow
    Declare Sub onFocusWindow()
    As Boolean doGetFocus
    Declare Sub onResizeWindow()
    As Boolean doResizeWindow
    Declare Sub onMoveWindow()
    As Boolean doMoveWindow
    As UInteger Zorder
End Type

Constructor hWindow()
End Constructor

Constructor hWindow(id As Integer, x As Integer, y As Integer, w As Integer, h As Integer, t As String, c As ULong)
  This.id = id
  This.x = x
  This.y = y
  This.w = w
  This.h = h
  This.title = t
  This.c = c
  This.hasCloseButton = True
  This.hasMaximizeButton = True
  This.hasMinimizeButton = True
  This.doCloseWindow = False
  This.doGetFocus = False
  This.doResizeWindow = False
  This.doMoveWindow = False
  This.Zorder = 0
  redraw()
End Constructor

Sub hWindow.DoEvents()
	This.onCloseWindow()
	This.onFocusWindow()
	This.onResizeWindow()
	This.onMoveWindow()
End Sub

Sub hWindow.onMoveWindow()
	Dim As Integer mx, my, mb

    GetMouse mx, my, , mb
    If mb = 1 Then
    	If mx > This.x And mx < This.x + This.w And my > This.y And my < This.y + TBH Then
    		This.doMoveWindow = True
    		iActiveWindow = This.id
    	End If
    End If
End Sub

Sub hWindow.onResizeWindow()
	Dim As Integer mx, my, mb

    GetMouse mx, my, , mb
    If mb = 1 Then
    	If mx > This.x + This.w - 10 And mx < This.x + This.w And my > This.y + This.h - 10 And my < This.y + This.h Then
    		This.doResizeWindow = True
    		iActiveWindow = This.id
    	End If
    End If
End Sub

Sub hWindow.onFocusWindow()
	Dim As Integer mx, my, mb

    GetMouse mx, my, , mb
    If mb = 1 Then
    	If mx > This.x And mx < This.x + This.w And my > This.y And my < This.y + This.h Then
    		This.doGetFocus = True
    		iActiveWindow = This.id
    	End If
    End If
End Sub

Sub hWindow.onCloseWindow()
	Dim As Integer mx, my, mb

	GetMouse mx, my, , mb
	If mb = 1 Then
		If mx > x + w - 13 And mx < x + w - 13 + 6 And my > y + TBH / 2 - 3 And my < y + TBH Then
			'title = "Window " & id & " " & Str(mx) & " " & Str(my)
			doCloseWindow = True
			iActiveWindow = This.id 
		End If
	End If
End Sub

Sub hWindow.redraw()
	Line(x, y) - (x + w, y + h), &hffffff, BF				'frame
	Line(x + w - 10, y + h - 10) - (x + w, y + h), 0, BF	'angle
	Line(x + 4, y + TBH) - (x + w - 4, y + h - 4), c, BF	'box
	Draw String(x + 4, y + 8), title						'title
	
	If This.hasCloseButton = True Then
		'close window button
		Circle (x + w - 10, (y + TBH / 2)), 6, RGB(255, 0, 0), , , , F
		Draw String(x + w - 13, y + TBH / 2 - 3), "X", RGB(255, 255, 255)
	EndIf
	
	If This.hasMinimizeButton = True Then 
		'minimize window button
		Circle (x + w - 24, (y + TBH / 2)), 6, RGB(0, 255, 0), , , , F
		Draw String(x + w - 27, y + TBH / 2 - 3), "-", RGB(255, 255, 255)
	EndIf
	
	If This.hasMaximizeButton = True Then 
		'maximize window button
		Circle (x + w - 38, (y + TBH / 2)), 6, RGB(0, 0, 255), , , , F
		Draw String(x + w - 41, y + TBH / 2 - 3), "+", RGB(255, 255, 255)
	EndIf
	
End Sub
main.bas

Code: Select all

Dim Shared iActiveWindow As Integer = 0

#include once "fbgfx.bi"
#include once "window.bi"
#define MAXW 800 'max desktop width
#define MAXH 600 'max desktop height

Using FB

Dim Shared iWindowPopulation As UInteger = 0	'holds the number of created windows
Dim Shared pWindows() As hWindow Ptr			'array of ptr windows

Declare Sub Init()
Declare Sub NewWindow(id As Integer, x As Integer, y As Integer, w As Integer, h As Integer, title As String, c As ULong)
Declare Sub MAINLOOP()
Declare Sub DoEvents()
Declare Sub RePaint()

Declare Sub GetFocusWindow()
Declare Sub ResizeWindow()
Declare Sub MoveWindow()
Declare Sub CloseWindow()

Sub Init()
	ScreenRes MAXW, MAXH, 32, 2
	ScreenSet( 0, 1 )
	Color RGB(0, 0, 0), RGB(15, 120, 180)
	Cls
	
	NewWindow(1, 10, 10, 200, 140, "Window 1", &h9e9e9e) 
	NewWindow(2, 40, 40, 200, 140, "Window 2", &h9e9e9e)
	NewWindow(3, 80, 80, 200, 140, "Window 3", &h9e9e9e)
	NewWindow(4, 120, 120, 200, 140, "Window 4", &h9e9e9e)
	NewWindow(5, 160, 160, 200, 140, "Window 5", &h9e9e9e)
	
	RePaint()

End Sub

Sub NewWindow(id As Integer, x As Integer, y As Integer, w As Integer, h As Integer, title As String, c As ULong) '...'
	'new window
	iWindowPopulation += 1
	ReDim Preserve pWindows(1 To iWindowPopulation)
	pWindows(iWindowPopulation) = New hWindow(iWindowPopulation, x, y, w, h, title, c)
End Sub

Sub ResizeWindow()

	Dim As Integer mx, my, mb, x1, y1
'	RePaint()

    GetMouse mx, my, , mb
    x1 = mx
    y1 = my
    If mb = 1 Then
		For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
			If pWindows(i) = 0 Then Continue For
			If pWindows(i)->doResizeWindow = True Then
				pWindows(i)->doResizeWindow = False
				If pWindows(i)->id = CInt(iActiveWindow) Then
	                Swap pWindows(i), pWindows(UBound(pWindows))
                    Do
                        GetMouse mx,my,,mb
                        pWindows(UBound(pWindows))->w += mx - x1
                        pWindows(UBound(pWindows))->h += my - y1
                        x1 = mx
                        y1 = my
                        If pWindows(UBound(pWindows))->w < MINWH Then  pWindows(UBound(pWindows))->w = MINWH
                        If pWindows(UBound(pWindows))->h < MINWH Then  pWindows(UBound(pWindows))->h = MINWH
                        If pWindows(UBound(pWindows))->w >= MAXW Then  pWindows(UBound(pWindows))->w = MAXW
                        If pWindows(UBound(pWindows))->h >= MAXH Then  pWindows(UBound(pWindows))->h = MAXH
                        RePaint()
                    Loop Until mb = 0
					Exit For
				EndIf
			End If
		Next
    End If
End Sub

Sub MoveWindow()
	Dim As Integer mx, my, mb, x1, y1
'	RePaint()

    GetMouse mx, my, , mb
    x1 = mx
    y1 = my
    If mb = 1 Then
		For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
			If pWindows(i) = 0 Then Continue For
			If pWindows(i)->doMoveWindow = True Then
				pWindows(i)->doMoveWindow = False
				#print Typeof(pWindows(i)->id)
				#print Typeof(iActiveWindow)
				If pWindows(i)->id = CInt(iActiveWindow) Then
	                Swap pWindows(i), pWindows(UBound(pWindows))
                    Do
                        GetMouse mx,my,,mb
                        pWindows(UBound(pWindows))->x += mx - x1
                        pWindows(UBound(pWindows))->y += my - y1
                        x1 = mx
                        y1 = my
                        RePaint()
                    Loop Until mb = 0
					Exit For
				EndIf
			End If
		Next
    End If
End Sub

Sub GetFocusWindow()
Dim As Integer mx, my, mb

'	RePaint()
    GetMouse mx, my, , mb
    If mb = 1 Then

		For i As Integer = UBound(pWindows) To LBound(pWindows) Step -1
			If pWindows(i) = 0 Then Continue For
			If pWindows(i)->doGetFocus = True Then
				pWindows(i)->doGetFocus = False
				If pWindows(i)->id = CInt(iActiveWindow) Then
					Swap pWindows(i), pWindows(UBound(pWindows))
					RePaint()
					Exit For
				EndIf
			End If
		Next

	End If
End Sub

Sub CloseWindow()
	For i As Integer = 1 To UBound(pWindows) 'doevents of every window
		If pWindows(i) = 0 Then Continue For	'skip deleted windows
		'if close window
		If pWindows(i)->doCloseWindow = True Then
			Delete pWindows(i)
			pWindows(i) = 0
			RePaint()
		End If
	Next
End Sub

Sub DoEvents()
'	ResizeWindow()
'	MoveWindow()
'	GetFocusWindow()
'	CloseWindow()


	For i As Integer = 1 To UBound(pWindows)	'doevents of every window
		If pWindows(i) = 0 Then Continue For	'skip deleted windows
		pWindows(i)->DoEvents
	Next
	
	CloseWindow()
	ResizeWindow()
	MoveWindow()
	GetFocusWindow()
	
End Sub

Sub MAINLOOP()
	Do
		DoEvents()
		Sleep( 1, 1 )
	Loop Until MultiKey(SC_ESCAPE) 'loop until ESC pressed

End Sub

Sub RePaint()
	Cls
	For i As Integer = 1 To UBound(pWindows)
		If pWindows(i) = 0 Then Continue For
		pWindows(i)->redraw()
		pWindows(i)->Zorder = i
'		pWindows(1)->title = Str(iActiveWindow)
	Next
	Flip()
End Sub

Init()
MAINLOOP()
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

dodicat wrote: Sep 13, 2022 11:17 You can do it all without that pointer.
I think your sleep 1,1 should be directly after flip.
But I don't have dos, I am running win 10.
And that license, you would need to live in Philadelphia to get it deciphered.
i use that window pointer in order to be able to create/delete windows
what about the license...? i didn't understand. :?:
dodicat
Posts: 7996
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Let's develop OpenWinDOS

Post by dodicat »

I get
42: Variable not declared, iActiveWindow in 'iActiveWindow = This.id'
But, as I say, I don't have dos here, maybe it is not an error fb fbdos.
So I created a shared integer iActiveWindow, and it seems OK here on windows fb.
If you don't put sleep 1,1 after flip you get a huge framerate while dragging, it might upset some cpu's.
Using a pointer is of course your choice, I would prefer just using an array of instances.
You can still create/delete or not show windows.
Your licence is huge, is it really necessary?
Your choice of course.
Anyway, good luck with your project.
Post Reply