Class: Shoes

Inherits:
Object show all
Defined in:
lib/plugins/systray.rb,
lib/shoes/basic.rb,
lib/shoes/style.rb,
lib/shoes/colors.rb,
lib/shoes/manual.rb,
lib/shoes/widget.rb,
lib/plugins/httpd.rb,
lib/plugins/video.rb,
lib/plugins/video.rb,
lib/plugins/thread.rb,
lib/plugins/thread.rb,
lib/shoes/download.rb,
lib/shoes/projector.rb,
lib/plugins/code_box.rb,
lib/plugins/treeview.rb,
lib/shoes/helper_methods.rb

Overview

syst_icon HAPPY_ICON,

syst_add_button "Edit configuration"  {|state| edit_conf() } ,

syst_add_button “Execute Test” {|state| $win.show; update(true) }, syst_add_sepratator syst_add_check “Option” {|state| }, syst_quit_button true

Direct Known Subclasses

Manual

Defined Under Namespace

Modules: Mod, Mod2 Classes: Background, Banner, Basic, Border, Button, Caption, Check, CodeBox, Download, EditBox, EditLine, Image, Inscription, Line, ListBox, Native, Oval, Para, Pattern, Progress, Radio, Rect, Shape, ShapeBase, Star, Subtitle, Tagline, TextBlock, Title, ToggleButton, Video, Widget

Class Method Summary collapse

Class Method Details

.call_back_procs(app) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/shoes/helper_methods.rb', line 217

def self.call_back_procs app
  init_contents app.cslot.contents
  app.cslot.width, app.cslot.height = app.width, app.height
  scrollable_height = contents_alignment app.cslot
  repaint_all app.cslot
  mask_control app
  repaint_all_by_order app
  repaint_textcursors app
  app.canvas.set_size 0, scrollable_height unless(app.prjct or app.trvw)
  n = app.focus_ele ? app.focusables.index(app.focus_ele) : 0
  app.canvas.focus_chain = (app.focusables[n..-1] + app.focusables[0...n]).map(&:real) if n and !app.canvas.is_a?(Gtk::DrawingArea)
  true
end

.contents_alignment(slot) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/shoes/helper_methods.rb', line 162

def self.contents_alignment slot
  x, y = slot.left.to_i, slot.top.to_i
  max = Struct.new(:top, :height).new
  max.top, max.height = y, 0
  slot_height, slot_top = 0, y

  slot.contents.each do |ele|
    next if ele.is_a?(Basic) && ele.cleared && !ele.is_a?(Pattern)
    if ele.is_a? ShapeBase
      ele.hide if slot.masked
      next
    end
    if slot.masked and ele.is_a? Image
      ele.hide
      next
    end
    tmp = max
    max, flag = ele.positioning x, y, max
    x, y = ele.left + ele.width, ele.top + ele.height
    unless max == tmp
      slot_height = max.top + max.height - slot_top
    end
  end
  slot_height
end

.download_images_control(app) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/shoes/helper_methods.rb', line 393

def self.download_images_control app
  flag = false
  app.dics.each do |e, d, tmpname|
    args = e.args
    if d.finished?
      flag = true
      app.canvas.remove e.real
      img = Gtk::Image.new tmpname
      e.full_width, e.full_height = img.size_request
      unless args[:width].zero? and args[:height].zero?
        img = Gtk::Image.new img.pixbuf.scale(args[:width], args[:height])
      end
      app.canvas.put img, e.left, e.top
      img.show_now
      e.real = img
      e.width, e.height = img.size_request
      app.dics.delete [e, d, tmpname]
      File.delete tmpname
    end
  end
  flag
end

.init_contents(contents) ⇒ Object



231
232
233
234
235
236
237
238
# File 'lib/shoes/helper_methods.rb', line 231

def self.init_contents contents
  contents.each do |ele|
    next unless ele.is_a? Slot
    ele.initials.each do |k, v|
      ele.send "#{k}=", v
    end
  end
end

.mask_control(app) ⇒ Object



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/shoes/helper_methods.rb', line 353

