Let's develop OpenWinDOS

DOS specific questions.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: Let's develop OpenWinDOS

Post by dasyar »

This is something that I was working on, a few years age. This might work for you, for creating buttons. Hope this helps.

Code: Select all

' fbtermg.bas
'
' October 23, 2017
'

#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using fb
#endif



Dim e As EVENT

Dim Shared As String Key,title,titlecon,titledis,event1,blank1,buffer
Dim Shared As String titleport,port1,port2,port3,port4,port5,p
Dim Shared As String titlebaud,baud1,baud2,baud3,baud4,baud5,b
Dim Shared As Long res, x, y, buttons, column, row
Dim Shared As Integer title1
Dim Shared As Double t
Dim Shared As Double flag

Screen 20  ' 1024x768
WindowTitle "FBtermG Program"

Declare Sub Connect()
Declare Sub Disconnect()
Declare Sub CommBox()
Declare Sub CommBoxB()
Declare Sub PortBox()
Declare Sub PortBox1()
Declare Sub PortBox2()
Declare Sub PortBox3()
Declare Sub PortBox4()
Declare Sub PortBox5()
Declare Sub BaudBox()
Declare Sub BaudBox1()
Declare Sub BaudBox2()
Declare Sub BaudBox3()
Declare Sub BaudBox4()
Declare Sub BaudBox5()
Declare Sub BlankOut()
Declare Sub TextCursor(ByRef flag As Double)

Connect()
PortBox()
BaudBox()
color 0,0
locate 1,1
Do
	res = GetMouse(x, y, ,buttons)  ' Start mouse
	Key = InKey   ' Start keyboard
	TextCursor(flag)  ' Start cursor
	
	If(ScreenEvent(@e)) Then
		Select Case e.Type
		Case EVENT_KEY_PRESS
			If(e.scancode = SC_ESCAPE) Then  ' Esc key to end program.
				Close
				End
			End If
		Case EVENT_WINDOW_CLOSE  ' Close window
			Close
			End
		End Select
	End If
' Mouse over connect/disconnect	
	If x > 5 And x <= 88 And y > 1 And y <= 18 And buttons And 1 Then		
		Sleep 200,1
		if title1 = 0 then
			Disconnect()
			CommBox()
			Open Com p & b & ",n,8,1,cs0,ds0,cd0,rs" As #1
			View Print 2 to 47
		elseif title1 = 1 then
			Connect()
			Close
			CommBoxB()
		End If
	End If
' Mouse over Port	
	If x > 93 And x <= 261 And y > 1 And y <= 18 And buttons And 1 Then
		PortBox1()
		PortBox2()
		PortBox3()
		PortBox4()
		PortBox5()
	End If
' Mouse over portbox1
	If x > 157 And x <= 261 And y > 18 And y <= 35 And buttons And 1 Then
		PortBox()
		port1 = "/dev/ttyAMA0:"
		Draw String (159,2),port1,4
		p = port1
		BlankOut()	
	End If
' Mouse over portbox2
	If x > 157 And x <= 261 And y > 36 And y <= 73 And buttons And 1 Then
		PortBox()
		port2 = "/dev/ttyUSB0:"
		Draw String (159,2),port2,4
		p = port2
		BlankOut()	
	End If
' Mouse over portbox3
	If x > 157 And x <= 261 And y > 52 And y <= 68 And buttons And 1 Then
		PortBox()
		port3 = "/dev/ttyUSB1:"
		Draw String (159,2),port3,4
		p = port3
		BlankOut()	
	End If
' Mouse over portbox4
	If x > 157 And x <= 261 And y > 68 And y <= 84 And buttons And 1 Then
		PortBox()
		port4 = "/dev/ttyUSB2:"
		Draw String (159,2),port4,4
		p = port4
		BlankOut()	
	End If
' Mouse over portbox5
	If x > 157 And x <= 261 And y > 80 And y <= 96 And buttons And 1 Then
		PortBox()
		port5 = "/dev/ttyUSB3:"
		Draw String (159,2),port5,4
		p = port5
		BlankOut()	
	End If	
