/
scribble.rb
executable file
·175 lines (148 loc) · 5.06 KB
/
scribble.rb
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env ruby
# coding: utf-8
require 'fxruby-enhancement'
include Fox
include Fox::Enhancement::Mapper
fx_app :app do
app_name "Scribble"
vendor_name "Example"
fx_main_window (:scribble_window) {
title "Scribble Application"
width 800
height 600
fx_horizontal_frame (:contents) {
opts LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y
pad_left 0
pad_right 0
pad_top 0
pad_bottom 0
fx_vertical_frame (:canvas_frame) {
opts FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT
pad_left 10
pad_right 10
pad_top 10
pad_bottom 10
fx_label {
text "Canvas Frame"
opts JUSTIFY_CENTER_X|LAYOUT_FILL_X
}
fx_horizontal_separator { opts SEPARATOR_GROOVE|LAYOUT_FILL_X }
fx_canvas (:canvas) {
opts LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT
instance { |c|
c.sel_paint { |sender, sel, event|
fx_dc :canvas, event do |dc|
dc.foreground = ref(:canvas).backColor
dc.fillRectangle(event.rect.x, event.rect.y, event.rect.w, event.rect.h)
end
}
c.sel_leftbuttonpress {
ref(:canvas).grab
@mouseDown = true
}
c.sel_motion { |sender, sel, event|
if @mouseDown
# Get device context for the canvas
fx_dc (:canvas) { |dc|
# Set the foreground color for drawing
dc.foreground = @drawColor
# Draw a line from the previous mouse coordinates to the current ones
if ref(:mirror_mode).value
cW = ref(:canvas).width
cH = ref(:canvas).height
dc.drawLine(cW-event.last_x, event.last_y, cW-event.win_x, event.win_y)
dc.drawLine(event.last_x, cH-event.last_y, event.win_x, cH-event.win_y)
dc.drawLine(cW-event.last_x, cH-event.last_y, cW-event.win_x, cH-event.win_y)
end
dc.drawLine(event.last_x, event.last_y, event.win_x, event.win_y)
# We have drawn something, so now the canvas is dirty
@dirty = true
}
end
}
c.sel_leftbuttonrelease { |sender, sel, event|
ref(:canvas).ungrab
if @mouseDown
# Get device context for the canvas
fx_dc (:canvas) { |dc|
# Set the foreground color for drawing
dc.foreground = @drawColor
# Draw a line from the previous mouse coordinates to the current ones
dc.drawLine(event.last_x, event.last_y, event.win_x, event.win_y)
# We have drawn something, so now the canvas is dirty
@dirty = true
# Mouse no longer down
@mouseDown = false
}
end
}
}
}
}
fx_vertical_frame (:button_frame) {
opts FRAME_SUNKEN|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT
pad_left 10
pad_right 10
pad_top 10
pad_bottom 10
fx_label {
text "Button Frame"
opts JUSTIFY_CENTER_X|LAYOUT_FILL_X
}
fx_horizontal_separator {opts SEPARATOR_RIDGE|LAYOUT_FILL_X }
as (:app) {
fx_data_target (:mirror_mode) { value false }
}
fx_check_button {
text "Mirror"
target refc(:mirror_mode)
selector FXDataTarget::ID_VALUE
opts CHECKBUTTON_NORMAL|LAYOUT_FILL_X
}
fx_button (:clear_button) {
text "&Clear"
opts FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT
pad_left 10
pad_right 10
pad_top 5
pad_bottom 5
instance { |b|
b.sel_command {
fx_dc :canvas do |dc|
dc.foreground = ref(:canvas).backColor
dc.fillRectangle(0, 0, ref(:canvas).width, ref(:canvas).height)
@dirty = false
end
}
b.sel_update { |sender, sel, ptr|
message = @dirty ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE
sender.handle(ref(:scribble_window), MKUINT(message, SEL_COMMAND), nil)
}
}
}
fx_button {
text "&Exit"
selector FXApp::ID_QUIT
target refc(:app)
opts FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT
pad_left 10
pad_right 10
pad_top 5
pad_bottom 5
}
}
}
instance { |w|
@drawColor = "red"
@mouseDown = false
@dirty = false
w.show PLACEMENT_SCREEN
}
}
end
if __FILE__ == $0
# alias for fox_component is fxc
fox_component :app do |app|
app.launch
end
end