sGUI

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

@ Muttonhead
Can you comment/correct this improvements ?, here are my temporary changes :
(without docs enhanced only what I see to improve for my purposes...)
1/ new custom color for 'Dot' in Radiobutton gadget
- added global variable 'dotColor'
- 'Dot' routine slightly changed

Code: Select all

	
	'NEW - in "sGUI.bas"
static shared as uinteger dotColor=rgb(0,0,0)
	
	'OLD - in "sGUI_Drawing.bas"	
'declare sub Dot (xpos as integer,ypos as integer, col as uinteger)
'...
'sub Dot (xpos as integer,ypos as integer, col as uinteger)
'  dim as uinteger topleft,bottomright
'  topleft=ShiftRGB(col,contrast/2)
'  bottomright=ShiftRGB(col,-contrast/2)
'...

	'NEW - in "sGUI_Drawing.bas"
declare sub Dot (xpos as integer,ypos as integer)
'...
sub Dot (xpos as integer,ypos as integer)
  dim as uinteger topleft,bottomright,col
	'passed global variable
	col=dotColor	'col is GadgetColor or user defined
	topleft=ShiftRGB(col,contrast/2)
    bottomright=ShiftRGB(col,-contrast/2)
'...
2/ added creation of horizontal Radiobutton - easy - only correct coordinates

Code: Select all

	'NEW - in "Demo_ActivationTest.bas"
dim as Gadget ptr label2
dim as Gadget ptr radioaH,radiobH,radiocH
'...
'menu (event,1,6,1,"End")	
'dotColor=
label2=AddLabel(event,10,380,"a dynamic widget with custom Dot color added",rgb(192,192,192))
'note: if placed as priority dynamic widget >> plus Save & Renew background needed (similar as in 'MessageBox' )
line (10,415)-(280,440),rgb(128,128,0),BF
radioaH  =AddRadioButton(event,20,420,1,"Hori",0)
radiobH  =AddRadioButton(event,80,420,0,"zon",radioaH)
radiocH  =AddRadioButton(event,130,420,0,"tal radioButton",radioaH)
GadgetOn (label2,radiocH)
dotColor=GadgetColor
'...
3/ added 'Enter' keypress check for 'MessageBox' - 'MsgType OK and YESNO'

Code: Select all

	'Changed Do-Loop cycle - in "MessageBox.bas"
      do
        event->xSleep(1,0)
'new - if some KEY pressed ..
' if more  MessageBoxes opened - problems ??
        if KEY<>"" then
				'MsgType OK and YESNO
			if ASCCODE=13 and MsgType=MBType_OK then result=MBButton_OK
			if ASCCODE=13 and MsgType=MBType_YESNO then result=MBButton_YES
			if ASCCODE<>13 and MsgType=MBType_YESNO then result=MBButton_NO
				'other MsgType howto define ?
           event->EXITEVENT=1
        end if

        if event->GADGETMESSAGE then
'...
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Q- if I understand correctly, event->GADGETMESSAGE value is passed/setted by mouse hover/click on drawn gadget ??
Therefore for correct ( keyboard control ) keypress catching to targeted gadget here must be opened only one gadget, or activated/switched targeted gadget by pressing 'TAB' keybrd. button ?
Am I on right thinkin' way ?
Muttonhead
Posts: 143
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

sGUI ColorSheme
***********

I like your idea for recoloring the dot, i will built it in.

The origin method for colorizing sGUI looks like this example:

Code: Select all

'Screen....

CustomColors=1  'dont use the default color definitions in InitGFX
'now define all colors "by hand"
'please define all colors, if not the color is black !
BackGroundColor	=&HC8C8C8
TextColor	=black
GadgetColor	=&HCFDFFF
GadgetGlowColor	=&HFFEFAF
GadgetTextColor	=black
CursorColor	=&H337FFF
MenuColor       =BackGroundColor
MenuTextColor   =black
MenuHiliteColor =GadgetColor
MenuGhostedColor=&H444444
'RBDotColor=&HFFFFFF

InitGFX
'......
So i would define a new color variable in "sGUI.bas" at row 73 or 74, "RBDotColor"(nice name for that?)
Changes in"sGUI_Drawing.bas"
"InitGFX" should contain a default value for RBDotColor
"Dot" should work like your modification, with RBDotColor

