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.
@@ -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(window, font, x, y, original_text, default_width)
17
+ def initialize(x, y, original_text, default_width)
14
18
  super()
15
19
 
16
- @window, @font, @x, @y = window, font, x, y
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 @window.text_input == self then
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
- @window.draw_quad(x - PADDING, y - PADDING, background_color,
30
- x + width + PADDING, y - PADDING, background_color,
31
- x - PADDING, y + height + PADDING, background_color,
32
- x + width + PADDING, y + height + PADDING, background_color, 9)
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
- @window.draw_quad(sel_x, y, SELECTION_COLOR,
41
- pos_x, y, SELECTION_COLOR,
42
- sel_x, y + height, SELECTION_COLOR,
43
- pos_x, y + height, SELECTION_COLOR, 50)
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 @window.text_input == self then
47
- @window.draw_line(pos_x, y, CARET_COLOR,
48
- pos_x, y + height, CARET_COLOR, 50)
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, 50)
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
@@ -1,3 +1,3 @@
1
1
  module Wads
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end