fidgit 0.0.2alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/COPYING.txt +674 -0
- data/Gemfile +4 -0
- data/README.textile +138 -0
- data/Rakefile +38 -0
- data/config/default_schema.yml +180 -0
- data/examples/_all_examples.rb +9 -0
- data/examples/align_example.rb +56 -0
- data/examples/button_and_toggle_button_example.rb +27 -0
- data/examples/color_picker_example.rb +17 -0
- data/examples/color_well_example.rb +25 -0
- data/examples/combo_box_example.rb +24 -0
- data/examples/file_dialog_example.rb +42 -0
- data/examples/grid_packer_example.rb +29 -0
- data/examples/helpers/example_window.rb +17 -0
- data/examples/label_example.rb +17 -0
- data/examples/list_example.rb +23 -0
- data/examples/media/images/head_icon.png +0 -0
- data/examples/menu_pane_example.rb +27 -0
- data/examples/message_dialog_example.rb +65 -0
- data/examples/radio_button_example.rb +37 -0
- data/examples/readme_example.rb +32 -0
- data/examples/scroll_window_example.rb +49 -0
- data/examples/slider_example.rb +30 -0
- data/examples/splash_example.rb +42 -0
- data/examples/text_area_example.rb +28 -0
- data/fidgit.gemspec +28 -0
- data/lib/fidgit.rb +4 -0
- data/lib/fidgit/chingu_ext/window.rb +6 -0
- data/lib/fidgit/clipboard.rb +23 -0
- data/lib/fidgit/cursor.rb +38 -0
- data/lib/fidgit/elements/button.rb +68 -0
- data/lib/fidgit/elements/color_picker.rb +63 -0
- data/lib/fidgit/elements/color_well.rb +39 -0
- data/lib/fidgit/elements/combo_box.rb +85 -0
- data/lib/fidgit/elements/composite.rb +17 -0
- data/lib/fidgit/elements/container.rb +187 -0
- data/lib/fidgit/elements/element.rb +252 -0
- data/lib/fidgit/elements/file_browser.rb +152 -0
- data/lib/fidgit/elements/grid_packer.rb +219 -0
- data/lib/fidgit/elements/group.rb +66 -0
- data/lib/fidgit/elements/horizontal_packer.rb +12 -0
- data/lib/fidgit/elements/label.rb +77 -0
- data/lib/fidgit/elements/list.rb +47 -0
- data/lib/fidgit/elements/menu_pane.rb +149 -0
- data/lib/fidgit/elements/packer.rb +42 -0
- data/lib/fidgit/elements/radio_button.rb +86 -0
- data/lib/fidgit/elements/scroll_area.rb +75 -0
- data/lib/fidgit/elements/scroll_bar.rb +114 -0
- data/lib/fidgit/elements/scroll_window.rb +92 -0
- data/lib/fidgit/elements/slider.rb +119 -0
- data/lib/fidgit/elements/text_area.rb +351 -0
- data/lib/fidgit/elements/toggle_button.rb +67 -0
- data/lib/fidgit/elements/tool_tip.rb +35 -0
- data/lib/fidgit/elements/vertical_packer.rb +12 -0
- data/lib/fidgit/event.rb +99 -0
- data/lib/fidgit/gosu_ext/color.rb +123 -0
- data/lib/fidgit/history.rb +85 -0
- data/lib/fidgit/redirector.rb +83 -0
- data/lib/fidgit/schema.rb +123 -0
- data/lib/fidgit/selection.rb +106 -0
- data/lib/fidgit/standard_ext/hash.rb +21 -0
- data/lib/fidgit/states/dialog_state.rb +42 -0
- data/lib/fidgit/states/file_dialog.rb +24 -0
- data/lib/fidgit/states/gui_state.rb +301 -0
- data/lib/fidgit/states/message_dialog.rb +61 -0
- data/lib/fidgit/thumbnail.rb +29 -0
- data/lib/fidgit/version.rb +5 -0
- data/lib/fidgit/window.rb +19 -0
- data/media/images/arrow.png +0 -0
- data/media/images/file_directory.png +0 -0
- data/media/images/file_file.png +0 -0
- data/media/images/pixel.png +0 -0
- data/spec/fidgit/elements/helpers/helper.rb +3 -0
- data/spec/fidgit/elements/label_spec.rb +49 -0
- data/spec/fidgit/event_spec.rb +149 -0
- data/spec/fidgit/gosu_ext/color_spec.rb +130 -0
- data/spec/fidgit/gosu_ext/helpers/helper.rb +3 -0
- data/spec/fidgit/helpers/helper.rb +4 -0
- data/spec/fidgit/helpers/tex_play_helper.rb +9 -0
- data/spec/fidgit/history_spec.rb +144 -0
- data/spec/fidgit/redirector_spec.rb +78 -0
- data/spec/fidgit/schema_spec.rb +67 -0
- data/spec/fidgit/schema_test.yml +32 -0
- data/spec/fidgit/thumbnail_spec.rb +50 -0
- metadata +177 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
module Fidgit
|
3
|
+
# A simple dialog that manages a message with a set of buttons beneath it.
|
4
|
+
class MessageDialog < DialogState
|
5
|
+
VALID_TYPES = [:ok, :ok_cancel, :yes_no, :yes_no_cancel, :quit_cancel, :quit_save_cancel]
|
6
|
+
|
7
|
+
attr_reader :type
|
8
|
+
|
9
|
+
# @param [String] message
|
10
|
+
#
|
11
|
+
# @option options [Symbol] :type (:ok) One from :ok, :ok_cancel, :yes_no, :yes_no_cancel, :quit_cancel or :quit_save_cancel
|
12
|
+
# @option options [String] :ok_text ("OK")
|
13
|
+
# @option options [String] :yes_text ("Yes")
|
14
|
+
# @option options [String] :no_text ("No")
|
15
|
+
# @option options [String] :cancel_text ("Cancel")
|
16
|
+
# @option options [String] :save_text ("Save")
|
17
|
+
# @option options [String] :quit_text ("Quit")
|
18
|
+
# @option options [Boolean] :show (true) Whether to show the message immediately (otherwise need to use #show later).
|
19
|
+
#
|
20
|
+
# @yield when the dialog is closed.
|
21
|
+
# @yieldparam [Symbol] result :ok, :yes, :no, :quit, :save or :cancel, depending on the button pressed.
|
22
|
+
def initialize(message, options = {}, &block)
|
23
|
+
options = {
|
24
|
+
type: :ok,
|
25
|
+
ok_text: "OK",
|
26
|
+
yes_text: "Yes",
|
27
|
+
no_text: "No",
|
28
|
+
quit_text: "Quit",
|
29
|
+
save_text: "Save",
|
30
|
+
cancel_text: "Cancel",
|
31
|
+
show: true,
|
32
|
+
background_color: DEFAULT_BACKGROUND_COLOR,
|
33
|
+
border_color: DEFAULT_BORDER_COLOR,
|
34
|
+
width: $window.width / 2
|
35
|
+
}.merge! options
|
36
|
+
|
37
|
+
@type = options[:type]
|
38
|
+
raise ArgumentError, ":type must be one of #{VALID_TYPES}, not #{@type}" unless VALID_TYPES.include? @type
|
39
|
+
|
40
|
+
super(options)
|
41
|
+
|
42
|
+
# Dialog is forced to the centre.
|
43
|
+
options[:align_h] = options[:align_v] = :center
|
44
|
+
|
45
|
+
pack :vertical, options do
|
46
|
+
text_area(text: message, enabled: false, width: options[:width] - padding_left - padding_right)
|
47
|
+
|
48
|
+
pack :horizontal, align_h: :center do
|
49
|
+
@type.to_s.split('_').each do |type|
|
50
|
+
button(options[:"#{type}_text"]) do
|
51
|
+
hide
|
52
|
+
block.call type.to_sym if block
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
show if options[:show]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative "helpers/helper"
|
2
|
+
|
3
|
+
include Fidgit
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
describe Label do
|
8
|
+
before :each do
|
9
|
+
Chingu::Window.new(10, 10, false)
|
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
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with default parameters" do
|
23
|
+
subject { Label.new( "Hello world!") }
|
24
|
+
|
25
|
+
it "should have text value set" do
|
26
|
+
subject.text.should eq "Hello world!"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have white text" do
|
30
|
+
subject.color.should eq Gosu::Color.rgb(255, 255, 255)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have a transparent background" do
|
34
|
+
subject.background_color.should be_transparent
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have a transparent border" do
|
38
|
+
subject.border_color.should be_transparent
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be enabled" do
|
42
|
+
subject.should be_enabled
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not have an icon" do
|
46
|
+
subject.icon.should be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require_relative 'helpers/helper'
|
2
|
+
|
3
|
+
require 'event'
|
4
|
+
|
5
|
+
module Fidgit
|
6
|
+
describe Event do
|
7
|
+
before :each do
|
8
|
+
class Test
|
9
|
+
include Event
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
Fidgit.send :remove_const, :Test
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { Test }
|
18
|
+
|
19
|
+
describe "events" do
|
20
|
+
it "should initially be empty" do
|
21
|
+
subject.events.should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "event" do
|
26
|
+
it "should add the event to the list of events handled" do
|
27
|
+
subject.event :frog
|
28
|
+
subject.events.should include :frog
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should inherit parent's events and be able to add more" do
|
32
|
+
Test.event :frog
|
33
|
+
class Test2 < Test; end
|
34
|
+
Test2.event :fish
|
35
|
+
Test2.events.should include :frog
|
36
|
+
Test2.events.should include :fish
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "When included into a class that is instanced" do
|
41
|
+
subject { Test.event :frog; Test.new }
|
42
|
+
|
43
|
+
describe "#subscribe" do
|
44
|
+
it "should add a handler as a block" do
|
45
|
+
subject.subscribe(:frog) { puts "hello" }
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should fail if the event name isn't handled by this object" do
|
49
|
+
->{ subject.subscribe(:unhandled_event) {} }.should raise_error ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add a handler as a method" do
|
53
|
+
subject.stub! :handler
|
54
|
+
subject.subscribe(:frog, subject.method(:handler))
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should fail if neither a method or a block is passed" do
|
58
|
+
->{ subject.subscribe(:frog) }.should raise_error ArgumentError
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should fail if both a method and a block is passed" do
|
62
|
+
subject.stub! :handler
|
63
|
+
->{ subject.subscribe(:frog, subject.method(:handler)) { } }.should raise_error ArgumentError
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#publish" do
|
68
|
+
it "should return nil if there are no handlers" do
|
69
|
+
subject.publish(:frog).should be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return nil if there are no handlers that handle the event" do
|
73
|
+
subject.should_receive(:frog).with(subject)
|
74
|
+
subject.should_receive(:handler).with(subject)
|
75
|
+
subject.subscribe(:frog, subject.method(:handler))
|
76
|
+
subject.publish(:frog).should be_nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return :handled if a manual handler handled the event and not call other handlers" do
|
80
|
+
subject.should_not_receive(:handler1)
|
81
|
+
subject.should_receive(:handler2).with(subject).and_return(:handled)
|
82
|
+
subject.subscribe(:frog, subject.method(:handler1))
|
83
|
+
subject.subscribe(:frog, subject.method(:handler2))
|
84
|
+
subject.publish(:frog).should == :handled
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return :handled if an automatic handler handled the event and not call other handlers" do
|
88
|
+
subject.should_receive(:frog).with(subject).and_return(:handled)
|
89
|
+
subject.should_not_receive(:handler2)
|
90
|
+
subject.subscribe(:frog, subject.method(:handler2))
|
91
|
+
subject.publish(:frog).should == :handled
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should pass the object as the first parameter" do
|
95
|
+
subject.should_receive(:handler).with(subject)
|
96
|
+
subject.subscribe(:frog, subject.method(:handler))
|
97
|
+
subject.publish :frog
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call all the handlers, once each" do
|
101
|
+
subject.should_receive(:handler1).with(subject)
|
102
|
+
subject.should_receive(:handler2).with(subject)
|
103
|
+
subject.subscribe(:frog, subject.method(:handler1))
|
104
|
+
subject.subscribe(:frog, subject.method(:handler2))
|
105
|
+
subject.publish(:frog).should be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should pass parameters passed to it" do
|
109
|
+
subject.should_receive(:handler).with(subject, 1, 2)
|
110
|
+
subject.subscribe(:frog, subject.method(:handler))
|
111
|
+
subject.publish(:frog, 1, 2).should be_nil
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should do nothing if the subject is disabled" do
|
115
|
+
subject.should_receive(:enabled?).and_return(false)
|
116
|
+
subject.should_not_receive(:handler)
|
117
|
+
subject.subscribe(:frog, subject.method(:handler))
|
118
|
+
subject.publish(:frog, 1, 2).should be_nil
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should act normally if the subject is enabled" do
|
122
|
+
subject.should_receive(:enabled?).and_return(true)
|
123
|
+
subject.should_receive(:handler)
|
124
|
+
subject.subscribe(:frog, subject.method(:handler))
|
125
|
+
subject.publish(:frog, 1, 2).should be_nil
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should only call the handlers requested" do
|
129
|
+
Test.event :fish
|
130
|
+
|
131
|
+
subject.should_receive(:handler1).with(subject)
|
132
|
+
subject.should_not_receive(:handler2)
|
133
|
+
subject.subscribe(:frog, subject.method(:handler1))
|
134
|
+
subject.subscribe(:fish, subject.method(:handler2))
|
135
|
+
subject.publish(:frog).should be_nil
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should automatically call a method on the publisher if it exists" do
|
139
|
+
subject.should_receive(:frog).with(subject)
|
140
|
+
subject.publish(:frog).should be_nil
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should fail if the event name isn't handled by this object" do
|
144
|
+
->{ subject.publish(:unhandled_event) }.should raise_error ArgumentError
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require_relative "helpers/helper"
|
2
|
+
|
3
|
+
include Gosu
|
4
|
+
|
5
|
+
describe Color do
|
6
|
+
describe "rgb" do
|
7
|
+
it "should create a color with the correct values from channel values" do
|
8
|
+
color = Color.rgb(1, 2, 3)
|
9
|
+
color.red.should equal 1
|
10
|
+
color.green.should equal 2
|
11
|
+
color.blue.should equal 3
|
12
|
+
color.alpha.should equal 255
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "rgba" do
|
17
|
+
it "should create a color with the correct value from channel valuess" do
|
18
|
+
color = Color.rgba(1, 2, 3, 4)
|
19
|
+
color.red.should equal 1
|
20
|
+
color.green.should equal 2
|
21
|
+
color.blue.should equal 3
|
22
|
+
color.alpha.should equal 4
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "argb" do
|
27
|
+
it "should create a color with the correct values from channel values" do
|
28
|
+
color = Color.argb(1, 2, 3, 4)
|
29
|
+
color.red.should equal 2
|
30
|
+
color.green.should equal 3
|
31
|
+
color.blue.should equal 4
|
32
|
+
color.alpha.should equal 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "ahsv" do
|
37
|
+
it "should create a color with the correct values from channel values" do
|
38
|
+
color = Color.ahsv(1, 180.0, 0.5, 0.7)
|
39
|
+
color.hue.should be_within(0.001).of(180.0)
|
40
|
+
color.saturation.should be_within(0.01).of(0.5)
|
41
|
+
color.value.should be_within(0.01).of(0.7)
|
42
|
+
color.alpha.should equal 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "hsva" do
|
47
|
+
it "should create a color with the correct values from channel values" do
|
48
|
+
color = Color.hsva(180.0, 0.5, 0.7, 4)
|
49
|
+
color.hue.should be_within(0.001).of(180.0)
|
50
|
+
color.saturation.should be_within(0.01).of(0.5)
|
51
|
+
color.value.should be_within(0.01).of(0.7)
|
52
|
+
color.alpha.should equal 4
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "from_tex_play" do
|
57
|
+
it "should create a color with the correct values" do
|
58
|
+
color = Color.from_tex_play([1 / 255.0, 2 / 255.0, 3 / 255.0, 4 / 255.0])
|
59
|
+
color.red.should equal 1
|
60
|
+
color.green.should equal 2
|
61
|
+
color.blue.should equal 3
|
62
|
+
color.alpha.should equal 4
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#to_tex_play" do
|
67
|
+
it "should create an array with the correct values" do
|
68
|
+
array = Color.rgba(1, 2, 3, 4).to_tex_play
|
69
|
+
array.should eq [1 / 255.0, 2 / 255.0, 3 / 255.0, 4 / 255.0]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#==" do
|
74
|
+
it "should return true for colours that are identical" do
|
75
|
+
(Color.rgb(1, 2, 3) == Color.rgb(1, 2, 3)).should be_true
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return false for colours that are not the same" do
|
79
|
+
(Color.rgb(1, 2, 3) == Color.rgb(4, 2, 3)).should be_false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#transparent?" do
|
84
|
+
it "should be true if alpha is 0" do
|
85
|
+
Color.rgba(1, 1, 1, 0).should be_transparent
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should be false if 0 > alpha > 255" do
|
89
|
+
Color.rgba(1, 1, 1, 2).should_not be_transparent
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be false if alpha == 255" do
|
93
|
+
Color.rgba(1, 1, 1, 255).should_not be_transparent
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#opaque?" do
|
98
|
+
it "should be true if alpha is 0" do
|
99
|
+
Color.rgba(1, 1, 1, 0).should_not be_opaque
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be false if 0 > alpha > 255" do
|
103
|
+
Color.rgba(1, 1, 1, 2).should_not be_opaque
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should be false if alpha == 255" do
|
107
|
+
Color.rgba(1, 1, 1, 255).should be_opaque
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#+" do
|
112
|
+
it "should add two colours together" do
|
113
|
+
(Color.rgba(1, 2, 3, 4) + Color.rgba(10, 20, 30, 40)).should == Color.rgba(11, 22, 33, 44)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should cap values at 255" do
|
117
|
+
(Color.rgba(56, 56, 56, 56) + Color.rgba(200, 200, 200, 200)).should == Color.rgba(255, 255, 255, 255)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#-" do
|
122
|
+
it "should subtract one color from another two colours together" do
|
123
|
+
(Color.rgba(10, 20, 30, 40) - Color.rgba(1, 2, 3, 4)).should == Color.rgba(9, 18, 27, 36)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should cap values at 0" do
|
127
|
+
(Color.rgba(56, 56, 56, 56) - Color.rgba(57, 57, 57, 57)).should == Color.rgba(0, 0, 0, 0)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|