Dont understand your last question...
If you take a look inside the code of xSleep you will find the routine GadgetControl.
This routine combines the SystemEvents with the Controls and "built" a GadgetEvent.
The GadgetEvents are:
GADGET_HIT=1 'LMB HITs a control successfully (start of the "click sequence", very weird !)
GADGET_HOLD=2 'LMB HOLD over control
GADGET_HOLDOFF=3 'LMB HOLD but not over control
GADGET_RELEASE=4 'LMB RELEASE over control
GADGET_RELEASEOFF=5 'LMB RELEASE but not over control
GADGET_MOUSEOVER=6 'not in use
GADGET_MOUSENEXT=7 'not in use
GADGET_KEYBOARD=8 'a control "receive keyboard signals"
GADGET_KEYBOARDOFF=9 'stop keyboard "receiving"
GADGET_WHEELMOVE=10 'mouse wheel was moved

You see, very limited actions a sGUI control can react :/
But dont forget: sGUI is not runing in an extra thread. All that visual stuff and
all internals calculation a happend at last when calling xSLeep!
The main goal was to return back in the mainloop as fast as possible.

Mutton
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

@ keybord control
a) presently not needed complete key-control for all gadgets.Only two main for now&my purpose.
1- Emergency exit from event-loop if mouse kaput.
2- Closing Messageboxes speedily, if in event-loop control via keyboard.

b) xSleep is clear, I use very similar routine in my apps.
GadgetControl is unknown - what, when, why calls it ? (examples ?)
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

I made my first dynamic widget with sGUI, for real use.

Image

Founded a few new questions.
- missing any QuickStart helpfile (already a simple TXT file is really helpfull).
Coder doesn't know some things about routines - what is what&where, t.m. which routines are internal by sGUI calling itself, and which ones are for gadgets creation.
Seems, they are all routines in "sGUI.bas", "ToGadgetBindings.bas" and all 'Add..somename'+'Update..somename' in all other files.

1/ Where is located/explained creation of string 't' - ToAppendLine (gad,t)?
I see three parts - ITM:/LBL: + some number + visible printed name of item.
? "LBL:Label 1" ? LBL: is not printed
? "ITM:003:Item 3" ? ITM:003: is not printed
First and third is clear I think, but what represents a number on second position in string 't' ?
2/ Howto set label color - ToAppendLine (...)?
3/ Howto set background color for radiobutton gadget?
4/ Where is AddSeparator function/example ?; in which gadgets can be used ?
5/ If (e.g.) four radiobuttons in cascade hooked (ball,cube,cone,cylinder), is here some function to get number/position in cascade of pressed/selected radiobutton ?
Nothing such placed in "Radiobutton.bas", searched somelike as 'GetRBlistOfset(radioa,radiod)'.

#1/ Fixed in QuickReference, thx
#3/ Solved
#4/ Solved Line separator.
Last edited by petan on Oct 10, 2014 6:10, edited 2 times in total.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

"QuickStart.txt" .e.g.

Code: Select all

   List of commands sGUI:
Everything in "sGUI.bas" and "ToGadgetBindings.bas"
'   Listbox - "listbox.bas"
- AddListBox ()
?? - ListActions ()
?? - DrawList ()
- UpdateLB ()

'   Combobox - "combobox.bas"
- AddComboBox
?? - ComboBoxActions
?? - DrawComboBox
?? - SetComboBoxVal
- GetComboBoxVal

'	BMPSimpleGadget - "BMPSimpleGadget.bas"
- AddBMPSimpleGadget
?? - BMPSGActions
?? - DrawBMPSimpleGadget

'   Menu
...
' 	RadioButton
...
... etc.
'
Hints/Warnings:
 Place nothing after 'delete events'.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

"RBDotColor"(nice name for that?)
a bit evocating some "RGB..." command
'rbDotColor' or 'DotColorRB' maybe better ?,
in case of 'Dot' routine is used only for radiobutton gadget..
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

"mouseKey_test.bas"
very simple mouse+key events..

Code: Select all

#include "sGUI\sGUI.bas"
using sGUI
'user's color
const cBlack=rgb(0,0,0)		
const cRed=rgb(255,0,0)
const cGold=rgb(128,128,0)	

screen 17,32,3,&H04		'more videopages
InitGFX

screenset 0,0
color cGold,cBlack
cls

