-
Notifications
You must be signed in to change notification settings - Fork 1
/
DrawOverlayRect_no.nim
69 lines (60 loc) · 1.58 KB
/
DrawOverlayRect_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
import fltk_main
# test of:
# DrawOverlayRect
# DrawOverlayClear
type DRAWJOB = object
state: integer
x,y,x2,y2: long
proc DrawCB(self: ptr FL_WIDGET): long {.cdecl.}=
var dj: ptr DRAWJOB = cast[ptr DRAWJOB](Fl_WidgetGetUserData(self))
var x = dj[].x
var y = dj[].y
var w = dj[].x2-x
var h = dj[].y2-y
case dj[].state:
of 2:
DrawOverlayClear()
DrawOverlayRect x,y,w,h
of 3:
DrawOverlayClear()
DrawSetRGBColor 0, 0, 255
if w < 0 :
x += w
w = -w
if h < 0 :
y += h
h = -h
DrawRect x,y,w,h
dj[].state = 0
else:
return 1
return 1
proc HandleCB(self: ptr FL_WIDGET, event: FL_EVENT) :long {.cdecl.}=
var dj: ptr DRAWJOB = cast[ptr DRAWJOB](Fl_WidgetGetUserData(self))
case int(event):
of FL_EVENT_PUSH:
dj[].state=1
dj[].x=Fl_EventX()
dj[].y=Fl_EventY()
of FL_EVENT_DRAG:
dj[].state=2
dj[].x2=Fl_EventX()
dj[].y2=Fl_EventY()
of FL_EVENT_RELEASE:
if dj[].state == 2:
dj[].state=3
else:
return 0
Fl_WidgetRedraw self
return 1
#
# main
#
var win = Fl_WindowNew(640,480,"DrawOverlayRect.nim")
var box = Fl_BoxExNew(0,0,640,480)
var dj: DRAWJOB
Fl_WidgetSetUserData box,dj
Fl_BoxExSetDrawCB box,DrawCB
Fl_BoxExSetHandleCB box,HandleCB
Fl_WindowShow win
Fl_Run()