Class: Shoes::Basic

Inherits:
Object show all
Includes:
Mod
Defined in:
lib/shoes/basic.rb,
lib/shoes/style.rb

Direct Known Subclasses

Image, Native, Pattern, ShapeBase, TextBlock

Instance Attribute Summary collapse

Attributes included from Mod

#hover_proc, #hovered, #leave_proc, #margin_bottom, #margin_left, #margin_right, #margin_top

Instance Method Summary collapse

Methods included from Mod

#click, #hided, #hover, #leave, #release, #set_margin

Constructor Details

#initialize(args) ⇒ Basic

Returns a new instance of Basic.



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
# File 'lib/shoes/basic.rb', line 4

def initialize args
  @initials = args
  @hided = true if args[:hidden]
  args.delete :hidden
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end

  (@app.order << self) unless @noorder
  (@app.cslot.contents << self) unless @nocontrol

  @parent = @app.cslot
  
  Basic.class_eval do
    attr_accessor *args.keys
  end

  if @real
    if @real.is_a? Swt::Image
      @width = @full_width if @width.zero?
      @height = @full_height if @height.zero?
    elsif @real.is_a? Symbol
      # do nothing
    else
      @width, @height = @real.getSize.x, @real.getSize.y
    end
  end

  set_margin
  @width += (@margin_left + @margin_right)
  @height += (@margin_top + @margin_bottom)

  [:app, :real].each{|k| args.delete k}
  @args = args
  @dps = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



41
42
43
# File 'lib/shoes/basic.rb', line 41

def args
  @args
end

#dpsObject

Returns the value of attribute dps.



42
43
44
# File 'lib/shoes/basic.rb', line 42

def dps
  @dps
end

#initialsObject (readonly)

Returns the value of attribute initials.



41
42
43
# File 'lib/shoes/basic.rb', line 41

def initials
  @initials
end

#lnObject

Returns the value of attribute ln.



42
43
44
# File 'lib/shoes/basic.rb', line 42

def ln
  @ln
end

#parentObject

Returns the value of attribute parent.



42
43
44
# File 'lib/shoes/basic.rb', line 42

def parent
  @parent
end

#plObject

Returns the value of attribute pl.



42
43
44
# File 'lib/shoes/basic.rb', line 42

def pl
  @pl
end

Instance Method Details

#center_at(x, y) ⇒ Object



62
63
64
# File 'lib/shoes/basic.rb', line 62

def center_at x, y
  [x - (@width / 2), y - (@height / 2)]
end

#clearObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/shoes/basic.rb', line 77

def clear
  unless @app.cs.isDisposed
    @app.cs.removePaintListener pl if pl
    @app.cs.removeListener Swt::SWT::MouseDown, ln if ln
    @app.cs.removeListener Swt::SWT::MouseUp, ln if ln
    @real.dispose unless @real.is_a? Symbol
    @dps.each{|dp| dp.dispose if dp}
    @dps.clear
    @parent.contents -= [self]
    @app.mscs -= [self]
    @app.mhcs -= [self]
    hide
  end
end

#fix_sizeObject



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
# File 'lib/shoes/basic.rb', line 108

def fix_size
  flag = false
  set_margin
  case self
  when EditBox, Button
    if 0 < @initials[:width] and @initials[:width] <= 1.0
      @width = @parent.width * @initials[:width] - @margin_left - @margin_right
      flag = true
    end
    if 0 < @initials[:height] and @initials[:height] <= 1.0
      @height = @parent.height * @initials[:height] - @margin_top - @margin_bottom
      flag = true
    end
  when EditLine, ListBox
    if 0 < @initials[:width] and @initials[:width] <= 1.0
      @width = @parent.width * @initials[:width] - @margin_left - @margin_right
      @height = 20
      flag = true
    end
  else
  end
  if flag
    @real.setSize @width, @height
    move @left, @top
  end
end

#hideObject



97
98
99
100
# File 'lib/shoes/basic.rb', line 97

def hide
  @hided = false
  toggle
end

#move(x, y) ⇒ Object



44
45
46
47
48
# File 'lib/shoes/basic.rb', line 44

def move x, y
  @app.cslot.contents -= [self]
  move3 x, y
  self
end

#move2(x, y) ⇒ Object



50
51
52
# File 'lib/shoes/basic.rb', line 50

def move2 x, y
  move3 x, y
end

#move3(x, y) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/shoes/basic.rb', line 54

def move3 x, y
  unless @app.cs.isDisposed
    @app.cs.redraw @left, @top, @width, @height, false
    @app.cs.redraw x, y, @width, @height, false
  end
  @left, @top = x, y
end

#positioning(x, y, max) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/shoes/basic.rb', line 66

def positioning x, y, max
  if parent.is_a?(Flow) and x + @width <= parent.left + parent.width
    move3 x + parent.margin_left, max.top + parent.margin_top
    max = self if max.height < @height
  else
    move3 parent.left + parent.margin_left, max.top + max.height + parent.margin_top
    max = self
  end
  max
end

#set_args(args) ⇒ Object



17
18
19
20
21
# File 'lib/shoes/style.rb', line 17

def set_args args
  @args.merge!({left: @left, top: @top})
  @args.merge! args
  @args.each{|k, v| instance_variable_set "@#{k}", v}
end

#showObject



92
93
94
95
# File 'lib/shoes/basic.rb', line 92

def show
  @hided = true
  toggle
end

#style(args = nil) ⇒ Object



11
12
13
14
15
# File 'lib/shoes/style.rb', line 11

def style args = nil
  return @args unless args
  set_args args
  @app.cs.redraw @left, @top, @width, @height, false unless @app.cs.isDisposed
end

#toggleObject



102
103
104
105
106
# File 'lib/shoes/basic.rb', line 102

def toggle
  @hided = !@hided
  @app.cs.redraw @left, @top, @width, @height, false unless @app.cs.isDisposed
  self
end