Author Topic: GUI Functions[BB2D]  (Read 521 times)

0 Members and 1 Guest are viewing this topic.

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
GUI Functions[BB2D]
« on: January 06, 2007 »


Just incase any of you guys ever need a dropdown menu or scrollbar in Blitz youre welcome to use these functions I made  :)

Dropdown menu:
Code: [Select]
Graphics 1024, 768
SetBuffer BackBuffer()
;-----------------------------------------------------------------------------------------------------
;**********************!!! GLOBALS NEEDED IN PROGRAM !!! *********************************************
Global menuopen, listlength, x_select ;Menu variables
Global sublength, y_substart, parentnum ;Submenu variables
Global inputstring$ ;Selected action
Const  menu_fields = 10 ;Set array dimensions
Const  list_fields = 10
Const  sub_fields  = 10
Dim menus$(menu_fields, list_fields, sub_fields) ;Create the array
Global dropdown_font_1 = LoadFont(verdana ,16 , True, False,False) ;First font is for titles
Global dropdown_font_2 = LoadFont(verdana ,16 , False, False,False) ;Second font for list items
;*****************************************************************************************************
;-----------------------------------------------------------------------------------------------------

;DEMO STUFF
Global demofont = LoadFont(verdana ,30 , True, False,False)
inputstring$ = "Nothing yet"
;Declare Menu Titles
menus$(0,0,0) = "File"
menus$(1,0,0) = "Options"
menus$(2,0,0) = "Preferences"
menus$(3,0,0) = "Graphics"
menus$(4,0,0) = "Sound"
menus$(5,0,0) = "Controls"
menus$(8,0,0) = "Other Things"
;Name items on menu lists
menus$(0,1,0) = "New"
menus$(0,2,0) = "Save"
menus$(0,3,0) = "Save As"
menus$(0,4,0) = "Load"
menus$(0,5,0) = "Quit"

menus$(1,1,0) = "Option 1"
menus$(1,2,0) = "Option 2"
menus$(1,3,0) = "Option 3"
menus$(1,4,0) = "Option 4"
menus$(1,5,0) = "Option 5"
menus$(1,6,0) = "Option 6"
menus$(1,7,0) = "Option 7"
menus$(1,8,0) = "Option 8"
menus$(1,9,0) = "Option 9"

menus$(2,1,0) = "Preference 1"
menus$(2,2,0) = "Preference 2"

menus$(3,1,0) = "Nice"
menus$(3,2,0) = "Not So Nice"
menus$(3,3,0) = "Bad"

menus$(4,1,0) = "On"
menus$(4,2,0) = "Off"

menus$(5,1,0) = "Cofigure"

menus$(8,1,0) = "This Thing"
menus$(8,2,0) = "That Thing"
menus$(8,3,0) = "Something"
menus$(8,4,0) = "Nothing"
menus$(8,5,0) = "Everything"
;Name items in sub lists
menus$(0,1,1) = "Big Thing"
menus$(0,1,2) = "Medium Thing"
menus$(0,1,3) = "Small Thing"
menus$(0,1,4) = "Other Thing"

menus$(0,3,1) = "This"
menus$(0,3,2) = "That"
menus$(0,3,3) = "Whatever"

menus$(1,3,1) = "Woohoo"
menus$(1,3,2) = "Somethings"
menus$(1,3,3) = "Here"

menus$(1,8,1) = "Sub List 1"
menus$(1,8,2) = "Sub List 2"
menus$(1,8,3) = "Sub List 3"
menus$(1,8,4) = "Sub List 4"
menus$(1,8,5) = "Sub List 5"
;-------------------------------------------------------------------------------------------------------
;****************************** MAIN LOOP **************************************************************
;-------------------------------------------------------------------------------------------------------
While Not KeyHit(1)
Cls
DROPDOWNMENU(1024, 20)
Color 255, 255, 255: Rect MouseX(), MouseY(), 3, 3, 1
SetFont demofont: Color 100, 100, 100 :Text 330, 500, "You have selected: "+inputstring$
Flip
Wend

;-------------------------------------------------------------------------------------------------------
;****************************** FUNCTION ***************************************************************
;-------------------------------------------------------------------------------------------------------

