Code: Select all
#include "sGUI\sGUI.bas"
#include once "sGUI\ComboBox.bas"
#include once "sGUI\SimpleGadget.bas"
#include once "sGUI\BMPSimpleGadget.bas"
#include once "sGUI\ToggleGadget.bas"
#include once "sGUI\CheckMarkGadget.bas"
#include once "sGUI\RadioButton.bas"
#include once "sGUI\StringGadget.bas"
#include once "sGUI\TrackBar.bas"
#include once "sGUI\ScrollBar.bas"
#include once "sGUI\Arrows.bas"
#include once "sGUI\ListBox.bas"
#include once "sGUI\MultiLineEditBox.bas"
#include once "sGUI\FileRequester.bas"
#include once "sGUI\Label.bas"
#include once "sGUI\Menu.bas"
using sGUI
'my colors
const cBlack=rgb(0,0,0)
const cGold=rgb(128,128,0)
const cRed=rgb(255,0,0)
const cGreen=rgb(0,255,0)
const cSilver=rgb(192,192,192)
declare sub dynaWiget()
declare sub wiget2()
'screen 19,32,3,&H04 'orig
'width 800\8,600\16 'orig
'screen 20,32,4,&H04 'my1
screenres 1000,752,32,3,&H04 'my2
width 1000\8,752\16
'screenres 1024,768,32,3,&H01 'my3 fullscreen
'width 1024\8,768\16
InitGFX
screenset 0,0
' BackGroundColor=cGold
'color TextColor,BackGroundColor
'cls
windowtitle "videopage 0 switched..."
? "dynamic & static demo... & two videopages"
bload "BMPs\stives.bmp",0
dim as EventHandle ptr event=new EventHandle
dim as Gadget ptr check,acton,actsleep,actoff
dim as single kolik
dim as string someText="3",someText2=""
acton =AddRadioButton(event,730,460,1,"On",0)
actsleep =AddRadioButton(event,730,480,0,"Sleep",acton)
actoff =AddRadioButton(event,730,500,0,"Off",acton)
check=AddCheckMarkGadget(event,730,440,1,"Menue")
GadgetOn(acton,check)
'? "GadgetOn(acton,check)...":sleep
'examples of all buttons
dim as Gadget ptr checkrs2(1 to 4),optas3(1 to 3),optas4(1 to 3)
dim as Gadget ptr okay,opta,checker,radioa,radiob,radioc,radiod
dim as Gadget ptr stringer,track,scroll
dim as Gadget ptr arrowl,arrowr,arrowu,arrowd,sarrowl,sarrowr,sarrowu,sarrowd
dim as Gadget ptr bmpplus,bmpminus,label,label2,label3,label4,bmpPMvalue
dim as Gadget ptr listbox,combobox,textbox
dim as Gadget ptr list2,separe
okay =AddSimpleGadget(event,20,30,130,20,"Dynamic")
opta =AddToggleGadget(event,20,60,70,20,1,"Option A","")
checker =AddCheckMarkGadget(event,20,90,1,"Option")
checkrs2(1)=AddCheckMarkGadget(event,210,240,1,"aaa")
checkrs2(2)=AddCheckMarkGadget(event,210,260,0,"bbb")
checkrs2(3)=AddCheckMarkGadget(event,210,280,0,"ccc")
checkrs2(4)=AddCheckMarkGadget(event,210,300,1,"ddd")
label3=AddLabel(event,20,450,"'Centered' print style",&HFFDD00)
optas3(1)=AddToggleGadget(event,20,480,170,20,0,"Choice A","")
optas3(2)=AddToggleGadget(event,20,500,170,20,1,"The best choice of the day..","")
optas3(3)=AddToggleGadget(event,20,520,170,20,1,"Bad choice","")
label4=AddLabel(event,260,450,"'Lefty' print style",&HFFDD00)
optas4(1)=AddToggleGadget(event,260,480,170,20,0,"Choice A","L")
optas4(2)=AddToggleGadget(event,260,500,170,20,1,"Better choice..","L")
optas4(3)=AddToggleGadget(event,260,520,170,20,1,"Bad choice","L")
radioa =AddRadioButton(event,20,110,0,"ball",0)
radiob =AddRadioButton(event,20,130,0,"cube",radioa)
radioc =AddRadioButton(event,20,150,1,"cone",radioa)
radiod =AddRadioButton(event,20,170,0,"cylinder",radioa)
stringer=AddStringGadget(event,20,190,10,"Text")
track =AddTrackBar(event,20,220,150,-5,2,1,0)
scroll =AddScrollBar(event,20,250,150,1,100,22,30,0)
arrowl =AddArrow(event,20,280,0)
arrowr =AddArrow(event,40,280,1)
arrowu =AddArrow(event,60,280,2)
arrowd =AddArrow(event,80,280,3)
sarrowl =AddSmallArrow(event,20,310,0)
sarrowr =AddSmallArrow(event,40,310,1)
sarrowu =AddSmallArrow(event,60,310,2)
sarrowd =AddSmallArrow(event,80,310,3)
bmpplus= AddBMPSimpleGadget(event,30,330,"BMPs\PlusUnSelected.bmp","BMPs\PlusSelected.bmp","BMPs\PlusMask.bmp")
bmpminus= AddBMPSimpleGadget(event,41,330,"BMPs\MinusUnSelected.bmp","BMPs\MinusSelected.bmp","BMPs\MinusMask.bmp")
bmpPMvalue=AddStringGadget(event,80,330,10,someText)
bmpPMvalue->caption=someText
label=AddLabel(event,10,360,"a clickable label",&HFFDD00)
listbox=AddListBox(event,530,25,10,10)
TO_LoadText(listbox,"Scrolltext.txt")
UpdateGadget(listbox)
combobox=AddComboBox(event,500,200,10,20) 'moved here to get continuous checkprint area
TO_LoadText(combobox,"Scrolltext.txt")
SetComboBoxVal(combobox,100)
UpdateGadget(combobox)
textbox=AddMultiLineEditBox(event,150,25,40,10,1)
TO_SetText(textbox,"Ein editierbarer mehrzeiliger Text|||und ja, es sind mehrere Zeilen","|")
UpdateGadget(textbox)
GadgetOn (okay,textbox)
'? "GadgetOn(okay,textbox)...":sleep
MenuOn(event) 'activated upper bar
menu (event,1,0,1,"Project")
menu (event,1,1,1,"Load")
menu (event,1,2,0,"Save")
menu (event,1,3,4,)
menu (event,1,4,3,"Option")
'menu (event,1,5,4,) 'orig
menu (event,1,5,4,"")
menu (event,1,6,1,"End")
'switch off activation messagebox
/'
GadgetSleep (acton,textbox)
MessageBox(200,300,"Activation Demo","!",MBType_OK)
RestoreActivation (acton,textbox)
'/
'MessageBox(200,200,"End Demo ???","Question",MBType_YESNO)
if MessageBox(200,300,"End Demo ???","Question",MBType_YESNO)=MBButton_YES then
'event->EXITEVENT=1
else
end if
' open console for output
dim as integer ff=freefile
open cons for output as ff
dim as integer menunum,itemnum
dim as string openfile
do
event->xSleep(1)
if KEY<>"" then 'my
if KEY="q" then exit do 'my
if ASCCODE=27 then
/'
'? "esc pressed.."
GadgetOff(label2,radiocH)
sleep
getkey
GadgetOn (label2,radiocH)
'/
end if
'if ASCCODE then ? tab(68);"pressed..";ASCCODE
end if
'check menu events
if event->MENUMESSAGE then
menunum=event->MENUNUMBER
itemnum=event->ITEMNUMBER
if menunum=1 then
'? tab(84);"menunum=1... itemnum= ";itemnum
select case itemnum
case 1
MenuOff(event)
GadgetOff (acton,textbox)
openfile=FileRequester(160,80,"Load",curdir,,1)
TO_LoadText(textbox,openfile)
UpdateGadget(textbox)
RestoreActivation (acton,textbox)
MenuOn (event)
case 4
if GetChecked(event,1,4) then
Menu (event,1,4,1,"Option")
else
Menu (event,1,4,3,"Option")
end if
case 6
'GadgetSleep (acton,textbox) 'orig - remmed
if MessageBox(200,200,"End Demo ???","Question",MBType_YESNO)=MBButton_YES then
event->EXITEVENT=1
else
'RestoreActivation (acton,textbox)
RestoreActivation (okay,textbox)
end if
end select
end if
end if
if event->GADGETMESSAGE then
select case event->GADGETMESSAGE
case acton
GadgetOn (okay,textbox)
'? tab(84);"case acton- GadgetOn (okay,textbox)"
case actsleep
GadgetSleep (okay,textbox)
'? tab(84);"case actSleep- GadSleep (okay,textbox)"
case actoff
GadgetOff (okay,textbox)
'? tab(84);"case actoff- GadgetOff (okay,textbox)"
case check
if GetSelect(check) then
MenuOn(event)
else
MenuOff(event)
end if
case okay
GadgetOff (okay,textbox)
dynaWiget()
GadgetOn (okay,textbox)
case bmpplus
bmpPMvalue->caption=str(val(bmpPMvalue->caption)+0.1)
kolik=val(bmpPMvalue->caption)
bmpPMvalue->caption=str(kolik)
SetString (bmpPMvalue,bmpPMvalue->caption)
UpdateGadget(bmpPMvalue)
' kolik=val(bmpPMvalue->caption)
locate 21,40:? using "###.#";kolik
someText2="second"
SetString (stringer,someText2)
UpdateGadget(stringer)
case bmpminus
bmpPMvalue->caption=str(val(bmpPMvalue->caption)-0.1)
kolik=val(bmpPMvalue->caption)
bmpPMvalue->caption=str(kolik)
SetString (bmpPMvalue,bmpPMvalue->caption)
UpdateGadget(bmpPMvalue)
' kolik=val(bmpPMvalue->caption)
locate 21,40:? using "###.#";kolik
someText2="third"
SetString (stringer,someText2)
UpdateGadget(stringer)
end select
end if
loop until event->EXITEVENT
? tab(84);"is out..."
MenuOff(event) 'works
GadgetOff (okay,textbox) 'works
delete event
sleep 2000
end
sub dynaWiget()
dim as EventHandle ptr event2=new EventHandle
dim as Gadget ptr radioaH,radiobH,radiocH,label2
dim as Gadget ptr button1,button2,button3
dim as integer pozX,pozY
pozX=20
'pozY=
/'
screenset 1,0
BackGroundColor=cGold
color TextColor,BackGroundColor
'color BackGroundColor
cls
'/
dotColor=cBlack
label2=AddLabel(event2,10,380,"a dynamic widget with custom Dot color added",rgb(192,192,192))
radioaH =AddRadioButton(event2,20,420,1,"Hori",0)
radiobH =AddRadioButton(event2,80,420,0,"zon",radioaH)
radiocH =AddRadioButton(event2,130,420,0,"tal radioButton",radioaH)
screenset 2,2
paint (100,100),cGreen
windowtitle "videopage 1 switched... press .. (H)elp"
?:? ,"dynamic widgets demo ..."
'line (10,415)-(280,440),cGold,BF
'line (10,415)-(280,440),cSilver,B
button1= AddToggleGadget(event2,pozX,50,150,20,0,"Hori","")
button2= AddToggleGadget(event2,pozX+button1->gadw,50,150,20,0,"zon","")
button3= AddToggleGadget(event2,pozX+button1->gadw+button2->gadw,50,150,20,0,"tal toggleButton","")
do
event2->xSleep(1)
if KEY="q" or ASCCODE=27 then event2->EXITEVENT=1
if KEY="h" then MessageBox(200,300,"ToggleRadiobuttons >> A|Radiobuttons >> B|Widget >> S|||Esc+q >> Quit|Right_MB >> Off","Videopage 1 - Help ... press btn.",MBType_OK)
if KEY="s" then wiget2()
if KEY="a" then
GadgetOn(button1,button3)
end if
if KEY="b" then
GadgetOn (radioaH,radiocH)
end if
' if RMB then GadgetOff(radioaH,button3)
if RMB then GadgetOff(button1,button3)
if event2->GADGETMESSAGE then
select case event2->GADGETMESSAGE
case button1
if GetSelect(button1) then '1
SetSelect(button2,0)
SetSelect(button3,0)
end if
case button2
if GetSelect(button2) then '1
SetSelect(button1,0)
SetSelect(button3,0)
end if
case button3
if GetSelect(button3) then '1
SetSelect(button1,0)
SetSelect(button2,0)
end if
end select
end if
loop until event2->EXITEVENT
event2->EXITEVENT=0
GadgetOff (radioaH,radiocH)
'GadgetOff (button1,button3)
delete event2
screenset 0,0
windowtitle "videopage 0 switched..."
dotColor=GadgetColor
end sub
sub wiget2()
dim as any ptr gfxbackup5
dim as integer y2,y1,x2,x1,gX,gY,ramikX,ramikY,widzetW,widzetH
dim as integer x,y,w,h
dim as EventHandle ptr event=new EventHandle
dim as Gadget ptr list2,label1,separe
dim as Gadget ptr radioa,radiob,radioc,radiod
gX=400
gY=200
list2=AddListBox(event,gX,gY,26,10,1)'<-!!!! mode 0=bisherige Darstellung, mode=1 Spielerei mit Label und Item
'TO_AppendLine(list2, " Aieee !, distro runs ? ")
TO_AppendLine(list2, "Dynamic widget, close it !")
TO_AppendLine(list2, "LBL:distros:")
TO_AppendLine(list2, "ITM:001:Danix")
TO_AppendLine(list2, "ITM:002: Knoppix 7")
TO_AppendLine(list2, "ITM:003: Slacko 533")
TO_AppendLine(list2, "ITM:004: Mint 9")
TO_AppendLine(list2, "ITM:005: Ultima 1")
TO_AppendLine(list2, "ITM:006: DSL 4.10")
TO_AppendLine(list2, "ITM:007:OpenSuSe 12")
UpdateGadget(list2)
screenset 1,0
paint (100,100),cGold
label1=AddLabel(event,gX+16,gY+5+list2->gadh,"terminal:",cSilver)
dotColor=cBlack
radioa=AddRadioButton(event,420,390,1,"none",0)
radiob=AddRadioButton(event,420,410,0,"xTerm",radioa)
radioc=AddRadioButton(event,420,430,0,"rxvt",radioa)
radiod=AddRadioButton(event,420,450,0,"urxvt",radioa)
'separe=AddSeparator(event,420,470,"Dole ??",cSilver,radiod->gadw)
separe=AddLabel(event,420,470,"Ready ??",cSilver)
screenset 2,2
/' 'old code
ramikX=20 'frame
ramikY=10
x1=gX-ramikX
y1=gY-ramikY
x2=gX+ramikX+list2->gadw
y2=separe->posy+separe->gadh+ramikY
'/
'NEW elegant way
ramikX=20 'frame
ramikY=10
CalcMinBBox (event,x,y,w,h)
x1=x-ramikX
y1=y-ramikY
x2=x+ramikX+w
y2=y+ramikY+h
'? "x1,x2 y1,y2";x1,x2,y1,y2
widzetW=x2-x1+1 'wiget size
widzetH=y2-y1+1
'? "widzetW x widzetH ";widzetW;"x";widzetH
gfxbackup5=imagecreate(widzetW,widzetH)
if gfxbackup5>0 then get (x1,y1)-(x2,y2),gfxbackup5
line (x1,y1)-(x2,y2),cGold,BF
line (x1,y1)-(x2,y2),cSilver,B
GadgetOn (list2,separe)
Separator (420+10+separe->gadw,470+10,x2-x1-separe->gadw-3*ramikX)
do
event->xSleep(1)
if KEY<>"" or RMB then event->EXITEVENT=1
if event->GADGETMESSAGE then
end if
loop until event->EXITEVENT
GadgetOff (list2,radiod)
'refresh
put (x1,y1),gfxbackup5,pset
imagedestroy gfxbackup5
delete event
end sub
Here is "Demo-activation2.bas" with gold dynamic widget and 3 videopages.
Trouble of dynamic widget creation is that I don't know size of all single gadgets sooner, prior using Add.. routine,
for drawing golden square widget background.
Only after that I can use Add... routines.So missing me group of routines like 'GetGadgetSize.Add...()' with the same header as 'Add...()' routine has.