-
Notifications
You must be signed in to change notification settings - Fork 1
/
Fl_Canvas01_no.nim
89 lines (69 loc) · 1.95 KB
/
Fl_Canvas01_no.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import fltk_main
#~ 'test of Fl_Canvas
proc `\` (x: long; y: long): long = long(x.float / y.float)
proc CanvasDrawCB (me: pointer,
dstX: var long, dstY: var long,
cpyW: var long, cpyH: var long,
srcX: var long, srcY: var long) {.cdecl.} =
var
xp {.global.}:long = -1000
xs {.global.}:long = 1
yp {.global.}:long = -1000
ys {.global.}:long = 1
sw {.global.}:long = 0
sh {.global.}:long = 0
#~ var me = cast[ptr Fl_Canvas](me)
var par = Fl_WidgetGetParent(me)
var x = Fl_WidgetGetX(me)
var y = Fl_WidgetGetY(me)
var w = cpyW #Fl_WidgetGetW(me)
var h = cpyH #Fl_WidgetGetH(me)
var x2 = x + w
var y2 = y + h
echo x
echo y
echo w
echo h
if sw == 0 or sh == 0 :
DrawSetFont Fl_HELVETICA_BOLD, 50
sw = DrawGetStrWidth("Canvas")
sh = DrawGetFontHeight() - DrawGetFontDescent()
if xp == -1000 :
xp=x+w\2-sw\2
if yp == -1000 :
yp=y+h\2-sh\2
DrawPushClip 0, 0, w, h
DrawSetColor FL_WHITE
DrawRectFill 0, 0, w, h
DrawSetColor FL_BLACK
DrawRect 0, 0, w, h
DrawSetColor FL_BLACK
DrawStr "Canvas", xp+3, yp+3
DrawSetColor FL_RED
DrawStr "Canvas", xp , yp
DrawPopClip()
xp += xs # move x position
if xp < 1 :
xp = 0
xs *= -1
elif (xp+sw+3) >= w :
xs *= -1
xp = w-(sw+3)
yp += ys # move y position
if yp < sh-y :
yp = sh-y
ys *= -1
elif yp >= h :
ys *= -1
yp = h
proc TimeoutCB (can: pointer){.cdecl.} =
Fl_WidgetDraw can
Fl_RepeatTimeout 1.0/80, TimeoutCB, can
var win = Fl_Double_WindowNew(640, 120, "Fl_Canvas resize me ...")
var can = Fl_CanvasNew(10, 10, Fl_WidgetGetW(win)-20, Fl_WidgetGetH(win)-20)
Fl_CanvasSetDrawCB can, CanvasDrawCB
Fl_WindowSizeRange win, 240, 100
Fl_GroupSetResizable win, can
Fl_WindowShow win
Fl_AddTimeout 1.0, TimeoutCB, can
Fl_Run()