fidgit 0.2.4 → 0.2.5
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/.gitignore +7 -7
- data/.rspec +2 -2
- data/CHANGELOG.md +30 -30
- data/Gemfile +3 -3
- data/LICENSE.txt +19 -19
- data/README.textile +139 -139
- data/Rakefile +37 -37
- data/config/default_schema.yml +216 -216
- data/examples/_all_examples.rb +9 -9
- data/examples/align_example.rb +55 -55
- data/examples/button_and_toggle_button_example.rb +37 -37
- data/examples/color_picker_example.rb +16 -16
- data/examples/color_well_example.rb +24 -24
- data/examples/combo_box_example.rb +23 -23
- data/examples/file_dialog_example.rb +41 -41
- data/examples/grid_packer_example.rb +28 -28
- data/examples/helpers/example_window.rb +16 -16
- data/examples/label_example.rb +22 -22
- data/examples/list_example.rb +22 -22
- data/examples/menu_pane_example.rb +26 -26
- data/examples/message_dialog_example.rb +64 -64
- data/examples/radio_button_example.rb +36 -36
- data/examples/readme_example.rb +31 -31
- data/examples/scroll_window_example.rb +48 -48
- data/examples/slider_example.rb +33 -33
- data/examples/splash_example.rb +41 -41
- data/examples/text_area_example.rb +32 -32
- data/fidgit.gemspec +35 -35
- data/lib/fidgit.rb +50 -50
- data/lib/fidgit/chingu_ext/window.rb +5 -5
- data/lib/fidgit/cursor.rb +37 -37
- data/lib/fidgit/elements/button.rb +112 -112
- data/lib/fidgit/elements/color_picker.rb +62 -62
- data/lib/fidgit/elements/color_well.rb +38 -38
- data/lib/fidgit/elements/combo_box.rb +113 -113
- data/lib/fidgit/elements/composite.rb +16 -16
- data/lib/fidgit/elements/container.rb +208 -208
- data/lib/fidgit/elements/element.rb +297 -297
- data/lib/fidgit/elements/file_browser.rb +151 -151
- data/lib/fidgit/elements/grid.rb +226 -226
- data/lib/fidgit/elements/group.rb +64 -64
- data/lib/fidgit/elements/horizontal.rb +11 -11
- data/lib/fidgit/elements/image_frame.rb +64 -64
- data/lib/fidgit/elements/label.rb +84 -84
- data/lib/fidgit/elements/list.rb +46 -46
- data/lib/fidgit/elements/main_packer.rb +24 -24
- data/lib/fidgit/elements/menu_pane.rb +160 -160
- data/lib/fidgit/elements/packer.rb +41 -41
- data/lib/fidgit/elements/radio_button.rb +85 -85
- data/lib/fidgit/elements/scroll_area.rb +67 -67
- data/lib/fidgit/elements/scroll_bar.rb +127 -127
- data/lib/fidgit/elements/scroll_window.rb +82 -82
- data/lib/fidgit/elements/slider.rb +124 -124
- data/lib/fidgit/elements/text_area.rb +493 -493
- data/lib/fidgit/elements/text_line.rb +91 -91
- data/lib/fidgit/elements/toggle_button.rb +66 -66
- data/lib/fidgit/elements/tool_tip.rb +34 -34
- data/lib/fidgit/elements/vertical.rb +11 -11
- data/lib/fidgit/event.rb +158 -158
- data/lib/fidgit/gosu_ext/color.rb +135 -135
- data/lib/fidgit/gosu_ext/gosu_module.rb +24 -24
- data/lib/fidgit/history.rb +90 -90
- data/lib/fidgit/redirector.rb +82 -82
- data/lib/fidgit/schema.rb +123 -123
- data/lib/fidgit/selection.rb +105 -105
- data/lib/fidgit/standard_ext/hash.rb +20 -20
- data/lib/fidgit/states/dialog_state.rb +51 -51
- data/lib/fidgit/states/file_dialog.rb +24 -24
- data/lib/fidgit/states/gui_state.rb +329 -329
- data/lib/fidgit/states/message_dialog.rb +60 -60
- data/lib/fidgit/version.rb +4 -4
- data/lib/fidgit/window.rb +19 -19
- data/spec/fidgit/elements/helpers/helper.rb +2 -2
- data/spec/fidgit/elements/helpers/tex_play_helper.rb +8 -8
- data/spec/fidgit/elements/image_frame_spec.rb +68 -68
- data/spec/fidgit/elements/label_spec.rb +36 -36
- data/spec/fidgit/event_spec.rb +209 -209
- data/spec/fidgit/gosu_ext/color_spec.rb +129 -129
- data/spec/fidgit/gosu_ext/helpers/helper.rb +2 -2
- data/spec/fidgit/helpers/helper.rb +3 -3
- data/spec/fidgit/history_spec.rb +153 -153
- data/spec/fidgit/redirector_spec.rb +77 -77
- data/spec/fidgit/schema_spec.rb +66 -66
- data/spec/fidgit/schema_test.yml +32 -32
- metadata +67 -22
data/examples/splash_example.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
require_relative 'helpers/example_window'
|
2
|
-
|
3
|
-
# By using a splash screen of some sort, one can switch to another resolution for the main game.
|
4
|
-
class ExampleState < Fidgit::GuiState
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
vertical do
|
8
|
-
horizontal do
|
9
|
-
text = label "Width:"
|
10
|
-
|
11
|
-
@width_combo = combo_box(value: [640, 480]) do
|
12
|
-
[[640, 480], [800, 600], [Gosu::screen_width, Gosu::screen_height]].each do |width, height|
|
13
|
-
item "#{width}x#{height}", [width, height]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
@full_screen_button = toggle_button "Fullscreen?"
|
19
|
-
|
20
|
-
button "Load game", icon: Gosu::Image["head_icon.png"] do
|
21
|
-
$window.close
|
22
|
-
window = Chingu::Window.new(*@width_combo.value, @full_screen_button.value)
|
23
|
-
window.push_game_state ExampleAfterState
|
24
|
-
window.show
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class ExampleAfterState < GuiState
|
31
|
-
def initialize
|
32
|
-
super
|
33
|
-
|
34
|
-
on_input(:esc, :exit)
|
35
|
-
|
36
|
-
vertical do
|
37
|
-
label "Game loaded!", icon: Gosu::Image["head_icon.png"], border_color: Gosu::Color.rgb(255, 255, 255)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
1
|
+
require_relative 'helpers/example_window'
|
2
|
+
|
3
|
+
# By using a splash screen of some sort, one can switch to another resolution for the main game.
|
4
|
+
class ExampleState < Fidgit::GuiState
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
vertical do
|
8
|
+
horizontal do
|
9
|
+
text = label "Width:"
|
10
|
+
|
11
|
+
@width_combo = combo_box(value: [640, 480]) do
|
12
|
+
[[640, 480], [800, 600], [Gosu::screen_width, Gosu::screen_height]].each do |width, height|
|
13
|
+
item "#{width}x#{height}", [width, height]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
@full_screen_button = toggle_button "Fullscreen?"
|
19
|
+
|
20
|
+
button "Load game", icon: Gosu::Image["head_icon.png"] do
|
21
|
+
$window.close
|
22
|
+
window = Chingu::Window.new(*@width_combo.value, @full_screen_button.value)
|
23
|
+
window.push_game_state ExampleAfterState
|
24
|
+
window.show
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ExampleAfterState < GuiState
|
31
|
+
def initialize
|
32
|
+
super
|
33
|
+
|
34
|
+
on_input(:esc, :exit)
|
35
|
+
|
36
|
+
vertical do
|
37
|
+
label "Game loaded!", icon: Gosu::Image["head_icon.png"], border_color: Gosu::Color.rgb(255, 255, 255)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
42
|
ExampleWindow.new.show
|
@@ -1,33 +1,33 @@
|
|
1
|
-
require_relative 'helpers/example_window'
|
2
|
-
|
3
|
-
class ExampleState < Fidgit::GuiState
|
4
|
-
def initialize
|
5
|
-
super
|
6
|
-
|
7
|
-
Gosu.register_entity(:entity, Gosu::Image["head_icon.png"])
|
8
|
-
|
9
|
-
string = "<c=3333ff>Hello, my name</c> is <c=ff0000>Brian</c> the&entity;&entity;snail!"
|
10
|
-
horizontal do
|
11
|
-
vertical do
|
12
|
-
label 'disabled'
|
13
|
-
text_area(text: "Can't even select this text", width: 200, enabled: false)
|
14
|
-
end
|
15
|
-
|
16
|
-
vertical do
|
17
|
-
label 'mirrors to right'
|
18
|
-
text_area(width: 200, text: string) do |_, text|
|
19
|
-
@mirror.text = text
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
vertical do
|
24
|
-
my_label = label 'not editable'
|
25
|
-
font = Gosu::Font.new($window, "", my_label.font.height)
|
26
|
-
font["a"] = Gosu::Image["head_icon.png"]
|
27
|
-
@mirror = text_area(text: string, width: 200, editable: false, font: font)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
1
|
+
require_relative 'helpers/example_window'
|
2
|
+
|
3
|
+
class ExampleState < Fidgit::GuiState
|
4
|
+
def initialize
|
5
|
+
super
|
6
|
+
|
7
|
+
Gosu.register_entity(:entity, Gosu::Image["head_icon.png"])
|
8
|
+
|
9
|
+
string = "<c=3333ff>Hello, my name</c> is <c=ff0000>Brian</c> the&entity;&entity;snail!"
|
10
|
+
horizontal do
|
11
|
+
vertical do
|
12
|
+
label 'disabled'
|
13
|
+
text_area(text: "Can't even select this text", width: 200, enabled: false)
|
14
|
+
end
|
15
|
+
|
16
|
+
vertical do
|
17
|
+
label 'mirrors to right'
|
18
|
+
text_area(width: 200, text: string) do |_, text|
|
19
|
+
@mirror.text = text
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
vertical do
|
24
|
+
my_label = label 'not editable'
|
25
|
+
font = Gosu::Font.new($window, "", my_label.font.height)
|
26
|
+
font["a"] = Gosu::Image["head_icon.png"]
|
27
|
+
@mirror = text_area(text: string, width: 200, editable: false, font: font)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
33
|
ExampleWindow.new.show
|
data/fidgit.gemspec
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
-
require "fidgit/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "fidgit"
|
7
|
-
s.version = Fidgit::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Bil Bas (Spooner)"]
|
10
|
-
s.email = ["bil.bagpuss@gmail.com"]
|
11
|
-
s.homepage = "http://github.com/Spooner/fidgit/"
|
12
|
-
s.summary = %q{Fidgit is a GUI library built on Gosu/Chingu}
|
13
|
-
s.description = %q{Fidgit is a GUI library built on Gosu/Chingu}
|
14
|
-
|
15
|
-
s.rubyforge_project = "fidgit"
|
16
|
-
s.has_rdoc = true
|
17
|
-
s.required_ruby_version = "~> 1.9.2"
|
18
|
-
|
19
|
-
s.files = `git ls-files`.split("\n")
|
20
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
-
s.require_paths = ["lib"]
|
23
|
-
s.license = "MIT"
|
24
|
-
|
25
|
-
s.add_runtime_dependency('gosu', '~> 0.7.41')
|
26
|
-
s.add_runtime_dependency('chingu', '~> 0.9rc7')
|
27
|
-
s.add_runtime_dependency('clipboard', '~> 0.9.9')
|
28
|
-
s.add_runtime_dependency('ffi', '~> 1.0.11')
|
29
|
-
|
30
|
-
s.add_development_dependency('rspec', '~> 2.8.0')
|
31
|
-
s.add_development_dependency('texplay', '~> 0.3
|
32
|
-
s.add_development_dependency('rake')
|
33
|
-
s.add_development_dependency('yard')
|
34
|
-
s.add_development_dependency('RedCloth', "~> 4.2.9")
|
35
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require "fidgit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fidgit"
|
7
|
+
s.version = Fidgit::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Bil Bas (Spooner)"]
|
10
|
+
s.email = ["bil.bagpuss@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/Spooner/fidgit/"
|
12
|
+
s.summary = %q{Fidgit is a GUI library built on Gosu/Chingu}
|
13
|
+
s.description = %q{Fidgit is a GUI library built on Gosu/Chingu}
|
14
|
+
|
15
|
+
s.rubyforge_project = "fidgit"
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.required_ruby_version = "~> 1.9.2"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
s.license = "MIT"
|
24
|
+
|
25
|
+
s.add_runtime_dependency('gosu', '~> 0.7.41')
|
26
|
+
s.add_runtime_dependency('chingu', '~> 0.9rc7')
|
27
|
+
s.add_runtime_dependency('clipboard', '~> 0.9.9')
|
28
|
+
s.add_runtime_dependency('ffi', '~> 1.0.11')
|
29
|
+
|
30
|
+
s.add_development_dependency('rspec', '~> 2.8.0')
|
31
|
+
s.add_development_dependency('texplay', '~> 0.4.3')
|
32
|
+
s.add_development_dependency('rake')
|
33
|
+
s.add_development_dependency('yard')
|
34
|
+
s.add_development_dependency('RedCloth', "~> 4.2.9")
|
35
|
+
end
|
data/lib/fidgit.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'chingu'
|
3
|
-
require 'clipboard'
|
4
|
-
|
5
|
-
require_relative "fidgit/cursor"
|
6
|
-
require_relative "fidgit/event"
|
7
|
-
require_relative "fidgit/history"
|
8
|
-
require_relative "fidgit/redirector"
|
9
|
-
require_relative "fidgit/schema"
|
10
|
-
require_relative "fidgit/selection"
|
11
|
-
require_relative "fidgit/version"
|
12
|
-
require_relative "fidgit/window"
|
13
|
-
|
14
|
-
require_relative "fidgit/chingu_ext/window"
|
15
|
-
require_relative "fidgit/gosu_ext/color"
|
16
|
-
require_relative "fidgit/gosu_ext/gosu_module"
|
17
|
-
require_relative "fidgit/standard_ext/hash"
|
18
|
-
|
19
|
-
require_relative "fidgit/elements/element"
|
20
|
-
require_relative "fidgit/elements/container"
|
21
|
-
require_relative "fidgit/elements/packer"
|
22
|
-
require_relative "fidgit/elements/composite"
|
23
|
-
require_relative "fidgit/elements/grid"
|
24
|
-
require_relative "fidgit/elements/group"
|
25
|
-
require_relative "fidgit/elements/label"
|
26
|
-
require_relative "fidgit/elements/button"
|
27
|
-
require_relative "fidgit/elements/radio_button"
|
28
|
-
|
29
|
-
require_relative "fidgit/elements/color_picker"
|
30
|
-
require_relative "fidgit/elements/color_well"
|
31
|
-
require_relative "fidgit/elements/combo_box"
|
32
|
-
require_relative "fidgit/elements/file_browser"
|
33
|
-
require_relative "fidgit/elements/horizontal"
|
34
|
-
require_relative "fidgit/elements/image_frame"
|
35
|
-
require_relative "fidgit/elements/list"
|
36
|
-
require_relative "fidgit/elements/main_packer"
|
37
|
-
require_relative "fidgit/elements/menu_pane"
|
38
|
-
require_relative "fidgit/elements/scroll_area"
|
39
|
-
require_relative "fidgit/elements/scroll_bar"
|
40
|
-
require_relative "fidgit/elements/scroll_window"
|
41
|
-
require_relative "fidgit/elements/slider"
|
42
|
-
require_relative "fidgit/elements/text_area"
|
43
|
-
require_relative "fidgit/elements/text_line"
|
44
|
-
require_relative "fidgit/elements/toggle_button"
|
45
|
-
require_relative "fidgit/elements/tool_tip"
|
46
|
-
require_relative "fidgit/elements/vertical"
|
47
|
-
|
48
|
-
require_relative "fidgit/states/gui_state"
|
49
|
-
require_relative "fidgit/states/dialog_state"
|
50
|
-
require_relative "fidgit/states/file_dialog"
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'chingu'
|
3
|
+
require 'clipboard'
|
4
|
+
|
5
|
+
require_relative "fidgit/cursor"
|
6
|
+
require_relative "fidgit/event"
|
7
|
+
require_relative "fidgit/history"
|
8
|
+
require_relative "fidgit/redirector"
|
9
|
+
require_relative "fidgit/schema"
|
10
|
+
require_relative "fidgit/selection"
|
11
|
+
require_relative "fidgit/version"
|
12
|
+
require_relative "fidgit/window"
|
13
|
+
|
14
|
+
require_relative "fidgit/chingu_ext/window"
|
15
|
+
require_relative "fidgit/gosu_ext/color"
|
16
|
+
require_relative "fidgit/gosu_ext/gosu_module"
|
17
|
+
require_relative "fidgit/standard_ext/hash"
|
18
|
+
|
19
|
+
require_relative "fidgit/elements/element"
|
20
|
+
require_relative "fidgit/elements/container"
|
21
|
+
require_relative "fidgit/elements/packer"
|
22
|
+
require_relative "fidgit/elements/composite"
|
23
|
+
require_relative "fidgit/elements/grid"
|
24
|
+
require_relative "fidgit/elements/group"
|
25
|
+
require_relative "fidgit/elements/label"
|
26
|
+
require_relative "fidgit/elements/button"
|
27
|
+
require_relative "fidgit/elements/radio_button"
|
28
|
+
|
29
|
+
require_relative "fidgit/elements/color_picker"
|
30
|
+
require_relative "fidgit/elements/color_well"
|
31
|
+
require_relative "fidgit/elements/combo_box"
|
32
|
+
require_relative "fidgit/elements/file_browser"
|
33
|
+
require_relative "fidgit/elements/horizontal"
|
34
|
+
require_relative "fidgit/elements/image_frame"
|
35
|
+
require_relative "fidgit/elements/list"
|
36
|
+
require_relative "fidgit/elements/main_packer"
|
37
|
+
require_relative "fidgit/elements/menu_pane"
|
38
|
+
require_relative "fidgit/elements/scroll_area"
|
39
|
+
require_relative "fidgit/elements/scroll_bar"
|
40
|
+
require_relative "fidgit/elements/scroll_window"
|
41
|
+
require_relative "fidgit/elements/slider"
|
42
|
+
require_relative "fidgit/elements/text_area"
|
43
|
+
require_relative "fidgit/elements/text_line"
|
44
|
+
require_relative "fidgit/elements/toggle_button"
|
45
|
+
require_relative "fidgit/elements/tool_tip"
|
46
|
+
require_relative "fidgit/elements/vertical"
|
47
|
+
|
48
|
+
require_relative "fidgit/states/gui_state"
|
49
|
+
require_relative "fidgit/states/dialog_state"
|
50
|
+
require_relative "fidgit/states/file_dialog"
|
51
51
|
require_relative "fidgit/states/message_dialog"
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module Chingu
|
2
|
-
class Window
|
3
|
-
# Include fidgits extra functionality in the Chingu window (which is minimal).
|
4
|
-
include Fidgit::Window
|
5
|
-
end
|
1
|
+
module Chingu
|
2
|
+
class Window
|
3
|
+
# Include fidgits extra functionality in the Chingu window (which is minimal).
|
4
|
+
include Fidgit::Window
|
5
|
+
end
|
6
6
|
end
|
data/lib/fidgit/cursor.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
class Cursor < Chingu::GameObject
|
5
|
-
ARROW = 'arrow.png'
|
6
|
-
HAND = 'hand.png'
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
options = {
|
10
|
-
image: Gosu::Image[ARROW],
|
11
|
-
rotation_center: :top_left,
|
12
|
-
zorder: Float::INFINITY
|
13
|
-
}.merge!(options)
|
14
|
-
|
15
|
-
super(options)
|
16
|
-
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
|
20
|
-
# Is the mouse pointer position inside the game window pane?
|
21
|
-
def inside_window?
|
22
|
-
x >= 0 and y >= 0 and x < $window.width and y < $window.height
|
23
|
-
end
|
24
|
-
|
25
|
-
def update
|
26
|
-
self.x, self.y = $window.mouse_x, $window.mouse_y
|
27
|
-
|
28
|
-
super
|
29
|
-
|
30
|
-
nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def draw
|
34
|
-
# Prevent system and game mouse from being shown at the same time.
|
35
|
-
super if inside_window? and $window.current_game_state.is_a? GuiState and not $window.needs_cursor?
|
36
|
-
end
|
37
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
class Cursor < Chingu::GameObject
|
5
|
+
ARROW = 'arrow.png'
|
6
|
+
HAND = 'hand.png'
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
options = {
|
10
|
+
image: Gosu::Image[ARROW],
|
11
|
+
rotation_center: :top_left,
|
12
|
+
zorder: Float::INFINITY
|
13
|
+
}.merge!(options)
|
14
|
+
|
15
|
+
super(options)
|
16
|
+
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# Is the mouse pointer position inside the game window pane?
|
21
|
+
def inside_window?
|
22
|
+
x >= 0 and y >= 0 and x < $window.width and y < $window.height
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
self.x, self.y = $window.mouse_x, $window.mouse_y
|
27
|
+
|
28
|
+
super
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def draw
|
34
|
+
# Prevent system and game mouse from being shown at the same time.
|
35
|
+
super if inside_window? and $window.current_game_state.is_a? GuiState and not $window.needs_cursor?
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
@@ -1,113 +1,113 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
class Button < Label
|
5
|
-
# @param (see Label#initialize)
|
6
|
-
# @option (see Label#initialize)
|
7
|
-
# @option options [Symbol] :shortcut (nil) Adds a shortcut key for this element, that activates it. :auto takes the first letter of the text.
|
8
|
-
def initialize(text, options = {}, &block)
|
9
|
-
options = {
|
10
|
-
color: default(:color),
|
11
|
-
background_color: default(:background_color),
|
12
|
-
border_color: default(:border_color),
|
13
|
-
shortcut_color: default(:shortcut_color),
|
14
|
-
shortcut: nil,
|
15
|
-
}.merge! options
|
16
|
-
|
17
|
-
@shortcut_color = options[:shortcut_color].dup
|
18
|
-
|
19
|
-
@shortcut = if options[:shortcut] == :auto
|
20
|
-
raise ArgumentError.new("Can't use :auto for :shortcut without text") if text.empty?
|
21
|
-
text[0].downcase.to_sym
|
22
|
-
else
|
23
|
-
options[:shortcut]
|
24
|
-
end
|
25
|
-
|
26
|
-
raise ArgumentError.new(":shortcut must be a symbol") unless @shortcut.nil? or @shortcut.is_a? Symbol
|
27
|
-
|
28
|
-
super(text, options)
|
29
|
-
|
30
|
-
self.text = text # Force shortcut to be written out properly.
|
31
|
-
|
32
|
-
update_colors
|
33
|
-
end
|
34
|
-
|
35
|
-
def text=(value)
|
36
|
-
if @shortcut
|
37
|
-
super value.sub(/#{Regexp.escape @shortcut}/i) {|char| "<c=#{@shortcut_color.to_hex}>#{char}</c>" }
|
38
|
-
else
|
39
|
-
super value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def parent=(value)
|
44
|
-
if @shortcut
|
45
|
-
state = $window.game_state_manager.inside_state || $window.current_game_state
|
46
|
-
if parent
|
47
|
-
raise ArgumentError.new("Repeat of shortcut #{@shortcut.inspect}") if state.input.has_key? @shortcut
|
48
|
-
state.on_input(@shortcut) { activate unless state.focus }
|
49
|
-
else
|
50
|
-
state.input.delete @shortcut
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
super(value)
|
55
|
-
end
|
56
|
-
|
57
|
-
def clicked_left_mouse_button(sender, x, y)
|
58
|
-
# TODO: Play click sound?
|
59
|
-
nil
|
60
|
-
end
|
61
|
-
|
62
|
-
def enabled=(value)
|
63
|
-
super(value)
|
64
|
-
update_colors
|
65
|
-
|
66
|
-
value
|
67
|
-
end
|
68
|
-
|
69
|
-
def enter(sender)
|
70
|
-
@mouse_over = true
|
71
|
-
update_colors
|
72
|
-
|
73
|
-
nil
|
74
|
-
end
|
75
|
-
|
76
|
-
def leave(sender)
|
77
|
-
@mouse_over = false
|
78
|
-
update_colors
|
79
|
-
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
|
83
|
-
protected
|
84
|
-
def update_colors
|
85
|
-
[:color, :background_color].each do |attribute|
|
86
|
-
send :"#{attribute.to_s}=", enabled? ? default(attribute) : default(:disabled, attribute)
|
87
|
-
end
|
88
|
-
|
89
|
-
self.background_color = if @mouse_over and enabled?
|
90
|
-
default(:hover, :background_color)
|
91
|
-
else
|
92
|
-
default(:background_color)
|
93
|
-
end
|
94
|
-
|
95
|
-
@icon.enabled = enabled? if @icon
|
96
|
-
|
97
|
-
nil
|
98
|
-
end
|
99
|
-
|
100
|
-
protected
|
101
|
-
# A block added to any button subscribes to LMB click.
|
102
|
-
def post_init_block(&block)
|
103
|
-
subscribe :clicked_left_mouse_button, &block
|
104
|
-
end
|
105
|
-
|
106
|
-
public
|
107
|
-
# Activate the button, as though it had been clicked on.
|
108
|
-
# Does not do anything if the button is disabled.
|
109
|
-
def activate
|
110
|
-
publish(:clicked_left_mouse_button, x + width / 2, y + height / 2) if enabled?
|
111
|
-
end
|
112
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
class Button < Label
|
5
|
+
# @param (see Label#initialize)
|
6
|
+
# @option (see Label#initialize)
|
7
|
+
# @option options [Symbol] :shortcut (nil) Adds a shortcut key for this element, that activates it. :auto takes the first letter of the text.
|
8
|
+
def initialize(text, options = {}, &block)
|
9
|
+
options = {
|
10
|
+
color: default(:color),
|
11
|
+
background_color: default(:background_color),
|
12
|
+
border_color: default(:border_color),
|
13
|
+
shortcut_color: default(:shortcut_color),
|
14
|
+
shortcut: nil,
|
15
|
+
}.merge! options
|
16
|
+
|
17
|
+
@shortcut_color = options[:shortcut_color].dup
|
18
|
+
|
19
|
+
@shortcut = if options[:shortcut] == :auto
|
20
|
+
raise ArgumentError.new("Can't use :auto for :shortcut without text") if text.empty?
|
21
|
+
text[0].downcase.to_sym
|
22
|
+
else
|
23
|
+
options[:shortcut]
|
24
|
+
end
|
25
|
+
|
26
|
+
raise ArgumentError.new(":shortcut must be a symbol") unless @shortcut.nil? or @shortcut.is_a? Symbol
|
27
|
+
|
28
|
+
super(text, options)
|
29
|
+
|
30
|
+
self.text = text # Force shortcut to be written out properly.
|
31
|
+
|
32
|
+
update_colors
|
33
|
+
end
|
34
|
+
|
35
|
+
def text=(value)
|
36
|
+
if @shortcut
|
37
|
+
super value.sub(/#{Regexp.escape @shortcut}/i) {|char| "<c=#{@shortcut_color.to_hex}>#{char}</c>" }
|
38
|
+
else
|
39
|
+
super value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def parent=(value)
|
44
|
+
if @shortcut
|
45
|
+
state = $window.game_state_manager.inside_state || $window.current_game_state
|
46
|
+
if parent
|
47
|
+
raise ArgumentError.new("Repeat of shortcut #{@shortcut.inspect}") if state.input.has_key? @shortcut
|
48
|
+
state.on_input(@shortcut) { activate unless state.focus }
|
49
|
+
else
|
50
|
+
state.input.delete @shortcut
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
super(value)
|
55
|
+
end
|
56
|
+
|
57
|
+
def clicked_left_mouse_button(sender, x, y)
|
58
|
+
# TODO: Play click sound?
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def enabled=(value)
|
63
|
+
super(value)
|
64
|
+
update_colors
|
65
|
+
|
66
|
+
value
|
67
|
+
end
|
68
|
+
|
69
|
+
def enter(sender)
|
70
|
+
@mouse_over = true
|
71
|
+
update_colors
|
72
|
+
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def leave(sender)
|
77
|
+
@mouse_over = false
|
78
|
+
update_colors
|
79
|
+
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
def update_colors
|
85
|
+
[:color, :background_color].each do |attribute|
|
86
|
+
send :"#{attribute.to_s}=", enabled? ? default(attribute) : default(:disabled, attribute)
|
87
|
+
end
|
88
|
+
|
89
|
+
self.background_color = if @mouse_over and enabled?
|
90
|
+
default(:hover, :background_color)
|
91
|
+
else
|
92
|
+
default(:background_color)
|
93
|
+
end
|
94
|
+
|
95
|
+
@icon.enabled = enabled? if @icon
|
96
|
+
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
100
|
+
protected
|
101
|
+
# A block added to any button subscribes to LMB click.
|
102
|
+
def post_init_block(&block)
|
103
|
+
subscribe :clicked_left_mouse_button, &block
|
104
|
+
end
|
105
|
+
|
106
|
+
public
|
107
|
+
# Activate the button, as though it had been clicked on.
|
108
|
+
# Does not do anything if the button is disabled.
|
109
|
+
def activate
|
110
|
+
publish(:clicked_left_mouse_button, x + width / 2, y + height / 2) if enabled?
|
111
|
+
end
|
112
|
+
end
|
113
113
|
end
|