sGUI

User projects written in or related to FreeBASIC.
Muttonhead
Posts: 113
Joined: May 28, 2009 20:07

sGUI

Postby Muttonhead » May 28, 2009 20:27

(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
... and a kind of english short reference for v0.8.4:
http://www.muttonhead.homepage.t-online.de/data/sGUI_ShortReference_v0.8.4.pdf
hope its usable for someone...

Mutton
Last edited by Muttonhead on May 29, 2016 15:24, edited 20 times in total.
vdecampo
Posts: 2977
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » May 28, 2009 21:38

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

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

Re: sGUI

Postby VANYA » Jun 02, 2012 4:21

Hi Muttonhead!

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

Re: sGUI

Postby Coolman » Jun 02, 2012 13:32

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: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: sGUI

Postby Roland Chastain » Jun 02, 2012 13:51

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

Postby 1000101 » Jun 02, 2012 18:25

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: 2230
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Re: sGUI

Postby Lachie Dazdarian » Jun 02, 2012 19:38

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

sGUI example

Postby Roland Chastain » Jun 03, 2012 8:59

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: 551
Joined: Jun 11, 2009 20:15

Re: sGUI

Postby MOD » Jun 03, 2012 9:48

The (german) helpfile wrote:GetString (gad as Gadget ptr) as string

So text = GetString(textedit1) should do the job.
Roland Chastain
Posts: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: sGUI

Postby Roland Chastain » Jun 03, 2012 10:00

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: 551
Joined: Jun 11, 2009 20:15

Re: sGUI

Postby MOD » Jun 03, 2012 10:17

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: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: sGUI

Postby Roland Chastain » Jun 03, 2012 10:36

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: 113
Joined: May 28, 2009 20:07

Re: sGUI

Postby Muttonhead » Jun 03, 2012 12:05

@ 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: 733
Joined: Nov 24, 2011 19:49
Location: Dakar, Senegal
Contact:

Re: sGUI

Postby Roland Chastain » Jun 03, 2012 13:58

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: 113
Joined: May 28, 2009 20:07

Re: sGUI

Postby Muttonhead » Jun 03, 2012 15:14

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

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests