Class: MINT::CIO
- Inherits:
-
Interactor
show all
- Includes:
- Cassowary
- Defined in:
- lib/MINT-core/model/cui/gfx/CIO.rb
Direct Known Subclasses
ARFrame, BasicText, Button, CIC, HTMLHead, Image, Label, MinimalOutputSlider, MinimalVerticalOutputSlider, ProgressBar, RadioButton, Slider
Constant Summary
Constants inherited
from Interactor
Interactor::PUBLISH_ATTRIBUTES
Class Method Summary
collapse
Instance Method Summary
collapse
-
#calculate_position(parent_cic, elements, solver, i, b, layer = 0) ⇒ Object
(also: #cio_calculate_position)
-
#calculateMinimumSize(border = 5) ⇒ Object
-
#down ⇒ Object
-
#getAIO ⇒ Object
-
#getSCXML ⇒ Object
-
#highlight_down ⇒ Object
-
#highlight_left ⇒ Object
-
#highlight_right ⇒ Object
-
#highlight_up ⇒ Object
-
#initialize_points ⇒ Object
-
#left ⇒ Object
-
#pos(x = -1,, y = -1)) ⇒ Object
-
#print ⇒ Object
-
#right ⇒ Object
-
#setFixedPositionConstraints(solver) ⇒ Object
-
#setFixedSizeConstraints(solver) ⇒ Object
-
#setMinimumSizeConstraints(solver) ⇒ Object
-
#setTableElementConstraints(solver, elements, cic, act_col, act_row, i, b) ⇒ Object
-
#size(width = -1,, height = -1)) ⇒ Object
-
#store_calculated_values_in_model ⇒ Object
-
#up ⇒ Object
Methods inherited from Interactor
class_from_channel_name, #create_attribute_channel_name, create_channel_name, #create_channel_w_name, get, get_dm, #init_statemachine, #is_in?, #new_states, notify, #process_event, #process_event!, #process_event_vars, #publish_update, #states, #states=, #sync_event, #sync_states, #to_dot, wait
#restart_timeout, #start_timeout, #stop_timeout
Class Method Details
.createCIOfromAIO(e, layer) ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 252
def CIO.createCIOfromAIO(e,layer)
p "creating CIO for #{e.class}"
case e.class.name
when "MINT::AIContainer","MINT::AISinglePresence"
aic = AIContainer.first(:name=>e.name)
elements_count = aic.children.length
elements_count = 1 if elements_count== 0
cio = CIC.create(:name=>e.name,:cols=>1,:rows=>elements_count,:layer =>layer+1)
p "create #{e.name} rows: #{elements_count}"
when "MINT::AIMultiChoice"
cio = CheckBoxGroup.create(:name=>e.name,:layer =>layer+1)
when "MINT::AISingleChoice"
cio = RadioButtonGroup.create(:name=>e.name,:layer =>layer+1)
when "MINT::AIMultiChoiceElement"
cio = CheckBox.create(:name=>e.name,:layer =>layer+1)
when "MINT::AISingleChoiceElement"
cio = RadioButton.create(:name=>e.name,:layer =>layer+1)
when "MINT::AIOUTContext"
cio = BasicText.create(:name=>e.name,:layer =>layer+1)
when "MINT::AIINReference"
cio = Label.create(:name=>e.name,:layer =>layer+1)
when "MINT::AICommand"
cio = Button.create(:name=>e.name,:layer =>layer+1)
else
cio = CIO.create(:name=>e.name,:layer =>layer+1)
end
p "Created #{cio.inspect}"
return cio
end
|
.getModel ⇒ Object
6
7
8
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 6
def self.getModel
"cui-gfx"
end
|
Instance Method Details
#calculate_position(parent_cic, elements, solver, i, b, layer = 0) ⇒ Object
Also known as:
cio_calculate_position
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 161
def calculate_position(parent_cic,elements,solver,i,b,layer =0)
if self.process_event("position")
p "cio #{self.inspect} parent #{parent_cic.inspect}"
self.layer=layer
setMinimumSizeConstraints(solver)
setTableElementConstraints(solver,elements,parent_cic,self.col,self.row,i,b) if elements and elements.length>0
self.process_event("calculated")
else
p "cio fixed#{self.inspect}"
setFixedPositionConstraints(solver)
setFixedSizeConstraints(solver)
end
end
|
#calculateMinimumSize(border = 5) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 143
def calculateMinimumSize(border = 5)
if text
label = Magick::Draw.new
label.font = fontname
label.text_antialias(true)
label.font_style=Magick::NormalStyle
label.font_weight=Magick::NormalWeight
label.gravity=Magick::CenterGravity
label.text(0,0,text)
label.pointsize = fontsize
metrics = label.get_type_metrics(text)
self.minheight=metrics.height+2*border
self.minwidth=metrics.width+2*border
end
end
|
#down ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 81
def down
p = super
if p
CIO.get(CIO.getModel,p)
else
nil
end
end
|
#getAIO ⇒ Object
50
51
52
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 50
def getAIO
AIO.get(AIO.getModel(),name)
end
|
#getSCXML ⇒ Object
287
288
289
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 287
def getSCXML
"#{File.dirname(__FILE__)}/cio.scxml"
end
|
#highlight_down ⇒ Object
302
303
304
305
306
307
308
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 302
def highlight_down
if (self.down)
self.down.process_event("highlight")
else
return nil end
end
|
#highlight_left ⇒ Object
310
311
312
313
314
315
316
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 310
def highlight_left
if (self.left)
self.left.process_event("highlight")
else
return nil end
end
|
#highlight_right ⇒ Object
318
319
320
321
322
323
324
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 318
def highlight_right
if (self.right)
self.right.process_event("highlight")
else
return nil end
end
|
#highlight_up ⇒ Object
294
295
296
297
298
299
300
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 294
def highlight_up
if (self.up)
self.up.process_event("highlight")
else
return nil end
end
|
#initialize_points ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 91
def initialize_points
@pos = Cassowary::ClPoint.new()
if (self.x and self.y)
@pos = Cassowary::ClPoint.new(self.x,self.y)
end
@size = Cassowary::ClPoint.new()
if (self.width and self.height)
@size = Cassowary::ClPoint.new(self.width, self.height)
elsif (self.minwidth and self.minheight)
@size = Cassowary::ClPoint.new(self.minwidth, self.minheight)
end
true
end
|
#left ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 54
def left
p = super
if p
CIO.get(CIO.getModel,p)
else
nil
end
end
|
#pos(x = -1,, y = -1)) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 114
def pos(x=-1,y=-1)
if (x > -1 and y> -1)
@pos = Cassowary::ClPoint.new(x,y)
elsif not @pos
@pos = Cassowary::ClPoint.new
if (attribute_get(:x) and attribute_get(:y))
@pos = Cassowary::ClPoint.new(attribute_get(:x),attribute_get(:y))
end
end
return @pos
end
|
#print ⇒ Object
327
328
329
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 327
def print
puts "\"#{self.name}\",#{pos.Xvalue}, #{pos.Yvalue}, #{size.Xvalue}, #{size.Yvalue}"
end
|
#right ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 63
def right
p = super
if p
CIO.get(CIO.getModel,p)
else
nil
end
end
|
#setFixedPositionConstraints(solver) ⇒ Object
179
180
181
182
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 179
def setFixedPositionConstraints(solver)
solver.AddConstraint(ClLinearEquation.new(self.pos.X,ClLinearExpression.new(self.pos.X.Value),Cassowary.ClsStrong))
solver.AddConstraint(ClLinearEquation.new(self.pos.Y,ClLinearExpression.new(self.pos.Y.Value),Cassowary.ClsStrong))
end
|
#setFixedSizeConstraints(solver) ⇒ Object
184
185
186
187
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 184
def setFixedSizeConstraints(solver)
solver.AddConstraint(ClLinearEquation.new(self.size.X,ClLinearExpression.new(self.size.X.Value),Cassowary.ClsStrong))
solver.AddConstraint(ClLinearEquation.new(self.size.Y,ClLinearExpression.new(self.size.Y.Value),Cassowary.ClsStrong))
end
|
#setMinimumSizeConstraints(solver) ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 189
def setMinimumSizeConstraints(solver)
if self.minwidth
solver.AddConstraint(ClLinearInequality.new(self.size.X,CnGEQ,ClLinearExpression.new(self.minwidth),Cassowary.ClsStrong))
else
solver.AddConstraint(ClLinearInequality.new(self.size.X,CnGEQ,ClLinearExpression.new(0),Cassowary.ClsStrong))
end
if self.minheight
solver.AddConstraint(ClLinearInequality.new(self.size.Y,CnGEQ,ClLinearExpression.new(self.minheight),Cassowary.ClsStrong))
else
solver.AddConstraint(ClLinearInequality.new(self.size.Y,CnGEQ,ClLinearExpression.new(0),Cassowary.ClsStrong))
end
end
|
#setTableElementConstraints(solver, elements, cic, act_col, act_row, i, b) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 210
def setTableElementConstraints(solver,elements, cic,act_col,act_row,i,b)
total_cols = cic.cols
total_rows = cic.rows
if (act_col == 0)
solver.AddConstraint(ClLinearEquation.new(self.pos.X,ClLinearExpression.new(cic.pos.X.Value).Plus(ClLinearExpression.new(b)),Cassowary.ClsStrong))
else
solver.AddConstraint(ClLinearEquation.new(self.pos.X,ClLinearExpression.new(elements[i-1].pos.X.Value).Plus(ClLinearExpression.new(elements[i-1].size.X)).Plus(ClLinearExpression.new(b))))
end
if (i<total_cols)
solver.AddConstraint(ClLinearEquation.new(self.pos.Y,ClLinearExpression.new(cic.pos.Y.Value).Plus(ClLinearExpression.new(b))))
else
solver.AddConstraint(ClLinearEquation.new(self.pos.Y,ClLinearExpression.new(elements[i-total_cols].pos.Y.Value).Plus(ClLinearExpression.new(elements[i-total_cols].size.Y)).Plus(ClLinearExpression.new(b))))
end
solver.AddConstraint(ClLinearEquation.new(self.size.X,ClLinearExpression.new(
cic.size.X.Value).Divide(total_cols).Minus(ClLinearExpression.new(((total_cols+1)*b)/total_cols)),Cassowary.ClsWeak
))
solver.AddConstraint(ClLinearEquation.new(self.size.Y,ClLinearExpression.new(
cic.size.Y.Value).Divide(total_rows).Minus(ClLinearExpression.new(((total_rows+1)*b)/total_rows)),Cassowary.ClsWeak
))
end
|
#size(width = -1,, height = -1)) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 128
def size(width=-1,height=-1)
if (width > -1 and height> -1)
@size = Cassowary::ClPoint.new(width,height)
elsif not @size
@size = Cassowary::ClPoint.new
if (attribute_get(:width) and attribute_get(:height))
@size = Cassowary::ClPoint.new(attribute_get(:width), attribute_get(:height))
elsif (attribute_get(:minwidth) and attribute_get(:minheight))
@size = Cassowary::ClPoint.new(attribute_get(:minwidth), attribute_get(:minheight))
end
end
return @size
end
|
#store_calculated_values_in_model ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 105
def store_calculated_values_in_model
attribute_set(:x,pos.Xvalue)
attribute_set(:y,pos.Yvalue)
attribute_set(:width,size.Xvalue)
attribute_set(:height,size.Yvalue)
end
|
#up ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/MINT-core/model/cui/gfx/CIO.rb', line 72
def up
p = super
if p
CIO.get(CIO.getModel,p)
else
nil
end
end
|