Mouse.ButtonChoose ("multibutton")
var bfont : int := Font.New ("System:12")
type txtbox :
record
text : string
active, cd, drawn : boolean
ctime : int
end record
function timedelay (var r : int, t : int) : boolean
var tt : int
if r = 0 then
clock (r)
result false
end if
clock (tt)
if tt - r >= t then
r := tt
result true
else
result false
end if
end timedelay
function mouseover (x1, y1, x2, y2 : int, var button : int) : boolean
var x, y, b : int
mousewhere (x, y, b)
button := b
if x >= x1 and x <= x2 then
if y >= y1 and y <= y2 then
result true
end if
end if
result false
end mouseover
procedure button (x1, y1, x2, y2, bgcolor, textcolor : int, s : string, var pressed : boolean)
var kd := 0
if mouseover (x1, y1, x2, y2, kd) then
drawline (x1, y1, x2, y1, 30)
drawline (x2, y1, x2, y2, 30)
drawline (x2, y2, x1, y2, 25)
drawline (x1, y2, x1, y1, 25)
if kd = 1 then
pressed := true
drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, 1)
Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2) + 1, ((y1 + ((y2 - y1) div 2)) - 4) - 1, bfont, 14)
else
pressed := false
drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, bgcolor)
Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2) + 1, ((y1 + ((y2 - y1) div 2)) - 4) - 1, bfont, textcolor)
end if
else
drawline (x1, y1, x2, y1, 25)
drawline (x2, y1, x2, y2, 25)
drawline (x2, y2, x1, y2, 30)
drawline (x1, y2, x1, y1, 30)
drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, bgcolor)
Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2), (y1 + ((y2 - y1) div 2)) - 4, bfont, textcolor)
end if
end button
procedure button2 (x1, y1, x2, y2, c, textcolor : int, s : string)
drawline (x1, y1, x2, y1, 30)
drawline (x2, y1, x2, y2, 30)
drawline (x2, y2, x1, y2, 25)
drawline (x1, y2, x1, y1, 25)
drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, c)
%Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2), (y1 + ((y2 - y1) div 2)) - 4, bfont, textcolor)
Font.Draw (s, x1 + 5, (y1 + ((y2 - y1) div 2)) - 4, bfont, textcolor)
end button2
procedure textfield (x, y, l, c, cb, cursortime : int, var txt : txtbox)
var ch : char
var st, st2 := txt.text
var keydown := 0
if not txt.drawn then
button2 (x, y, x + l, y + 20, c, cb, st)
txt.drawn := true
end if
if txt.active then
if hasch then
ch := getchar
if ch = chr (8) then
st2 := st
st := ""
for i : 1 .. Str.length (st2) - 1
st := st + st2 (i)
end for
else
if ch not= chr (10) then
if (Font.Width (st, bfont) + 10) < l then
st := st + ch
end if
end if
end if
button2 (x, y, x + l, y + 20, c, cb, st)
txt.text := st
end if
if timedelay (txt.ctime, cursortime) then
if txt.cd then
drawline (x + Font.Width (st, bfont) + 7, y + 3, x + Font.Width (st, bfont) + 7, y + 17, c)
txt.cd := not txt.cd
else
drawline (x + Font.Width (st, bfont) + 7, y + 3, x + Font.Width (st, bfont) + 7, y + 17, cb)
txt.cd := not txt.cd
end if
View.Update
delay (5)
end if
if not mouseover (x, y, x + l, y + 20, keydown) and (keydown not= 0) then
txt.active := false
end if
else
if mouseover (x, y, x + l, y + 20, keydown) and (keydown not= 0) then
txt.active := true
end if
end if
end textfield
procedure resettextbox (var txt : txtbox)
txt.text := ""
txt.ctime := 0
txt.cd := false
txt.active := false
txt.drawn := false
end resettextbox
procedure resetmenu (var arr : array 1 .. * of boolean)
for i : 1 .. upper (arr)
arr (i) := false
end for
end resetmenu
procedure normalizekeyboard
if hasch then
var ch := getchar
end if
end normalizekeyboard
% main program starts here% main program starts here% main program starts here
% main program starts here% main program starts here% main program starts here
% main program starts here% main program starts here% main program starts here
colorback (8)
cls
View.Set ("offscreenonly")
var txt1 : txtbox % Declaring a textbox named txt1
resettextbox (txt1) % Giving the txt1 null values so we dont get errors
var menu : array 1 .. 3 of boolean %declaring an array of booleans for our button menu
resetmenu (menu) %giving our menu null value so we dont get errors
loop
textfield (100, 100, 350, white, black, 1000, txt1)%draws a textfield at coord 100,100 and length of 350 background color white and textcolorback cursor blinks every 1 second and the values will be assigned to txt1
button (500, 100, 600, 120, grey, black, "Button 1", menu (1))%draws a button with coordinates 500, 100, 600, 120 and grey for background color and black for text color
button (500, 130, 600, 150, grey, black, "Button 2", menu (2))
button (500, 160, 600, 180, grey, black, "Button 3", menu (3))
normalizekeyboard %We have to put this function at the end so we dont face keyboard bugs
locate (1, 1)
put "txt1.text :", txt1.text
put "txt1.active :", txt1.active
put "txt1.drawn :", txt1.drawn
put "button 1:", menu (1)
put "button 2:", menu (2)
put "button 3:", menu (3)
View.Update
delay (5)
end loop
|