;"BAR_WIDTH" SHOULD BE GRAPHICS X RESOLUTION UNLESS YOU WANT THE BAR TO ONLY SPAN PART OF THE SCREEN
;"BAR_HEIGHT" DETERMINES THE HEIGHT OF THE BAR, FONT SIZES SHOULD BE SET APPROPRIATELY
;THE BAR IS DIVIDED INTO AN AMOUNT OF FIELDS DETERMINED BY THE "MENU_FIELDS" CONSTANT
;THE MAXIMUM NUMBER OF ITEMS ON THE MENU LISTS IS THE "LIST_FIELDS" CONSTANT -1 FOR THE TITLE

Function DROPDOWNMENU(bar_width, bar_height)

field_width = bar_width / menu_fields
x_pos = x_select * field_width
list_height = listlength * bar_height

;Draw Menu Bar
Color 50,  50, 60   :Rect 0, 0, bar_width, bar_height, 1
Color 150, 150, 200 :Rect 0, 0, bar_width, bar_height, 0
;Draw menu bar titles
SetFont dropdown_font_1
Color 100, 100, 100
For i = 0 To 100
Text 6+(i*field_width), 2, menus$(i,0,0)
If i = menu_fields Then Exit
Next

;IF THE CURSOR IS OVER THE MENUBAR
If MouseY() < bar_height And MouseX() < bar_width
listlength = 0
x_select = (MouseX() / field_width)
If menus$(x_select, 0,0) <> ""
For i = 1 To 100
If menus$(x_select, i,0) <> "" Then listlength = listlength +1
If i = list_fields Then Exit
Next
x_pos = x_select * field_width
list_height = listlength * bar_height
Color 50, 50, 60 :Rect x_pos, bar_height-1, field_width, list_height+1
Color 150, 150, 200 :Rect x_pos, 0, field_width, bar_height+list_height, 0
Color 100, 100, 100
SetFont dropdown_font_2
For i = 1 To 100
Text x_pos+4, (i*bar_height), menus$(x_select, i, 0)
If menus$(x_select, i, 1) <> ""
SetFont dropdown_font_1
Text (x_pos+field_width-10), (i*bar_height), ">"
SetFont dropdown_font_2
EndIf
If i = list_fields Then Exit
Next
menuopen = 1
EndIf
;ELSE IF THE MENU IS OPENED AND CURSOR MOVED DOWN OVER THE LIST
Else If menuopen > 0 And MouseX() > x_pos And MouseX() < (x_pos+field_width) And MouseY() < (list_height+bar_height)
Color 50, 50, 60 :Rect x_pos, bar_height-1, field_width, list_height+1
Color 150, 150, 200 :Rect x_pos, 0, field_width, bar_height+list_height,0
Color 100, 100, 100
SetFont dropdown_font_2
For i = 1 To 100
Text x_pos+4, (i*bar_height), menus$(x_select, i, 0)
If menus$(x_select, i, 1) <> ""
SetFont dropdown_font_1
Text (x_pos+field_width-10), (i*bar_height), ">"
SetFont dropdown_font_2
EndIf
If i = list_fields Then Exit
Next
;HIGHLIGHT ITEM ON LIST THAT CURSOR IS OVER
y_select = (MouseY()/bar_height) :parentnum = y_select
Color 100, 100, 100 :Rect x_pos+1, (y_select*bar_height), field_width-2, bar_height-1
Color 50, 50, 60 :Text x_pos+4, (y_select*bar_height), menus$(x_select, y_select,0) 
;IF MOUSEHIT INPUT ACTION
If MouseHit(1) Then inputstring$ = menus$(x_select, y_select,0)
;IF THERE IS A SUB MENU UNDER SELECTED ENTRY THEN DISPLAY IT
If menus$(x_select, y_select, 1) <> ""
sublength = 0
For i = 1 To 100
If menus$(x_select, y_select, i) <> ""
sublength = sublength + 1
y_substart = ((y_select*bar_height)+(i*bar_height)-bar_height)
EndIf 
If i = sub_fields Then Exit
Next
y_substart = y_substart - (sublength*bar_height)+bar_height
Color 50, 50, 60 :Rect (x_pos+field_width), y_substart, field_width, (sublength*bar_height)
Color 150, 150, 200 :Rect (x_pos+field_width), y_substart, field_width, (sublength*bar_height),0
Color 50, 50, 60 :Rect (x_pos+field_width)-1, y_substart+1, 2, bar_height-2
Color 100, 100, 100
For i = 1 To 100
If menus$(x_select, y_select, i) <> ""
Text (x_pos+field_width+4), (y_substart+(i*bar_height)-bar_height), menus$(x_select, y_select, i)
EndIf
If i = sub_fields Then Exit
Next 
menuopen = 2
Else
menuopen = 1
EndIf
;ELSE IF MENU OPEN AND CURSOR IS OVER A SUB LIST
Else If menuopen=2 And MouseX()>=(x_pos+field_width-1) And MouseX()<(x_pos+(field_width*2)) And MouseY() > y_substart And MouseY() < (y_substart+(sublength*bar_height))
;DRAW PARENT LIST
Color 50, 50, 60 :Rect x_pos, bar_height-1, field_width, list_height+1
Color 150, 150, 200 :Rect x_pos, 0, field_width, bar_height+list_height,0
Color 100, 100, 100
SetFont dropdown_font_2
For i = 1 To 100
Text x_pos+4, (i*bar_height), menus$(x_select, i, 0)
If menus$(x_select, i, 1) <> ""
SetFont dropdown_font_1
Text (x_pos+field_width-10), (i*bar_height), ">"
SetFont dropdown_font_2
EndIf
If i = list_fields Then Exit
Next
;DRAW SUBLIST
Color 50, 50, 60 :Rect (x_pos+field_width), y_substart, field_width, (sublength*bar_height)
Color 150, 150, 200 :Rect (x_pos+field_width), y_substart-1, field_width, (sublength*bar_height)+1,0
Color 50, 50, 60 :Rect (x_pos+field_width)-1, y_substart+1, 2, bar_height-2
Color 100, 100, 100
For i = 1 To 100
If menus$(x_select, parentnum, i) <> ""
Text (x_pos+field_width+4), (y_substart+(i*bar_height)-bar_height), menus$(x_select, parentnum, i)
EndIf
If i = sub_fields Then Exit
Next 
;HIGHLIGHT SELECTED ITEM ON SUBLIST
y_select = ((MouseY()-y_substart)/bar_height)
Color 100, 100, 100 :Rect x_pos+field_width+1, ((y_select*bar_height)+y_substart), field_width-2, bar_height-1
Color 50, 50, 60 :Text x_pos+field_width+4, ((y_select*bar_height)+y_substart), menus$(x_select, parentnum,y_select+1)
;IF MOUSEHIT INPUT ACTION
If MouseHit(1) Then inputstring$ = menus$(x_select, parentnum,y_select+1)
;ELSE RESET GLOBALS
Else
menuopen = 0 :listlength = 0 :x_select = 0 :sublength = 0
EndIf
End Function
Scrollbars:
Code: [Select]
;-------------------------------------------------------------------------------------------------------
Graphics 1024, 768
SetBuffer BackBuffer()
Global scroll_h#, scroll_v#, grab_bar
ClsColor 30,20, 10
;-----------------------------------------------------------------------------------------------------
While quit = 0
Cls
BACKGROUND()
Color 160, 160, 110
SCROLLBAR_V(200,0, 16, 200, 1200)
SCROLLBAR_H(0, 200, 200, 16, 800)
CURSOR()
Flip
If KeyHit(1) Then quit = 1
Wend
End
;-----------------------------------------------------------------------------------------------------
Function CURSOR()
Color 255, 255, 255
Rect MouseX(), MouseY(), 3, 3
End Function
;-----------------------------------------------------------------------------------------------------
Function BACKGROUND()
Viewport 0, 0, 200, 200
For i = 0 To 800
Color R, G, B
Line 0+i-scroll_h#, 0-scroll_v#, 0+i-scroll_h# , 1200-scroll_v#
If G < 200 And set1 = 0
If R > 0 Then R = R - 1
G = G + 1
Else If B < 200 And set2 = 0
If G > 1 Then G = G - 1
B = B + 1
set1 = 1
Else If R < 200
If B > 1 Then B = B - 1
R = R + 1
set2 = 1
Else
set1 = 0
set2 = 0
EndIf 
Next
Color 0, 0, 0
For i = 0 To 1600 Step 10
Color D, D, D
Text 2-scroll_h, i-scroll_v,"SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING SCROLLING"
D = D + 10
Next
Viewport 0, 0, 1024, 768
End Function
;-----------------------------------------------------------------------------------------------------
Function SCROLLBAR_V(x_pos, y_pos, bar_w, bar_h, list_l#)

slider_l# = bar_h - (2 * bar_w)
bar_percent# = 100 / (list_l# / slider_l#)
slider_div# =  slider_l# / 100
bar_height# = bar_percent# * slider_div#
slide_spd# = (scroll_v# * ((slider_l# - bar_height#)/(list_l# -bar_h)))

If MouseDown(1) And grab_bar = 0
If MouseX() > x_pos  And MouseX() < x_pos + bar_w
If MouseY() > y_pos And MouseY() < y_pos + bar_w
If scroll_v# > 0 Then scroll_v# = scroll_v# - 2
  Else If MouseY() > y_pos +(bar_h - bar_w) And MouseY() < y_pos + bar_h
If scroll_v# < list_l# - bar_h Then scroll_v# = scroll_v# + 2
Else If MouseY() > y_pos + slide_spd# +bar_w And MouseY() < y_pos+slide_spd#+bar_w+bar_height#
grab_bar = 1
EndIf
EndIf
EndIf

If grab_bar = 1
old_y = MouseY()
Delay 20
diff# = MouseY() - old_y 
drag_slider# = diff# * (list_l# / slider_l#)
If scroll_v# >= 0 And scroll_v# < list_l#
If scroll_v# + drag_slider# < 0
scroll_v# = 0
Else If scroll_v# + drag_slider# > list_l# -bar_h
scroll_v# = list_l# - bar_h
Else
scroll_v# = scroll_v# + drag_slider#
EndIf
EndIf
EndIf

If Not MouseDown(1) Then grab_bar = 0

Color 0, 0, 0
Rect x_pos, y_pos, bar_w, bar_h
For i = 0 To 1
Color 20, 20, 20
Rect x_pos, y_pos+(i * (slider_l# +bar_w)), bar_w, bar_w
Color 80, 80, 80
Rect x_pos+1, y_pos+(i * (slider_l# +bar_w)), bar_w-1, bar_w-1
Color 50, 50, 50
Rect x_pos+1, y_pos+1+(i * (slider_l# +bar_w)), bar_w-2, bar_w-2
Next

For z = 0 To (bar_w / 2) - (bar_w / 4)
Color 140, 40, 40
Rect x_pos+(bar_w/2) - 1 -z, y_pos +(bar_w / 4)-1 +(z*2) , 2 +(z*2), 2
Rect x_pos+(bar_w/2) - 1 -z, y_pos +bar_h -(bar_w / 4)-1 -(z*2), 2 +(z*2), 2
Next

Color 50, 50, 50
Rect x_pos+1, y_pos + bar_w +slide_spd#+1, bar_w-2, bar_height#-2
Color 120, 120, 120
Rect x_pos+2, y_pos + bar_w +slide_spd#+1, bar_w-3, bar_height#-3
Color 80, 80, 80
Rect x_pos+2, y_pos+2 + bar_w +slide_spd#, bar_w-4, bar_height#-4
Color 140, 40, 40
Rect x_pos+5, y_pos+5 + bar_w +slide_spd#, bar_w-10, bar_height#-10

End Function
;-----------------------------------------------------------------------------------------------------
Function SCROLLBAR_H(x_pos, y_pos, bar_w, bar_h, list_l#)

slider_l# = bar_w - (2 * bar_h)
bar_percent# = 100 / (list_l# / slider_l#)
slider_div# =  slider_l# / 100
bar_height# = bar_percent# * slider_div#
slide_spd# = (scroll_h# * ((slider_l# - bar_height#)/(list_l# -bar_w)))


If MouseDown(1) And grab_bar = 0
If MouseY() > y_pos  And MouseY() < y_pos + bar_h
If MouseX() > x_pos And MouseX() < x_pos + bar_h
If scroll_h# > 0 Then scroll_h# = scroll_h# - 2
  Else If MouseX() > x_pos +(bar_w - bar_h) And MouseX() < x_pos + bar_w
If scroll_h# < list_l# - bar_w Then scroll_h# = scroll_h# + 2
Else If MouseX() > x_pos + slide_spd# +bar_h And MouseX() < x_pos+slide_spd#+bar_h+bar_height#
grab_bar = 2
EndIf
EndIf
EndIf

If grab_bar = 2
old_x = MouseX()
Delay 20
diff# = MouseX() - old_x 
drag_slider# = diff# * (list_l# / slider_l#)
If scroll_h# >= 0 And scroll_h# < list_l#
If scroll_h# + drag_slider#  < 0
scroll_h# = 0
Else If scroll_h# + drag_slider#  > list_l# -bar_w
scroll_h# = list_l# - bar_w
Else
scroll_h# = scroll_h# + drag_slider#   
EndIf
EndIf
EndIf

If Not MouseDown(1) Then grab_bar = 0

Color 60, 60, 50
Rect x_pos, y_pos, bar_w, bar_h
Color 160, 160, 110
Rect x_pos, y_pos, bar_h, bar_h
Rect x_pos +(slider_l# +bar_h), y_pos , bar_h, bar_h
Color 110, 160, 160
Rect x_pos + bar_h +slide_spd#, y_pos , bar_height#, bar_h
End Function
Slow and unfinished windows:
Code: [Select]
Graphics 1024, 768
SetBuffer BackBuffer()

;-----------------------------------------------------------------------------------------------------
;**************************** VARIABLES NEEDED *******************************************************
;-----------------------------------------------------------------------------------------------------
Global font1 = LoadFont(verdana ,16 , True, False,False)
Global font2 = LoadFont(verdana ,16 , False, False,False)

Const graphics_width = 1024,  graphics_height = 768
Global old_mouse_x, old_mouse_y
Type window
;MAIN WINDOW VARIABLES
Field x, y, w, h, title$, hh, stretch
Field s_bar, d_down,locked
;DROPDOWN MENU VARIABLES
Field menus$[100], inputstring$
Field menuopen, listlength, x_select
;SCROLLBAR VARIABLES
End Type
Dim win_han(20)

;s_bar SETS SCROLLBARS: 0=NONE, 1=VERTICAL , 2=VERTICAL AND HORIZONTAL, 3=HORIZONTAL
;d_down = 1 THEN INCLUDE DROPDOWN MENU IN WINDOW
;locked = 1 THEN WINDOW CANNOT BE STRETCHED, DRAGGED, OR MOVED TO THE FRONT BY CLICKING ON IT

;-----------------------------------------------------------------------------------------------------
;************************** SET WINDOW COLOURS *******************************************************
;-----------------------------------------------------------------------------------------------------

;BORDERS ;BORDER HILITE
Const wr1=30, wg1=40, wb1=33, wr2=100, wg2=130, wb2=110
;BACKGROUND ;CLOSE BUTTON
Const wr3=20, wg3=30, wb3=35, wr4=150, wg4=40, wb4=40
  ;MENU BAR ;TEXT COLOUR
Const wr5=20, wg5=30, wb5=25, wr6=100, wg6=100, wb6=100


;-----------------------------------------------------------------------------------------------------
;********************** CREATE SOME WINDOWS AND DEMO LOOP ********************************************
;-----------------------------------------------------------------------------------------------------

w.window = New window
w\x=100: w\y=100: w\w=128: w\h=200: w\title$="WINDOW": w\hh=20
win_han(1) = Handle(w)
w.window = New window
w\x=120: w\y=200: w\w=300: w\h=300: w\title$="ANOTHER ONE": w\hh=20 :w\d_down=1
win_han(2) = Handle(w)
w\menus$[00] = "File"
w\menus$[10] = "Options"
w\menus$[20] = "Preferences"
w\menus$[30] = "Graphics"
w\menus$[40] = "Sound"
w\menus$[50] = "Controls"
w\menus$[80] = "Other Things"
;Name items on menu lists
w\menus$[01] = "New"
w\menus$[02] = "Save"
w\menus$[03] = "Save As"
w\menus$[04] = "Load"
w\menus$[05] = "Quit"

w\menus$[11] = "Option 1"
w\menus$[12] = "Option 2"
w\menus$[13] = "Option 3"
w\menus$[14] = "Option 4"
w\menus$[15] = "Option 5"
w\menus$[16] = "Option 6"
w\menus$[17] = "Option 7"
w\menus$[18] = "Option 8"
w\menus$[19] = "Option 9"

w\menus$[21] = "Preference 1"
w\menus$[22] = "Preference 2"

w\menus$[31] = "Nice"
w\menus$[32] = "Not So Nice"
w\menus$[33] = "Bad"

w\menus$[41] = "On"
w\menus$[42] = "Off"

w\menus$[51] = "Cofigure"

w\menus$[81] = "This Thing"
w\menus$[82] = "That Thing"
w\menus$[83] = "Something"
w\menus$[84] = "Nothing"
w\menus$[85] = "Everything"
w.window = New window
w\x=300: w\y=460: w\w=230: w\h=100: w\title$="THE THIRD ONE": w\hh=20
win_han(3) = Handle(w)
w.window = New window
w\x=60: w\y=440: w\w=160: w\h=120: w\title$="FOURTH": w\hh=20 :w\d_down=1
win_han(4) = Handle(w)

w\menus$[00] = "File"
w\menus$[10] = "Options"
w\menus$[01] = "New"
w\menus$[02] = "Save"
w\menus$[03] = "Save As"
w\menus$[04] = "Load"
w\menus$[05] = "Quit"

w\menus$[11] = "Option 1"
w\menus$[12] = "Option 2"
w\menus$[13] = "Option 3"
w\menus$[14] = "Option 4"
w\menus$[15] = "Option 5"
w\menus$[16] = "Option 6"

t = MilliSecs() + 1000
While Not KeyHit(1)

; Frame rate
If MilliSecs() >= t Then
lastFPS = FPS
FPS = 0
t = MilliSecs() + 1000
End If
FPS = FPS + 1

Cls
WINDOW()
Color 255, 255, 255: Rect MouseX(), MouseY(), 3, 3
Text 2,2, lastFPS
Flip
Wend
;-----------------------------------------------------------------------------------------------------
;*****************************************************************************************************
;-----------------------------------------------------------------------------------------------------
Function WINDOW()
For w.window = Each window
;DRAW THE WINDOWS
If w\d_down = 1
drop_bit = 16
Else
drop_bit = 0
EndIf

Color wr1, wg1, wb1: Rect w\x, w\y, w\w, w\h+drop_bit,1 ;WINDOW FRAME
Color wr2, wg2, wb2: Rect w\x, w\y, w\w, w\h+drop_bit,0 ;WINDOW FRAME BORDER
Color wr3, wg3, wb3: Rect w\x+6, w\y+w\hh+drop_bit, w\w-12, w\h-w\hh-6, 1;WINDOW CONTENTS
Color wr2, wg2, wb2: Rect w\x+6, w\y+w\hh+drop_bit, w\w-12, w\h-w\hh-6,0 ;INNER BORDER

Viewport w\x, w\y, (w\w-w\hh), w\hh
Color wr6, wg6, wb6: SetFont font1: Text w\x+6, w\y+4, w\title$ ;WINDOW TITLE
Viewport 0, 0, graphics_width, graphics_height

Color wr4, wg4, wb4: Rect w\x+w\w-w\hh+4,w\y+4,w\hh-8,w\hh-8,1 ;CLOSE BUTTON
;-----------------------------------------------------------------------------------------------------
;IF WINDOW HAS SCROLLBARS THEN DRAW THEM
If w\s_bar = 1

Else If w\s_bar = 2

Else If w\s_bar = 3

EndIf
;-----------------------------------------------------------------------------------------------------

;IF WINDOW HAS A DROPDOWN MENU THEN DRAW IT
win_num = win_num + 1
If w\d_down = 1
;SET VARIABLES
field_width = 100
bx=w\x+6: by=w\y+20: bar_width=1000: bar_height=16
;VIEWPORT THE BAR
Color wr2, wg2, wb2   :Line bx+w\w-13, by, bx+w\w-13, by+16
If w\menuopen = 1 And MouseX() > bx+(((w\w-12)/100)*100)
portwidth = (((w\w-12)/100)*100)+100
Viewport(w\x+6, w\y+20, portwidth, 17)
Else
Viewport(w\x+6, w\y+20, w\w-13, 17)
EndIf
;DRAW MENU BAR
Color wr5, wg5, wb5   :Rect bx, by, bar_width, bar_height, 1
Color wr2, wg2, wb2   :Rect bx, by, bar_width, bar_height+1, 0

;DRAW MENU BAR TITLES
SetFont font1
Color wr6, wg6, wb6
For i = 0 To 9
Text bx+2+(i*field_width), by, w\menus$[i*10]
Next
Viewport(0,0,graphics_width,graphics_height)
;IF THE CURSOR IS OVER THE MENUBAR
If MouseX() > bx And MouseX() < (bx+w\w-12) And MouseY() > by And MouseY() < (by+16)
w\x_select = ((MouseX()-bx) / field_width)
If w\menus$[w\x_select*10] <> ""
w\listlength = 0
For i = 1 To 9
If w\menus$[(w\x_select*10)+i] <> "" Then w\listlength = w\listlength +1
Next
x_pos = w\x_select * field_width
list_height = w\listlength * bar_height
Color wr5, wg5, wb5 :Rect bx+x_pos, by+bar_height-1, field_width, list_height+1
Color wr2, wg2, wb2 :Rect bx+x_pos, by, field_width, bar_height+list_height, 0
Color wr6, wg6, wb6
SetFont font2
For i = 1 To 9
Text bx+x_pos+4, by+(i*bar_height), w\menus$[(w\x_select*10)+i]
Next
w\menuopen = 1
EndIf
;ELSE IF THE MENU IS OPENED AND CURSOR MOVED DOWN OVER THE LIST
Else If w\menuopen = 1
x_pos = w\x_select * field_width
list_height = w\listlength * bar_height
If MouseX() > (bx+x_pos) And MouseX() < (bx+x_pos+field_width) And MouseY() > by And MouseY() < (by+list_height+bar_height)
Color wr5, wg5, wb5 :Rect bx+x_pos, by+bar_height-1, field_width, list_height+1
Color wr2, wg2, wb2 :Rect bx+x_pos, by, field_width, bar_height+list_height, 0
Color wr6, wg6, wb6
SetFont font2
For i = 1 To 9
Text bx+x_pos+4, by+(i*bar_height), w\menus$[(w\x_select*10)+i]
Next
;HIGHLIGHT ITEM ON LIST THAT CURSOR IS OVER
y_select = ((MouseY()-by)/bar_height)
Color wr6, wg6, wb6 :Rect bx+x_pos+1, by+(y_select*bar_height), field_width-2, bar_height-1
Color wr5, wg5, wb5 :Text bx+x_pos+4, by+(y_select*bar_height), w\menus$[(w\x_select*10)+y_select] 
Else
w\menuopen = 0 :w\listlength = 0 :w\x_select = 0
EndIf
Else ;ELSE RESET GLOBALS
w\menuopen = 0 :w\listlength = 0 :w\x_select = 0
EndIf

EndIf
;-----------------------------------------------------------------------------------------------------
;IF CLICK ON WINDOW MOVE IT TO THE FRONT
If MouseHit(1) Or clicked = 1
;check that mouse is over window
If MouseX() > w\x And MouseX() < (w\x+w\w) And MouseY() > w\y And MouseY() < (w\y+w\h+drop_bit)
;check that there are no windows on top of it
For w2.window = Each window
win_num2 = win_num2 + 1
;make sure that the window is above it, not below
If win_num2 > win_num
;if a window is overlapping then do nothing and exit the loop
If MouseX() > w2\x And MouseX() < (w2\x+w2\w) And MouseY() > (w2\y) And MouseY() < ((w2\y+w2\h)+(w2\d_down*16))
  no_go = 1
Exit 
EndIf 
EndIf
Next
win_num2 = 0
;if there are no windows overlapping it then move it to the front
If no_go = 0
Insert w.window After Last window
EndIf
Else
clicked = 1
EndIf
EndIf

;-----------------------------------------------------------------------------------------------------
;MANIPULATE THE WINDOWS
If MouseDown(1)
If w.window = Last window
If w\stretch = 0
;STRETCH DIAGONAL
If MouseX() > (w\x+w\w-6) And MouseX() < (w\x+w\w) And MouseY() > (w\y+w\h-6+drop_bit) And MouseY() < (w\y+w\h+drop_bit)
w\stretch = 3
;STRETCH WIDTH
Else If MouseX() > (w\x+w\w-6) And MouseX() < (w\x+w\w) And MouseY() > (w\y+w\hh) And MouseY() < (w\y+w\h)
w\stretch = 1
;STRETCH HEIGHT
Else If MouseY() > (w\y+w\h-6+drop_bit) And MouseY() < (w\y+w\h+drop_bit) And MouseX() > w\x And MouseX() < (w\x+w\w)
w\stretch = 2
;DRAG WINDOW
Else If MouseX() > w\x And MouseX() < (w\x+w\w-w\hh) And MouseY() > w\y And MouseY() < (w\y+w\hh)
w\stretch = 4
old_mouse_x = MouseX()
old_mouse_y = MouseY()
;CLOSE WINDOW
Else If MouseX() > (w\x+w\w-w\hh+4) And MouseX() < (w\x+w\w-4) And MouseY() > (w\y+4) And MouseY() < (w\y+w\hh-4)
w\stretch = 5
EndIf
EndIf
EndIf 

If w\stretch = 1
If w\w > (w\hh*2)
w\w = (MouseX()-w\x)
Else
w\w =((w\hh*2)+10)
w\stretch = 0
EndIf
Else If w\stretch = 2
If w\h > (w\hh*2)
w\h = (MouseY()-w\y)
Else
w\h = ((w\hh*2)+10)
w\stretch = 0
EndIf
Else If w\stretch = 3
If w\w > (w\hh*2)
w\w = (MouseX()-w\x)
Else
w\w =((w\hh*2)+10)
w\stretch = 0
EndIf
If w\h > (w\hh*2)
w\h = (MouseY()-w\y)
Else
w\h = ((w\hh*2)+10)
w\stretch = 0
EndIf
Else If w\stretch = 4
w\x = w\x +(MouseX()-old_mouse_x)
w\y = w\y +(MouseY()-old_mouse_y)
old_mouse_x = MouseX()
old_mouse_y = MouseY()
Else If w\stretch = 5
Delete w.window
Exit
EndIf
Else
w\stretch = 0
EndIf
Next
End Function
« Last Edit: July 21, 2007 by Shockwave »

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: GUI Functions
« Reply #1 on: January 06, 2007 »
I like the look of the menus's
and when you say slow 75 fps? thats fast enough :D
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: GUI Functions
« Reply #2 on: January 06, 2007 »
Thanks.

The thing about the windows it that they are a background task so they really need to be fast especially if you want to have, say, a game in the window. The version I posted is an old version that draws each window each loop.

I made a newer version that draws them to an image buffer that only updates when a change is made they also had the option of having scroll bars in them. Unfortunately I seem to have turned it into a horrible mess though and its not something I look forward to gong back to  :'(

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: GUI Functions
« Reply #3 on: January 06, 2007 »
1 thing you could do (maybe) is to use viewport to only redraw the current window
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: GUI Functions
« Reply #4 on: January 06, 2007 »
With the way things are at the moment all the windows need to be redrawn since the screen would be cleared each loop.

I think I get what you mean and it would work  using an image buffer to draw the windows to. The only problem would be that it wouldent work if you were dragging a window, or shrinking it, over other ones as the ones behind would need to be drawn.

 

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 886
  • Karma: 63
    • View Profile
    • zac-interactive
Re: GUI Functions
« Reply #5 on: January 12, 2007 »
In the gui systems that I have made for blitz2d, I have used imagebuffers for all windows. So when creating a new window, I would create an image and draw the contents of the window into that. Then in the main loop I would have it draw the window images with drawblock which is quite fast. If the content of a window needed updating then I would set the buffer to the image buffer and redraw what needed changing. Just an alternative way of doing things I guess.


Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: GUI Functions
« Reply #6 on: January 13, 2007 »
Yeah I had considered doing that. But then I thought about resizing them since the image would have to be resized when the windows are stretched. It would either be that or create a screen sized image for each window which would take up a lot of RAM.

That said with the way I was doing things I would have had some difficulties drawing stuff inside the windows when another window was overlapping it. Anyway if I ever go back to working on it I might make the windows each with their own image.