dim as EventHandle ptr event=new EventHandle
?:? " Mouse or Key ... move on window / press/hold some btn."
?:?:? "..just  simple test of mouse key status."
windowtitle " Mouse + Key event checking  ' q >> Quit '"
color cRed
?:? ,"press 'q' to quit.."
color cGold
do
  event->xSleep(1)
  ? "(X,Y) ";:? using "#### ### ";MOUSEX;MOUSEY
  if LMB then ? "LEFT maus pressed. "
  if RMB then ? "RIGHT maus pressed."
  if LMB and RMB then ? "BOTH maus pressed.  "  
    if KEY<>"" then	'key pressed
    ? "key pressed..",
	? "KEY & ASCCODE=";KEY,ASCCODE
   if KEY="q" then ?:?:? "Quit..":event->EXITEVENT=1
  end if
loop until event->EXITEVENT
delete event
?:? "is out.. Ending"
sleep 1500		'wait 1.5sec
end
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Howto add Separator.

Simply placed behind gadget's activation

Code: Select all

...
GadgetOn (okay,textbox)					'e.g.
Separator (gX+20,gY+2+list->gadh,150)	'e.g.
...
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

sGUI 'ToggleGadget' incorporated into my small app, I found one feature, which is invisible in "Demo_Activationtest.bas".
Creating one field/block of more 'ToggleGadgets' & founded there hidden default 'Centered' printing style.
It would be better to making visible this feature ("Demo_Activationtest.bas" example) by adding a code:

Code: Select all

...
dim as Gadget ptr optas3(1 to 3)		'new line
okay    =AddSimpleGadget(event,20,30,80,20,"Okay")			'orig
opta    =AddToggleGadget(event,20,60,70,20,1,"Option A")	'orig
checker =AddCheckMarkGadget(event,20,90,1,"Option")			'orig
'new 3 lines
optas3(1)=AddToggleGadget(event,20,450,170,20,0,"Choice A")
optas3(2)=AddToggleGadget(event,20,470,170,20,1,"The best choice of the day..")
optas3(3)=AddToggleGadget(event,20,490,170,20,1,"Bad choice")
I see this can be easily enhanced by adding a flag+code in 'DrawToggleGadget' routine.

Code: Select all

'Old
sub DrawToggleGadget (gad as Gadget ptr)
'NEw
sub DrawToggleGadget (gad as Gadget ptr,printStyleFlag as string)
rem simple flags "R-C-L" enough ?
...
if printStyleFlag='Centered' then
	'rounding to center
if printStyleFlag='Lefty' then
	'rounding to left side
if printStyleFlag='Righty' then
	'rounding to right side	
	...
Last edited by petan on Oct 06, 2014 12:24, edited 1 time in total.
Muttonhead
Posts: 143
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

its not recommended to change the count of parameters of DrawToggleGadget.
Take a look at the UTD Gadget in "sGUI_GadgetType.bas"
You will find a static integer array Ctrl(). Here you can place any stuff.

Modify the AddToggleGadget() routine:
*add a new parameter for your flag
*if Ctrl(1) not in use, save it in Ctrl(1)

Modify the DrawToggleGadget() routine
*via gad->Ctrl(1) you have access to your flag

Mutton
Muttonhead
Posts: 143
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

need help :)
I've "translated" my short reference of sGUI.
I think its an accident!!!
Id would be nice a native english speaker can take a look at it

Mutton
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Perfect !
Founded, thinked, tuned UDT Gadget (detailed parameters of pointed gadget).
Ctrl(15) ( as integer variable ) doesn't satisfies me, as I want to pass clear/readable/understanding string parameter "L-R-C" or "Left-Right-Center".
Due printing text in various gadgets ( where printing style can be needed to set ) I see two ways to fix it.
Common is adding new parameter to UDT Gadget 'gadPS as string*1 'text PrintStyle - rounding on - Left,Right,Center'
and tuning 'DrawToggleGadget' routine:

Code: Select all

sub DrawToggleGadget (gad as Gadget ptr)
	dim as integer PosX,PosY,GadWidth,GadHeight
	dim as integer sideWalk			'new
  dim as string txtu,txts
  dim as string GadPrintStyle		'new
  PosX   =gad->PosX
	PosY   =gad->posy
	GadWidth		=gad->gadw
	GadHeight		=gad->gadh  
    GadPrintstyle=gad->gadPS		'new
  screenlock
    if gad->act=0 then
