sGUI
-
- Posts: 139
- Joined: May 28, 2009 20:07
sGUI
(sorry about my english)
here is my "GUI Simulation" written in native(!) FB
list of simulated controls:
*SimpleGadget
*BMPSimpleGadget
*ToggleGadget
*CheckmarkGadget
*RadioButton
*StringGadget
*TrackBar
*ScrollBar
*FileRequester (very simple)
*SelectBox (a kind of)
*MultiLineEditBox/TextViewBox
*MessageBox
*Label
*PullDownMenu
sGUI_v0.8.4 latest version
hope its usable for someone...
update:
... its successor, unfortunately absolutely incompatible to the version above, sGUI2,currently only available as an appetizer:
https://www.freebasic-portal.de/downloa ... 2-401.html
Mutton
here is my "GUI Simulation" written in native(!) FB
list of simulated controls:
*SimpleGadget
*BMPSimpleGadget
*ToggleGadget
*CheckmarkGadget
*RadioButton
*StringGadget
*TrackBar
*ScrollBar
*FileRequester (very simple)
*SelectBox (a kind of)
*MultiLineEditBox/TextViewBox
*MessageBox
*Label
*PullDownMenu
sGUI_v0.8.4 latest version
hope its usable for someone...
update:
... its successor, unfortunately absolutely incompatible to the version above, sGUI2,currently only available as an appetizer:
https://www.freebasic-portal.de/downloa ... 2-401.html
Mutton
Last edited by Muttonhead on Jan 17, 2023 5:14, edited 22 times in total.
Re: sGUI
Hi Muttonhead!
Will be Select and copy the text in the editor? Thanks to an excellent library.
Will be Select and copy the text in the editor? Thanks to an excellent library.
Re: sGUI
great job. shame that the comments are in German in the source codes. English would have been better. thank you for the examples provided. missing documentation. I know. This is most annoying to do ...
-
- Posts: 1003
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: sGUI
Very nice library. As I already said to you in the german forum, I dream I will use it for my chess program. But before this, I hope I will find time to write at less a little example.
Just one thing : I wonder why you call it a "GUI simulation". Why "simulation" ?
Just one thing : I wonder why you call it a "GUI simulation". Why "simulation" ?
Re: sGUI
Very nice UI. I looked at the source and I like it's simple coding interface and how it's easy method to handle input.
-
- Posts: 2338
- Joined: May 31, 2005 9:59
- Location: Croatia
- Contact:
Re: sGUI
Nice stuff. As others said, some documentation would be nice.
-
- Posts: 1003
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
sGUI example
Hello gentlemen !
MuttonHead, could you have a look at this code ?
I would like to make an octet to ubyte converter. Here is my question: How can I get the value of my string s from textedit1, when the user presses Enter?
[EDIT]
New code with corrections suggested by MOD.
[EDIT]
New code with corrections suggested by MuttonHead.
MuttonHead, could you have a look at this code ?
I would like to make an octet to ubyte converter. Here is my question: How can I get the value of my string s from textedit1, when the user presses Enter?
[EDIT]
New code with corrections suggested by MOD.
[EDIT]
New code with corrections suggested by MuttonHead.
Code: Select all
'*******************************************************************************
' Binary_and_decimal.bas
'
' Ecriture binaire et écriture décimale
' d'un nombre compris entre 0 et 255
'
' Exemple d'usage de la librairie sGUI
'
'*******************************************************************************
#include "sGUI\sGUI.bas"
#include once "sGUI\SimpleGadget.bas"
#include once "sGUI\StringGadget.bas"
screenres 152,80,32,,4
width 152\8,80\16
InitGFX
'windowtitle "sGUI example"
dim as EventHandle ptr event
event=CreateEventHandle
dim as Gadget ptr textedit1,textedit2
textedit1=AddStringGadget(event,10,10,9,"00000000",0)
textedit2=AddStringGadget(event,10,42,4,"0",0)
GadgetOn (textedit1)
GadgetOn (textedit2)
declare function two_power(n as ubyte) as uinteger
declare function octet_to_ubyte(octet as string) as ubyte
declare function ubyte_to_octet(u as ubyte) as string
color &h000000f0
draw string (100,13),"Octet"
draw string (100,45),"UByte"
do
event->xSleep(1)
if event->GADGETMESSAGE then
select case event->GADGETMESSAGE
case textedit1
SetString(textedit2,str(octet_to_ubyte(GetString(textedit1))))
case textedit2
SetString(textedit1,ubyte_to_octet(valint(GetString(textedit2))))
end select
end if
loop until event->EXITEVENT
DestroyEventHandle (event)
end
'*******************************************************************************
' my functions
function two_power(n as ubyte) as uinteger
dim i as ubyte
dim tmp as uinteger
if n=0 then return 1
if n=1 then return 2
tmp=2
for i=2 to n
tmp=tmp*2
next i
return tmp
end function
function octet_to_ubyte(octet as string) as ubyte
dim i as ubyte
dim tmp as ubyte=0
for i=1 to len(octet)
if octet[len(octet)-i]=asc("1") then tmp+=two_power(i-1)
next i
return tmp
end function
function ubyte_to_octet(u as ubyte) as string
dim tmp as string=""
do
if u mod 2 = 1 then
tmp="1"+tmp
else
tmp="0"+tmp
end if
u = u\2
loop until u=0
return tmp
end function
'*******************************************************************************
Last edited by Roland Chastain on Jun 03, 2012 19:13, edited 7 times in total.
Re: sGUI
So text = GetString(textedit1) should do the job.The (german) helpfile wrote:GetString (gad as Gadget ptr) as string
-
- Posts: 1003
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: sGUI
Thank you. It works. I modify the code (see my previous post).MOD wrote:So text = GetString(textedit1) should do the job.The (german) helpfile wrote:GetString (gad as Gadget ptr) as string
Now I would like the string value to be changed only after the user presses Enter.
Re: sGUI
You can check for keypress like that:
And set the new text with SetString (gad as Gadget ptr, txt as string).
To make it readonly I see just GadgetSleep(gad as Gadget ptr) as a solution.
Code: Select all
If event->KEY = !"\r" Then Print "enter" 'or
If event->ASCCODE = 13 Then Print "enter"
To make it readonly I see just GadgetSleep(gad as Gadget ptr) as a solution.
-
- Posts: 1003
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: sGUI
MOD wrote:You can check for keypress like that:Code: Select all
If event->KEY = !"\r" Then Print "enter" 'or If event->ASCCODE = 13 Then Print "enter"
Thank you, MOD. It works. (See the new code in my previous post.)MOD wrote:To make it readonly I see just GadgetSleep(gad as Gadget ptr) as a solution.
One could do better, but it works and it makes what I wanted. ;-)
-
- Posts: 139
- Joined: May 28, 2009 20:07
Re: sGUI
@ all: Thanks for the feedback :)
@Roland:
if you finish your input with return, then StringGagdet sends a normal GADGETMESSAGE, that you can verify.
both methods of changing the text are working: SetString() ist the encapsuled version of "TO_SetLineContent+UpdateGadget"
Dont forget the 6. Parameter of AddStringGadet.Its a char limitation: 0=all >asc(31), 1=integer, 2=float, 3=binary, 4=hexadecimal, 5=IPAddresses ;)
Mutton
@Roland:
if you finish your input with return, then StringGagdet sends a normal GADGETMESSAGE, that you can verify.
both methods of changing the text are working: SetString() ist the encapsuled version of "TO_SetLineContent+UpdateGadget"
Dont forget the 6. Parameter of AddStringGadet.Its a char limitation: 0=all >asc(31), 1=integer, 2=float, 3=binary, 4=hexadecimal, 5=IPAddresses ;)
Code: Select all
#include "sGUI\sGUI.bas"
#include once "sGUI\SimpleGadget.bas"
#include once "sGUI\StringGadget.bas"
screenres 145,225,32
width 145\8,225\16
InitGFX
windowtitle ""
dim as EventHandle ptr event
event=CreateEventHandle
dim as Gadget ptr textedit1,textedit2
textedit1=AddStringGadget(event,10,10,10,"11111111")
textedit2=AddStringGadget(event,10,42,4,"")
GadgetOn (textedit1)
GadgetOn (textedit2)
'GadgetSleep (textedit2)
declare function two_power(n as ubyte) as uinteger
declare function octet_to_ubyte(octet as string) as ubyte
dim s as string
do
event->xSleep(1)
if event->GADGETMESSAGE then
select case event->GADGETMESSAGE
case textedit1
SetString(textedit2 , str( octet_to_ubyte( GetString(textedit1) ) ) )
case textedit2
'may be... reverse convert?????
'SetString(textedit1,ubyte_to_octet(GetString(textedit2))
end select
end if
loop until event->EXITEVENT
DestroyEventHandle (event)
end
function two_power(n as ubyte) as uinteger
dim i as ubyte
dim tmp as uinteger
if n=0 then return 1
if n=1 then return 2
tmp=2
for i=2 to n
tmp=tmp*2
next i
return tmp
end function
function octet_to_ubyte(octet as string) as ubyte
dim i as ubyte
dim tmp as ubyte=0
for i=1 to len(octet)
if octet[len(octet)-i]=asc("1") then tmp+=two_power(i-1)
next i
return tmp
end function
-
- Posts: 1003
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: sGUI
Thank you for your tips, MuttonHead. You can see the code in my first post.
One thing again. How can I add static text in the window, for example if I want to write a help message: "Enter a number and press Enter" ?
One thing again. How can I add static text in the window, for example if I want to write a help message: "Enter a number and press Enter" ?
-
- Posts: 139
- Joined: May 28, 2009 20:07
Re: sGUI
feel free to use the standard print, draw string command. all fbgfx commands are also usable.
The best place, i think, directly before the event loop.
ps:
But, if you want to load a nice bmp as background, do this before you Add() any control.
Mutton
The best place, i think, directly before the event loop.
ps:
But, if you want to load a nice bmp as background, do this before you Add() any control.
Mutton