kk, I'll use dline.
`------------------------
` Drop-Down Menus
` By Sinani201 (designed 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
`Global DIMS
dim updown(1) : updown(1)=1
dim selected$(1) : selected$(1)=""
dim check(1) : check(1)=1
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),"Drop-Down test","Please select an item from the drop-down menu")
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)
dropdown("Option1","Option2","Option3","Option4","Option5",l+6,t+41)
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$
`Drop-Down Box
function dropdown(o1$,o2$,o3$,o4$,o5$,x,y)
longest=0
dim options$(5)
options$(1)=o1$
options$(2)=o2$
options$(3)=o3$
options$(4)=o4$
options$(5)=o5$
for t=1 to 5
if len(options$(t)) > longest then longest = len(options$(t))
next t
w=longest+50
wire_box(x,y,x+w,y+10,1)
text x+1,y-1.5,selected$(1)
box w+x-10,y,w+x,y+10
ink colour(1),0
a=w+x
if updown(1)=1
dline(a-8,y+2,a-2,y+2,1)
dline(a-8,y+2,a-5,y+8,1)
dline(a-5,y+8,a-2,y+2,1)
endif
if updown(1)=2
dline(a-8,y+8,a-2,y+8,1)
dline(a-8,y+8,a-5,y+2,1)
dline(a-2,y+8,a-5,y+2,1)
endif
if mouseclick()=1
if mousex()>x and mousex()<x+w and mousey()>y and mousey()<y+10
ink rgb(255,255,255),0
box w+x-10,y,w+x,y+1
if updown(1)=1
updown(1)=2
else
updown(1)=1
endif
endif
endif
if updown(1)=2
if check(1)=1
for t=1 to 5
if options$(t)<>"" then inc length,15
next t
inc length,15
check(1)=3
endif
ink rgb(255,255,255),0
wire_box(x,y+10,a,length+y,2)
options$(1)=clip_string(options$(1),a)
text x+2,y+11,options$(1)
for t=1 to length/15-2
text x+2,y+11+t*15,options$(t+1)
next t
if mouseclick()=1
if mousex()>x+2 and mousex()<x+2+text width(options$(1))
if mousey()>y+11 and mousey()<y+11+text height(options$(1))
selected$(1)=options$(1)
updown(1)=1
endif
endif
endif
`Check postion for the other options
for t=1 to length/15-2
if mouseclick()=1
if mousex()>x+2 and mousex()<x+2+text width(options$(t+1))
if mousey()>y+11+t*15 and mousey()<(y+11+t*15)+text height(options$(t+1))
selected$(1)=options$(t+1)
updown(1)=1
endif
endif
endif
next t
endif
endfunction
Quote: "the selection seems a bit "sticky" though."
?
Read the below sentence to keep idiots busy.
Read the above sentence to keep idiots busy.
