34
34
mine_num_color = gtk .gdk .color_parse ('#FFF' )
35
35
36
36
unknown_color = gtk .gdk .color_parse ('#aaa' )
37
- unknown_num_color = gtk .gdk .color_parse ('#555' )
38
37
39
38
def pango_layout_from_box (context , text , width , height ):
40
39
desc = pango .FontDescription ('Sans' )
@@ -111,16 +110,23 @@ def on_area_expose(self, widget, event):
111
110
gc .set_rgb_fg_color (unknown_color )
112
111
drawable .draw_polygon (gc , True , polygon )
113
112
113
+ if space in self .board .flagged_spaces :
114
+ value = self .board .flagged_spaces [space ]
115
+
116
+ if value :
117
+ gc .set_rgb_fg_color (mine_color )
118
+ else :
119
+ gc .set_rgb_fg_color (clear_color )
120
+
121
+ drawable .draw_rectangle (gc , True , box [0 ] + box [2 ]/ 4 , box [1 ] + box [3 ]/ 4 , box [2 ]/ 2 , box [3 ]/ 2 )
122
+
114
123
adjacent = - 1
115
124
if space in self .board .known_spaces :
116
125
value , adjacent = self .board .known_spaces [space ]
117
126
if value :
118
127
gc .set_rgb_fg_color (mine_num_color )
119
128
else :
120
129
gc .set_rgb_fg_color (clear_num_color )
121
- elif space in self .board .flagged_spaces :
122
- value , adjacent = self .board .known_spaces [space ]
123
- gc .set_rgb_fg_color (unknown_num_color )
124
130
125
131
if adjacent != - 1 :
126
132
context = widget .get_pango_context ()
@@ -138,6 +144,9 @@ def on_area_expose(self, widget, event):
138
144
return True
139
145
140
146
def on_button_press (self , widget , event ):
147
+ if self .held_mouse_button is not None :
148
+ return
149
+
141
150
allocation = widget .get_allocation ()
142
151
mouse_space = self .board .space_at_point (event .x , event .y , allocation .width , allocation .height )
143
152
@@ -148,11 +157,17 @@ def on_button_press(self, widget, event):
148
157
self .drawing_area .queue_draw ()
149
158
150
159
def on_button_release (self , widget , event ):
160
+ if event .button != self .held_mouse_button :
161
+ return
162
+
151
163
allocation = widget .get_allocation ()
152
164
mouse_space = self .board .space_at_point (event .x , event .y , allocation .width , allocation .height )
153
165
154
- if self .held_mouse_button == 1 and mouse_space is not None :
155
- self .board .reveal_space (mouse_space )
166
+ if mouse_space is not None :
167
+ if self .held_mouse_button == 1 :
168
+ self .board .reveal_space (mouse_space )
169
+ elif self .held_mouse_button == 3 :
170
+ self .board .flag_space (mouse_space , 1 )
156
171
157
172
self .mouse_space = None
158
173
self .held_mouse_button = None
0 commit comments