sGUI

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
Muttonhead
Posts: 138
Joined: May 28, 2009 20:07

sGUI

Post by Muttonhead »

(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
Image
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
Image

Mutton
Last edited by Muttonhead on Jan 17, 2023 5:14, edited 22 times in total.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

I really love your control rendering! Very professional looking. I wish my controls in KwikGUI looked this good. ;)

-Vince
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: sGUI

Post by VANYA »

Hi Muttonhead!

Will be Select and copy the text in the editor? Thanks to an excellent library.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: sGUI

Post by Coolman »

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 ...
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: sGUI

Post by Roland Chastain »

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" ?
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Re: sGUI

Post by 1000101 »

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.
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Re: sGUI

Post by Lachie Dazdarian »

Nice stuff. As others said, some documentation would be nice.
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

sGUI example

Post by Roland Chastain »

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.

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.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: sGUI

Post by MOD »

The (german) helpfile wrote:GetString (gad as Gadget ptr) as string
So text = GetString(textedit1) should do the job.
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: sGUI

Post by Roland Chastain »

MOD wrote:
The (german) helpfile wrote:GetString (gad as Gadget ptr) as string
So text = GetString(textedit1) should do the job.
Thank you. It works. I modify the code (see my previous post).

Now I would like the string value to be changed only after the user presses Enter.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: sGUI

Post by MOD »

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"
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.
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: sGUI

Post by Roland Chastain »

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"
MOD wrote:To make it readonly I see just GadgetSleep(gad as Gadget ptr) as a solution.
Thank you, MOD. It works. (See the new code in my previous post.)

One could do better, but it works and it makes what I wanted. ;-)
Muttonhead
Posts: 138
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

@ 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 ;)

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
Mutton
Roland Chastain
Posts: 992
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: sGUI

Post by Roland Chastain »

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" ?
Muttonhead
Posts: 138
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

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
Post Reply