Same tree generation code as above but with a simple GUI tacked on to control the main parameters.
Max Branches - The maximum number of branches
Max Sections - The number of sections the trunk is made from
Branch Diameter - The Diameter of the base of the trunk
Amount Of Bend - The bendiness of the branches
Section size - The space between sections
Render New Tree - Renders a new tree
Save Tree - Saves the current tree as a dbo file for later use
This is a massive piece of code and was originally a set of includes so be warned readability is not good as one big file,ill split it all back up and post a zip later if any one wants.
`%DarkTreeGUI v1.1%
`======================
`©P.Parkinson
`======================
`Main Source File
`*********************************
`enviroment set up
IF CHECK DISPLAY MODE(1024,768,32)
SET DISPLAY MODE 1024,768,32
h=DESKTOP HEIGHT()
w=DESKTOP WIDTH()
posx=w/2-512
posy=h/2-384
ELSE
TEXT 0,0,"sorry this cant run in this resolution minimum 1024,768"
SYNC
SYNC
WAIT 1000
END
ENDIF
SET WINDOW POSITION posx,posy
SET WINDOW TITLE "DarkTreeGUI V1.1"
SYNC ON
SYNC RATE 60
AUTOCAM OFF
``HIDE MOUSE
COLOR BACKDROP 0,0
SET TEXT FONT "Arial"
SET TEXT SIZE 12
SET TEXT TRANSPARENT
POSITION CAMERA -50,30,-150
POINT CAMERA 0,80,0
POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
dummy=MOUSEMOVEX()
dummy=MOUSEMOVEY()
COLOR BACKDROP RGB(150,150,255)
RANDOMIZE TIMER()
SYNC
SYNC
`*********************************
`gui type set up
TYPE gui_object
in_use AS INTEGER
active AS INTEGER
object_type AS INTEGER
on_window AS INTEGER
position_x AS INTEGER
position_y AS INTEGER
size_x AS INTEGER
size_y AS INTEGER
active_border_color AS DOUBLE INTEGER
inactive_border_color AS DOUBLE INTEGER
active_fill_color AS DOUBLE INTEGER
inactive_fill_color AS DOUBLE INTEGER
active_text_color AS DOUBLE INTEGER
inactive_text_color AS DOUBLE INTEGER
hover_over_color AS DOUBLE INTEGER
label AS STRING
input_label AS STRING
min_value AS INTEGER
max_value AS INTEGER
current_value AS INTEGER
step_value AS INTEGER
pressed AS INTEGER
image_number AS INTEGER
delete_on_close AS INTEGER
ENDTYPE
`types of gui objects
`these objects except for windows will only be created if they are given valid window number
`they will return a number other than 0 if they are created
`if making a window then its on_window value must be 0
`every other object must be created on a window you cant pass a value of a frame box or picture box for example and expect a button to me made on it
GLOBAL window=1`window sized to fit initial label given if smaller than size given
GLOBAL button=2`button sized to fit initial label given if smaller than size given
GLOBAL tbox=3`text box sized to fit initial label given if smaller than size given
GLOBAL vsbox=4`vertical slider box sized to text size if too small a size_x given
GLOBAL hsbox=5`horizontal slider box sized to text size if too small a size_y given
GLOBAL ibox=6`text input box sized to text size if too small a size_y given
GLOBAL fbox=7`frame box sized to fit on the window its made on if the values are bigger than it
GLOBAL pbox=8`picture box sized to fit on the window its made on if the values are bigger than it
`max gui objects and array to hold there data
GLOBAL max_gui=100 `change to suit project
DIM gui(max_gui)AS gui_object
`global gui control variables
GLOBAL clicked=0
GLOBAL click_time=5
GLOBAL moved=0
GLOBAL button_pressed=0
GLOBAL slider_change=0
GLOBAL last_key_pressed$
GLOBAL last_text_input$
GLOBAL old_text_input$
GLOBAL input_from=0
GLOBAL blink_time=0
GLOBAL blink_rate=20
GLOBAL hover=0
GLOBAL comp_moves=0
`*********************************
`declarations and setup for tree maker starts here
make_test_texture()
make_leaves_texture()
CLS
TYPE branch_type
used AS INTEGER
posx AS FLOAT
posy AS FLOAT
posz AS FLOAT
angx AS FLOAT
angy AS FLOAT
angz AS FLOAT
num_sections AS INTEGER
start_size AS FLOAT
ENDTYPE
TYPE branch_data_type
obj AS INTEGER
posx AS FLOAT
posy AS FLOAT
posz AS FLOAT
angx AS FLOAT
angy AS FLOAT
angz AS FLOAT
size AS FLOAT
section AS INTEGER
step_size AS FLOAT
ENDTYPE
``max number of branches
GLOBAL max_branches AS INTEGER=25
DIM branch(max_branches) AS branch_type
``max number of sections on each branch
GLOBAL max_sections AS INTEGER=40
DIM branch_data(max_branches,max_sections) AS branch_data_type
``max size of each section
GLOBAL max_branch_thickness AS FLOAT:max_branch_thickness=10.0
``max step size between sections
GLOBAL max_step_size AS FLOAT:max_step_size=3.5
``used to pass data between functions
GLOBAL step_size AS FLOAT
``max bend amount
GLOBAL bend AS FLOAT:bend=40.0
``counts the branches used in the loops
GLOBAL used_branches AS INTEGER=0
``hides the creation objects so you cant see the rings used to build the mesh
GLOBAL hide AS INTEGER=1
``counts the actual objects used
GLOBAL num_objects AS INTEGER=0
``ground plain using matrix1
obj=free_object()
MAKE OBJECT PLAIN obj,500,500,32,32,274
SET OBJECT WIREFRAME obj,1
``makes the ring of limbs used to get data for the mesh creation
GLOBAL tree_section AS INTEGER
make_tree_section()
``if set to 0 it makes a bisic model out of cubes
GLOBAL render_tree AS INTEGER=1
``object for the actual finished tree
GLOBAL tree_model AS INTEGER
tree_model=free_object()
MAKE OBJECT CUBE tree_model,1
``used for saving models
GLOBAL number_of_trees_rendered AS INTEGER=1
`*********************************
`gui creation starts here
SET CAMERA TO IMAGE 0,3,1008,736
main_window=make_gui_object(window,0,8,16,1008,736,"DarkTreeGUI V1.1")
gui(main_window).active_fill_color=RGB(0,0,0)
gui(main_window).active_text_color=RGB(255,255,255)
pbox1=make_gui_object(pbox,main_window,0,0,0,0,"test")
gui(pbox1).image_number=3
``max branches slider
max_branches_tbox=make_gui_object(tbox,main_window,10,10,0,TEXT SIZE()," Max Branches 25")
gui(max_branches_tbox).active_text_color=RGB(0,0,0)
max_branches_slider=make_gui_object(hsbox,main_window,10,30,180,10,"max_branches_slider")
gui(max_branches_slider).min_value=5
gui(max_branches_slider).max_value=50
gui(max_branches_slider).current_value=25
gui(max_branches_slider).step_value=1
``max sections slider
max_sections_tbox=make_gui_object(tbox,main_window,10,50,0,TEXT SIZE()," Max sections 40")
gui(max_sections_tbox).active_text_color=RGB(0,0,0)
max_sections_slider=make_gui_object(hsbox,main_window,10,70,180,10,"max_sections_slider")
gui(max_sections_slider).min_value=10
gui(max_sections_slider).max_value=80
gui(max_sections_slider).current_value=40
gui(max_sections_slider).step_value=1
``max branch diameter slider
max_diameter_tbox=make_gui_object(tbox,main_window,10,90,0,TEXT SIZE()," Branch Diameter 10.0")
gui(max_diameter_tbox).active_text_color=RGB(0,0,0)
max_diameter_slider=make_gui_object(hsbox,main_window,10,110,180,10,"max_diameter_slider")
gui(max_diameter_slider).min_value=10
gui(max_diameter_slider).max_value=400
gui(max_diameter_slider).current_value=100
gui(max_diameter_slider).step_value=1
``bend slider
bend_tbox=make_gui_object(tbox,main_window,10,130,0,TEXT SIZE()," Amount Of Bend 40.0")
gui(bend_tbox).active_text_color=RGB(0,0,0)
bend_slider=make_gui_object(hsbox,main_window,10,150,180,10,"bend_slider")
gui(bend_slider).min_value=50
gui(bend_slider).max_value=800
gui(bend_slider).current_value=400
gui(bend_slider).step_value=1
``section_size slider
section_size_tbox=make_gui_object(tbox,main_window,10,170,0,TEXT SIZE()," Section Size 3.5")
gui(section_size_tbox).active_text_color=RGB(0,0,0)
section_size_slider=make_gui_object(hsbox,main_window,10,190,180,10,"section_size_slider")
gui(section_size_slider).min_value=10
gui(section_size_slider).max_value=100
gui(section_size_slider).current_value=35
gui(section_size_slider).step_value=1
render_button=make_gui_object(button,main_window,40,700,0,TEXT SIZE()*2,"RENDER NEW TREE!")
save_button=make_gui_object(button,main_window,800,700,0,TEXT SIZE()*2,"SAVE TREE AS - "+"tree model "+STR$(number_of_trees_rendered)+".dbo")
info_tbox=make_gui_object(tbox,main_window,220,700,510,TEXT SIZE()*2," FPS= Left Click On Window To Move Camera - Arrow Keys To Move Tree")
`*********************************
`main loop starts here
DO
IF LEFTKEY()
POSITION OBJECT tree_model,OBJECT POSITION X(tree_model)-1,OBJECT POSITION Y(tree_model),OBJECT POSITION Z(tree_model)
ENDIF
IF RIGHTKEY()
POSITION OBJECT tree_model,OBJECT POSITION X(tree_model)+1,OBJECT POSITION Y(tree_model),OBJECT POSITION Z(tree_model)
ENDIF
IF UPKEY()
POSITION OBJECT tree_model,OBJECT POSITION X(tree_model),OBJECT POSITION Y(tree_model),OBJECT POSITION Z(tree_model)+1
ENDIF
IF DOWNKEY()
POSITION OBJECT tree_model,OBJECT POSITION X(tree_model),OBJECT POSITION Y(tree_model),OBJECT POSITION Z(tree_model)-1
ENDIF
gui(info_tbox).label=" FPS= "+STR$(SCREEN FPS())+" Left Click On Window To Move Camera - Arrow Keys To Move Tree"
update_gui()
`*********************************
``respond to gui commands
``change number of branches
IF slider_change=max_branches_slider
gui(max_branches_tbox).label=" Max Branches "+STR$(gui(max_branches_slider).current_value)
clear_data()
max_branches=gui(max_branches_slider).current_value
UNDIM branch()
UNDIM branch_data()
DIM branch(max_branches) AS branch_type
DIM branch_data(max_branches,max_sections) AS branch_data_type
ENDIF
``change number of sections
IF slider_change=max_sections_slider
gui(max_sections_tbox).label=" Max sections "+STR$(gui(max_sections_slider).current_value)
clear_data()
max_sections=gui(max_sections_slider).current_value
UNDIM branch()
UNDIM branch_data()
DIM branch(max_branches) AS branch_type
DIM branch_data(max_branches,max_sections) AS branch_data_type
ENDIF
``change max diameter of branches
IF slider_change=max_diameter_slider
gui(max_diameter_tbox).label=" Branch Diameter "+LEFT$(STR$(gui(max_diameter_slider).current_value/10.0),4)
max_branch_thickness=gui(max_diameter_slider).current_value/10.0
DELETE OBJECT tree_section
make_tree_section()
ENDIF
``change bend of branches
IF slider_change=bend_slider
gui(bend_tbox).label=" Amount Of Bend "+LEFT$(STR$(gui(bend_slider).current_value/10.0),4)
bend=gui(bend_slider).current_value/10.0
ENDIF
``change section size
IF slider_change=section_size_slider
gui(section_size_tbox).label=" Section Size "+LEFT$(STR$(gui(section_size_slider).current_value/10.0),4)
max_step_size=gui(section_size_slider).current_value/10.0
ENDIF
``render new tree
IF button_pressed=render_button
HIDE MOUSE
SYNC
clear_data()
make_tree()
make_tree_object(tree_model)
SHOW MOUSE
ENDIF
IF MOUSECLICK()=1 AND button_pressed=0 AND slider_change=0
mouse_control(1.0)
ENDIF
SYNC
IF button_pressed=save_button
IF FILE EXIST("tree model "+STR$(number_of_trees_rendered)+".dbo")
DELETE FILE "tree model "+STR$(number_of_trees_rendered)+".dbo"
ENDIF
SAVE OBJECT "tree model "+STR$(number_of_trees_rendered)+".dbo",tree_model
INC number_of_trees_rendered
WAIT 1000
gui(save_button).label="SAVE TREE AS - "+"tree model "+STR$(number_of_trees_rendered)+".dbo"
ENDIF
LOOP
`*********************************
`functions start here
FUNCTION mouse_control(speed AS FLOAT)
XROTATE CAMERA CAMERA ANGLE X()+MOUSEMOVEY()
YROTATE CAMERA CAMERA ANGLE Y()+MOUSEMOVEX()
// IF MOUSECLICK()=1 THEN MOVE CAMERA speed
// IF MOUSECLICK()=2 THEN MOVE CAMERA (0-speed)
dummy=MOUSEMOVEX()
dummy=MOUSEMOVEY()
ENDFUNCTION
FUNCTION free_object()
num_objects=0
REPEAT
INC i
IF OBJECT EXIST(i)=0
found=1
ELSE
INC num_objects
ENDIF
UNTIL found
ENDFUNCTION i
FUNCTION make_tree()
``make trunk
branch(used_branches).used=1
branch(used_branches).posx=0.0
branch(used_branches).posy=0.0
branch(used_branches).posz=0.0
branch(used_branches).angx=-90.0
branch(used_branches).angy=0.0
branch(used_branches).angz=0.0
branch(used_branches).num_sections=max_sections
branch(used_branches).start_size=max_branch_thickness
obj=free_object()
scale#=branch(used_branches).start_size/(max_branch_thickness/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
IF hide=1 THEN HIDE OBJECT obj
POSITION OBJECT obj,branch(used_branches).posx,branch(used_branches).posy,branch(used_branches).posz
ROTATE OBJECT obj,branch(used_branches).angx,branch(used_branches).angy,branch(used_branches).angz
branch_data(used_branches,1).obj=obj
branch_data(used_branches,1).posx=branch(used_branches).posx
branch_data(used_branches,1).posy=branch(used_branches).posy
branch_data(used_branches,1).posz=branch(used_branches).posz
branch_data(used_branches,1).angx=branch(used_branches).angx
branch_data(used_branches,1).angy=branch(used_branches).angy
branch_data(used_branches,1).angz=branch(used_branches).angz
branch_data(used_branches,1).size=branch(used_branches).start_size
branch_data(used_branches,1).section=1
step_size=max_step_size
branch_data(used_branches,1).step_size=step_size
FOR l=2 TO branch(used_branches).num_sections
obj=free_object()
new_size#=(branch(used_branches).start_size/max_sections)*(max_sections-l)
scale#=new_size#/(max_branch_thickness/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
IF hide=1 THEN HIDE OBJECT obj
ok=1
DO
POSITION OBJECT obj,branch_data(used_branches,l-1).posx,branch_data(used_branches,l-1).posy,branch_data(used_branches,l-1).posz
SET OBJECT TO OBJECT ORIENTATION obj,branch_data(used_branches,l-1).obj
IF l>2
XROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE X(obj)+RND(bend/2.0)-(bend/4.0))
YROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Y(obj)+RND(bend/2.0)-(bend/4.0))
ZROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Z(obj)+RND(bend/2.0)-(bend/4.0))
ENDIF
MOVE OBJECT obj,step_size
IF OBJECT POSITION Y(obj)>0 THEN ok=1
IF ok=1 THEN EXIT
LOOP
branch_data(used_branches,l).obj=obj
branch_data(used_branches,l).posx=OBJECT POSITION X(obj)
branch_data(used_branches,l).posy=OBJECT POSITION Y(obj)
branch_data(used_branches,l).posz=OBJECT POSITION Z(obj)
branch_data(used_branches,l).angx=OBJECT ANGLE X(obj)
branch_data(used_branches,l).angy=OBJECT ANGLE Y(obj)
branch_data(used_branches,l).angz=OBJECT ANGLE Z(obj)
branch_data(used_branches,l).size=new_size#
branch_data(used_branches,l).section=l
IF step_size>branch_data(used_branches,l).size THEN step_size=step_size*0.99
branch_data(used_branches,l).step_size=step_size
NEXT l
INC used_branches
``make branches
FOR ll=2 TO max_branches
IF used_branches>max_branches/3
branch_to_use=RND(used_branches)-1
ELSE
branch_to_use=1
ENDIF
IF branch_to_use<1 THEN branch_to_use=1
section_to_use=RND(branch(branch_to_use).num_sections)
IF branch_to_use=1
IF section_to_use<10 THEN section_to_use=10
ELSE
IF section_to_use<2 THEN section_to_use=2
ENDIF
branch(used_branches).used=1
branch(used_branches).posx=branch_data(branch_to_use,section_to_use).posx
branch(used_branches).posy=branch_data(branch_to_use,section_to_use).posy
branch(used_branches).posz=branch_data(branch_to_use,section_to_use).posz
branch(used_branches).angx=branch_data(branch_to_use,section_to_use).angx
branch(used_branches).angy=branch_data(branch_to_use,section_to_use).angy
branch(used_branches).angz=branch_data(branch_to_use,section_to_use).angz
branch(used_branches).num_sections=branch(branch_to_use).num_sections-branch_data(branch_to_use,section_to_use).section
branch(used_branches).start_size=branch_data(branch_to_use,section_to_use).size
obj=free_object()
scale#=branch(used_branches).start_size/(max_branch_thickness/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
IF hide=1 THEN HIDE OBJECT obj
POSITION OBJECT obj,branch(used_branches).posx,branch(used_branches).posy,branch(used_branches).posz
ROTATE OBJECT obj,branch(used_branches).angx,branch(used_branches).angy,branch(used_branches).angz
XROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE X(obj)+RND(bend)-(bend/2.0))
YROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Y(obj)+RND(bend)-(bend/2.0))
ZROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Z(obj)+RND(bend)-(bend/2.0))
IF branch_to_use>1 THEN COLOR OBJECT obj,RGB(255,0,0)
branch_data(used_branches,1).obj=obj
branch_data(used_branches,1).posx=branch(used_branches).posx
branch_data(used_branches,1).posy=branch(used_branches).posy
branch_data(used_branches,1).posz=branch(used_branches).posz
branch_data(used_branches,1).angx=branch(used_branches).angx
branch_data(used_branches,1).angy=branch(used_branches).angy
branch_data(used_branches,1).angz=branch(used_branches).angz
branch_data(used_branches,1).size=branch(used_branches).start_size
branch_data(used_branches,1).section=1
step_size=branch_data(branch_to_use,section_to_use).step_size
FOR l=2 TO branch(used_branches).num_sections
obj=free_object()
new_size#=(branch(used_branches).start_size)/branch(used_branches).num_sections*(branch(used_branches).num_sections-l)
scale#=new_size#/(max_branch_thickness/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
IF hide=1 THEN HIDE OBJECT obj
ok=1
DO
POSITION OBJECT obj,branch_data(used_branches,l-1).posx,branch_data(used_branches,l-1).posy,branch_data(used_branches,l-1).posz
SET OBJECT TO OBJECT ORIENTATION obj,branch_data(used_branches,l-1).obj
IF l>4
XROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE X(obj)+RND(bend)-(bend/2.0))
YROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Y(obj)+RND(bend)-(bend/2.0))
ZROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Z(obj)+RND(bend)-(bend/2.0))
ENDIF
MOVE OBJECT obj,step_size
IF OBJECT POSITION Y(obj)>0 THEN ok=1
IF ok=1 THEN EXIT
LOOP
IF branch_to_use>1 THEN COLOR OBJECT obj,RGB(255,0,0)
branch_data(used_branches,l).obj=obj
branch_data(used_branches,l).posx=OBJECT POSITION X(obj)
branch_data(used_branches,l).posy=OBJECT POSITION Y(obj)
branch_data(used_branches,l).posz=OBJECT POSITION Z(obj)
branch_data(used_branches,l).angx=OBJECT ANGLE X(obj)
branch_data(used_branches,l).angy=OBJECT ANGLE Y(obj)
branch_data(used_branches,l).angz=OBJECT ANGLE Z(obj)
branch_data(used_branches,l).size=new_size#
branch_data(used_branches,l).section=l
IF step_size>branch_data(used_branches,l).size THEN step_size=step_size*0.99
branch_data(used_branches,l).step_size=step_size
NEXT l
INC used_branches
NEXT ll
ENDFUNCTION
FUNCTION clear_data()
FOR l=1 TO max_branches
branch(l).used=0
branch(l).posx=0.0
branch(l).posy=0.0
branch(l).posz=0.0
branch(l).angx=-0.0
branch(l).angy=0.0
branch(l).angz=0.0
branch(l).num_sections=0
branch(l).start_size=0.0
FOR ll=1 TO max_sections
IF branch_data(l,ll).obj>0
IF OBJECT EXIST(branch_data(l,ll).obj) THEN DELETE OBJECT branch_data(l,ll).obj
ENDIF
branch_data(l,ll).obj=0
branch_data(l,ll).posx=0.0
branch_data(l,ll).posy=0.0
branch_data(l,ll).posz=0.0
branch_data(l,ll).angx=0.0
branch_data(l,ll).angy=0.0
branch_data(l,ll).angz=0.0
branch_data(l,ll).size=0.0
branch_data(l,ll).section=0.0
branch_data(l,ll).step_size=0.0
NEXT ll
NEXT l
used_branches=1
ENDFUNCTION
FUNCTION make_tree_section()
tree_section=free_object()
MAKE OBJECT CUBE tree_section,1
obj=free_object()
MAKE OBJECT CUBE obj,1
MAKE MESH FROM OBJECT 1,obj
FOR l=1 TO 18
POSITION OBJECT obj,COS(l*20)*max_branch_thickness/2.0,SIN(l*20)*max_branch_thickness/2.0,0
ADD LIMB tree_section,l,1
OFFSET LIMB tree_section,l,OBJECT POSITION X(obj),OBJECT POSITION Y(obj),0
NEXT l
DELETE OBJECT obj
DELETE MESH 1
HIDE OBJECT tree_section
COLOR LIMB tree_section,1,RGB(255,0,0)
COLOR LIMB tree_section,8,RGB(0,255,0)
ENDFUNCTION
FUNCTION make_tree_object(obj)
IF render_tree=1
IF OBJECT EXIST(obj) THEN DELETE OBJECT obj
MAKE OBJECT CUBE obj,1
lmb=1
FOR b=1 TO max_branches
sections=branch(b).num_sections
IF sections>1
num_vertices=(sections-1)*120
create_memblockobject(1,num_vertices)
v=0
FOR s=1 TO sections-1
FOR l=1 TO 17
px#=LIMB POSITION X (branch_data(b,s).obj,l):py#=LIMB POSITION Y (branch_data(b,s).obj,l):pz#=LIMB POSITION Z (branch_data(b,s).obj,l)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,l+1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,l+1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,l+1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,l):py#=LIMB POSITION Y (branch_data(b,s+1).obj,l):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,l)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,l):py#=LIMB POSITION Y (branch_data(b,s).obj,l):pz#=LIMB POSITION Z (branch_data(b,s).obj,l)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,l+1):py#=LIMB POSITION Y (branch_data(b,s).obj,l+1):pz#=LIMB POSITION Z (branch_data(b,s).obj,l+1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,l+1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,l+1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,l+1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
NEXT l
px#=LIMB POSITION X (branch_data(b,s).obj,18):py#=LIMB POSITION Y (branch_data(b,s).obj,18):pz#=LIMB POSITION Z (branch_data(b,s).obj,18)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,18):py#=LIMB POSITION Y (branch_data(b,s+1).obj,18):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,18)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,18):py#=LIMB POSITION Y (branch_data(b,s).obj,18):pz#=LIMB POSITION Z (branch_data(b,s).obj,18)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,1):py#=LIMB POSITION Y (branch_data(b,s).obj,1):pz#=LIMB POSITION Z (branch_data(b,s).obj,1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
NEXT s
IF MESH EXIST(1) THEN DELETE MESH 1
MAKE MESH FROM MEMBLOCK 1,1
ADD LIMB obj,lmb,1
INC lmb
ENDIF
NEXT b
TEXTURE OBJECT obj,1
SET OBJECT NORMALS obj
SET OBJECT SMOOTHING obj,25
leaves=free_object()
FOR l=1 TO max_branches
IF branch_data(l,branch(l).num_sections).posy>5
IF OBJECT EXIST(leaves) THEN DELETE OBJECT leaves
make_bush(leaves,RND(15)+5)
IF MESH EXIST(1) THEN DELETE MESH 1
MAKE MESH FROM OBJECT 1,leaves
ADD LIMB obj,lmb,1
OFFSET LIMB obj,lmb,branch_data(l,branch(l).num_sections).posx,branch_data(l,branch(l).num_sections).posy,branch_data(l,branch(l).num_sections).posz
TEXTURE LIMB obj,lmb,2
SET LIMB TRANSPARENCY obj,lmb,4
SCALE LIMB obj,lmb,RND(30)+100,RND(20)+80,RND(30)+100
INC lmb
ENDIF
IF branch_data(l,(branch(l).num_sections/2)).posy>5
IF OBJECT EXIST(leaves) THEN DELETE OBJECT leaves
make_bush(leaves,RND(30)+10)
IF MESH EXIST(1) THEN DELETE MESH 1
MAKE MESH FROM OBJECT 1,leaves
ADD LIMB obj,lmb,1
OFFSET LIMB obj,lmb,branch_data(l,(branch(l).num_sections/2)).posx,branch_data(l,(branch(l).num_sections/2)).posy,branch_data(l,(branch(l).num_sections/2)).posz
TEXTURE LIMB obj,lmb,2
SET LIMB TRANSPARENCY obj,lmb,4
SCALE LIMB obj,lmb,RND(30)+100,RND(20)+30,RND(30)+100
INC lmb
ENDIF
NEXT l
DELETE OBJECT leaves
DELETE MESH 1
ELSE
IF OBJECT EXIST(obj) THEN DELETE OBJECT obj
MAKE OBJECT CUBE obj,1
IF MESH EXIST(1) THEN DELETE MESH 1
MAKE MESH FROM OBJECT 1,obj
lmb=1
FOR b=1 TO max_branches
FOR s=1 TO branch(b).num_sections
ADD LIMB obj,lmb,1
OFFSET LIMB obj,lmb,branch_data(b,s).posx,branch_data(b,s).posy,branch_data(bs).posz
ROTATE LIMB obj,lmb,branch_data(b,s).angx,branch_data(b,s).angy,branch_data(bs).angz
INC lmb
NEXT s
NEXT b
ENDIF
ENDFUNCTION
FUNCTION create_memblockobject(memnum,v)
IF MEMBLOCK EXIST(memnum) THEN DELETE MEMBLOCK memnum
MAKE MEMBLOCK memnum,12+(36*v)
WRITE MEMBLOCK DWORD memnum,0,338
WRITE MEMBLOCK DWORD memnum,4,36
WRITE MEMBLOCK DWORD memnum,8,v
ENDFUNCTION
FUNCTION create_vertex(memnum,v,vposx#,vposy#,vposz#,color AS DWORD,u#,v#)
WRITE MEMBLOCK FLOAT memnum,v*36+12,vposx#
WRITE MEMBLOCK FLOAT memnum,v*36+16,vposy#
WRITE MEMBLOCK FLOAT memnum,v*36+20,vposz#
WRITE MEMBLOCK DWORD memnum,v*36+36,color `not needed in 274fvf format diffuse color seems to mess up some shader code
WRITE MEMBLOCK FLOAT memnum,v*36+40,u#
WRITE MEMBLOCK FLOAT memnum,v*36+44,v#
ENDFUNCTION
FUNCTION set_normal(memnum,v,normalx#,normaly#,normalz#)
WRITE MEMBLOCK FLOAT memnum,v*36+24,normalx#
WRITE MEMBLOCK FLOAT memnum,v*36+28,normaly#
WRITE MEMBLOCK FLOAT memnum,v*36+32,normalz#
ENDFUNCTION
FUNCTION make_object(objnum,meshnum,memnum,imgnum)
IF OBJECT EXIST (objnum) THEN DELETE OBJECT objnum
IF MESH EXIST (meshnum) THEN DELETE MESH meshnum
MAKE MESH FROM MEMBLOCK meshnum,memnum
MAKE OBJECT objnum,meshnum,imgnum
ENDFUNCTION
FUNCTION make_test_texture()
BOX 0,0,128,128,RGB(130,100,50)
FOR l=1 TO 10000
col1=RND(20)
col2=RND(20)
DOT RND(128),RND(128),RGB(65+col1,50+col2,25)
NEXT l
GET IMAGE 1,0,0,32,32
IF FILE EXIST("bark.png")=0
SAVE IMAGE "bark.png",1
ENDIF
DELETE IMAGE 1
LOAD IMAGE "bark.png",1
ENDFUNCTION
FUNCTION make_leaves_texture()
CLS
FOR l=1 TO 50000
xs=RND(256)
ys=RND(256)
col=RGB(0,RND(100)+100,0)
IF RND(100)<50
col=RGB(RND(40)+40,RND(40),0)
ENDIF
DOT xs,ys,col
NEXT l
GET IMAGE 2,0,0,256,256
`set image alpha
MAKE MEMBLOCK FROM IMAGE 1,2
DELETE IMAGE 2
pos=12
FOR y=1 TO 256
FOR x=1 TO 256
b=MEMBLOCK BYTE (1,pos):INC pos
g=MEMBLOCK BYTE (1,pos):INC pos
r=MEMBLOCK BYTE (1,pos):INC pos
IF g<=0
WRITE MEMBLOCK BYTE 1,pos,0
ELSE
WRITE MEMBLOCK BYTE 1,pos,255
ENDIF
INC pos
NEXT x
NEXT y
MAKE IMAGE FROM MEMBLOCK 2,1
DELETE MEMBLOCK 1
IF FILE EXIST("leaves.png")=0
SAVE IMAGE "leaves.png",2
ENDIF
DELETE IMAGE 2
LOAD IMAGE "leaves.png",2
ENDFUNCTION
FUNCTION make_bush(obj,size#)
`leaves
MAKE OBJECT SPHERE obj,size#,20,20
`TRICK TO CHANGE objECT TO NO SHARED VERTICES FORMAT
MAKE MESH FROM OBJECT 1,obj
DELETE OBJECT obj
MAKE MEMBLOCK FROM MESH 1,1
MAKE MESH FROM MEMBLOCK 1,1
DELETE MEMBLOCK 1
MAKE OBJECT obj,1,0
LOCK VERTEXDATA FOR LIMB obj,0,1
nv=GET VERTEXDATA VERTEX COUNT()
FOR l=0 TO nv-1
xv#=GET VERTEXDATA POSITION X(l)
yv#=GET VERTEXDATA POSITION Y(l)
zv#=GET VERTEXDATA POSITION Z(l)
SET VERTEXDATA POSITION l,xv#+RND(size#/4.0)-size#/8.0,yv#+RND(size#/4.0)-size#/8.0,zv#+RND(size#/4.0)-size#/8.0
NEXT l
UNLOCK VERTEXDATA
ENDFUNCTION
``*****************************************************************************************
`GUI functions start here
FUNCTION update_gui()
IF moved=1 THEN CLS
INC blink_time
IF blink_time>blink_rate
blink_time=0
ENDIF
IF clicked>0 THEN button_pressed=0
``IF clicked=0 THEN check_for_active_window_move()
IF clicked=0 AND moved=0 THEN check_for_active_window_change()
``IF clicked=0 AND moved=0 THEN check_for_active_window_close()
IF clicked=0 AND moved=0 THEN check_for_active_button_press()
IF clicked=0 AND moved=0 THEN check_for_active_ibox_change()
IF clicked=0 AND moved=0 THEN check_for_active_ibox_input()
IF moved=0 THEN check_for_active_slider_change()
IF clicked>0 AND MOUSECLICK()=0 THEN DEC clicked:update_button_pressed_status()
draw_gui()
ENDFUNCTION
FUNCTION draw_gui()
hover=0
`draw inactive objects first
FOR l=1 TO max_gui
IF gui(l).in_use=1 AND gui(l).active=0 AND gui(l).object_type=window
`draw inactive window
INK gui(l).inactive_border_color,0
BOX gui(l).position_x-1,gui(l).position_y-1-TEXT SIZE(),gui(l).position_x+gui(l).size_x+1,gui(l).position_y+gui(l).size_y+1
INK gui(l).inactive_fill_color,0
BOX gui(l).position_x,gui(l).position_y,gui(l).position_x+gui(l).size_x,gui(l).position_y+gui(l).size_y
INK gui(l).inactive_text_color,0
TEXT gui(l).position_x+1,gui(l).position_y-1-TEXT SIZE(),gui(l).label
`draw inactive objects
FOR l2=1 TO max_gui
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=fbox
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).inactive_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
ENDIF
NEXT l2
FOR l2=1 TO max_gui
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=pbox
IF IMAGE EXIST (gui(l2).image_number)
PASTE IMAGE gui(l2).image_number,gui(l2).position_x,gui(l2).position_y
ENDIF
ENDIF
NEXT l2
FOR l2=1 TO max_gui
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=button
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).inactive_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).inactive_text_color,0
CENTER TEXT gui(l2).position_x+(gui(l2).size_x/2),gui(l2).position_y,gui(l2).label
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=tbox
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).inactive_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).inactive_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y,gui(l2).label
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=hsbox
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).inactive_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).inactive_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y," -"
TEXT gui(l2).position_x+gui(l2).size_x-TEXT WIDTH(" +"),gui(l2).position_y,"+"
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=vsbox
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).inactive_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).inactive_text_color,0
CENTER TEXT gui(l2).position_x+gui(l2).size_x/2,gui(l2).position_y,"+"
CENTER TEXT gui(l2).position_x+gui(l2).size_x/2,gui(l2).position_y+gui(l2).size_y-TEXT SIZE(),"-"
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=ibox
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).inactive_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).inactive_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y,gui(l2).label
ENDIF
NEXT l2
ENDIF
NEXT l
`draw active objects last
mx=MOUSEX()
my=MOUSEY()
FOR l=1 TO max_gui
IF gui(l).in_use=1 AND gui(l).active=1 AND gui(l).object_type=window
`draw active window
INK gui(l).active_border_color,0
BOX gui(l).position_x-1,gui(l).position_y-1-TEXT SIZE(),gui(l).position_x+gui(l).size_x+1,gui(l).position_y+gui(l).size_y+1
INK gui(l).active_fill_color,0
BOX gui(l).position_x,gui(l).position_y,gui(l).position_x+gui(l).size_x,gui(l).position_y+gui(l).size_y
INK gui(l).active_text_color,0
TEXT gui(l).position_x+1,gui(l).position_y-1-TEXT SIZE(),gui(l).label
INK RGB(255,0,0),0
BOX gui(l).position_x+gui(l).size_x-TEXT SIZE(),gui(l).position_y-TEXT SIZE(),gui(l).position_x+gui(l).size_x,gui(l).position_y-1
INK gui(l).active_text_color,0
CENTER TEXT gui(l).position_x+gui(l).size_x-(TEXT SIZE()/2),gui(l).position_y-TEXT SIZE(),"X"
FOR l2=1 TO max_gui
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=fbox
INK gui(l2).active_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).active_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
ENDIF
NEXT l2
FOR l2=1 TO max_gui
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=pbox
IF IMAGE EXIST (gui(l2).image_number)
PASTE IMAGE gui(l2).image_number,gui(l2).position_x,gui(l2).position_y
ENDIF
ENDIF
NEXT l2
FOR l2=1 TO max_gui
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=button
INK gui(l2).active_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
IF mx>= gui(l2).position_x AND mx<=gui(l2).position_x+gui(l2).size_x AND my>=gui(l2).position_y AND my<=gui(l2).position_y+gui(l2).size_y
hover=l2
IF gui(l2).pressed=1
INK RGB(255,0,0),0
ELSE
INK gui(l2).hover_over_color,0
ENDIF
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
ELSE
INK gui(l2).active_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
ENDIF
INK gui(l2).active_text_color,0
CENTER TEXT gui(l2).position_x+(gui(l2).size_x/2),gui(l2).position_y,gui(l2).label
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=tbox
INK gui(l2).active_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).active_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).active_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y,gui(l2).label
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=hsbox
INK gui(l2).active_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).active_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).hover_over_color,0
l#=gui(l2).max_value-gui(l2).min_value
l#=gui(l2).size_x/l#
l#=l#*(gui(l2).current_value-gui(l2).min_value)
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+l#,gui(l2).position_y+gui(l2).size_y
INK gui(l2).active_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y," -"
TEXT gui(l2).position_x+gui(l2).size_x-TEXT WIDTH(" +"),gui(l2).position_y,"+"
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=vsbox
INK gui(l2).active_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).active_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).hover_over_color,0
l#=gui(l2).max_value-gui(l2).min_value
l#=gui(l2).size_y/l#
l#=l#*(gui(l2).current_value-gui(l2).min_value)
BOX gui(l2).position_x,gui(l2).position_y+(gui(l2).size_y-l#),gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).active_text_color,0
CENTER TEXT gui(l2).position_x+gui(l2).size_x/2,gui(l2).position_y,"+"
CENTER TEXT gui(l2).position_x+gui(l2).size_x/2,gui(l2).position_y+gui(l2).size_y-TEXT SIZE(),"-"
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=ibox AND gui(l2).active=1
INK gui(l2).active_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
INK gui(l2).active_fill_color,0
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).active_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y,gui(l2).label
IF blink_time<blink_rate/2
INK gui(l2).active_text_color,0
ELSE
INK gui(l2).active_fill_color,0
ENDIF
TEXT gui(l2).position_x+TEXT WIDTH(gui(l2).label),gui(l2).position_y,"_"
ENDIF
IF gui(l2).on_window=l AND gui(gui(l2).on_window).in_use=1 AND gui(l2).object_type=ibox AND gui(l2).active=0
INK gui(l2).inactive_border_color,0
BOX gui(l2).position_x-1,gui(l2).position_y-1,gui(l2).position_x+gui(l2).size_x+1,gui(l2).position_y+gui(l2).size_y+1
IF mx>= gui(l2).position_x AND mx<=gui(l2).position_x+gui(l2).size_x AND my>=gui(l2).position_y AND my<=gui(l2).position_y+gui(l2).size_y
INK gui(l2).hover_over_color,0
ELSE
INK gui(l2).inactive_fill_color,0
ENDIF
BOX gui(l2).position_x,gui(l2).position_y,gui(l2).position_x+gui(l2).size_x,gui(l2).position_y+gui(l2).size_y
INK gui(l2).inactive_text_color,0
TEXT gui(l2).position_x,gui(l2).position_y,gui(l2).label
ENDIF
NEXT l2
ENDIF
NEXT l
ENDFUNCTION
FUNCTION make_gui_object(obj_type,on_win,posx,posy,sizex,sizey,caption$)
gui_num=free_gui()
IF gui_num=0 THEN GOTO exit_function
IF obj_type=window AND on_win>0 THEN GOTO exit_function
IF obj_type<window OR obj_type>pbox THEN GOTO exit_function
IF on_win>0 AND gui(on_win).in_use=0 THEN GOTO exit_function
IF obj_type>window AND gui(on_win).object_type<>window THEN GOTO exit_function
IF obj_type=window OR obj_type=button
IF TEXT WIDTH(caption$)>sizex-TEXT SIZE()-10 THEN sizex=TEXT WIDTH(caption$)+TEXT SIZE()+10
ENDIF
IF obj_type=tbox
IF TEXT WIDTH(caption$)>sizex-10 THEN sizex=TEXT WIDTH(caption$)+10
ENDIF
IF obj_type=hsbox
IF sizey<TEXT SIZE() THEN sizey=TEXT SIZE()
ENDIF
IF obj_type=vsbox
IF sizex<TEXT SIZE() THEN sizex=TEXT SIZE()
ENDIF
IF obj_type=ibox
IF sizey<TEXT SIZE() THEN sizey=TEXT SIZE()
ENDIF
IF obj_type=fbox OR obj_type=pbox
IF posx<0 THEN posx=0
IF posy<0 THEN posy=0
IF sizex>gui(on_win).size_x THEN sizex=gui(on_win).size_x
IF sizey>gui(on_win).size_y THEN sizey=gui(on_win).size_y
ENDIF
gui(gui_num).in_use=1
gui(gui_num).on_window=on_win
gui(gui_num).object_type=obj_type
gui(gui_num).position_x=posx+gui(on_win).position_x
gui(gui_num).position_y=posy+gui(on_win).position_y
gui(gui_num).size_x=sizex
gui(gui_num).size_y=sizey
gui(gui_num).label=caption$
gui(gui_num).inactive_border_color=RGB(63,63,63)
gui(gui_num).inactive_fill_color=RGB(191,191,191)
gui(gui_num).active_border_color=RGB(0,0,255)
gui(gui_num).active_fill_color=RGB(255,255,255)
gui(gui_num).active_text_color=RGB(15,15,15)
gui(gui_num).inactive_text_color=RGB(0,0,0)
gui(gui_num).hover_over_color=RGB(0,255,255)
IF obj_type=window
FOR l=1 TO max_gui
gui(l).active=0
NEXT l
gui(gui_num).active=1
update_active_objects(gui_num)
ENDIF
exit_function:
ENDFUNCTION gui_num
FUNCTION free_gui()
gui_num=0
FOR l=1 TO max_gui
IF gui(l).in_use=0 THEN gui_num=l
NEXT l
ENDFUNCTION gui_num
FUNCTION update_active_objects(win_num)
FOR l=1 TO max_gui
IF gui(l).on_window=win_num AND gui(l).object_type<>ibox
gui(l).active=1
ENDIF
NEXT l
ENDFUNCTION
FUNCTION delete_gui_object(l)
IF l<1 OR l>max_gui THEN GOTO exit_function2
gui(l).in_use=0
gui(l).active=0
gui(l).on_window=0
gui(l).object_type=0
gui(l).position_x=0
gui(l).position_y=0
gui(l).size_x=0
gui(l).size_y=0
gui(l).label=""
gui(l).inactive_border_color=0
gui(l).inactive_fill_color=0
gui(l).active_border_color=0
gui(l).active_fill_color=0
gui(l).active_text_color=0
gui(l).inactive_text_color=0
gui(l).hover_over_color=0
exit_function2:
ENDFUNCTION
`window commands **************************************************************************************************************
FUNCTION find_active_window()
aw=0
FOR l=1 TO max_gui
IF gui(l).active=1 AND gui(l).object_type=window
aw=l
ENDIF
NEXT l
ENDFUNCTION aw
FUNCTION check_for_active_window_change()
active_win=find_active_window()
mx=MOUSEX()
my=MOUSEY()
mk=MOUSECLICK()
IF mk>0 AND active_win>0
IF mx<gui(active_win).position_x OR mx>gui(active_win).position_x+gui(active_win).size_x OR my<gui(active_win).position_y-TEXT SIZE() OR my>gui(active_win).position_y+gui(active_win).size_y
FOR l=1 TO max_gui
IF gui(l).object_type=window AND gui(l).in_use=1
IF mx>=gui(l).position_x AND mx<=gui(l).position_x+gui(l).size_x AND my>=gui(l).position_y-TEXT SIZE() AND my<=gui(l).position_y+gui(l).size_y
IF clicked=0
FOR l2=1 TO max_gui
gui(l2).active=0
NEXT l2
gui(l).active=1
update_active_objects(l)
clicked=click_time
ENDIF
ENDIF
ENDIF
NEXT l
ENDIF
ENDIF
ENDFUNCTION
FUNCTION check_for_active_window_move()
moved=0
active_win=find_active_window()
mx=MOUSEX()
my=MOUSEY()
mk=MOUSECLICK()
IF mk>0 AND active_win>0
IF mx>=gui(active_win).position_x AND mx<=gui(active_win).position_x+gui(active_win).size_x-TEXT SIZE() AND my>=gui(active_win).position_y-TEXT SIZE() AND my<=gui(active_win).position_y
ox=gui(active_win).position_x
oy=gui(active_win).position_y
gui(active_win).position_x=mx-gui(active_win).size_x/2
gui(active_win).position_y=my+TEXT SIZE()/2
nx=gui(active_win).position_x-ox
ny=gui(active_win).position_y-oy
`reposition any objects on the window
FOR l=1 TO max_gui
IF gui(l).on_window=active_win AND gui(l).object_type>window AND gui(l).object_type <=pbox
gui(l).position_x=gui(l).position_x+nx
gui(l).position_y=gui(l).position_y+ny
ENDIF
NEXT l
moved=1
ENDIF
ENDIF
ENDFUNCTION
FUNCTION check_for_active_window_close()
active_win=find_active_window()
mx=MOUSEX()
my=MOUSEY()
mk=MOUSECLICK()
IF mk>0 AND active_win>0
IF mx>=gui(active_win).position_x+gui(active_win).size_x-TEXT SIZE() AND mx<=gui(active_win).position_x+gui(active_win).size_x AND my>=gui(active_win).position_y-TEXT SIZE() AND my<=gui(active_win).position_y+TEXT SIZE()
close_window(active_win)
ENDIF
ENDIF
ENDFUNCTION
FUNCTION close_window(aw)
new_active=0
IF gui(aw).in_use=1 AND gui(aw).object_type=window AND gui(aw).delete_on_close=1
gui(aw).in_use=0
gui(aw).active=0
gui(aw).on_window=0
gui(aw).object_type=0
gui(aw).position_x=0
gui(aw).position_y=0
gui(aw).size_x=0
gui(aw).size_y=0
gui(aw).label=""
gui(aw).inactive_border_color=0
gui(aw).inactive_fill_color=0
gui(aw).active_border_color=0
gui(aw).active_fill_color=0
gui(aw).active_text_color=0
gui(aw).inactive_text_color=0
gui(aw).hover_over_color=0
moved=1:clicked=click_time
`remove all asociated objects
FOR l=1 TO max_gui
IF gui(l).on_window=aw
gui(l).in_use=0
gui(l).active=0
gui(l).on_window=0
gui(l).object_type=0
gui(l).position_x=0
gui(l).position_y=0
gui(l).size_x=0
gui(l).size_y=0
gui(l).label=""
gui(l).inactive_border_color=0
gui(l).inactive_fill_color=0
gui(l).active_border_color=0
gui(l).active_fill_color=0
gui(l).active_text_color=0
gui(l).inactive_text_color=0
gui(l).hover_over_color=0
ENDIF
NEXT l
`make a new active window if any available
FOR l=1 TO max_gui
IF gui(l).object_type=window AND gui(l).in_use=1 AND new_active=0
FOR l2=1 TO max_gui
gui(l2).active=0
NEXT l2
gui(l).active=1
update_active_objects(l)
new_active=1
ENDIF
NEXT l
ENDIF
IF gui(aw).in_use=1 AND gui(aw).object_type=window AND gui(aw).delete_on_close=0
gui(aw).in_use=0
CLS
`make a new active window if any available
FOR l=1 TO max_gui
IF gui(l).object_type=window AND gui(l).in_use=1 AND new_active=0
FOR l2=1 TO max_gui
gui(l2).active=0
NEXT l2
gui(l).active=1
update_active_objects(l)
new_active=1
ENDIF
NEXT l
ENDIF
ENDFUNCTION
`button commands *****************************************************************************************************
FUNCTION check_for_active_button_press()
button_pressed=0
active_win=find_active_window()
mx=MOUSEX()
my=MOUSEY()
mk=MOUSECLICK()
IF mk>0 AND active_win>0
FOR l=1 TO max_gui
IF gui(l).on_window=active_win AND gui(l).object_type=button
IF mx>=gui(l).position_x AND mx<=gui(l).position_x+gui(l).size_x AND my>=gui(l).position_y AND my<=gui(l).position_y+gui(l).size_y
button_pressed=l
gui(l).pressed=1
clicked=click_time
ENDIF
ENDIF
NEXT l
ENDIF
ENDFUNCTION
FUNCTION update_button_pressed_status()
FOR l=1 TO max_gui
IF clicked=0 AND gui(l).pressed=1 THEN gui(l).pressed=0
NEXT l
ENDFUNCTION
`slider commands ******************************************************************************************************
FUNCTION check_for_active_slider_change()
slider_change=0
active_win=find_active_window()
mx=MOUSEX()
my=MOUSEY()
mk=MOUSECLICK()
IF mk>0 AND active_win>0
FOR l=1 TO max_gui
IF gui(l).on_window=active_win AND gui(l).object_type=hsbox
IF mx>=gui(l).position_x AND mx<=gui(l).position_x+TEXT SIZE() AND my>=gui(l).position_y AND my<=gui(l).position_y+gui(l).size_y AND gui(l).current_value-gui(l).step_value>=gui(l).min_value
gui(l).current_value=gui(l).current_value-gui(l).step_value
slider_change=l
ENDIF
ENDIF
IF gui(l).on_window=active_win AND gui(l).object_type=hsbox
IF mx>=gui(l).position_x+gui(l).size_x-TEXT SIZE() AND mx<=gui(l).position_x+gui(l).size_x AND my>=gui(l).position_y AND my<=gui(l).position_y+gui(l).size_y AND gui(l).current_value+gui(l).step_value<=gui(l).max_value
gui(l).current_value=gui(l).current_value+gui(l).step_value
slider_change=l
ENDIF
ENDIF
IF gui(l).on_window=active_win AND gui(l).object_type=vsbox
IF mx>=gui(l).position_x AND mx<=gui(l).position_x+gui(l).size_x AND my>=gui(l).position_y AND my<=gui(l).position_y+TEXT SIZE() AND gui(l).current_value+gui(l).step_value<=gui(l).max_value
gui(l).current_value=gui(l).current_value+gui(l).step_value
slider_change=l
ENDIF
ENDIF
IF gui(l).on_window=active_win AND gui(l).object_type=vsbox
IF mx>=gui(l).position_x AND mx<=gui(l).position_x+gui(l).size_x AND my>=gui(l).position_y+gui(l).size_y-TEXT SIZE () AND my<=gui(l).position_y+gui(l).size_y AND gui(l).current_value-gui(l).step_value>=gui(l).min_value
gui(l).current_value=gui(l).current_value-gui(l).step_value
slider_change=l
ENDIF
ENDIF
NEXT l
ENDIF
ENDFUNCTION
`text commands ***********************************************************************************************************
FUNCTION check_for_active_ibox_input()
active_win=find_active_window()
IF active_win>0
FOR l=1 TO max_gui
IF gui(l).on_window=active_win AND gui(l).object_type=ibox AND gui(l).active=1
inp$=INKEY$()
IF inp$<>last_key_pressed$ AND ASC(inp$)<>8 AND ASC(inp$)<>13
IF TEXT WIDTH(gui(l).label+inp$+"-")<gui(l).size_x
gui(l).label=gui(l).label+inp$
ENDIF
last_key_pressed$=inp$
ENDIF
IF ASC(inp$)=8
gui(l).label=LEFT$(gui(l).label,LEN(gui(l).label)-1)
last_key_pressed$=inp$
clicked=click_time
ENDIF
IF ASC(inp$)=13
last_text_input$=gui(l).label
input_from=l
gui(l).label=""
last_key_pressed$=inp$
clicked=click_time
ENDIF
ENDIF
NEXT l
ENDIF
ENDFUNCTION
FUNCTION check_for_active_ibox_change()
active_win=find_active_window()
mx=MOUSEX()
my=MOUSEY()
mk=MOUSECLICK()
IF mk>0 AND active_win>0
FOR l=1 TO max_gui
IF gui(l).on_window=active_win AND gui(l).object_type=ibox
IF mx>=gui(l).position_x AND mx<=gui(l).position_x+gui(l).size_x AND my>=gui(l).position_y AND my<=gui(l).position_y+gui(l).size_y
FOR l2=1 TO max_gui
IF gui(l2).object_type=ibox
gui(l2).active=0
gui(l2).label=""
ENDIF
NEXT l2
gui(l).active=1
ENDIF
ENDIF
NEXT l
ENDIF
ENDFUNCTION
Hope this comes in handy and if anyone uses it just leave a credit somewhere to me in your game.