'OFF
      put(PosX,PosY),gad->Background,pset
    else
'ON   unselect/select
      FrameB PosX, PosY, GadWidth, GadHeight,gad->sel
      FillA PosX+1,PosY+1,GadWidth-2,GadHeight-2,GadgetColor,gad->sel
   'new
			if GadPrintstyle="L" then 			
				sideWalk=3
'			elseif GadPrintstyle="R" then 						
'				sideWalk=-10	'set formula later
			else  ' "C", default or another/wrong parameter passed >> centering text
				sideWalk=(GadWidth-len(gad->caption)*8)/2
			end if				      
      if gad->sel then'unselect/select Caption
'old
'        draw string ( PosX+(GadWidth-len(gad->caption)*8)/2 +1, PosY+(GadHeight-fontheight)/2+1 ),gad->caption,GadgetTextColor
'        draw string ( PosX+(GadWidth-len(gad->caption)*8)/2 , PosY+(GadHeight-fontheight)/2 ),gad->caption,white
  'new
        draw string ( PosX+sideWalk+1, PosY+(GadHeight-fontheight)/2+1 ),gad->caption,GadgetTextColor
        draw string ( PosX+sideWalk, PosY+(GadHeight-fontheight)/2 ),gad->caption,white			
      else
'old
'        draw string ( PosX+(GadWidth-len(gad->caption)*8)/2 , PosY+(GadHeight-fontheight)/2 ),gad->caption,GadgetTextColor
  'new
        draw string ( PosX+sideWalk, PosY+(GadHeight-fontheight)/2 ),gad->caption,GadgetTextColor      
      end if         
'SLEEP
      if gad->act=2 then put(PosX,PosY),gad->Background,alpha,SleepShade
    end if
  screenunlock  
end sub
1/ adding global variable 'static shared as string*1 RLCprintStyle ' in "sGUI.bas"
This variable is then able to set print style to every (text) gadget,( including new gadgets added in the future ).
Passing it to gadget parameters .e.g. this way:

Code: Select all

...
RLCprintstyle="L"	'if style omitted - default 'Centered' style used
optas3(1)=AddToggleGadget(event,20,480,170,20,0,"Choice A")
rem AddToggleGadget must delete RLCprintStyle to empty string before its End >> 1 new line 
rem RLCprintstyle=""
rem End function
...
2/ adding new parameter into the Add.. routine.
This way I made it in 'AddToggleGadget' routine.

Code: Select all

'new parameter 'RLCprintStyle' in header and 1 new line in the body

function AddToggleGadget (event as EventHandle ptr,PosX as integer,PosY as integer,GadWidth as integer,GadHeight as integer,s as integer,txt as string,RLCprintStyle as string) as Gadget ptr
  function=0
  dim as Gadget ptr gad
  gad=event->GadgetList->AppendNew (GadgetType)
  if gad then
    gad->event=event
  	gad->sel=s
    gad->act=0
    gad->PosX=PosX
    gad->posy=PosY
    gad->gadw=GadWidth
    gad->gadh=GadHeight
	gad->gadPS=RLCprintStyle	'new

    gad->caption=txt

    gad->DoDraw     =@DrawToggleGadget
    gad->DoAction   =@ToggleGadgetActions
    gad->DoUpdate   =@DrawToggleGadget

		gad->SaveBackGround
		function=gad
  end if
end function
and using in code can looks like

Code: Select all

...
optas3(1)=AddToggleGadget(event,20,480,170,20,0,"Choice A","L")
optas3(2)=AddToggleGadget(event,20,500,170,20,1,"The best choice of the day..","C")
optas3(3)=AddToggleGadget(event,20,520,170,20,1,"Bad choice","")
...
And result ? Perfect !!!
( See on actualised screenshot of sGUI flagship demoexample..bottom of previous page. )
Thanks for pointing me, Muttonhead !
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Muttonhead wrote:need help :)
I've "translated" my short reference of sGUI.
I think its an accident!!!
Id would be nice a native english speaker can take a look at it

Mutton
What for a problem are you seeing with docs ?? Show it somewhere, we 'll edit potential mistakes in the text.
( I am not native speaker, but if I'll understand docs, then no problem, IMHO ).
Muttonhead
Posts: 143
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

Last edited by Muttonhead on Oct 08, 2014 15:33, edited 2 times in total.
Post Reply