%the module
unit
module G % for (G)raphic
export button, procButton, colorChange, fontChange
%Mouse Vars
var mx, my, mz : int
%Font, I made this a universal var so it could be changed.
var bFont := Font.New ("OCR A Std:12")
var c1, c2, fc : int
c1 := 29 %Top color
c2 := 25 %Bottom color
fc := black %font color
% When the button is "pressed" the colors alternate
function button (x, y : int, text : string) : boolean
Mouse.Where (mx, my, mz)
var w := Font.Width (text, bFont) + 10
if mx > x and mx < x + w and my > y and my < y + 20 and mz = 1 then
Draw.FillBox (x, y, x + w, y + 20, c1)
Draw.FillBox (x + 2, y + 1, x + w - 1, y + 20 - 2, c2)
Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
View.Update
delay (200)
result true
else
Draw.FillBox (x, y, x + w, y + 20, c2) %25
Draw.FillBox (x + 1, y + 2, x + w - 2, y + 20 - 1, c1) %29
Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
View.Update
result false
end if
end button
procedure procButton (x, y : int, text : string, po : proc xx)
Mouse.Where (mx, my, mz)
var w := Font.Width (text, bFont) + 10
if mx > x and mx < x + w and my > y and my < y + 20 and mz = 1 then
Draw.FillBox (x, y, x + w, y + 20, c1)
Draw.FillBox (x + 2, y + 1, x + w - 1, y + 20 - 2, c2)
Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
View.Update
po
delay (200)
else
Draw.FillBox (x, y, x + w, y + 20, c2) %25
Draw.FillBox (x + 1, y + 2, x + w - 2, y + 20 - 1, c1) %29
Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
View.Update
end if
end procButton
proc colorChange (front, back, font : int)
c1 := front
c2 := back
fc := font
end colorChange
proc fontChange (newFont : string)
bFont := Font.New (newFont)
end fontChange
end G
|