Improved Simple Gadget Instructions

You can post your code snippets here for others to use and learn from

Improved Simple Gadget Instructions

Postby Redlion » Sat Sep 26, 2015 3:35 am

Hi All,

Here are the basic information and instructions for the Simple Gadgets.

First of all I have made it as includes so as to redue the size of programs if you do not needall the gadgets.

I made this as I was in need of some simple gadgets for a crossplatform project I have been working on, speed was not the
most important factor in this project, but on my Sam460 it seems very usable and on windows it is very fast.

You will have to include the G_Setup.hws and the three Event files, GadgetEvent.hw,s ButtonEvent.hws, and StringEvent.hws
and also the follow event setup in your program.

; Events ******************************************************************************************
Button = {OnMouseOver = p_EventButton, OnMouseOut = p_EventButton, OnMouseDown = p_EventButton, OnMouseUp = p_EventButton}
Gadget = {OnMouseOver = p_EventGadget, OnMouseOut = p_EventGadget, OnMouseDown = p_EventGadget, OnMouseUp = p_EventGadget}
eventstring = {OnKeyUp = p_StringText}

NOTE: Once you have setup all your gadgets, you will need to Dim the GadgetItem[][][] GadgetColumn[][]

Dim GadgetItem[43][10][60] ; Set to MaxGadgets+1 ( Gadget, Column,Row )
Dim GadgetColumn[43][10] ; Set to MaxGadgets+1 ( Gadget, column)

Inserting gadgets into your program.

Just use the @INCLUDE statement to add the files to your program, mack sure you place them before the Event section and any
of the gadget statements.

@INCLUDE "G_Setup.hws"
@INCLUDE "G_Label.hws"

The action function Function p_Actions(id)

This is the section that is used to respond to the gadget press for most of the gadgets ( Note: some gadget do not respond to
a press eg. Label and Frame gadgets ).

Gadget syntax
In general most of the gadget syntax is very simple

GadgetName(Gadget ID, gadget x pos, gadget y pos, gadget width, gadget height, gadget text, extra info)

Label Gadget
Used to display non editable text.

GadgetLabel(39,630,390,150, 25,"Gadget ID = ",2)
extra info is border style 0 = background same as Screen color
extra info is border style 1 = background set as GadgetBGcolor
extra info is border style 2 = background same as GadgetBGcolor with black single line outline

Does not respond to mouse press.

String Gadget

GadgetString(33,220,520,120, 25,"BLa Bla Bla")
Used to enter or display editable text
Input is limited to the size of the gadget. The | (pipe charactor is used as a sudo cursor).
If Text is too long to fit in the gadget it will be displayed with ... at the end but the gadget still retains the full text.

Frame Gadget

GadgetFrame(34,150,420,190,60,"Test Frame",1)
Used to display a border around an area of screen, gadget can be place inside a frame.
extra info is border style 0 = Single line
extra info is border style 1 = Double line

Does not respond to mouse press.

Color Selection Gadget

Used to select a color from the ColorTable setup in the G_Setup.hws file. ( These can be changed and more colors added
there will be a need to adjust the code a bit, maybe I will get to making it a little more flexible )
Shows your color selection in a box at the top right.

Check Gadget

GadgetCheck(12, 20,140,100,25,"Check A")
Use to make visible the gadget state Checked or Unchecked.
Gets the cross information from the table in the G_Setup.hws file

Spin Gadget

GadgetSpin(20, 150,220,150, 25,999,10000)
Use to display and adjust a couter, use the Up and Down arrows to move through the numbers.
No text entry for this gadget.
extra info Counter Start number
extra info Counter Stop number
On start up Counter Startup is displayed
Counter number is stored in GadgetState[Gadget ID]

Select Gadget

GadgetSelect(16, 20,300,170,25,"Select")
Used to cycle through a list, use the Down arrows to move through the list, once at the end of the list it will return to the beginning.
Use AddSelectRow to add new item to the list. ( adds to bottom of the list )
AddSelectRow(Gadget ID, Text to add)
AddSelectRow(16,"567 - Now this")
AddSelectRow(16,"345 - New number")
Selected Row is stored in GadgetItem[Gadget ID][SelColumn][GadgetState[Gadget ID]]

Slider Gadget

GadgetSlider(21,360,480,100, 25, 0, 20)
No text entry for this gadget.
extra info Slider Start number
extra info Slider Stop number
Slider number is stored in GadgetState[Gadget ID]

Option Gadget

GadgetOption(4, 150, 20, 80,25,"Opt 1-1",1)
Used to select one option only from list of options.
extra info Group that the Option gadget belongs to.
Selected Option has GadgetState[Gadget ID] set to 1 non selected set to 0

Table Gadget

GadgetTable(31,360, 20,420,350,"Col 1",80)
Used to display a table,
extra info column width
Add columns to an existing table
AddTableColumn(Gadget ID,"Column Name",column width)
AddTableColumn(31,"Col 2",80)
Add row of data to table
AddTableRow(Gadget ID,Row Text) each column text is seperated by | (pipe cahactor)
Chage Table Cell text.
ChangeTableCell(Gadget ID, text to insert, Column, Row)
ChangeTableCell(31,"Hello" ,2, 2)

SetGadgetText( 39, "Gadget ID = "..StrStr(id))
Used to change text for selected gadget.
SetGadgetText(Gadget ID, replacement text)

SetGadgetFColor(2, #WHITE)
Used to change text color for selected gadget.
SetGadgetFColor(Gadget ID, color)

SetGadgetBColor(3, #GREEN)
Used to change background color for selected gadget.
SetGadgetFColor(Gadget ID, color)

That it for now, I will add more later.

Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
User avatar
Posts: 62
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: Improved Simple Gadget Instructions

Postby airsoftsoftwair » Sat Sep 26, 2015 2:49 pm

Any screenshots what this GUI library looks like? :)
User avatar
Posts: 2025
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Return to Code snippets area

Who is online

Users browsing this forum: No registered users and 1 guest