fidgit 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +1 -0
- data/config/default_schema.yml +30 -5
- data/examples/align_example.rb +1 -1
- data/examples/button_and_toggle_button_example.rb +15 -4
- data/examples/file_dialog_example.rb +1 -1
- data/examples/grid_packer_example.rb +2 -2
- data/lib/fidgit/elements/button.rb +5 -1
- data/lib/fidgit/elements/combo_box.rb +10 -4
- data/lib/fidgit/elements/container.rb +29 -1
- data/lib/fidgit/elements/element.rb +11 -7
- data/lib/fidgit/elements/file_browser.rb +1 -1
- data/lib/fidgit/elements/grid.rb +6 -2
- data/lib/fidgit/elements/image_frame.rb +65 -0
- data/lib/fidgit/elements/label.rb +55 -74
- data/lib/fidgit/elements/main_packer.rb +0 -1
- data/lib/fidgit/elements/menu_pane.rb +12 -9
- data/lib/fidgit/elements/text_area.rb +6 -6
- data/lib/fidgit/elements/text_line.rb +92 -0
- data/lib/fidgit/elements/tool_tip.rb +1 -1
- data/lib/fidgit/states/gui_state.rb +8 -0
- data/lib/fidgit/version.rb +1 -1
- data/spec/fidgit/{helpers → elements/helpers}/tex_play_helper.rb +0 -0
- data/spec/fidgit/elements/image_frame_spec.rb +69 -0
- data/spec/fidgit/elements/label_spec.rb +3 -15
- metadata +18 -17
- data/lib/fidgit/thumbnail.rb +0 -29
- data/spec/fidgit/thumbnail_spec.rb +0 -50
data/README.textile
CHANGED
@@ -99,6 +99,7 @@ Elements can be placed inside a packer or group.
|
|
99
99
|
|
100
100
|
* _button(text, ...)_ - Button with text and/or icon (Block handles :clicked_left_mouse_button event).
|
101
101
|
* _color_picker(...)_ - Red, green and blue sliders and colour indicator (Block handles :changed event).
|
102
|
+
* _image_frame(image, ...)_ - Wrapper around a Gosu::Image to embed it in the GUI.
|
102
103
|
* _label(text, ...)_ - Label with text and, optionally, an icon (No block accepted).
|
103
104
|
* _slider(...)_ - Horizontal slider with handle (Block handles :changed event).
|
104
105
|
* _text_area(...)_ - An multi-line element, containing editable text (Block handles :changed event).
|
data/config/default_schema.yml
CHANGED
@@ -33,6 +33,10 @@
|
|
33
33
|
:border_color: ?light_gray
|
34
34
|
:border_thickness: 2
|
35
35
|
:shortcut_color: ?red
|
36
|
+
:padding_top: 2
|
37
|
+
:padding_right: 4
|
38
|
+
:padding_bottom: 2
|
39
|
+
:padding_left: 4
|
36
40
|
|
37
41
|
:disabled:
|
38
42
|
:background_color: ?very_dark_gray
|
@@ -63,7 +67,7 @@
|
|
63
67
|
:padding_left: 0
|
64
68
|
|
65
69
|
:Container: # < Element
|
66
|
-
|
70
|
+
{}
|
67
71
|
|
68
72
|
:Element:
|
69
73
|
:align_h: :left
|
@@ -73,13 +77,14 @@
|
|
73
77
|
:border_color: ?none
|
74
78
|
:border_thickness: 0
|
75
79
|
:color: ?white
|
76
|
-
:
|
80
|
+
:font_height: 30
|
77
81
|
:font_name: :default
|
78
82
|
:padding_top: 2
|
79
83
|
:padding_right: 4
|
80
84
|
:padding_bottom: 2
|
81
85
|
:padding_left: 4
|
82
86
|
|
87
|
+
|
83
88
|
:FileBrowser: # < Composite
|
84
89
|
:pattern: "*.*"
|
85
90
|
:show_extension: true
|
@@ -96,13 +101,21 @@
|
|
96
101
|
:padding_left: 0
|
97
102
|
|
98
103
|
:Horizontal: # < Grid
|
99
|
-
|
104
|
+
{}
|
100
105
|
|
101
106
|
:HorizontalScrollBar: # < ScrollBar
|
102
107
|
:height: ?scroll_bar_thickness
|
103
108
|
|
109
|
+
:ImageFrame: # <Element
|
110
|
+
:padding_top: 0
|
111
|
+
:padding_right: 0
|
112
|
+
:padding_bottom: 0
|
113
|
+
:padding_left: 0
|
114
|
+
|
104
115
|
:Label: # < Element
|
105
116
|
:justify: :left
|
117
|
+
:icon_position: :left
|
118
|
+
|
106
119
|
:disabled:
|
107
120
|
:color: ?light_gray
|
108
121
|
|
@@ -142,7 +155,7 @@
|
|
142
155
|
:border_color: ?blue
|
143
156
|
|
144
157
|
:ScrollArea: # < Composite
|
145
|
-
|
158
|
+
{}
|
146
159
|
|
147
160
|
:ScrollBar: # < Composite
|
148
161
|
:background_color: ?none
|
@@ -176,16 +189,28 @@
|
|
176
189
|
:focused:
|
177
190
|
:border_color: ?green
|
178
191
|
|
192
|
+
:TextLine: # < Element
|
193
|
+
:justify: :left
|
194
|
+
:padding_top: 0
|
195
|
+
:padding_right: 0
|
196
|
+
:padding_bottom: 0
|
197
|
+
:padding_left: 0
|
198
|
+
|
179
199
|
:ToggleButton: # < Button
|
180
200
|
:toggled:
|
181
201
|
:border_color: ?red
|
182
202
|
|
183
203
|
:ToolTip: # < Label
|
184
204
|
:background_color: ?very_dark_gray
|
205
|
+
:font_height: 20
|
185
206
|
:border_color: ?white
|
207
|
+
:padding_top: 2
|
208
|
+
:padding_right: 4
|
209
|
+
:padding_bottom: 2
|
210
|
+
:padding_left: 4
|
186
211
|
|
187
212
|
:Vertical: # < Grid
|
188
|
-
|
213
|
+
{}
|
189
214
|
|
190
215
|
:VerticalScrollBar: # < ScrollBar
|
191
216
|
:width: ?scroll_bar_thickness
|
data/examples/align_example.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative 'helpers/example_window'
|
2
2
|
|
3
3
|
# Change font and labels in the schema.
|
4
|
-
Fidgit::Element.schema.merge_elements!(Element: {
|
4
|
+
Fidgit::Element.schema.merge_elements!(Element: { font_height: 24 }, Label: { background_color: "?dark_blue" })
|
5
5
|
|
6
6
|
class ExampleState < Fidgit::GuiState
|
7
7
|
ROW_BACKGROUND = Gosu::Color.rgb(0, 100, 0)
|
@@ -8,17 +8,28 @@ class ExampleState < Fidgit::GuiState
|
|
8
8
|
vertical do
|
9
9
|
my_label = label "Label", tip: "I'm a label"
|
10
10
|
|
11
|
-
|
11
|
+
buttons = []
|
12
|
+
|
13
|
+
# A plain button, with some text on it.
|
14
|
+
buttons << button("Button", tip: "I'm a button; press me!", shortcut: :auto) do
|
12
15
|
my_label.text = "Pressed the button!"
|
13
16
|
end
|
14
17
|
|
15
|
-
|
18
|
+
# Buttons with icons in each possible positions.
|
19
|
+
[:left, :right, :top, :bottom].each do |position|
|
20
|
+
buttons << button("Icon at #{position}", icon: Gosu::Image["head_icon.png"], icon_position: position, icon_options: { factor: 2 }, tip: "I'm a button; press me!", shortcut: :auto) do
|
21
|
+
my_label.text = "Pressed the button (icon to #{position})!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# A toggling button.
|
26
|
+
buttons << toggle_button("ToggleButton", tip: "I'm a button that toggles", shortcut: :o) do |sender, value|
|
16
27
|
my_label.text = "Turned the toggle button #{value ? "on" : "off"}!"
|
17
28
|
end
|
18
29
|
|
30
|
+
# A toggle-button that controls whether all the other buttons are enabled.
|
19
31
|
toggle_button("Enable other two buttons", value: true) do |sender, value|
|
20
|
-
|
21
|
-
my_toggle_button.enabled = value
|
32
|
+
buttons.each {|button| button.enabled = value }
|
22
33
|
end
|
23
34
|
end
|
24
35
|
end
|
@@ -12,14 +12,14 @@ class ExampleState < Fidgit::GuiState
|
|
12
12
|
label "Grid with #{FIXED_NUM} columns"
|
13
13
|
grid num_columns: FIXED_NUM, border_color: BORDER_COLOR, cell_border_color: Gosu::Color.rgba(0, 255, 0, 255), cell_border_thickness: 1 do
|
14
14
|
NUM_CELLS.times do |i|
|
15
|
-
label "Cell #{i}",
|
15
|
+
label "Cell #{i}", font_height: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
label "Grid with #{FIXED_NUM} rows"
|
20
20
|
grid num_rows: FIXED_NUM, border_color: BORDER_COLOR, cell_background_color: Gosu::Color.rgba(0, 100, 100, 255) do
|
21
21
|
NUM_CELLS.times do |i|
|
22
|
-
label "Cell #{i}",
|
22
|
+
label "Cell #{i}", font_height: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -27,6 +27,8 @@ module Fidgit
|
|
27
27
|
|
28
28
|
super(text, options)
|
29
29
|
|
30
|
+
self.text = text # Force shortcut to be written out properly.
|
31
|
+
|
30
32
|
update_colors
|
31
33
|
end
|
32
34
|
|
@@ -86,12 +88,14 @@ module Fidgit
|
|
86
88
|
default(:background_color)
|
87
89
|
end
|
88
90
|
|
89
|
-
|
91
|
+
self.color = if enabled?
|
90
92
|
default(:color)
|
91
93
|
else
|
92
94
|
default(:disabled, :color)
|
93
95
|
end
|
94
96
|
|
97
|
+
@icon.enabled = enabled? if @icon
|
98
|
+
|
95
99
|
nil
|
96
100
|
end
|
97
101
|
|
@@ -4,6 +4,8 @@ module Fidgit
|
|
4
4
|
class ComboBox < Button
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
+
ARROW_IMAGE = "combo_arrow.png"
|
8
|
+
|
7
9
|
def_delegators :@menu, :each
|
8
10
|
|
9
11
|
event :changed
|
@@ -50,12 +52,12 @@ class ComboBox < Button
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
@@arrow ||= Gosu::Image[
|
55
|
+
@@arrow ||= Gosu::Image[ARROW_IMAGE]
|
54
56
|
|
55
57
|
super('', options)
|
56
58
|
|
57
|
-
rect.height = [height,
|
58
|
-
rect.width = [width,
|
59
|
+
rect.height = [height, font.height + padding_top + padding_bottom].max
|
60
|
+
rect.width = [width, font.height * 4 + padding_left + padding_right].max
|
59
61
|
end
|
60
62
|
|
61
63
|
def item(text, value, options = {}, &block)
|
@@ -67,6 +69,8 @@ class ComboBox < Button
|
|
67
69
|
self.icon = item.icon
|
68
70
|
end
|
69
71
|
|
72
|
+
recalc
|
73
|
+
|
70
74
|
item
|
71
75
|
end
|
72
76
|
|
@@ -93,7 +97,9 @@ class ComboBox < Button
|
|
93
97
|
protected
|
94
98
|
def layout
|
95
99
|
super
|
96
|
-
|
100
|
+
|
101
|
+
# Max width of all items + allow size for the arrow.
|
102
|
+
rect.width = [@menu.width + height, min_width].max
|
97
103
|
|
98
104
|
nil
|
99
105
|
end
|
@@ -80,6 +80,11 @@ module Fidgit
|
|
80
80
|
Group.new({parent: self}.merge!(options), &block)
|
81
81
|
end
|
82
82
|
|
83
|
+
# Create an icon.
|
84
|
+
def image_frame(image, options = {}, &block)
|
85
|
+
ImageFrame.new(image, {parent: self}.merge!(options), &block)
|
86
|
+
end
|
87
|
+
|
83
88
|
# Create a label within the container.
|
84
89
|
def label(text, options = {})
|
85
90
|
Label.new(text, {parent: self}.merge!(options))
|
@@ -165,7 +170,7 @@ module Fidgit
|
|
165
170
|
|
166
171
|
protected
|
167
172
|
def draw_foreground
|
168
|
-
each {
|
173
|
+
@children.each {|c| c.draw }
|
169
174
|
|
170
175
|
font.draw self.class.name, x, y, z if Fidgit.debug_mode?
|
171
176
|
|
@@ -177,5 +182,28 @@ module Fidgit
|
|
177
182
|
def post_init_block(&block)
|
178
183
|
with(&block)
|
179
184
|
end
|
185
|
+
|
186
|
+
public
|
187
|
+
def to_s
|
188
|
+
"#{super} [#{@children.size} #{@children.size == 1 ? 'child' : 'children'}]"
|
189
|
+
end
|
190
|
+
|
191
|
+
public
|
192
|
+
def write_tree(indent = "", index = 0)
|
193
|
+
puts self
|
194
|
+
|
195
|
+
indent = indent + " "
|
196
|
+
|
197
|
+
@children.each.with_index do |element, i|
|
198
|
+
print "#{indent}#{i}: "
|
199
|
+
|
200
|
+
case element
|
201
|
+
when Container
|
202
|
+
element.write_tree(indent)
|
203
|
+
else
|
204
|
+
puts element
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
180
208
|
end
|
181
209
|
end
|
@@ -37,7 +37,8 @@ module Fidgit
|
|
37
37
|
VALID_ALIGN_H = [:left, :center, :right, :fill]
|
38
38
|
VALID_ALIGN_V = [:top, :center, :bottom, :fill]
|
39
39
|
|
40
|
-
attr_reader :z, :tip, :
|
40
|
+
attr_reader :z, :tip, :padding_top, :padding_right, :padding_bottom, :padding_left,
|
41
|
+
:align_h, :align_v, :parent, :border_thickness, :font
|
41
42
|
|
42
43
|
attr_accessor :background_color
|
43
44
|
|
@@ -76,8 +77,6 @@ module Fidgit
|
|
76
77
|
@enabled = value
|
77
78
|
end
|
78
79
|
|
79
|
-
def font; @font ||= Gosu::Font[@font_name, @font_size]; end
|
80
|
-
|
81
80
|
def rect; @rect; end; protected :rect
|
82
81
|
|
83
82
|
def self.schema; @@schema ||= Schema.new(YAML.load(File.read(DEFAULT_SCHEMA_FILE)));; end
|
@@ -116,7 +115,7 @@ module Fidgit
|
|
116
115
|
#
|
117
116
|
# @option options [String] :tip ('') Tool-tip text
|
118
117
|
# @option options [String, :default] :font_name (:default, which resolves as the default Gosu font)
|
119
|
-
# @option options [String] :
|
118
|
+
# @option options [String] :font_height (30)
|
120
119
|
#
|
121
120
|
# @option options [Gosu::Color] :background_color (transparent)
|
122
121
|
# @option options [Gosu::Color] :border_color (transparent)
|
@@ -143,7 +142,7 @@ module Fidgit
|
|
143
142
|
z: 0,
|
144
143
|
tip: '',
|
145
144
|
font_name: default(:font_name),
|
146
|
-
|
145
|
+
font_height: default(:font_height),
|
147
146
|
background_color: default(:background_color),
|
148
147
|
border_color: default(:border_color),
|
149
148
|
border_thickness: default(:border_thickness),
|
@@ -181,13 +180,13 @@ module Fidgit
|
|
181
180
|
|
182
181
|
@z = options[:z]
|
183
182
|
@tip = options[:tip].dup
|
184
|
-
|
183
|
+
font_name = if options[:font_name].nil? or options[:font_name] == :default
|
185
184
|
Gosu::default_font_name
|
186
185
|
else
|
187
186
|
options[:font_name].dup
|
188
187
|
end
|
189
188
|
|
190
|
-
@
|
189
|
+
@font = Gosu::Font[font_name, options[:font_height]]
|
191
190
|
|
192
191
|
@rect = Chingu::Rect.new(options[:x], options[:y], options[:width] || 0, options[:height] || 0)
|
193
192
|
end
|
@@ -276,5 +275,10 @@ module Fidgit
|
|
276
275
|
def post_init_block(&block)
|
277
276
|
raise ArgumentError, "does not accept a block"
|
278
277
|
end
|
278
|
+
|
279
|
+
public
|
280
|
+
def to_s
|
281
|
+
"#{self.class} (#{x}, #{y}) #{width}x#{height}"
|
282
|
+
end
|
279
283
|
end
|
280
284
|
end
|
@@ -70,7 +70,7 @@ module Fidgit
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
@file_name_text = text_area(text: options[:file_name], max_height:
|
73
|
+
@file_name_text = text_area(text: options[:file_name], max_height: font.height * 1.5, width: options[:width], border_thickness: 1)
|
74
74
|
|
75
75
|
create_nav_buttons
|
76
76
|
|
data/lib/fidgit/elements/grid.rb
CHANGED
@@ -4,8 +4,12 @@ module Fidgit
|
|
4
4
|
# A vertically aligned element packing container.
|
5
5
|
|
6
6
|
class Grid < Packer
|
7
|
+
# @return [Symbol]
|
8
|
+
attr_reader :type
|
9
|
+
|
7
10
|
# @return [Integer]
|
8
11
|
attr_reader :num_rows
|
12
|
+
|
9
13
|
# @return [Integer]
|
10
14
|
attr_reader :num_columns
|
11
15
|
|
@@ -82,11 +86,11 @@ module Fidgit
|
|
82
86
|
@rows.each_with_index do |row, row_num|
|
83
87
|
row.each_with_index do |element, column_num|
|
84
88
|
fills = (element.align_h == :fill)
|
85
|
-
@widths[column_num] = [fills ?
|
89
|
+
@widths[column_num] = [fills ? element.min_width : element.outer_width, @widths[column_num]].max
|
86
90
|
filled_columns.push fills
|
87
91
|
|
88
92
|
fills = (element.align_v == :fill)
|
89
|
-
@heights[row_num] = [fills ?
|
93
|
+
@heights[row_num] = [fills ? element.min_width : element.outer_height, @heights[row_num]].max
|
90
94
|
filled_rows.push fills
|
91
95
|
end
|
92
96
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Fidgit
|
2
|
+
# A wrapper around a Gosu::Image to show it in the GUI.
|
3
|
+
class ImageFrame < Element
|
4
|
+
ENABLED_COLOR = Gosu::Color::WHITE
|
5
|
+
DISABLED_COLOR = Gosu::Color.rgb(150, 150, 150)
|
6
|
+
|
7
|
+
attr_reader :image, :factor_x, :factor_y
|
8
|
+
|
9
|
+
def thumbnail?; @thumbnail; end
|
10
|
+
|
11
|
+
# @param (see Element#initialize)
|
12
|
+
# @param [Gosu::Image] image Gosu image to display.
|
13
|
+
#
|
14
|
+
# @option (see Element#initialize)
|
15
|
+
# @option options [Boolean] :thumbnail (false) Is the image expanded to be square?
|
16
|
+
def initialize(image, options = {})
|
17
|
+
options = {
|
18
|
+
thumbnail: false,
|
19
|
+
factor: 1,
|
20
|
+
}.merge! options
|
21
|
+
|
22
|
+
@thumbnail = options[:thumbnail]
|
23
|
+
@factor_x = options[:factor_x] || options[:factor]
|
24
|
+
@factor_y = options[:factor_y] || options[:factor]
|
25
|
+
|
26
|
+
super(options)
|
27
|
+
|
28
|
+
self.image = image
|
29
|
+
end
|
30
|
+
|
31
|
+
def image=(image)
|
32
|
+
@image = image
|
33
|
+
|
34
|
+
recalc
|
35
|
+
|
36
|
+
image
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def draw_foreground
|
41
|
+
@image.draw(x + padding_left, y + padding_top, z, factor_x, factor_y, enabled? ? ENABLED_COLOR : DISABLED_COLOR) if @image
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
def layout
|
46
|
+
if @image
|
47
|
+
if @thumbnail
|
48
|
+
size = [@image.width, @image.height].max
|
49
|
+
rect.width = size * @factor_x
|
50
|
+
rect.height = size * @factor_y
|
51
|
+
else
|
52
|
+
rect.width = @image.width * @factor_x
|
53
|
+
rect.height = @image.height * @factor_y
|
54
|
+
end
|
55
|
+
else
|
56
|
+
rect.width = rect.height = 0
|
57
|
+
end
|
58
|
+
|
59
|
+
rect.width += padding_left + padding_right
|
60
|
+
rect.height += padding_top + padding_bottom
|
61
|
+
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,29 +1,58 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Fidgit
|
4
|
-
class Label <
|
5
|
-
|
6
|
-
attr_reader :text, :icon
|
4
|
+
class Label < Composite
|
5
|
+
ICON_POSITIONS = [:top, :bottom, :left, :right]
|
7
6
|
|
8
|
-
|
7
|
+
attr_reader :icon_position
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
attr_accessor :background_color, :border_color
|
10
|
+
|
11
|
+
def_delegators :@text, :text, :color, :font, :color=, :text=
|
12
|
+
|
13
|
+
def icon; @icon ? @icon.image : nil; end
|
14
|
+
|
15
|
+
def hit_element(x, y)
|
16
|
+
# The sub-elements should never get events.
|
17
|
+
hit?(x, y) ? self : nil
|
14
18
|
end
|
15
19
|
|
16
|
-
def icon=(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
def icon=(icon)
|
21
|
+
raise ArgumentError.new("Icon must be a Gosu::Image") unless icon.is_a? Gosu::Image or icon.nil?
|
22
|
+
|
23
|
+
@contents.remove(@icon) if @icon.image
|
24
|
+
@icon.image = icon
|
25
|
+
position = [:left, :top].include?(icon_position) ? 0 : 1
|
26
|
+
@contents.insert(position, @icon) if @icon.image
|
27
|
+
|
28
|
+
icon
|
29
|
+
end
|
30
|
+
|
31
|
+
# Set the position of the icon, respective to the text.
|
32
|
+
def icon_position=(position)
|
33
|
+
raise ArgumentError.new("icon_position must be one of #{ICON_POSITIONS}") unless ICON_POSITIONS.include? position
|
34
|
+
|
35
|
+
@icon_position = position
|
36
|
+
|
37
|
+
case @icon_position
|
38
|
+
when :top, :bottom
|
39
|
+
@contents.instance_variable_set :@type, :fixed_columns
|
40
|
+
@contents.instance_variable_set :@num_columns, 1
|
41
|
+
when :left, :right
|
42
|
+
@contents.instance_variable_set :@type, :fixed_rows
|
43
|
+
@contents.instance_variable_set :@num_rows, 1
|
44
|
+
end
|
45
|
+
|
46
|
+
self.icon = @icon.image if @icon.image # Force the icon into the correct position.
|
47
|
+
|
48
|
+
position
|
20
49
|
end
|
21
50
|
|
22
51
|
# @param (see Element#initialize)
|
23
52
|
# @param [String] text The string to display in the label.
|
24
53
|
#
|
25
54
|
# @option (see Element#initialize)
|
26
|
-
# @option options [
|
55
|
+
# @option options [Gosu::Image, nil] :icon (nil)
|
27
56
|
# @option options [:left, :right, :center] :justify (:left) Text justification.
|
28
57
|
def initialize(text, options = {})
|
29
58
|
options = {
|
@@ -31,74 +60,26 @@ module Fidgit
|
|
31
60
|
justify: default(:justify),
|
32
61
|
background_color: default(:background_color),
|
33
62
|
border_color: default(:border_color),
|
63
|
+
icon_options: {},
|
64
|
+
font_name: default(:font_name),
|
65
|
+
font_height: default(:font_height),
|
66
|
+
icon_position: default(:icon_position),
|
34
67
|
}.merge! options
|
35
68
|
|
36
|
-
@text = text.dup
|
37
|
-
@icon = options[:icon]
|
38
|
-
@color = options[:color].dup
|
39
|
-
|
40
|
-
raise "Justification must be one of #{VALID_JUSTIFICATION.inspect}" unless VALID_JUSTIFICATION.include? options[:justify]
|
41
|
-
@justify = options[:justify]
|
42
|
-
|
43
69
|
super(options)
|
44
70
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if @icon
|
51
|
-
@icon.draw(current_x, y + padding_top, z)
|
52
|
-
current_x += @icon.width + padding_left
|
53
|
-
end
|
54
|
-
|
55
|
-
unless @text.empty?
|
56
|
-
case @justify
|
57
|
-
when :left
|
58
|
-
rel_x = 0.0
|
59
|
-
center_x = current_x
|
60
|
-
|
61
|
-
when :right
|
62
|
-
rel_x = 1.0
|
63
|
-
center_x = x + rect.width - padding_right
|
64
|
-
|
65
|
-
when :center
|
66
|
-
rel_x = 0.5
|
67
|
-
center_x = (current_x + x + rect.width - padding_right) / 2.0
|
68
|
-
end
|
69
|
-
|
70
|
-
# Make text centered alongside the icon
|
71
|
-
# TODO: Probably should have this as an option.
|
72
|
-
center_y = y + padding_top + ((y + height - padding_bottom) - (y + padding_top)) / 2.0
|
73
|
-
|
74
|
-
font.draw_rel(@text, center_x, center_y, z, rel_x, 0.5, 1, 1, @color)
|
71
|
+
# Bit of a fudge since font info is managed circularly here!
|
72
|
+
# By using a grid, we'll be able to turn it around easily (in theory).
|
73
|
+
@contents = grid num_rows: 1, padding: 0, spacing_h: spacing_h, spacing_v: spacing_v, width: options[:width], height: options[:height], z: z do |contents|
|
74
|
+
@text = TextLine.new(text, parent: contents, justify: options[:justify], color: options[:color], padding: 0, z: z,
|
75
|
+
font_name: options[:font_name], font_height: options[:font_height], align_h: :fill, align_v: :center)
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
protected
|
81
|
-
def layout
|
82
|
-
if @icon
|
83
|
-
if @text.empty?
|
84
|
-
rect.width = [padding_left + @icon.width + padding_right, min_width].max
|
85
|
-
rect.height = [padding_top + @icon.height + padding_bottom, min_height].max
|
86
|
-
else
|
87
|
-
# Todo: Use padding_h inside here? Probably by making this a Composite.
|
88
|
-
rect.width = [padding_left + @icon.width + [padding_left + padding_right].max + font.text_width(@text) + padding_right, min_width].max
|
89
|
-
rect.height = [padding_top + [@icon.height, font_size].max + padding_bottom, min_height].max
|
90
|
-
end
|
91
|
-
else
|
92
|
-
if @text.empty?
|
93
|
-
rect.width = [padding_left + padding_right, min_width].max
|
94
|
-
rect.height = [padding_top + padding_bottom, min_height].max
|
95
|
-
else
|
96
|
-
rect.width = [padding_left + font.text_width(@text) + padding_right, min_width].max
|
97
|
-
rect.height = [padding_top + font_size + padding_bottom, min_height].max
|
98
|
-
end
|
99
|
-
end
|
78
|
+
# Create an image frame, but don't show it unless there is an image in it.
|
79
|
+
@icon = ImageFrame.new(nil, options[:icon_options].merge(z: z, align: :center))
|
80
|
+
@icon.image = options[:icon]
|
100
81
|
|
101
|
-
|
82
|
+
self.icon_position = options[:icon_position]
|
102
83
|
end
|
103
84
|
end
|
104
85
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Fidgit
|
4
2
|
class MenuPane < Composite
|
5
3
|
# An item within the menu.
|
@@ -26,8 +24,9 @@ module Fidgit
|
|
26
24
|
|
27
25
|
def draw_foreground
|
28
26
|
super
|
27
|
+
|
29
28
|
unless @shortcut_text.empty?
|
30
|
-
font.draw_rel("#{@shortcut_text}", rect.right - padding_right, y + ((height -
|
29
|
+
font.draw_rel("#{@shortcut_text}", rect.right - padding_right, y + ((height - font.height) / 2).floor, z, 1, 0, 1, 1, color)
|
31
30
|
end
|
32
31
|
|
33
32
|
nil
|
@@ -36,7 +35,10 @@ module Fidgit
|
|
36
35
|
protected
|
37
36
|
def layout
|
38
37
|
super
|
39
|
-
|
38
|
+
|
39
|
+
# Ignore layout request when asked before TextLine has been created.
|
40
|
+
rect.width += font.text_width(" #{@shortcut_text}") unless @shortcut_text.empty? or @text.nil?
|
41
|
+
|
40
42
|
nil
|
41
43
|
end
|
42
44
|
end
|
@@ -56,8 +58,6 @@ module Fidgit
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
# -------------------
|
60
|
-
|
61
61
|
extend Forwardable
|
62
62
|
|
63
63
|
def_delegators :@items, :each, :clear, :size, :[]
|
@@ -110,8 +110,11 @@ module Fidgit
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def item(text, value, options = {}, &block)
|
113
|
-
options
|
114
|
-
|
113
|
+
options = options.merge({
|
114
|
+
parent: @items,
|
115
|
+
z: z,
|
116
|
+
})
|
117
|
+
item = Item.new(text, value, options, &block)
|
115
118
|
|
116
119
|
item.subscribe :left_mouse_button, method(:item_selected)
|
117
120
|
item.subscribe :right_mouse_button, method(:item_selected)
|
@@ -146,7 +149,7 @@ module Fidgit
|
|
146
149
|
@items.y = y + padding_top
|
147
150
|
|
148
151
|
# Ensure that all items are of the same width.
|
149
|
-
max_width = @items.
|
152
|
+
max_width = @items.map(&:width).max || 0
|
150
153
|
@items.each {|c| c.rect.width = max_width }
|
151
154
|
|
152
155
|
@items.recalc # Move all the items inside the packer to correct ones.
|
@@ -136,14 +136,14 @@ module Fidgit
|
|
136
136
|
|
137
137
|
super(options)
|
138
138
|
|
139
|
-
min_height = padding_left + padding_right +
|
139
|
+
min_height = padding_left + padding_right + font.height
|
140
140
|
if options[:height]
|
141
141
|
@max_height = @min_height = [options[:height], min_height].max
|
142
142
|
else
|
143
143
|
@max_height = [options[:max_height], min_height].max
|
144
144
|
@min_height = options[:min_height] ? [options[:min_height], min_height].max : min_height
|
145
145
|
end
|
146
|
-
rect.height = [padding_left + padding_right +
|
146
|
+
rect.height = [padding_left + padding_right + font.height, @min_height].max
|
147
147
|
|
148
148
|
subscribe :left_mouse_button, method(:click_in_text)
|
149
149
|
subscribe :right_mouse_button, method(:click_in_text)
|
@@ -157,7 +157,7 @@ module Fidgit
|
|
157
157
|
mouse_x, mouse_y = x - (self.x + padding_left), y - (self.y + padding_top)
|
158
158
|
@char_widths.each_with_index do |width, i|
|
159
159
|
char_x, char_y = @caret_positions[i]
|
160
|
-
if mouse_x.between?(char_x, char_x + width) and mouse_y.between?(char_y, char_y +
|
160
|
+
if mouse_x.between?(char_x, char_x + width) and mouse_y.between?(char_y, char_y + font.height)
|
161
161
|
self.caret_position = @text_input.selection_start = i
|
162
162
|
break
|
163
163
|
end
|
@@ -210,7 +210,7 @@ module Fidgit
|
|
210
210
|
char_x, char_y = @caret_positions[pos]
|
211
211
|
char_width = @char_widths[pos]
|
212
212
|
left, top = x + padding_left + char_x, y + padding_top + char_y
|
213
|
-
draw_rect left, top, char_width,
|
213
|
+
draw_rect left, top, char_width, font.height, z, @selection_color
|
214
214
|
end
|
215
215
|
|
216
216
|
# Draw text.
|
@@ -222,14 +222,14 @@ module Fidgit
|
|
222
222
|
if focused? and ((Gosu::milliseconds / @caret_period) % 2 == 0)
|
223
223
|
caret_x, caret_y = @caret_positions[caret_position]
|
224
224
|
left, top = x + padding_left + caret_x, y + padding_top + caret_y
|
225
|
-
draw_rect left, top, 1,
|
225
|
+
draw_rect left, top, 1, font.height, z, @caret_color
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
229
|
# y position of the
|
230
230
|
protected
|
231
231
|
def y_at_line(lines_number)
|
232
|
-
lines_number * (
|
232
|
+
lines_number * (font.height + line_spacing)
|
233
233
|
end
|
234
234
|
|
235
235
|
protected
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Fidgit
|
2
|
+
# Used internally by the label.
|
3
|
+
class TextLine < Element
|
4
|
+
VALID_JUSTIFICATION = [:left, :right, :center]
|
5
|
+
|
6
|
+
attr_reader :color, :justify
|
7
|
+
|
8
|
+
def color=(color)
|
9
|
+
raise ArgumentError.new("Text must be a Gosu::Color") unless color.is_a? Gosu::Color
|
10
|
+
|
11
|
+
@color = color.dup
|
12
|
+
|
13
|
+
color
|
14
|
+
end
|
15
|
+
|
16
|
+
def text; @text.dup; end
|
17
|
+
|
18
|
+
def text=(text)
|
19
|
+
raise ArgumentError.new("Text must be a String") unless text.respond_to? :to_s
|
20
|
+
|
21
|
+
@text = text.to_s.dup
|
22
|
+
|
23
|
+
recalc
|
24
|
+
text
|
25
|
+
end
|
26
|
+
|
27
|
+
def justify=(justify)
|
28
|
+
raise ArgumentError.new("Justify must be one of #{VALID_JUSTIFICATION.inspect}") unless VALID_JUSTIFICATION.include? justify
|
29
|
+
@justify = justify
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param (see Element#initialize)
|
33
|
+
# @param [String] text The string to display in the line of text.
|
34
|
+
#
|
35
|
+
# @option (see Element#initialize)
|
36
|
+
# @option options [:left, :right, :center] :justify (:left) Text justification.
|
37
|
+
def initialize(text, options = {})
|
38
|
+
options = {
|
39
|
+
color: default(:color),
|
40
|
+
justify: default(:justify),
|
41
|
+
}.merge! options
|
42
|
+
|
43
|
+
super(options)
|
44
|
+
|
45
|
+
self.justify = options[:justify]
|
46
|
+
self.color = options[:color]
|
47
|
+
self.text = text
|
48
|
+
end
|
49
|
+
|
50
|
+
def draw_foreground
|
51
|
+
case @justify
|
52
|
+
when :left
|
53
|
+
rel_x = 0.0
|
54
|
+
draw_x = x + padding_left
|
55
|
+
|
56
|
+
when :right
|
57
|
+
rel_x = 1.0
|
58
|
+
draw_x = x + rect.width - padding_right
|
59
|
+
|
60
|
+
when :center
|
61
|
+
rel_x = 0.5
|
62
|
+
draw_x = (x + padding_left) + (rect.width - padding_right - padding_left) / 2.0
|
63
|
+
end
|
64
|
+
|
65
|
+
font.draw_rel(@text, draw_x, y + padding_top, z, rel_x, 0, 1, 1, color)
|
66
|
+
end
|
67
|
+
|
68
|
+
def min_width
|
69
|
+
if @text.empty?
|
70
|
+
[padding_left + padding_right, super].max
|
71
|
+
else
|
72
|
+
[padding_left + font.text_width(@text) + padding_right, super].max
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
def layout
|
78
|
+
rect.width = [min_width, max_width].min
|
79
|
+
|
80
|
+
if @text.empty?
|
81
|
+
rect.height = [[padding_top + padding_bottom, min_height].max, max_height].min
|
82
|
+
else
|
83
|
+
rect.height = [[padding_top + font.height + padding_bottom, min_height].max, max_height].min
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
public
|
88
|
+
def to_s
|
89
|
+
"#{super} '#{@text}'"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -143,6 +143,14 @@ module Fidgit
|
|
143
143
|
super
|
144
144
|
end
|
145
145
|
|
146
|
+
def write_tree
|
147
|
+
puts "=== #{self.class} ==="
|
148
|
+
indent = " "
|
149
|
+
@container.write_tree(indent)
|
150
|
+
@menu.write_tree(indent) if @menu
|
151
|
+
@tool_tip.write_tree(indent) if @tool_tip
|
152
|
+
end
|
153
|
+
|
146
154
|
def draw
|
147
155
|
@container.draw
|
148
156
|
@menu.draw if @menu
|
data/lib/fidgit/version.rb
CHANGED
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative 'helpers/helper'
|
2
|
+
require_relative 'helpers/tex_play_helper'
|
3
|
+
|
4
|
+
require 'fidgit'
|
5
|
+
|
6
|
+
def check_thumbnail_is_square
|
7
|
+
{square: [10, 10], tall: [5, 12], wide: [6, 5]}.each_pair do |type, dimensions|
|
8
|
+
context "with a #{type} image" do
|
9
|
+
it "should be square and just large enough to contain the image" do
|
10
|
+
subject = described_class.new(Gosu::Image.create(*dimensions), thumbnail: true)
|
11
|
+
subject.width.should equal dimensions.max
|
12
|
+
subject.height.should equal dimensions.max
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_image_dimensions
|
19
|
+
{square: [10, 10], tall: [5, 12], wide: [6, 5]}.each_pair do |type, dimensions|
|
20
|
+
context "with a #{type} image" do
|
21
|
+
it "should be just large enough to contain the image" do
|
22
|
+
subject = described_class.new(Gosu::Image.create(*dimensions))
|
23
|
+
subject.width.should equal dimensions.first
|
24
|
+
subject.height.should equal dimensions.last
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Fidgit
|
31
|
+
describe ImageFrame do
|
32
|
+
before :all do
|
33
|
+
$window = Chingu::Window.new(100, 100, false) unless $window
|
34
|
+
end
|
35
|
+
|
36
|
+
before :each do
|
37
|
+
@image = Gosu::Image.create(10, 10)
|
38
|
+
end
|
39
|
+
|
40
|
+
subject { described_class.new(@image) }
|
41
|
+
|
42
|
+
describe '#image' do
|
43
|
+
it "should have the image set" do
|
44
|
+
subject.image.should be @image
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#width and #height' do
|
49
|
+
check_image_dimensions
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "Thumbnails" do
|
53
|
+
subject { described_class.new(@image, thumbnail: true) }
|
54
|
+
|
55
|
+
describe '#image=' do
|
56
|
+
it "should update the height and width" do
|
57
|
+
image = Gosu::Image.create(8, 2)
|
58
|
+
subject.image = image
|
59
|
+
subject.height.should equal 8
|
60
|
+
subject.width.should equal 8
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#width and #height' do
|
65
|
+
check_thumbnail_is_square
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -2,21 +2,9 @@ require_relative "helpers/helper"
|
|
2
2
|
|
3
3
|
include Fidgit
|
4
4
|
|
5
|
-
|
6
|
-
|
7
5
|
describe Label do
|
8
|
-
before :
|
9
|
-
Chingu::Window.new(
|
10
|
-
end
|
11
|
-
|
12
|
-
after :each do
|
13
|
-
$window.close
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#intialize" do
|
17
|
-
it "should not accept a block" do
|
18
|
-
->{ Label.new( "Hello world!") { } }.should raise_error ArgumentError
|
19
|
-
end
|
6
|
+
before :all do
|
7
|
+
$window = Chingu::Window.new(100, 100, false) unless $window
|
20
8
|
end
|
21
9
|
|
22
10
|
context "with default parameters" do
|
@@ -42,7 +30,7 @@ describe Label do
|
|
42
30
|
subject.should be_enabled
|
43
31
|
end
|
44
32
|
|
45
|
-
it "should not have an
|
33
|
+
it "should not have an image" do
|
46
34
|
subject.icon.should be_nil
|
47
35
|
end
|
48
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fidgit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-17 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gosu
|
16
|
-
requirement: &
|
16
|
+
requirement: &22487064 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.7.32
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22487064
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: chingu
|
27
|
-
requirement: &
|
27
|
+
requirement: &22486788 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9rc5
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *22486788
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: clipboard
|
38
|
-
requirement: &
|
38
|
+
requirement: &22486512 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.9.8
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *22486512
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: ffi
|
49
|
-
requirement: &
|
49
|
+
requirement: &22486236 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.9
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *22486236
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &22485960 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.1.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *22485960
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: texplay
|
71
|
-
requirement: &
|
71
|
+
requirement: &22485684 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 0.3.5
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *22485684
|
80
80
|
description: Fidgit is a GUI library built on Gosu/Chingu
|
81
81
|
email:
|
82
82
|
- bil.bagpuss@gmail.com
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/fidgit/elements/grid.rb
|
127
127
|
- lib/fidgit/elements/group.rb
|
128
128
|
- lib/fidgit/elements/horizontal.rb
|
129
|
+
- lib/fidgit/elements/image_frame.rb
|
129
130
|
- lib/fidgit/elements/label.rb
|
130
131
|
- lib/fidgit/elements/list.rb
|
131
132
|
- lib/fidgit/elements/main_packer.rb
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- lib/fidgit/elements/scroll_window.rb
|
138
139
|
- lib/fidgit/elements/slider.rb
|
139
140
|
- lib/fidgit/elements/text_area.rb
|
141
|
+
- lib/fidgit/elements/text_line.rb
|
140
142
|
- lib/fidgit/elements/toggle_button.rb
|
141
143
|
- lib/fidgit/elements/tool_tip.rb
|
142
144
|
- lib/fidgit/elements/vertical.rb
|
@@ -152,7 +154,6 @@ files:
|
|
152
154
|
- lib/fidgit/states/file_dialog.rb
|
153
155
|
- lib/fidgit/states/gui_state.rb
|
154
156
|
- lib/fidgit/states/message_dialog.rb
|
155
|
-
- lib/fidgit/thumbnail.rb
|
156
157
|
- lib/fidgit/version.rb
|
157
158
|
- lib/fidgit/window.rb
|
158
159
|
- media/images/arrow.png
|
@@ -161,17 +162,17 @@ files:
|
|
161
162
|
- media/images/file_file.png
|
162
163
|
- media/images/pixel.png
|
163
164
|
- spec/fidgit/elements/helpers/helper.rb
|
165
|
+
- spec/fidgit/elements/helpers/tex_play_helper.rb
|
166
|
+
- spec/fidgit/elements/image_frame_spec.rb
|
164
167
|
- spec/fidgit/elements/label_spec.rb
|
165
168
|
- spec/fidgit/event_spec.rb
|
166
169
|
- spec/fidgit/gosu_ext/color_spec.rb
|
167
170
|
- spec/fidgit/gosu_ext/helpers/helper.rb
|
168
171
|
- spec/fidgit/helpers/helper.rb
|
169
|
-
- spec/fidgit/helpers/tex_play_helper.rb
|
170
172
|
- spec/fidgit/history_spec.rb
|
171
173
|
- spec/fidgit/redirector_spec.rb
|
172
174
|
- spec/fidgit/schema_spec.rb
|
173
175
|
- spec/fidgit/schema_test.yml
|
174
|
-
- spec/fidgit/thumbnail_spec.rb
|
175
176
|
homepage: http://github.com/Spooner/fidgit/
|
176
177
|
licenses: []
|
177
178
|
post_install_message:
|
data/lib/fidgit/thumbnail.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
# Wrapper for Gosu::Image that always pads the image out to being square.
|
5
|
-
class Thumbnail
|
6
|
-
DEFAULT_COLOR = Gosu::Color.rgb(255, 255, 255)
|
7
|
-
|
8
|
-
attr_reader :image, :height, :width
|
9
|
-
|
10
|
-
def image=(value)
|
11
|
-
@image = value
|
12
|
-
@height = [@image.width, @image.height].max
|
13
|
-
@width = [@image.width, @image.height].max
|
14
|
-
|
15
|
-
value
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(image)
|
19
|
-
raise ArgumentError, "image must be a Gosu::Image" unless image.is_a? Gosu::Image
|
20
|
-
self.image = image
|
21
|
-
end
|
22
|
-
|
23
|
-
def draw(x, y, z_order, scale_x = 1, scale_y = 1, color = DEFAULT_COLOR, mode = :default)
|
24
|
-
@image.draw x + (@width - @image.width) * scale_x / 2, y + (@height - @image.height) * scale_y / 2, z_order, scale_x, scale_y, color, mode
|
25
|
-
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require_relative 'helpers/helper'
|
2
|
-
require_relative 'helpers/tex_play_helper'
|
3
|
-
|
4
|
-
require 'fidgit'
|
5
|
-
|
6
|
-
def check_thumbnail_is_square(dimension)
|
7
|
-
{square: [10, 10], tall: [5, 12], wide: [6, 5]}.each_pair do |type, dimensions|
|
8
|
-
context "with a #{type} image" do
|
9
|
-
it "should be square and just large enough to contain the image" do
|
10
|
-
subject = described_class.new(Image.create(*dimensions))
|
11
|
-
subject.width.should equal dimensions.max
|
12
|
-
subject.height.should equal dimensions.max
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Fidgit
|
19
|
-
describe Thumbnail do
|
20
|
-
before :all do
|
21
|
-
$window = Chingu::Window.new(100, 100, false)
|
22
|
-
@image = Image.create(10, 10)
|
23
|
-
end
|
24
|
-
|
25
|
-
subject { Thumbnail.new(@image) }
|
26
|
-
|
27
|
-
describe '#image' do
|
28
|
-
it "should have the image set" do
|
29
|
-
subject.image.should be @image
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#image=' do
|
34
|
-
it "should update the height and width" do
|
35
|
-
image = Image.create(8, 2)
|
36
|
-
subject.image = image
|
37
|
-
subject.height.should equal 8
|
38
|
-
subject.width.should equal 8
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#width' do
|
43
|
-
check_thumbnail_is_square :width
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#height' do
|
47
|
-
check_thumbnail_is_square :height
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|