' Mouse over BAUD	
	If x > 262 And x <= 382 And y > 1 And y <= 18 And buttons And 1 Then
		BaudBox1()
		BaudBox2()
		BaudBox3()
		BaudBox4()
		BaudBox5()
	End If
' Mouse over baudbox1
	If x > 300 And x <= 382 And y > 18 And y <= 35 And buttons And 1 Then
		BaudBox()
		baud1 = "9600"
		Draw String (316,2),baud1,4
		b = baud1
		BlankOut()		
	End If
' Mouse over baudbox2
	If x > 300 And x <= 382 And y > 36 And y <= 48 And buttons And 1 Then
		BaudBox()
		baud2 = "19200"
		Draw String (316,2),baud2,4
		b = baud2
		BlankOut()		
	End If
' Mouse over baudbox3
	If x > 300 And x <= 382 And y > 52 And y <= 68 And buttons And 1 Then
		BaudBox()
		baud3 = "38400"
		Draw String (316,2),baud3,4
		b = baud3
		BlankOut()		
	End If
' Mouse over baudbox4
	If x > 300 And x <= 382 And y > 68 And y <= 84 And buttons And 1 Then
		BaudBox()
		baud4 = "57600"
		Draw String (316,2),baud4,4
		b =baud4
		BlankOut()		
	End If
