wads 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/README.md +62 -2
- data/data/sample_graph.csv +11 -0
- data/data/starwars-episode-4-interactions.json +336 -0
- data/lib/wads/app.rb +41 -183
- data/lib/wads/data_structures.rb +705 -17
- data/lib/wads/textinput.rb +66 -15
- data/lib/wads/version.rb +1 -1
- data/lib/wads/widgets.rb +2827 -271
- data/lib/wads.rb +1 -1
- data/media/CircleAlpha.png +0 -0
- data/media/CircleAqua.png +0 -0
- data/media/CircleBlue.png +0 -0
- data/media/CircleGray.png +0 -0
- data/media/CircleGreen.png +0 -0
- data/media/CirclePurple.png +0 -0
- data/media/CircleRed.png +0 -0
- data/media/CircleWhite.png +0 -0
- data/media/CircleYellow.png +0 -0
- data/media/SampleGraph.png +0 -0
- data/media/StocksSample.png +0 -0
- data/media/WadsScreenshot.png +0 -0
- data/run-graph +3 -0
- data/run-star-wars +3 -0
- data/run-stocks +3 -0
- data/run-theme-test +3 -0
- data/samples/basic_gosu_with_graph_widget.rb +66 -0
- data/samples/graph.rb +72 -0
- data/samples/star_wars.rb +112 -0
- data/samples/stocks.rb +126 -0
- data/samples/theme_test.rb +256 -0
- metadata +26 -5
- data/run-sample-app +0 -3
- data/sample_app.rb +0 -52
data/lib/wads/textinput.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'gosu'
|
2
2
|
|
3
|
+
module Wads
|
4
|
+
|
3
5
|
class TextField < Gosu::TextInput
|
4
6
|
# Some constants that define our appearance.
|
5
7
|
INACTIVE_COLOR = 0xcc666666
|
@@ -9,27 +11,33 @@ class TextField < Gosu::TextInput
|
|
9
11
|
PADDING = 5
|
10
12
|
|
11
13
|
attr_reader :x, :y
|
14
|
+
attr_accessor :base_z
|
15
|
+
attr_accessor :old_value
|
12
16
|
|
13
|
-
def initialize(
|
17
|
+
def initialize(x, y, original_text, default_width)
|
14
18
|
super()
|
15
19
|
|
16
|
-
@
|
20
|
+
@x = x
|
21
|
+
@y = y
|
22
|
+
@font = WadsConfig.instance.current_theme.font
|
17
23
|
@default_width = default_width
|
24
|
+
@base_z = 0
|
18
25
|
self.text = original_text
|
26
|
+
@old_value = self.text
|
19
27
|
end
|
20
28
|
|
21
29
|
def draw
|
22
30
|
# Depending on whether this is the currently selected input or not, change the
|
23
31
|
# background's color.
|
24
|
-
if
|
32
|
+
if WadsConfig.instance.get_window.text_input == self then
|
25
33
|
background_color = ACTIVE_COLOR
|
26
34
|
else
|
27
35
|
background_color = INACTIVE_COLOR
|
28
36
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
WadsConfig.instance.get_window.draw_quad(x - PADDING, y - PADDING, background_color,
|
38
|
+
x + width + PADDING, y - PADDING, background_color,
|
39
|
+
x - PADDING, y + height + PADDING, background_color,
|
40
|
+
x + width + PADDING, y + height + PADDING, background_color, @base_z + 9)
|
33
41
|
|
34
42
|
# Calculate the position of the caret and the selection start.
|
35
43
|
pos_x = x + @font.text_width(self.text[0...self.caret_pos])
|
@@ -37,19 +45,19 @@ class TextField < Gosu::TextInput
|
|
37
45
|
|
38
46
|
# Draw the selection background, if any; if not, sel_x and pos_x will be
|
39
47
|
# the same value, making this quad empty.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
WadsConfig.instance.get_window.draw_quad(sel_x, y, SELECTION_COLOR,
|
49
|
+
pos_x, y, SELECTION_COLOR,
|
50
|
+
sel_x, y + height, SELECTION_COLOR,
|
51
|
+
pos_x, y + height, SELECTION_COLOR, @base_z + 10)
|
44
52
|
|
45
53
|
# Draw the caret; again, only if this is the currently selected field.
|
46
|
-
if
|
47
|
-
|
48
|
-
|
54
|
+
if WadsConfig.instance.get_window.text_input == self then
|
55
|
+
WadsConfig.instance.get_window.draw_line(pos_x, y, CARET_COLOR,
|
56
|
+
pos_x, y + height, CARET_COLOR, @base_z + 10)
|
49
57
|
end
|
50
58
|
|
51
59
|
# Finally, draw the text itself!
|
52
|
-
@font.draw_text(self.text, x, y,
|
60
|
+
@font.draw_text(self.text, x, y, @base_z + 10)
|
53
61
|
end
|
54
62
|
|
55
63
|
# This text field grows with the text that's being entered.
|
@@ -71,6 +79,10 @@ class TextField < Gosu::TextInput
|
|
71
79
|
mouse_x > x - PADDING and mouse_x < x + width + PADDING and
|
72
80
|
mouse_y > y - PADDING and mouse_y < y + height + PADDING
|
73
81
|
end
|
82
|
+
|
83
|
+
def contains_click(mouse_x, mouse_y)
|
84
|
+
under_point?(mouse_x, mouse_y)
|
85
|
+
end
|
74
86
|
|
75
87
|
# Tries to move the caret to the position specifies by mouse_x
|
76
88
|
def move_caret(mouse_x)
|
@@ -84,4 +96,43 @@ class TextField < Gosu::TextInput
|
|
84
96
|
# Default case: user must have clicked the right edge
|
85
97
|
self.caret_pos = self.selection_start = self.text.length
|
86
98
|
end
|
99
|
+
|
100
|
+
def button_down(id, mouse_x, mouse_y)
|
101
|
+
if id == Gosu::MsLeft
|
102
|
+
move_caret(mouse_x)
|
103
|
+
else
|
104
|
+
if @old_value == self.text
|
105
|
+
# nothing to do
|
106
|
+
else
|
107
|
+
@old_value = self.text
|
108
|
+
return WidgetResult.new(false, EVENT_TEXT_INPUT, [self.text])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def button_up(id, mouse_x, mouse_y)
|
114
|
+
# empty base implementation
|
115
|
+
end
|
116
|
+
|
117
|
+
def update(update_count, mouse_x, mouse_y)
|
118
|
+
# empty base implementation
|
119
|
+
end
|
120
|
+
|
121
|
+
def handle_mouse_down mouse_x, mouse_y
|
122
|
+
# empty base implementation
|
123
|
+
end
|
124
|
+
|
125
|
+
def handle_mouse_up mouse_x, mouse_y
|
126
|
+
# empty base implementation
|
127
|
+
end
|
128
|
+
|
129
|
+
def handle_key_press id, mouse_x, mouse_y
|
130
|
+
# empty base implementation
|
131
|
+
end
|
132
|
+
|
133
|
+
def handle_update update_count, mouse_x, mouse_y
|
134
|
+
# empty base implementation
|
135
|
+
end
|
87
136
|
end
|
137
|
+
|
138
|
+
end # end wads module
|
data/lib/wads/version.rb
CHANGED