Here is my first try at a String input gadet, it works but it could be a bit better.
Code: Select all
@VERSION 6,0
@APPTITLE "Gadgets"
@APPVERSION "$VER: 1.0 (04.07.15)"
@APPCOPYRIGHT "©2015, George Leo den Hollander"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "Simple Gadgets"
@DISPLAY 1, {Width=400,Height=320,Color=#gray,Title=" Gadgets by Leo den Hollander"}
; Setup tables
GadgetText = {}
GadgetState = {}
GadgetFColor = {}
GadgetBColor = {}
GadgetFont = {}
GadgetFontSize = {}
; Setup Globals
global Gadget
global Gadgetx
global Gadgety
global Gadgetw
global Gadgeth
Function GadgetButton(ID,x,y,w,h,Text$,BC,FC)
SetFillStyle(#FILLGradient,#Linear,#Silver,RGB(64,64,64),12)
Box(x, y, w, h, #GRAY)
SetFillStyle(#FILLCOLOR)
Box(x+2, y+2, w-4, h-4, BC)
SetFont("DejaVu Sans",18)
TW = Textwidth(Text$)
t =(w/2)-(tw/2)
SetFontColor(FC)
Textout(x+t,y+3,Text$)
MakeButton(ID, #SIMPLEBUTTON, x+2, y+2, w-4, h-4, Events)
GadgetFColor[ID] = FC
GadgetBColor[ID] = BC
EndFunction
Function GadgetLabel(ID,x,y,w,h,Text$,BC,FC)
Setlinewidth(1)
SetFillStyle(#FILLGradient,#Linear,RGB(96,96,96),#Silver,27)
Box(x, y, w, h, #Gray)
SetFillStyle(#FILLCOLOR)
Box(x+2, y+2, w-4, h-4, BC)
Line(x+1, y+1, x+w-2, y+1, #Black)
Line(x+1, y+1, x+1, y+h-2, #Black)
Line(x+1, y+h-2, x+w-2, y+h-2, #White)
Line(x+w-2, y+1,x+w-2,y+h-2, #White)
SetFont("DejaVu Sans",18)
SetFontColor(FC)
Textout(x+4,y+3,Text$)
GadgetFColor[ID] = FC
GadgetBColor[ID] = BC
EndFunction
Function GadgetCheck(ID,x,y,Text$,BC,FC)
Setlinewidth(1)
SetFillStyle(#FILLGradient,#Linear,RGB(96,96,96),#Silver,27)
Box(x, y, 25,25, #Gray)
SetFillStyle(#FILLCOLOR)
Box(x+2, y+2, 21, 21, BC)
Line(x+1, y+1, x+23, y+1, #Black)
Line(x+1, y+1, x+1, y+23, #Black)
Line(x+1, y+23, x+23, y+23, #White)
Line(x+23, y+1,x+23,y+23, #White)
SetFont("DejaVu Sans",18)
SetFontColor(FC)
Textout(x+30,y+3,Text$)
MakeButton(ID, #SIMPLEBUTTON, x+2, y+2, 21, 21, Events)
GadgetState[ID] = 0
GadgetFColor[ID] = FC
GadgetBColor[ID] = BC
EndFunction
Function GadgetOption(ID,x,y,Text$,BC,FC)
Setformstyle(#ANTIALIAS)
SetFillStyle(#FILLGradient,#Linear,#white,#Black,45)
Circle(x,y,12,#White)
SetFillStyle(#FILLCOLOR)
Circle(x+2,y+2,10,#Silver)
SetFillStyle(#FILLNONE)
Setlinewidth(2)
Circle(x+4,y+4,8,#Gray)
Textout(x+30,y+3,Text$)
Setformstyle(#Normal)
MakeButton(ID, #SIMPLEBUTTON, x+2, y+2, 21, 21, options)
GadgetState[ID] = 0
GadgetFColor[ID] = FC
GadgetBColor[ID] = BC
EndFunction
Function GadgetString(ID,x,y,w,h,Text$,BC,FC)
Setlinewidth(1)
SetFillStyle(#FILLGradient,#Linear,RGB(96,96,96),#Silver,27)
Box(x, y, w, h, #Gray)
SetFillStyle(#FILLCOLOR)
Box(x+2, y+2, w-4, h-4, BC)
Line(x+1, y+1, x+w-2, y+1, #Black)
Line(x+1, y+1, x+1, y+h-2, #Black)
Line(x+1, y+h-2, x+w-2, y+h-2, #White)
Line(x+w-2, y+1,x+w-2,y+h-2, #White)
SetFont("DejaVu Sans",18)
GadgetFont[ID] = "DejaVu Sans"
GadgetFontSize[ID] = 18
SetFontColor(FC)
GadgetText[ID] = Text$
GadgetFColor[ID] = FC
GadgetBColor[ID] = BC
Textout(x+4,y+3,GadgetText[ID],GadgetFColor[ID])
MakeButton(ID, #SIMPLEBUTTON, x+2, y+2, w-4, h-4, Events)
EndFunction
Function GadgetButtonImage(ID,x,y,w,h,Text$)
SetFillStyle(#FILLGradient,#Linear,#Silver,RGB(64,64,64),12)
Box(x, y, w, h, #GRAY)
SetFillStyle(#FILLCOLOR)
Box(x+2, y+2, w-4, h-4,#Silver)
LoadBrush(ID,Text$)
DisplayBrush(ID,x+2, y+2, {width = w-4, height = h-4})
MakeButton(ID, #SIMPLEBUTTON, x+2, y+2, w-4, h-4, Events)
EndFunction
Function p_EventGad(msg)
Switch msg.action
Case "OnMouseDown":
Setlinewidth(1)
SetFillStyle(#FILLNONE)
Gadget = (msg.id)
Gadgetx = msg.x
Gadgety = msg.y
Gadgetw = msg.width
Gadgeth = msg.height
Box(msg.x, msg.y, msg.width, msg.height, #Teal)
p_SetCheck(Gadget)
Case "OnMouseOut":
Setlinewidth(1)
SetFillStyle(#FILLNONE)
Box(msg.x, msg.y, msg.width, msg.height, #Silver)
Case "OnMouseUp":
Setlinewidth(1)
SetFillStyle(#FILLNONE)
Box(msg.x, msg.y, msg.width, msg.height, #Silver)
Case "OnMouseOver":
Setlinewidth(1)
SetFillStyle(#FILLNONE)
Box(msg.x, msg.y, msg.width, msg.height,#Gray)
endswitch
EndFunction
Function p_StringText(msg)
Switch Gadget
Case 9
Key$ = (msg.key)
if (msg.key) = "BACKSPACE"
GadgetText[Gadget] = leftstr(GadgetText[Gadget],strlen(GadgetText[Gadget])-1)
elseif (msg.key) = "DEL"
GadgetText[Gadget] = ""
Key$ = ""
else
if TextWidth(GadgetText[Gadget]) < Gadgetw-10
GadgetText[Gadget] = GadgetText[Gadget] .. Key$
endif
endif
SetFillStyle(#FILLCOLOR)
SetFontColor(GadgetFColor[Gadget])
Box(Gadgetx+1, Gadgety+1,Gadgetw-2, Gadgeth-2, GadgetBColor[Gadget])
SetFont(GadgetFont[Gadget],GadgetFontSize[Gadget])
Textout(Gadgetx+2,Gadgety,GadgetText[Gadget])
Case 10
Key$ = (msg.key)
if (msg.key) = "BACKSPACE"
GadgetText[Gadget] = leftstr(GadgetText[Gadget],strlen(GadgetText[Gadget])-1)
elseif (msg.key) = "DEL"
GadgetText[Gadget] = ""
Key$ = ""
else
if TextWidth(GadgetText[Gadget]) < Gadgetw-10
GadgetText[Gadget] = GadgetText[Gadget] .. Key$
endif
endif
SetFillStyle(#FILLCOLOR)
SetFontColor(GadgetFColor[Gadget])
Box(Gadgetx+1, Gadgety+1,Gadgetw-2, Gadgeth-2, GadgetBColor[Gadget])
SetFont(GadgetFont[Gadget],GadgetFontSize[Gadget])
Textout(Gadgetx+2,Gadgety,GadgetText[Gadget])
Case 11
Key$ = (msg.key)
if (msg.key) = "BACKSPACE"
GadgetText[Gadget] = leftstr(GadgetText[Gadget],strlen(GadgetText[Gadget])-1)
elseif (msg.key) = "DEL"
GadgetText[Gadget] = ""
Key$ = ""
else
if TextWidth(GadgetText[Gadget]) < Gadgetw-10
GadgetText[Gadget] = GadgetText[Gadget] .. Key$
endif
endif
SetFillStyle(#FILLCOLOR)
SetFontColor(GadgetFColor[Gadget])
Box(Gadgetx+1, Gadgety+1,Gadgetw-2, Gadgeth-2, GadgetBColor[Gadget])
SetFont(GadgetFont[Gadget],GadgetFontSize[Gadget])
Textout(Gadgetx+2,Gadgety,GadgetText[Gadget])
Endswitch
EndFunction
Function p_Eventopt(msg)
Setformstyle(#ANTIALIAS)
Switch msg.action
Case "OnMouseOut":
Setlinewidth(2)
SetFillStyle(#FILLNONE)
Circle(msg.x+1,msg.y+1,8,#Gray)
Case "OnMouseOver":
Setlinewidth(2)
SetFillStyle(#FILLNONE)
Circle(msg.x+1,msg.y+1,8,#Silver)
Case "OnMouseDown":
Setlinewidth(2)
SetFillStyle(#FILLNONE)
Circle(msg.x+1,msg.y+1,8,#Teal)
Gadget = (msg.id)
Gadgetx = msg.x
Gadgety = msg.y
p_SetCheck(Gadget)
Case "OnMouseUp":
Setlinewidth(2)
SetFillStyle(#FILLNONE)
Circle(msg.x+1,msg.y+1,8,#Silver)
EndSwitch
Setformstyle(#Normal)
EndFunction
Function p_SetCheck(Gadget)
SetFontColor(#GREEN)
SetFillStyle(#FILLCOLOR)
Switch Gadget
Case 5
Box(Gadgetx+1, Gadgety+1,Gadgetw-2, Gadgeth-2, #Silver)
SetFont("DejaVu Sans Bold",20)
if GadgetState[Gadget] = 0
Textout(Gadgetx+4,Gadgety+1,"X")
GadgetState[Gadget] = 1
else
Textout(Gadgetx+4,Gadgety+1," ")
GadgetState[Gadget] = 0
endif
Case 6
Box(Gadgetx+1, Gadgety+1,Gadgetw-2, Gadgeth-2, #Silver)
SetFont("DejaVu Sans Bold",20)
if GadgetState[Gadget] = 0
Textout(Gadgetx+4,Gadgety+1,"X")
GadgetState[Gadget] = 1
else
Textout(Gadgetx+4,Gadgety+12," ")
GadgetState[Gadget] = 0
endif
Case 7
if GadgetState[Gadget] = 0
Circle(Gadgetx+4,Gadgety+4,6,#Green)
GadgetState[Gadget] = 1
else
Circle(Gadgetx+4,Gadgety+4,6,#Silver)
GadgetState[Gadget] = 0
endif
Case 8
if GadgetState[Gadget] = 0
Circle(Gadgetx+4,Gadgety+4,6,#Green)
GadgetState[Gadget] = 1
else
Circle(Gadgetx+4,Gadgety+4,6,#Silver)
GadgetState[Gadget] = 0
endif
EndSwitch
Endfunction
eventstring={OnKeyUp = p_StringText}
events = {OnMouseOver = p_EventGad, OnMouseOut = p_EventGad, OnMouseDown = p_EventGad, OnMouseUp = p_EventGad}
options = {OnMouseOver = p_Eventopt, OnMouseOut = p_Eventopt, OnMouseDown = p_Eventopt,OnMouseUp = p_Eventopt}
InstallEventHandler(eventstring)
; Escape ******************************************************************************************
EscapeQuit(True)
GadgetButton(1,20, 30,100,25,"Button",#Silver,#Black)
GadgetButton(2,20, 60,100,25,"Button",#Silver,#Black)
GadgetLabel(3,20, 90,100,25,"Label",#Silver,#Black)
GadgetLabel(4,20,120,100,25,"Label",#Silver,#Black)
GadgetCheck(5,20,150,"Check",#Silver,#Black)
GadgetCheck(6,20,180,"Check",#Silver,#Black)
GadgetOption(7,20,210,"Option",#Silver,#Blue)
GadgetOption(8,20,240,"Option",#Silver,#Blue)
GadgetString(9,20,270,100,25,"Test1",#silver,#Black)
GadgetString(10,150,30,220,25,"",#silver,#Black)
GadgetString(11,150,60,100,25,"",#silver,#Black)
GadgetButtonImage(12,150,120,220,170,"Test.jpg")
; Main Program Loop *******************************************************************************
Repeat
WaitEvent
ForEver
I am sure it could be improved, I should be able to use the tables better.
Hope it helps someone else, if you improve it please post your improvements here.
Have fun.