def self.mask_control app
  app.mcs.each do |m|
    w, h = m.parent.width, m.parent.height
    w = app.width if w.zero?
    h = app.height if h.zero?
    surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, w, h
    context = Cairo::Context.new surface
    context.push_group do
      m.parent.contents.each do |ele|
        x, y = ele.left - m.parent.left, ele.top - m.parent.top
        context.translate x, y
        context.set_source_pixbuf ele.real.pixbuf
        context.paint
        context.translate -x, -y
      end
    end

    sf = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, w, h
    ct = Cairo::Context.new surface
    pat = ct.push_group nil, false do
      m.contents.each do |ele|
        if ele.is_a? TextBlock
          ele.height = h
          ele.text = ele.args[:markup]
        end
        x, y = ele.left - m.parent.left, ele.top - m.parent.top
        ct.translate x, y
        ct.set_source_pixbuf ele.real.pixbuf
        ct.paint
        ct.translate -x, -y
      end
    end

    context.mask pat
    m.real = img = app.create_tmp_png(surface)
    app.canvas.put img, 0, 0
    img.show_now
  end
end

.mouse_click_control(app) ⇒ Object



240
241
242
243
244
# File 'lib/shoes/helper_methods.rb', line 240

def self.mouse_click_control app
  app.mccs.each do |e|
    e.click_proc[*app.mouse] if mouse_on?(e) && !$dde
  end
end

.mouse_hover_control(app) ⇒ Object



258
259
260
261
262
263
264
265
# File 'lib/shoes/helper_methods.rb', line 258

def self.mouse_hover_control app
  app.mhcs.each do |e|
    if mouse_on?(e) and !e.hovered
      e.hovered = true
      e.hover_proc[e] if e.hover_proc
    end
  end
end

.mouse_leave_control(app) ⇒ Object



267
268
269
270
271
272
273
274
# File 'lib/shoes/helper_methods.rb', line 267

def self.mouse_leave_control app
  app.mhcs.each do |e|
    if !mouse_on?(e) and e.hovered
      e.hovered = false
      e.leave_proc[e] if e.leave_proc
    end
  end
end


276
277
278
279
280
281
282
# File 'lib/shoes/helper_methods.rb', line 276

def self.mouse_link_control app
  app.mlcs.each do |tb|
    next if tb.hided
    link_proc,  = mouse_on_link(tb, app)
    link_proc.call if link_proc && !$dde
  end
end

.mouse_motion_control(app) ⇒ Object



252
253
254
255
256
# File 'lib/shoes/helper_methods.rb', line 252

def self.mouse_motion_control app
  app.mmcs.each do |blk|
    blk[*app.win.pointer]
  end
end

.mouse_on?(e) ⇒ Boolean

Returns:

  • (Boolean)


314
315
316
317
318
# File 'lib/shoes/helper_methods.rb', line 314

def self.mouse_on? e
  mouse_x, mouse_y = e.app.win.pointer
  mouse_y += e.app.scroll_top
  (e.left..e.left+e.width).include?(mouse_x) and (e.top..e.top+e.height).include?(mouse_y)
end


320
321
322
323
324
325
326
327
328
329
# File 'lib/shoes/helper_methods.rb', line 320

def self.mouse_on_link tb, app
  mouse_x, mouse_y = app.win.pointer
  mouse_y += app.scroll_top
  mouse_x -= tb.left
  mouse_y -= tb.top
  tb.links.each_with_index do |e, n|
    return [e.link_proc, n] if ((0..tb.width).include?(mouse_x) and (e.pos[1]..(e.pos[3]+e.pos[4])).include?(mouse_y) and !((0..e.pos[0]).include?(mouse_x) and (e.pos[1]..(e.pos[1]+e.pos[4])).include?(mouse_y)) and !((e.pos[2]..tb.width).include?(mouse_x) and (e.pos[3]..(e.pos[3]+e.pos[4])).include?(mouse_y)))
  end
  return false
end

.mouse_release_control(app) ⇒ Object



246
247
248
249
250
# File 'lib/shoes/helper_methods.rb', line 246

def self.mouse_release_control app
  app.mrcs.each do |e|
    e.release_proc[*app.mouse] if mouse_on? e
  end
