Post by n00b on Apr 17, 2018 11:35:30 GMT -6
This is the GUI library I wrote for building tools for my current game. It is not really meant to be a feature complete library as I only added stuff that I needed. Please feel free to use and modify it to fit your needs if you wish.
Gui Library: rc_gui.zip (423.35 KB)
And here is the demo I included in the download just to show what the code looks like:
Gui Library: rc_gui.zip (423.35 KB)
And here is the demo I included in the download just to show what the code looks like:
Include "gui.bas" 'include the gui library
Gui_Init 'initialize the library
Gui_WindowOpen("Test Gui", WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, 640, 480) 'open a window
B = Gui_CreateButton("Test Button", 100, 20) 'Create a button
B2 = Gui_CreateButton("Test Button 2", 100, 20)
txt_field = Gui_CreateTextField(150, 20) 'Create a text field
d = Gui_CreateDropDown(100, 20) 'Create a dropdown selection
d_item1 = Gui_DropDown_AddItem(d, "item 1") 'Add an item to the dropdown selection
d_item2 = Gui_DropDown_AddItem(d, "item 2")
d_item3 = Gui_DropDown_AddItem(d, "item 3")
d_item4 = Gui_DropDown_AddItem(d, "item 4")
d_item5 = Gui_DropDown_AddItem(d, "item 5")
lbox = Gui_CreateListBox(100, 60) 'Create a listbox
lbox_item1 = Gui_ListBox_AddItem(lbox, "First") 'Add an item to the listbox
lbox_item2 = Gui_ListBox_AddItem(lbox, "item 2")
lbox_item3 = Gui_ListBox_AddItem(lbox, "item 3")
lbox_item4 = Gui_ListBox_AddItem(lbox, "item 4")
lbox_item5 = Gui_ListBox_AddItem(lbox, "item 5")
lbox_item6 = Gui_ListBox_AddItem(lbox, "item 6")
lbox_item7 = Gui_ListBox_AddItem(lbox, "item 7")
lbox_item8 = Gui_ListBox_AddItem(lbox, "item 8")
lbox_item9 = Gui_ListBox_AddItem(lbox, "item 9")
lbox_item10 = Gui_ListBox_AddItem(lbox, "item 10")
lbox_item11 = Gui_ListBox_AddItem(lbox, "item 11")
lbox_item12 = Gui_ListBox_AddItem(lbox, "Last")
cb = Gui_CreateCheckBox(20, 20) 'Create a checkbox
label = Gui_CreateLabel("test label", 40, 15) 'Create a label
p = Gui_CreatePanel(300, 300) 'Create a panel
Gui_Panel_AddObject(p, d, 20, 60) 'add an item to a panel: first argument is the panel, second item is the item to add, last 2 items is the (x,y) position
'in the panel to place the object
Gui_Panel_AddObject(p, b, 20, 20)
Gui_Panel_AddObject(p, cb, 20, 120)
Gui_Panel_AddObject(p, label, 50, 120)
Gui_Window_AddPanel(0, p, 150, 50) 'add a panel to the window: first argument is the window, second argument is the panel, and last 2 arguments is the (x,y) position
'in the window to place the panel
p2 = Gui_CreatePanel(300, 400)
Gui_Panel_AddObject(p2, b2, 50, 50)
Gui_Panel_AddObject(p2, lbox, 50, 150)
Gui_Panel_AddObject(p2, txt_field, 50, 250)
Gui_Window_AddPanel(0, p2, 0, 0)
t = Gui_CreateTabGroup(300, 20) 'Create a group of tabs
tab1 = Gui_TabGroup_AddTab(t, "item 0") 'Add a tab to the tab group
tab2 = Gui_TabGroup_AddTab(t, "item 1")
tab3 = Gui_TabGroup_AddTab(t, "item 2")
t2 = Gui_CreateTabGroup(300, 20)
tab2_1 = Gui_TabGroup_AddTab(t2, "item 10")
tab2_2 = Gui_TabGroup_AddTab(t2, "item 11")
tab2_3 = Gui_TabGroup_AddTab(t2, "item 21")
Gui_Window_AddTabGroup(0, t2, 20, 400) 'Add a tab group to the window
'Note: Tab groups and panels are the only items that must be added directly to the window
Gui_TabGroup_Tab_AddObject(t, tab2, p) 'Add an object (panel or tab) to a tab of a tab group:
'first argument is the tab group, second argument is the tab in the group, and third argument is the object (panel or tab) to add
Gui_TabGroup_Tab_AddObject(t, tab1, t2)
Gui_TabGroup_Tab_AddObject(t2, tab2_1, p2)
Gui_Window_AddTabGroup(0, t, 20, 20)
redthing = Gui_LoadImage(Dir + "/gfx/redthing.png") 'Load an image
ic = Gui_CreateImageClip(redthing, 32, 32, 64, 64) 'Create an image clip
Gui_Panel_AddObject(p2, ic, 0, 100)
slide = Gui_CreateImageSlide(96, 32, 32, 32) 'create a sliding box of image clips
Gui_ImageSlide_AddImageClip(slide, ic) 'add an image clip to a slide
Gui_ImageSlide_AddImageClip(slide, ic)
Gui_Panel_AddObject(p2, slide, 10, 350)
surface = Gui_CreateSurface(200, 200) 'Create a Drawing surface
p3 = Gui_CreatePanel(300, 300)
Gui_Panel_AddObject(p3, surface, 10, 10)
Gui_Window_AddPanel(0, p3, 130, 70)
Gui_TabGroup_Tab_AddObject(t, tab3, p3)
Print "Press 3 to draw image on surface"
While Not Key(K_Q)
'Checking for various events
If Gui_Button_Clicked(b) Then
SetColor(RGB(255,255,255))
PrintS(Gui_TextField_GetValue$(txt_field))
ElseIf Gui_Button_Clicked(b2) Then
SetColor(RGB(255,255,255))
Gui_ImageSlide_MoveOffset(slide, 5, 0)
PrintS(Gui_ListBox_GetValue$(lbox, 11))
ElseIf Key(K_1) Then
Gui_TextField_SetValue(txt_field, "this is war")
ElseIf Key(K_2) Then
'Gui_SetPanelActive(p, true)
ElseIf Key(K_3) Then
Gui_Surface_DrawImage(surface, redthing, 20, 20)
Gui_Surface_Update(surface)
ElseIf Gui_CheckBox_ValueChanged(cb) Then
Print Gui_CheckBox_GetValue(cb)
ElseIf Gui_Surface_Down(surface) Then
mx = 0
my = 0
Gui_Surface_GetMouse(surface, mx, my)
Print "Surface Pos: "; mx; ", ";my
End If
Gui_Update() 'update must be called at the end of the main loop
Wend