I've started making a window-based GUI, initially this is for a hacking game I've started making but of course it will be useful for many things.
Here's my code so far, if anyone has any tips or suggestions for features I'd be grateful, I've never tried something like this before so I'd be interested to hear from others who have tried.
thanks in advance
[EDIT]
I had an empty variable in the bind window function, fixed now.
`------------------------
` Panes
` By Obese87
`------------------------
`------------------------
` SETUP
`------------------------
set display mode 1024,768,16
hide mouse
sync on : sync rate 40
`colours
DIM colour(3)
colour(0) = rgb(255,255,255)
colour(1) = rgb(100,100,255)
colour(2) = rgb(0,0,128)
colour(3) = rgb(0,0,64)
`Windows
DIM win(1,4)
win(1,0) = 1 : `0 = closed >1 = order (1 at front)
win(1,1) = 50 : `window x origin
win(1,2) = 100 : `window y origin
win(1,3) = 200 : `window width
win(1,4) = 200 : `window height
set text font "courier new" : set text size 14
`------------------------
` MAIN LOOP
`------------------------
DO
`* Control
If mouseclick() = 1
repeat : until mouseclick() = 0
If action > 0 : `stop current action
action = 0
Else : `new action
if mousey() > win(1,2) and Mousey() < win(1,2)+15 : `title bar actions
if mousex() > win(1,1) and mousex() < (win(1,1)+win(1,3))-40 : `main title bar click = move window
action = 1
endif
if mousex() > (win(1,1)+win(1,3))-32 and mousex() < (win(1,1)+win(1,3))-18 : `resize window
position mouse win(1,1)+win(1,3),win(1,2)+win(1,4) : `set mouse to bottom left of window
action = 2
endif
if mousex() > (win(1,1)+win(1,3))-18 and mousex() < (win(1,1)+win(1,3))-2 : `close window
win(1,0) = 1-win(1,0) : `pretty stupid as toggling would obviously be impossible!
endif
endif
Endif
Endif
`----
`* Calculations
SELECT action
case 1 : move_win(1) : endcase
case 2 : resize_win(1) : endcase
ENDSELECT
bind_win(1)
`----
`* Display
cls colour(3)
`if window visible then draw it
if win(1,0) = 1
draw_win(win(1,1),win(1,2),win(1,1)+win(1,3),win(1,2)+win(1,4),"Welcome To The Agency","Welcome agent. Get to work!")
endif
mouse(mousex(),mousey()) : `control mouse cursor
sync
LOOP
`------------------------
` FUNCTIONS
`------------------------
`Draw Mouse Cursor
FUNCTION mouse(x,y)
ink colour(0),0
dline(x,y,x,y+3,1) : dline(x,y,x+3,y,1) : dline(x,y,x+5,y+5,1)
ENDFUNCTION
`Draw Window
FUNCTION draw_win(l,t,r,b,title$,body$)
ink colour(2),0
box l,t,r,b : `window background
ink colour(1),0
box l+1,t+1,r-1,t+15 : `title bar
wire_box(l+2,t+17,r-2,b-2,1) : `frame
wire_box(r-17,t+17,r-2,b-2,1) : `scroll bar frame
wire_box(r-17,t+17,r-2,t+31,1) : `top scroll button frame
wire_box(r-17,t+17,r-2,b-16,1) : `bottom scroll button frame
ink colour(0),0
wire_box(r-30,t+4,r-22,t+12,2) : wire_box(r-30,t+4,r-24,t+10,1) : `resize button
dline(r-12,t+8,r-8,t+8,1) : `close button
dline(r-12,t+25,r-10,t+23,1) : dline(r-10,t+23,r-8,t+25,1) : `top scroll button
dline(r-12,b-10,r-10,b-8,1) : dline(r-10,b-8,r-8,b-10,1) : `top scroll button
title$ = clip_string(title$,win(1,3)-40)
body$ = clip_string(body$,win(1,3)-25)
text l+4,t+1,title$ : `title (add clipping if title is too long [Welc...])
text l+6,t+21,body$ : `text box (add wordwrap and scrolling)
ENDFUNCTION
`Draw Wireframe Rectangle
FUNCTION wire_box(l,t,r,b,s)
dline(l,t,r,t,s) : dline(r,t,r,b,s) : dline(r,b,l,b,s) : dline(l,b,l,t,s) : `clockwise box
ENDFUNCTION
`Dotted Line
FUNCTION dline(l,t,r,b,sp) : `sp=1 normal, sp=2 dotted
w = r-l : h = b-t
if w >= 0 then xstep = 1*sp else xstep = -1*sp
if h >= 0 then ystep = 1*sp else ystep = -1*sp
w# = ABS(w) : h# = ABS(h)
if w#=0 then w#=0.1
if h#=0 then h#=0.1
xfact# = w#/h#
yfact# = h#/w#
x = 0 : y = 0
repeat
`don't overshoot
if abs(x+xstep) > abs(w) then xstep = 0
if abs(y+ystep) > abs(h) then ystep = 0
dot x+l,y+t
if yfact# > xfact#
inc y,ystep
if ABS(x) < ABS(y*xfact#) then inc x,xstep
else
inc x,xstep
if ABS(y) < ABS(x*yfact#) then inc y,ystep
endif
until xstep = 0 and ystep = 0
ENDFUNCTION
`Bind Window To Screen
FUNCTION bind_win(w)
`bind size
if win(w,3) < 100 then win(w,3) = 100
if win(w,4) < 50 then win(w,4) = 50
`bind position
if win(w,1)+win(w,3) > screen width()-1 then win(w,1)=(Screen width()-1-win(w,3))
if win(w,2)+win(w,4) > screen height()-1 then win(w,2)=(Screen height()-1-win(w,4))
ENDFUNCTION
`Move Window
FUNCTION move_win(w)
win(w,1) = mousex()
win(w,2) = mousey()
ENDFUNCTION
`Re-Size Window
FUNCTION resize_win(w)
mx = mousex() : my = mousey()
win(w,3) = mx - win(w,1)
win(w,4) = my - win(w,2)
ENDFUNCTION
`Clip String
FUNCTION clip_string(main$,width)
While text width(main$) > width
main$ = left$(main$,len(main$)-4)
main$ = main$ + "..."
Endwhile
ENDFUNCTION main$
Click the title bar to move the window, the small square to resize and the "-" to close (click in the same spot to get it back).
Here are my designs for other things I want to create.
This game will be very similar to Uplink so if you have a look at that you'll see what I'm trying to do.
http://www.introversion.co.uk/uplink/
The world map is the only external media!!
[EDIT]
20 views and no posts? I will add more detail.

Console
I want to make a DOS style console for the game to access virtual files and manipulate them, this provides an alternative way of hacking in the game.

Text Window
I want the text window to wordwrap and have a scroll bar.

Cascading Windows
Display multiple windows at once in order.
[UPDATE]

I've added a colour gradient! wooow

It absoloutly kills the FPS though

anyone have any tips on how to speed this up?
`------------------------
` SETUP
`------------------------
set display mode 1024,768,32
hide mouse
sync on : sync rate 0
`colours
DIM colour(3)
colour(0) = rgb(255,255,255)
colour(1) = rgb(100,100,255)
colour(2) = rgb(0,0,128)
colour(3) = rgb(0,0,64)
`Windows
DIM win(1,4)
win(1,0) = 1 : `0 = closed >1 = order (1 at front)
win(1,1) = 50 : `window x origin
win(1,2) = 100 : `window y origin
win(1,3) = 200 : `window width
win(1,4) = 200 : `window height
set text font "courier new" : set text size 14
`------------------------
` MAIN LOOP
`------------------------
DO
`* Control
If mouseclick() = 1
repeat : until mouseclick() = 0
If action > 0 : `stop current action
action = 0
Else : `new action
if mousey() > win(1,2) and Mousey() < win(1,2)+15 : `title bar actions
if mousex() > win(1,1) and mousex() < (win(1,1)+win(1,3))-40 : `main title bar click = move window
action = 1
endif
if mousex() > (win(1,1)+win(1,3))-32 and mousex() < (win(1,1)+win(1,3))-18 : `resize window
position mouse win(1,1)+win(1,3),win(1,2)+win(1,4) : `set mouse to bottom left of window
action = 2
endif
if mousex() > (win(1,1)+win(1,3))-18 and mousex() < (win(1,1)+win(1,3))-2 : `close window
win(1,0) = 1-win(1,0) : `pretty stupid as toggling would obviously be impossible!
endif
endif
Endif
Endif
`----
`* Calculations
SELECT action
case 1 : move_win(1) : endcase
case 2 : resize_win(1) : endcase
ENDSELECT
bind_win(1)
`----
`* Display
cls colour(3)
`if window visible then draw it
if win(1,0) = 1
draw_win(win(1,1),win(1,2),win(1,1)+win(1,3),win(1,2)+win(1,4),"Welcome To The Agency","Welcome agent. Get to work!")
endif
mouse(mousex(),mousey()) : `control mouse cursor
sync
LOOP
`------------------------
` FUNCTIONS
`------------------------
`Draw Mouse Cursor
FUNCTION mouse(x,y)
ink colour(0),0
dline(x,y,x,y+3,1) : dline(x,y,x+3,y,1) : dline(x,y,x+5,y+5,1)
ENDFUNCTION
`Draw Window
FUNCTION draw_win(l,t,r,b,title$,body$)
`window background
b#=b : `store as float for division
For row = t to b
ink rgb(0,0,(1-(row/b#))*190+65),0
line l,row,r,row
Next row
box l+1,t+1,r-1,t+15 : `title bar
`title bar
r#=r-1
For col = l+1 to r-1
ink rgb((col/r#)*127+65,0,(1-(col/r#))*190+65),0
line col,t+1,col,t+15
Next col
ink colour(1),0
wire_box(l+2,t+17,r-2,b-2,1) : `frame
wire_box(r-17,t+17,r-2,b-2,1) : `scroll bar frame
wire_box(r-17,t+17,r-2,t+31,1) : `top scroll button frame
wire_box(r-17,t+17,r-2,b-16,1) : `bottom scroll button frame
ink colour(0),0
wire_box(r-30,t+4,r-22,t+12,2) : wire_box(r-30,t+4,r-24,t+10,1) : `resize button
dline(r-12,t+8,r-8,t+8,1) : `close button
dline(r-12,t+25,r-10,t+23,1) : dline(r-10,t+23,r-8,t+25,1) : `top scroll button
dline(r-12,b-10,r-10,b-8,1) : dline(r-10,b-8,r-8,b-10,1) : `top scroll button
title$ = clip_string(title$,win(1,3)-40)
body$ = clip_string(body$,win(1,3)-25)
text l+4,t+1,title$ : `title (add clipping if title is too long [Welc...])
text l+6,t+21,body$ : `text box (add wordwrap and scrolling)
ENDFUNCTION
`Draw Wireframe Rectangle
FUNCTION wire_box(l,t,r,b,s)
dline(l,t,r,t,s) : dline(r,t,r,b,s) : dline(r,b,l,b,s) : dline(l,b,l,t,s) : `clockwise box
ENDFUNCTION
`Dotted Line
FUNCTION dline(l,t,r,b,sp) : `sp=1 normal, sp=2 dotted
w = r-l : h = b-t
if w >= 0 then xstep = 1*sp else xstep = -1*sp
if h >= 0 then ystep = 1*sp else ystep = -1*sp
w# = ABS(w) : h# = ABS(h)
if w#=0 then w#=0.1
if h#=0 then h#=0.1
xfact# = w#/h#
yfact# = h#/w#
x = 0 : y = 0
repeat
`don't overshoot
if abs(x+xstep) > abs(w) then xstep = 0
if abs(y+ystep) > abs(h) then ystep = 0
dot x+l,y+t
if yfact# > xfact#
inc y,ystep
if ABS(x) < ABS(y*xfact#) then inc x,xstep
else
inc x,xstep
if ABS(y) < ABS(x*yfact#) then inc y,ystep
endif
until xstep = 0 and ystep = 0
ENDFUNCTION
`Bind Window To Screen
FUNCTION bind_win(w)
`bind size
if win(w,3) < 100 then win(w,3) = 100
if win(w,4) < 50 then win(w,4) = 50
`bind position
if win(w,1)+win(w,3) > screen width() then win(w,1)=(ScrX-win(w,3))
if win(w,2)+win(w,4) > screen height() then win(w,2)=(ScrY-win(w,4))
ENDFUNCTION
`Move Window
FUNCTION move_win(w)
win(w,1) = mousex()
win(w,2) = mousey()
ENDFUNCTION
`Re-Size Window
FUNCTION resize_win(w)
mx = mousex() : my = mousey()
win(w,3) = mx - win(w,1)
win(w,4) = my - win(w,2)
ENDFUNCTION
`Clip String
FUNCTION clip_string(main$,width)
While text width(main$) > width
main$ = left$(main$,len(main$)-4)
main$ = main$ + "..."
Endwhile
ENDFUNCTION main$
Your signature has been erased by a mod because it was rubbish.