end

.pinning_control(app) ⇒ Object



416
417
418
419
420
# File 'lib/shoes/helper_methods.rb', line 416

def self.pinning_control app
  if d = app.scrolled?
    app.pinning_elements.each{|e| e.move e.left, e.top + d}
  end
end

.repaint_all(slot) ⇒ Object



188
189
190
191
192
193
194
195
# File 'lib/shoes/helper_methods.rb', line 188

def self.repaint_all slot
  return if slot.masked
  slot.contents.each do |ele|
    next if ele.is_a?(Basic) && ele.cleared && !ele.is_a?(Pattern)
    next if ele.is_a? ShapeBase
    ele.is_a?(Basic) ? ele.move2(ele.left + ele.margin_left, ele.top + ele.margin_top) : repaint_all(ele)
  end
end

.repaint_all_by_order(app) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'lib/shoes/helper_methods.rb', line 197

def self.repaint_all_by_order app
  tmp = app.order
  (app.fronts + app.backs).each{|e| tmp.delete e}
  (app.backs + tmp + app.fronts).each do |e|
    if e.real and !e.is_a?(Pattern) and !e.hided and !e.real.destroyed?
      app.canvas.remove e.real
      app.canvas.put e.real, e.left, e.top
    end
  end
end

.repaint_textcursors(app) ⇒ Object



208
209
210
211
212
213
214
215
# File 'lib/shoes/helper_methods.rb', line 208

def self.repaint_textcursors app
  app.textcursors.each do |tb, v|
    n, cursor = v
    x, y = app.make_textcursor_pos(tb, n)
    x += tb.left; y += tb.top
    cursor ? cursor.move(x, y) : app.textcursors[tb][1] = app.line(x, y, x, y+tb.size*1.7, strokewidth: 1, stroke: app.black)
  end
end

.set_cursor_type(app) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/shoes/helper_methods.rb', line 284

def self.set_cursor_type app
  app.mccs.each do |e|
    next if e.is_a? Slot
    e.real.window.cursor = ARROW if e.real.window
    (e.real.window.cursor = HAND; return) if mouse_on? e
  end
  
  app.mlcs.each do |tb|
    next if tb.hided
    tb.text = tb.text unless tb.real
    tb.real.window.cursor = ARROW if tb.real.window
    if ret = mouse_on_link(tb, app)
      tb.real.window.cursor = HAND  if tb.real.window
      unless tb.links[ret[1]].link_hover
        markup = tb.args[:markup].gsub(app.linkhover_style, app.link_style)
        links = markup.mindex  app.link_style
        n = links[ret[1]]
        tb.text = markup[0...n] + markup[n..-1].sub(app.link_style, app.linkhover_style)
        tb.links.each{|e| e.link_hover = false}
        tb.links[ret[1]].link_hover = true
      end
      return
    end
    if tb.links.map(&:link_hover).include? true
      tb.text = tb.args[:markup].gsub(app.linkhover_style, app.link_style)
      tb.links.each{|e| e.link_hover = false}
    end
  end
end

.show_hide_control(app) ⇒ Object



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/shoes/helper_methods.rb', line 335

def self.show_hide_control app
  flag = false
  app.shcs.each do |e|
    case
      when(!e.shows and !e.hided)
        e.remove
        e.hided = true
        flag = true
      when(e.shows and e.hided)
        e.hided = false
        e.is_a?(Pattern) ? e.move2(e.left, e.top) : app.canvas.put(e.real, e.left, e.top)
        flag = true
      else
    end
  end
  repaint_all_by_order app if flag
end

.show_manual(lang = 'English') ⇒ Object



2
3
4
5
# File 'lib/shoes/manual.rb', line 2

def self.show_manual lang='English'
  $lang = lang
  load File.join(DIR, 'shoes/help.rb')
end

.size_allocated?(app) ⇒ Boolean

Returns:

  • (Boolean)


331
332
333
# File 'lib/shoes/helper_methods.rb', line 331

def self.size_allocated? app
  not (app.width_pre == app.width and app.height_pre == app.height)
end