tooday in history I made this program because I was lazy to listen the teacher (I'm pretty good at History and the teacher gave me his approbation
It's just a function which allow you to display (in graphic mode) interuption (like windows allerts)
The last section of the program is destinated to test it so if you want use a 'require' please remove it (as the requires on top)
They are fully usables with stylet (you can even move them on the screen)
require("draw")
showgraph()
keypad (0)
fullscreen(0)
draw.onbuffer(1)
tch = {}
-- Tchernoben's functions
-- tch.box ( pos_x, pos_y, width, height, s_title, s_body, args )
-- types of arguments :
-- pos_x, pos_y, width, height : unsigned integers ( pos_x, pos_y are the coordinates of the left-top corer )
-- s_title, s_body : strings
-- args : integers {1,2,3} (1="ok", 2="Y/N", 3="Y/N + cancel")
-- EVERY ARGUMENTS MUST BE SET WHEN THE FUNCTION IS CALLED
tch.box = function ( pos_x, pos_y, width, height, s_title, s_body, args )
repeat
pen_x,pen_y = getpen()
if pen_x ~= nil then
if pen_x >= pos_x and pen_x <= pos_x + width and pen_y >= pos_y and pen_y <= pos_y +15 then
draw.rect ( pos_x, pos_y, pos_x + width+1, pos_y + height+1, 0,0,0 )
pos_x, pos_y = pen_x - 0.5*width, pen_y - 7
end
end
draw.rect ( pos_x, pos_y, pos_x + width, pos_y + height, 1,1,0 )
draw.text ( pos_x +5, pos_y +2, s_title, 1,9,2 )
draw.line ( pos_x, pos_y +13, pos_x + width, pos_y +13 )
draw.text ( pos_x +5, pos_y +15, s_body, 1,9,0 )
draw.line ( pos_x +width+1, pos_y +1, pos_x +width+1, pos_y +height+1 )
draw.line ( pos_x +1, pos_y +height+1, pos_x +width+1, pos_y +height+1 )
if type(args) == "number" then
if args == 1 then
draw.rect ( pos_x+0.5*width-15, pos_y + 29, pos_x+0.5*width+15, pos_y + 41 )
draw.text ( pos_x+0.5*width-5, pos_y + 31, "OK", 1,9,0 )
if pen_x ~= nil then
if pen_x >= pos_x+0.5*width-15 and pen_x <= pos_x+0.5*width+15 and pen_y >= pos_y +29 and pen_y <= pos_y +41 then
repeat
draw.rect ( pos_x+0.5*width-15, pos_y + 29, pos_x+0.5*width+15, pos_y + 41, 1,1,1 )
draw.update()
until not getpen()
return (0)
end
end
end
if args == 2 then
draw.rect ( pos_x + (1/3)*(width-60), pos_y + 29, pos_x + (1/3)*(width-60)+30, pos_y +41 )
draw.rect ( pos_x + (1/3)*(width-60)+(1/3)*(width-60)+30, pos_y + 29, pos_x + (1/3)*(width-60)+(1/3)*(width-60)+60, pos_y +41 )
draw.text ( pos_x + (1/3)*(width-60)+7, pos_y + 31, "YES", 1,9,0 )
draw.text ( pos_x + (1/3)*(width-60)+(1/3)*(width-60)+40, pos_y + 31, "NO", 1,9,0 )
if pen_x ~= nil then
if pen_x >= pos_x + (1/3)*(width-60) and pen_x <= pos_x + (1/3)*(width-60)+30 and pen_y >= pos_y + 29 and pen_y <= pos_y +41 then
repeat
draw.rect ( pos_x + (1/3)*(width-60), pos_y + 29, pos_x + (1/3)*(width-60)+30, pos_y +41, 1,1,1 )
draw.update()
until not getpen()
return(1)
end
if pen_x >= pos_x + (1/3)*(width-60)+(1/3)*(width-60)+30 and pen_x <= os_x + (1/3)*(width-60)+(1/3)*(width-60)+60 and pen_y >= pos_y + 29 and pen_y <= pos_y +41 then
repeat
draw.rect ( pos_x + (1/3)*(width-60)+(1/3)*(width-60)+30, pos_y + 29, pos_x + (1/3)*(width-60)+(1/3)*(width-60)+60, pos_y +41, 1,1,1 )
draw.update()
until not getpen()
return(2)
end
end
end
if args == 3 then
draw.rect ( pos_x + (1/4)*(width-90), pos_y +29, pos_x + (1/4)*(width-90)+30, pos_y + 41 )
draw.rect ( pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90), pos_y +29, pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30, pos_y +41)
draw.rect ( pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90), pos_y +29, pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90)+30, pos_y +41 )
draw.text ( pos_x + (1/3)*(width-60)-6, pos_y + 31, "YES", 1,9,0 )
draw.text ( pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+10, pos_y + 31, "NO", 1,9,0 )
draw.text ( pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90)+4, pos_y +31, "STOP", 1,9,0 )
if pen_x ~= nil then
if pen_x >= pos_x + (1/4)*(width-90) and pen_x <= pos_x + (1/4)*(width-90)+30 and pen_y >= pos_y +29 and pen_y <= pos_y + 41 then
repeat
draw.rect ( pos_x + (1/4)*(width-90), pos_y +29, pos_x + (1/4)*(width-90)+30, pos_y + 41, 1,1,1 )
draw.update()
until not getpen()
return(1)
end
if pen_x >= pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90) and pen_x <= pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 and pen_y >= pos_y +29 and pen_y <= pos_y + 41 then
repeat
draw.rect ( pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90), pos_y +29, pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30, pos_y +41, 1,1,1 )
draw.update()
until not getpen()
return(2)
end
if pen_x >= pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90) and pen_x <= pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 and pen_y >= pos_y +29 and pen_y <= pos_y + 41 then
repeat
draw.rect ( pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90), pos_y +29, pos_x + (1/4)*(width-90)+30 + (1/4)*(width-90)+30 + (1/4)*(width-90)+30, pos_y +41, 1,1,1 )
draw.update()
until not getpen()
return(3)
end
end
end
end
draw.update ()
until false
end
draw.clear ()
for i=1, 3 do
tch.box ( 10,20,120,50, "Question","N' "..i, i )
end