' Mouse over baudbox5
	If x > 300 And x <= 382 And y > 80 And y <= 96 And buttons And 1 Then
		BaudBox()
		baud5 = "115200"
		Draw String (316,2),baud5,4
		b = baud5
		BlankOut()		
	End If
			
	If Key <> "" Then
		If Key = Chr(13) Then
			Print Chr(13)
		Else
			print Key;
		End If
	End If	
	
	While LOC(1) > 0
		buffer = Input(LOC(1),#1)
		Print buffer;
	Wend

Sleep 1
Loop

Close
End
''''''''''''''''''''''''''''''
' Menu item Connect
Sub Connect()
titlecon = "Connect"
Draw "BM 8,1"               ' Start point x,y
Draw "C2"                    ' Set color
Draw "R85 D15 L85 U15"       ' Size of box
Draw "BM +1,1"               ' Move to inside of box
Draw "P 7,2"                 ' Flood fill up to border
Draw String (9,2),titlecon,2
title1 = 0
End Sub

' Menu item Disconnect
Sub Disconnect()
titledis = "Disconnect"
Draw "BM 8,1"               ' Start point x,y
Draw "C2"                    ' Set color
Draw "R85 D15 L85 U15"       ' Size of box
Draw "BM +1,1"               ' Move to inside of box
Draw "P 7,2"                 ' Flood fill up to border
Draw String (9,2),titledis,4
title1 = 1
End Sub

' Window for serial comms, open
Sub CommBox()
'Draw "BM 0,34"
'Draw "C2"
'Draw "R900 D700 L900 U700"
'Draw "BM +1,1"
'Draw "P 7,2"

line (1,18) - (900,740), 7, BF  'Create filled box
locate 2,1
color 0,7
End Sub

' Window for serial comms, close
Sub CommBoxB()
'Draw "BM 0,34"
'Draw "C0"
'Draw "R900 D700 L900 U700"
'Draw "BM +1,1"
'Draw "P 0,0"
Locate 2,1
color 0,0
line (1,18) - (900,740), 0, BF  'Blank filled box
End Sub

Sub PortBox()
titleport = "Port -"
Draw "BM 93,1"
Draw "C2"
'Draw "R85 D15 L85 U15"
Draw "R168 D15 L168 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (96,2),titleport,4
End Sub

Sub PortBox1()
port1 = "/dev/ttyAMA0:"
Draw "BM 157,16"
Draw "C2"
Draw "R104 D15 L104 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (159,18),port1,4
End Sub

Sub PortBox2()
port2 = "/dev/ttyUSB0:"
Draw "BM 157,32"
Draw "C2"
Draw "R104 D15 L104 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (159,34),port2,4
End Sub

Sub PortBox3()
port3 = "/dev/ttyUSB1"
Draw "BM 157,48"
Draw "C2"
Draw "R104 D15 L104 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (159,50),port3,4
End Sub

Sub PortBox4()
port4 = "/dev/ttyUSB2"
Draw "BM 157,64"
Draw "C2"
Draw "R104 D15 L104 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (159,66),port4,4
End Sub

Sub PortBox5()
port5 = "/dev/ttyUSB3"
Draw "BM 157,80"
Draw "C2"
Draw "R104 D15 L104 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (159,82),port5,4
End Sub

Sub BaudBox()
titlebaud = "BAUD -"
Draw "BM 262,1"
Draw "C2"
Draw "R120 D15 L120 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (264,2),titlebaud,4
End Sub

Sub BaudBox1()
baud1 = "9600"
Draw "BM 300,16"
Draw "C2"
Draw "R82 D15 L82 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (316,18),baud1,4
End Sub

Sub BaudBox2()
baud2 = "19200"
Draw "BM 300,32"
Draw "C2"
Draw "R82 D15 L82 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (316,34),baud2,4
End Sub

Sub BaudBox3()
baud3 = "38400"
Draw "BM 300,48"
Draw "C2"
Draw "R82 D15 L82 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (316,50),baud3,4
End Sub

Sub BaudBox4()
baud4 = "57600"
Draw "BM 300,64"
Draw "C2"
Draw "R82 D15 L82 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (316,66),baud4,4
End Sub

Sub BaudBox5()
baud5 = "115200"
Draw "BM 300,80"
Draw "C2"
Draw "R82 D15 L82 U15"
Draw "BM +1,1"
Draw "P 7,2"
Draw String (316,82),baud5,4
End Sub

Sub BlankOut()
Locate 2,1
color 0,0
line (1,18) - (900,740), 0, BF  'Blank filled box
End Sub

' Cursor display
Sub TextCursor(ByRef flag As Double)
column = Pos
row = CsrLin
If Timer - t > .5 Then
	flag = Not(flag)
	If flag Then Print "_" Else Print " ";
	Locate row,column
	t = Timer
End If
End Sub

Last edited by fxm on Sep 20, 2022 13:18, edited 2 times in total.
Reason: Corrected code tag.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

Well i need to learn "callbacks" in order to write events for the window and controls UDTs as my friend Paul Doe suggested.

Paul Doe at discord gave the next code as example of callbacks

Code: Select all

sub foo1( s as string )
  ? s
end sub

sub foo2( s as string )
  ? "From foo2: "; s
end sub

dim as sub( as string ) f

f = @foo1

f( "Hello!" )

f = @foo2

f( "This is a callback!" )

sleep()
how a callback helps to write events for UDTs ?
should i write something like that ?

Code: Select all

dim as sub() f

f = @myObject.onClick

f = @p_myObject->onClick
i still dont understand how to use callbacks with UDT subs-events...
any example, help ?
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Let's develop OpenWinDOS

Post by fxm »

You cannot get the address of a non-static member procedure.
Thus, for each member procedure concerned, a static member procedure is added with a single line of code to launch the non-static member procedure.
Example transposed from example above:

Code: Select all

Type UDT
    Declare Sub foo1(Byref s As String)
    Declare Sub foo2(Byref s As String)
    Declare Static Sub foo1(Byref u As UDT, Byref s As String)
    Declare Static Sub foo2(Byref u As UDT, Byref s As String)
    Dim As Integer I
End Type

Sub UDT.foo1(Byref s As String)
  Print This.I, "From foo1: "; s
End Sub

Sub UDT.foo2(Byref s As String)
  Print This.I, "From foo2: "; s
End Sub

Sub UDT.foo1(Byref u As UDT, Byref s As String)
  u.foo1(s)
End Sub

Sub UDT.foo2(Byref u As UDT, Byref s As String)
  u.foo2(s)
End Sub


Dim As Sub(Byref u As UDT, Byref s As String) f
Dim As UDT u
u.I = 123

f = @UDT.foo1
f(u, "Hello!")

f = @UDT.foo2
f(u, "This is a callback!")

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

Re: Let's develop OpenWinDOS

Post by demosthenesk »

well Paul Doe gave me an example of callbacks and UDTs like button.onClick

Code: Select all

type as sub( as any ptr, as any ptr ) EventCallback

type Window
  declare sub doEvents()
  
  as EventCallback onClick
end type

sub Window.doEvents()
  if( onClick ) then
    onClick( @this, 0 )
  end if
end sub

sub w_onClick( sender as any ptr, e as any ptr )
  ? "User clicked on a window!"
end sub

dim as Window w

w.onClick = @w_onClick

w.doEvents()

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

Re: Let's develop OpenWinDOS

Post by demosthenesk »

so far i was not used callbacks.
i used Booleans that were triggered by onClick sub and a WatchWindow function in DoEvents loop which watch the boolean and call a sub.

i think it is easier this way
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

in the callbacks example

Code: Select all

type as sub( as any ptr, as any ptr ) EventCallback

type Window
  declare sub doEvents()
  
  as EventCallback onClick
end type

sub Window.doEvents()
  if( onClick ) then
    onClick( @this, 0 )
  end if
end sub

sub w_onClick( sender as any ptr, e as any ptr )
  ? "User clicked on a window!"
end sub

dim as Window w
w.onClick = @w_onClick
w.doEvents()
sleep()
the if( onClick ) why is always true ?
codeFoil
Posts: 256
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Let's develop OpenWinDOS

Post by codeFoil »

The callback implementation that you have been shown is using pointers to function/subs.
Pointers are memory addresses, and memory addresses are essentially integer types.
So, when coerced to a boolean value, the only time they will evaluate to false is when the memory address is 0.

Code: Select all

dim as Window w
' You have not initialized the .onClick member of w, so you are taking it on faith that it will be initialized to 0. 
' That's not a safe assumption to make.

w.onClick = @w_onClick
' The .onClick member now holds the entry address of the routine w_onClick

w.doEvents()
' The IF statement within doEvents will never evaluate to FALSE because of the previous assignment.

sleep()
dbickin
Posts: 59
Joined: Aug 03, 2005 16:40

Re: Let's develop OpenWinDOS

Post by dbickin »

I downloaded OpenWinDos and tried to compile main.bas, and I got a bunch of errors.

The errors were like:
hWindow.bi(45) error 18: Element not defined, hName
But it looks like hName is defined in hControl. All the fields of hControl were listed as "elements not defined."

I am using fbc version 1.06. Is that version too old to handle this type of inheritance?

My second question is that I noticed in hControl.bi, that the first line begins with ".Type hControl extends object"
What does that period do? I have never seen ".Type" before and couldn't find it in the free basic documentation.
Ching the line to "Type hControl extends object" did not chanfe any of the error messages returned.

Third question is what makes this Dos only? Everything looks like standard FB graphic functions, so I would have guessed it should run in any environment.

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

Re: Let's develop OpenWinDOS

Post by demosthenesk »

dbickin wrote: Sep 22, 2022 14:56 I downloaded OpenWinDos and tried to compile main.bas, and I got a bunch of errors.

The errors were like:
hWindow.bi(45) error 18: Element not defined, hName
But it looks like hName is defined in hControl. All the fields of hControl were listed as "elements not defined."

I am using fbc version 1.06. Is that version too old to handle this type of inheritance?
Please download the latest src from https://github.com/demosthenesk/OpenWinDOS
and use the latest fbc 1.09
My second question is that I noticed in hControl.bi, that the first line begins with ".Type hControl extends object"
What does that period do? I have never seen ".Type" before and couldn't find it in the free basic documentation.
Ching the line to "Type hControl extends object" did not chanfe any of the error messages returned.
This is a mistake. There is no . period in front of Type.
Third question is what makes this Dos only? Everything looks like standard FB graphic functions, so I would have guessed it should run in any environment.

Thanks,
David
So far it runs anywhere DOS, Win, Linux. But when GUI is finished it will be DOS GUI.
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

codeFoil wrote: Sep 22, 2022 1:41 The callback implementation that you have been shown is using pointers to function/subs.
Pointers are memory addresses, and memory addresses are essentially integer types.
So, when coerced to a boolean value, the only time they will evaluate to false is when the memory address is 0.

Code: Select all

dim as Window w
' You have not initialized the .onClick member of w, so you are taking it on faith that it will be initialized to 0. 
' That's not a safe assumption to make.

w.onClick = @w_onClick
' The .onClick member now holds the entry address of the routine w_onClick

w.doEvents()
' The IF statement within doEvents will never evaluate to FALSE because of the previous assignment.

sleep()
thanks pal!
demosthenesk
Posts: 237
Joined: Jul 15, 2021 7:23
Location: Greece
Contact:

Re: Let's develop OpenWinDOS

Post by demosthenesk »

how can i manage different objects with callbacks?
like this ?

Code: Select all

type as sub( as any ptr, as Integer ) EventCallback

type Window
  declare sub doEvents()
  as EventCallback onClick
  id As Integer
end type

sub Window.doEvents()
  if( onClick ) then
    onClick( @this, id )
  end if
end sub

sub w_onClick( sender as any ptr, id as Integer )
  'manage objects here
  If id=1 Then
    ? "User clicked on window1!"
  End If

  If id=2 Then
    ? "User clicked on window2!"
  End If
  
  
end sub

dim as Window w1
dim as Window w2

w1.id=1
w2.id=2

w1.onClick = @w_onClick
w1.doEvents()

w2.onClick = @w_onClick
w2.doEvents()

sleep()
inside

Code: Select all

sub w_onClick
?
exagonx
Posts: 315
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Re: Let's develop OpenWinDOS

Post by exagonx »

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
Almost 3 year ago I need a gui windows style under MSDOS, and I make something like a framework, its work good but I had to leave the project because I had no time for developing, at moment Im working on database and a interpreter when I done I will contine the framework windows style , its one problem, the tasking are emulated and are not able to run external program more than one, I have to find a way to make a multitasking code under MSDOS.

Tell me if you want see my code for windows style framework ( work with mouse driver and are compilable under windows and linux )
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Re: Let's develop OpenWinDOS

Post by angros47 »

I, too, experimented with a GUI for dos, years ago (a port of Windoze by Sami Kyostila). It can still be found on http://qbasicgui.datacomponents.net/230_WIN3.html

Like your project, it is basically abandoned, because I have no real use for it: it works, but on Windows or Linux it's pretty useless (what is the point of having a window with its own windowing subsystem inside? All those windows would still be drawn with FreeBasic primitives, and would still be all inside the single window created by FreeBasic for graphic output. Sure, under Linux it could be useful, using the framebuffer driver, to provide an alternative to X, but since only one FreeBasic application at time could do that, it would void the point of using the windows anyway

I assume that you stopped developing your own framework for the same reasons.

That's why I think, nowadays, that using FLTK would be better: at least, porting the software would be possible, and software written in DOS would be easily portable to other system, with a GUI able to integrate with the desktop environment
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Let's develop OpenWinDOS

Post by paul doe »

angros47 wrote: Oct 05, 2022 17:43 ...
Like your project, it is basically abandoned, because I have no real use for it: it works, but on Windows or Linux it's pretty useless (what is the point of having a window with its own windowing subsystem inside? All those windows would still be drawn with FreeBasic primitives, and would still be all inside the single window created by FreeBasic for graphic output.
...
Like Immediate Mode GUIs, it has its uses. Say, tooling for a game engine. Check, for example, Abuse from Crack Dot Com ca. 1995, one of the first examples of this kind of workflow. It has an inbuilt editor and windowing system, and you could edit elements even as the game is playing. That was pretty impressive for 1995 indeed...

Another, more recent example would be Raylib's IMGUI (Raygui), which they use extensively to add interactivity and customization for some usage examples.
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Re: Let's develop OpenWinDOS

Post by angros47 »

You have a point. Although usually in games the GUI is either customized for the game (like, scrolls instead of text boxes if the game is set in middle age, or futuristic semi-transparent areas to simulate a HUD in sci-fi games), or really simple (usually, just menus, text boxes and buttons are needed, no need for forms, or advanced widgets).

Of course there are exceptions (like the original Sim City, that featured a full set of windows).
By the way, I ported Windoze about 12 years ago, and as far as I know only one person showed interest in using it.
Post Reply