Class: GlimR::StretchableImage

Inherits:
Image show all
Defined in:
lib/glimr/widgets/stretchable_image.rb

Direct Known Subclasses

TextCursor

Constant Summary

Constants included from Layoutable

Layoutable::DIMENSIONS

Instance Attribute Summary

Attributes inherited from Image

#bound, #image

Attributes inherited from Widget

#focused, #hover

Attributes included from Layoutable

#align, #valign

Attributes inherited from Model

#geometry, #material, #shader, #texture, #transform

Attributes inherited from SceneObject

#children, #drawables, #mtime, #parent, #viewport

Attributes included from EventListener

#event_listeners, #listener_count

Instance Method Summary collapse

Methods inherited from Image

#create_colors, #default_config, #initialize, load, #load, load_theme, #load_theme, #texture=

Methods inherited from Widget

#activate, #blur, #click, #focus, for, #initialize, #key_down, #key_up, #lock, #mouse_down, #mouse_move, #mouse_out, #mouse_over, #mouse_up, #unlock

Methods included from Layoutable

#attach, #children_change, #constant_size?, #default_config, #detach, #expand!, #expand?, #expand_height, #expand_to_max_height!, #expand_to_max_width!, #expand_width, #fit_height!, #fit_to_children!, #fit_width!, #free_height, #free_width, #full_depth, #full_height, #full_width, #initialize, #inner_depth, #inner_height, #inner_width, #inspect, #layout, #layoutable_children, #margin, #margin=, #max_height=, #max_width=, #min_height=, #min_width=, #padding, #padding=, #parent=, #size_changing, size_changing_accessor, #tell_children_of_size_change, #x=, #y=

Methods inherited from Model

#absolute_transform, #apply, #initialize, #inspect, #pop_state, #push_state

Methods inherited from SceneObject

#<<, #absolute_geometry, #absolute_material, #absolute_shader, #absolute_texture, #absolute_transform, #absolute_transform_for_drawing, #add_drawables, #apply, #attach, #clone, #default_config, #detach, #detach_self, #initialize, #inspect, #pop_state, #push_state, #remove_drawables, #render, #replace_node, #root, #touch!, #visible

Methods included from Configurable

#default_config, #initialize

Methods included from EventListener

#add_event_listener, #decrement_listener_count, #dispatch_event, #event_root, #increment_listener_count, #initialize, #method_missing, #multicast_event, #process_event, #remove_event_listener

Constructor Details

This class inherits a constructor from GlimR::Image

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GlimR::EventListener

Instance Method Details

#create_normalsObject



60
61
62
# File 'lib/glimr/widgets/stretchable_image.rb', line 60

def create_normals
  super * 9
end

#create_texcoordsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/glimr/widgets/stretchable_image.rb', line 36

def create_texcoords
  tc = super
  tw = th = 0
  tc.each_with_index{|e,i|
    if i % 2 == 0
      tw = e if e > tw
    else
      th = e if e > th
    end
  }
  texcoords_3 = create_vertices(0.5*tw, 0.5*tw, tw, 0.5*th, 0.5*th, th)
  xcoords = []
  ycoords = []
  texcoords_3.each_with_index{|e,i|
    case i%3
    when 0
      xcoords << e
    when 1
      ycoords << e
    end
  }
  xcoords.zip(ycoords)
end

#create_vertices(hw = @texture.width / 2.0, fhw = @width - hw, w = @width, hh = @texture.height / 2.0, fhh = @height - hh, h = @height) ⇒ Object



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
# File 'lib/glimr/widgets/stretchable_image.rb', line 64

def create_vertices(
  hw = @texture.width / 2.0,
  fhw = @width - hw,
  w = @width,
  hh = @texture.height / 2.0,
  fhh = @height - hh,
  h = @height
)
  top_left_quad = [
    0, hh, 0,
    hw, hh, 0,
    hw, 0, 0,
    0,0,0
  ]
  top_middle_quad = [
    hw, hh, 0,
    fhw, hh, 0,
    fhw, 0, 0,
    hw, 0, 0
  ]
  top_right_quad = [
    fhw, hh, 0,
    w, hh, 0,
    w, 0, 0,
    fhw, 0, 0
  ]
  middle_left_quad = [
    0, fhh, 0,
    hw, fhh, 0,
    hw, hh, 0,
    0, hh, 0
  ]
  middle_middle_quad = [
    hw, fhh, 0,
    fhw, fhh, 0,
    fhw, hh, 0,
    hw, hh, 0
  ]
  middle_right_quad = [
    fhw, fhh, 0,
    w, fhh, 0,
    w, hh, 0,
    fhw, hh, 0
  ]
  bottom_left_quad = [
    0, h, 0,
    hw, h, 0,
    hw, fhh, 0,
    0, fhh, 0
  ]
  bottom_middle_quad = [
    hw, h, 0,
    fhw, h, 0,
    fhw, fhh, 0,
    hw, fhh, 0
  ]
  bottom_right_quad = [
    fhw, h, 0,
    w, h, 0,
    w, fhh, 0,
    fhw, fhh, 0
  ]
  (
    top_left_quad + top_middle_quad + top_right_quad +
    middle_left_quad + middle_middle_quad + middle_right_quad +
    bottom_left_quad + bottom_middle_quad + bottom_right_quad
  )
end

#height=(h) ⇒ Object



21
22
23
24
25
# File 'lib/glimr/widgets/stretchable_image.rb', line 21

def height=(h)
  return if h < @texture.height
  super
  update_geometry
end

#set_dimensions(w, h) ⇒ Object



9
10
11
12
13
# File 'lib/glimr/widgets/stretchable_image.rb', line 9

def set_dimensions(w,h)
  @width = w if w >= @texture.width
  @height = h if h >= @texture.height
  update_geometry
end

#update_geometryObject



27
28
29
30
31
32
33
# File 'lib/glimr/widgets/stretchable_image.rb', line 27

def update_geometry
  @min_width = @texture.width
  @min_height = @texture.height
  @width = [@width, @texture.width].max
  @height = [@height, @texture.height].max
  super
end

#width=(w) ⇒ Object



15
16
17
18
19
# File 'lib/glimr/widgets/stretchable_image.rb', line 15

def width=(w)
  return if w < @texture.width
  super
  update_geometry
end