Mercurial > traipse_dev
comparison orpg/mapper/whiteboard_handler.py @ 20:072ffc1d466f traipse_dev
2nd attempt. Still untested.
author | sirebral |
---|---|
date | Sat, 25 Jul 2009 19:23:25 -0500 |
parents | 78407d627cba |
children | c54768cffbd4 |
comparison
equal
deleted
inserted
replaced
19:78407d627cba | 20:072ffc1d466f |
---|---|
159 item = evt.GetId() | 159 item = evt.GetId() |
160 self.item_selection = self.selection_list[item] | 160 self.item_selection = self.selection_list[item] |
161 | 161 |
162 def on_text_properties(self,evt): | 162 def on_text_properties(self,evt): |
163 text_string = self.text_control.GetValue() | 163 text_string = self.text_control.GetValue() |
164 if self.style_control.GetStringSelection() == 'Normal': | 164 if self.style_control.GetStringSelection() == 'Normal': style = wx.NORMAL |
165 style = wx.NORMAL | 165 else: style = wx.ITALIC |
166 else: | 166 if self.weight_control.GetStringSelection() == 'Normal': weight = wx.NORMAL |
167 style = wx.ITALIC | 167 else: weight = wx.BOLD |
168 if self.weight_control.GetStringSelection() == 'Normal': | |
169 weight = wx.NORMAL | |
170 else: | |
171 weight = wx.BOLD | |
172 point = str(self.point_control.GetValue()) | 168 point = str(self.point_control.GetValue()) |
173 c = self.text_color_control.GetForegroundColour() | 169 c = self.text_color_control.GetForegroundColour() |
174 color = self.canvas.layers['whiteboard'].r_h.hexstring(c.Red(), c.Green(), c.Blue()) | 170 color = self.canvas.layers['whiteboard'].r_h.hexstring(c.Red(), c.Green(), c.Blue()) |
175 self.text_selected_item.set_text_props(text_string, style, point, weight, color) | 171 self.text_selected_item.set_text_props(text_string, style, point, weight, color) |
176 self.text_to_xml() | 172 self.text_to_xml() |
195 | 191 |
196 def get_text_properties(self, event=None): | 192 def get_text_properties(self, event=None): |
197 self.text_color_control.SetForegroundColour(self.text_selected_item.textcolor) | 193 self.text_color_control.SetForegroundColour(self.text_selected_item.textcolor) |
198 self.text_control.SetValue(self.text_selected_item.text_string) | 194 self.text_control.SetValue(self.text_selected_item.text_string) |
199 self.point_control.SetValue(int(self.text_selected_item.pointsize)) | 195 self.point_control.SetValue(int(self.text_selected_item.pointsize)) |
200 if int(self.text_selected_item.weight) == wx.NORMAL: | 196 if int(self.text_selected_item.weight) == wx.NORMAL: self.weight_control.SetSelection(0) |
201 self.weight_control.SetSelection(0) | 197 else: self.weight_control.SetSelection(1) |
202 else: | 198 |
203 self.weight_control.SetSelection(1) | 199 if int(self.text_selected_item.style) == wx.NORMAL: self.style_control.SetSelection(0) |
204 | 200 else: self.style_control.SetSelection(1) |
205 if int(self.text_selected_item.style) == wx.NORMAL: | |
206 self.style_control.SetSelection(0) | |
207 else: | |
208 self.style_control.SetSelection(1) | |
209 self.text_properties_dialog.Center() | 201 self.text_properties_dialog.Center() |
210 self.text_properties_dialog.Show(True) | 202 self.text_properties_dialog.Show(True) |
211 | 203 |
212 def do_text_menu(self, pos, items=None): | 204 def do_text_menu(self, pos, items=None): |
213 if items == None: | 205 if items == None: self.canvas.PopupMenu(self.text_menu) |
214 self.canvas.PopupMenu(self.text_menu) | |
215 else: | 206 else: |
216 menu = wx.Menu() | 207 menu = wx.Menu() |
217 self.ItemList = items | 208 self.ItemList = items |
218 self.tmpPos = pos | 209 self.tmpPos = pos |
219 for i in xrange(len(items)): | 210 for i in xrange(len(items)): |
224 | 215 |
225 def onItemSelect(self, evt): | 216 def onItemSelect(self, evt): |
226 id = evt.GetId()-1 | 217 id = evt.GetId()-1 |
227 self.text_selected_item = self.ItemList[id] | 218 self.text_selected_item = self.ItemList[id] |
228 self.text_selected_item.selected = True | 219 self.text_selected_item.selected = True |
229 if self.tmpPos == 'right': | 220 if self.tmpPos == 'right': self.canvas.PopupMenu(self.text_menu) |
230 self.canvas.PopupMenu(self.text_menu) | |
231 self.ItemList = None | 221 self.ItemList = None |
232 self.tmpPos = None | 222 self.tmpPos = None |
233 | 223 |
234 def on_right_down(self,evt): | 224 def on_right_down(self,evt): |
235 line = 0 | 225 line = 0 |
236 scale = self.canvas.layers['grid'].mapscale | 226 scale = self.canvas.layers['grid'].mapscale |
237 dc = wx.ClientDC(self.canvas) | 227 dc = wx.ClientDC(self.canvas) |
238 self.canvas.PrepareDC(dc) | 228 self.canvas.PrepareDC(dc) |
239 dc.SetUserScale(scale,scale) | 229 dc.SetUserScale(scale,scale) |
240 pos = evt.GetLogicalPosition(dc) | 230 pos = evt.GetLogicalPosition(dc) |
241 if self.drawing_mode == 'Text': | 231 if self.drawing_mode == 'Text': self.on_text_right_down(evt, dc) |
242 self.on_text_right_down(evt, dc) | |
243 elif self.drawing and ((self.drawing_mode == 'Circle') or (self.drawing_mode == 'Cone')): | 232 elif self.drawing and ((self.drawing_mode == 'Circle') or (self.drawing_mode == 'Cone')): |
244 self.check_draw_mode() | 233 self.check_draw_mode() |
245 self.drawing = False | 234 self.drawing = False |
246 elif (self.drawing_mode == 'Freeform') or (self.drawing_mode == 'Polyline') or (self.drawing_mode == 'Circle') or (self.drawing_mode == 'Cone'): | 235 elif (self.drawing_mode == 'Freeform') or (self.drawing_mode == 'Polyline') or (self.drawing_mode == 'Circle') or (self.drawing_mode == 'Cone'): |
247 line_list = self.canvas.layers['whiteboard'].find_line(pos) | 236 line_list = self.canvas.layers['whiteboard'].find_line(pos) |
248 if line_list: | 237 if line_list: |
249 self.sel_rline = self.canvas.layers['whiteboard'].get_line_by_id(line_list.id) | 238 self.sel_rline = self.canvas.layers['whiteboard'].get_line_by_id(line_list.id) |
250 if self.sel_rline: | 239 if self.sel_rline: |
251 self.do_line_menu(evt.GetPosition()) | 240 self.do_line_menu(evt.GetPosition()) |
252 self.canvas.Refresh(False) | 241 self.canvas.Refresh(False) |
253 else: | 242 else: base_layer_handler.on_right_down(self,evt) |
254 base_layer_handler.on_right_down(self,evt) | 243 else: base_layer_handler.on_right_down(self,evt) |
255 else: | |
256 base_layer_handler.on_right_down(self,evt) | |
257 del dc | 244 del dc |
258 | 245 |
259 def on_pen_color(self,evt): | 246 def on_pen_color(self,evt): |
260 data = wx.ColourData() | 247 data = wx.ColourData() |
261 data.SetChooseFull(True) | 248 data.SetChooseFull(True) |
286 session = self.canvas.frame.session | 273 session = self.canvas.frame.session |
287 if (session.my_role() != session.ROLE_GM) and (session.use_roles()): | 274 if (session.my_role() != session.ROLE_GM) and (session.use_roles()): |
288 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | 275 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") |
289 return | 276 return |
290 dlg = wx.MessageDialog(self, "Are you sure you want to delete all lines?","Delete All Lines",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) | 277 dlg = wx.MessageDialog(self, "Are you sure you want to delete all lines?","Delete All Lines",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) |
291 if dlg.ShowModal() != wx.ID_YES: | 278 if dlg.ShowModal() != wx.ID_YES: return |
292 return | |
293 self.canvas.layers['whiteboard'].del_all_lines() | 279 self.canvas.layers['whiteboard'].del_all_lines() |
294 dc = self.create_dc() | 280 dc = self.create_dc() |
295 self.un_highlight(dc) | 281 self.un_highlight(dc) |
296 self.selected = None | 282 self.selected = None |
297 del dc | 283 del dc |
324 self.lastpoint = None #because the end check function is not called we must force its lastpoint var to None again | 310 self.lastpoint = None #because the end check function is not called we must force its lastpoint var to None again |
325 self.polypoints = 0 | 311 self.polypoints = 0 |
326 self.line_string = "0,0;" | 312 self.line_string = "0,0;" |
327 if self.temp_circle: | 313 if self.temp_circle: |
328 self.canvas.layers['whiteboard'].del_temp_line(self.temp_circle) | 314 self.canvas.layers['whiteboard'].del_temp_line(self.temp_circle) |
329 if self.selected == self.temp_circle: | 315 if self.selected == self.temp_circle: self.selected = None |
330 self.selected = None | |
331 self.canvas.Refresh(True) | 316 self.canvas.Refresh(True) |
332 self.temp_circle = None | 317 self.temp_circle = None |
333 self.cone_start = None | 318 self.cone_start = None |
334 | 319 |
335 # Altered on_left_up to toggle between | 320 # Altered on_left_up to toggle between |
336 # drawing modes freeform vs polyline | 321 # drawing modes freeform vs polyline |
337 # 05-09-2003 Snowdog | 322 # 05-09-2003 Snowdog |
338 def on_left_down(self,evt): | 323 def on_left_down(self,evt): |
339 if not self.drawing: | 324 if not self.drawing: self.check_draw_mode() |
340 self.check_draw_mode() | 325 if self.drawing_mode == 'Freeform': pass |
341 if self.drawing_mode == 'Freeform': | 326 elif self.drawing_mode == 'Polyline': self.polyline_add_point( evt ) |
342 #Freeform mode ignores the inital down click | 327 elif self.drawing_mode == 'Text': self.on_text_left_down(evt) |
343 pass | |
344 elif self.drawing_mode == 'Polyline': | |
345 self.polyline_add_point( evt ) | |
346 elif self.drawing_mode == 'Text': | |
347 self.on_text_left_down(evt) | |
348 elif self.drawing_mode == 'Cone': | 328 elif self.drawing_mode == 'Cone': |
349 if self.cone_start == None: | 329 if self.cone_start == None: self.on_start_cone(evt) |
350 self.on_start_cone(evt) | 330 else: self.draw_temporary_cone(evt) |
351 else: | 331 elif self.drawing_mode == 'Circle': self.draw_temporary_circle(evt) |
352 self.draw_temporary_cone(evt) | |
353 elif self.drawing_mode == 'Circle': | |
354 self.draw_temporary_circle(evt) | |
355 | 332 |
356 # Added handling for double clicks within the map | 333 # Added handling for double clicks within the map |
357 # 05-09-2003 Snowdog | 334 # 05-09-2003 Snowdog |
358 def on_left_dclick(self, evt): | 335 def on_left_dclick(self, evt): |
359 if self.drawing_mode == 'Freeform': | 336 if self.drawing_mode == 'Freeform': |
360 #Freeform mode ignores the double click | 337 #Freeform mode ignores the double click |
361 pass | 338 pass |
362 elif self.drawing_mode == 'Polyline': | 339 elif self.drawing_mode == 'Polyline': self.polyline_last_point( evt ) |
363 self.polyline_last_point( evt ) | 340 elif self.drawing_mode == 'Text': pass |
364 elif self.drawing_mode == 'Text': | |
365 pass | |
366 elif self.drawing_mode == 'Circle' or self.drawing_mode == 'Cone': | 341 elif self.drawing_mode == 'Circle' or self.drawing_mode == 'Cone': |
367 self.canvas.layers['whiteboard'].del_temp_line(self.temp_circle) | 342 self.canvas.layers['whiteboard'].del_temp_line(self.temp_circle) |
368 #pointArray = self.temp_circle.line_string.split(";") | 343 #pointArray = self.temp_circle.line_string.split(";") |
369 self.canvas.layers['whiteboard'].add_line(self.temp_circle.line_string) | 344 self.canvas.layers['whiteboard'].add_line(self.temp_circle.line_string) |
370 self.temp_circle = None | 345 self.temp_circle = None |
373 | 348 |
374 # Altered on_left_up to toggle between | 349 # Altered on_left_up to toggle between |
375 # drawing modes freeform vs polyline | 350 # drawing modes freeform vs polyline |
376 # 05-09-2003 Snowdog | 351 # 05-09-2003 Snowdog |
377 def on_left_up(self,evt): | 352 def on_left_up(self,evt): |
378 if self.drawing_mode == 'Freeform': | 353 if self.drawing_mode == 'Freeform': self.on_freeform_left_up(evt) |
379 self.on_freeform_left_up(evt) | 354 elif self.drawing_mode == 'Polyline': pass |
380 elif self.drawing_mode == 'Polyline': | 355 elif self.drawing_mode == 'Text': pass |
381 #Polyline mode relies on the down click | |
382 #not the mouse button release | |
383 pass | |
384 elif self.drawing_mode == 'Text': | |
385 pass | |
386 | 356 |
387 # Altered on_left_up to toggle between | 357 # Altered on_left_up to toggle between |
388 # drawing modes freeform vs polyline | 358 # drawing modes freeform vs polyline |
389 # 05-09-2003 Snowdog | 359 # 05-09-2003 Snowdog |
390 def on_motion(self,evt): | 360 def on_motion(self,evt): |
392 if (session.my_role() != session.ROLE_GM) \ | 362 if (session.my_role() != session.ROLE_GM) \ |
393 and (session.my_role()!=session.ROLE_PLAYER) \ | 363 and (session.my_role()!=session.ROLE_PLAYER) \ |
394 and (session.use_roles()): | 364 and (session.use_roles()): |
395 return | 365 return |
396 if self.drawing_mode == 'Freeform': | 366 if self.drawing_mode == 'Freeform': |
397 if evt.m_leftDown: | 367 if evt.m_leftDown: self.freeform_motion(evt) |
398 self.freeform_motion(evt) | |
399 elif self.drawing_mode == 'Polyline': | 368 elif self.drawing_mode == 'Polyline': |
400 if self.drawing: | 369 if self.drawing: self.polyline_preview( evt ) |
401 self.polyline_preview( evt ) | |
402 dc = self.create_dc() | 370 dc = self.create_dc() |
403 pos = evt.GetLogicalPosition(dc) | 371 pos = evt.GetLogicalPosition(dc) |
404 hit = self.canvas.layers['whiteboard'].hit_test_lines(pos,dc) | 372 hit = self.canvas.layers['whiteboard'].hit_test_lines(pos,dc) |
405 if hit: | 373 if hit: self.highlight(hit,dc) |
406 self.highlight(hit,dc) | |
407 else: | 374 else: |
408 self.un_highlight(dc) | 375 self.un_highlight(dc) |
409 hit = self.canvas.layers['whiteboard'].hit_test_text(pos,dc) | 376 hit = self.canvas.layers['whiteboard'].hit_test_text(pos,dc) |
410 if hit: | 377 if hit: self.highlight(hit,dc) |
411 self.highlight(hit,dc) | 378 else: self.un_highlight(dc) |
412 else: | |
413 self.un_highlight(dc) | |
414 del dc | 379 del dc |
415 | 380 |
416 def create_dc(self): | 381 def create_dc(self): |
417 scale = self.canvas.layers['grid'].mapscale | 382 scale = self.canvas.layers['grid'].mapscale |
418 dc = wx.ClientDC( self.canvas ) | 383 dc = wx.ClientDC( self.canvas ) |
441 dc = wx.ClientDC( self.canvas ) | 406 dc = wx.ClientDC( self.canvas ) |
442 self.canvas.PrepareDC( dc ) | 407 self.canvas.PrepareDC( dc ) |
443 dc.SetUserScale(scale,scale) | 408 dc.SetUserScale(scale,scale) |
444 pos = evt.GetLogicalPosition(dc) | 409 pos = evt.GetLogicalPosition(dc) |
445 #reset the bounding points | 410 #reset the bounding points |
446 if pos.x < self.upperleft.x: | 411 if pos.x < self.upperleft.x: self.upperleft.x = pos.x |
447 self.upperleft.x = pos.x | 412 elif pos.x > self.lowerright.x: self.lowerright.x = pos.x |
448 elif pos.x > self.lowerright.x: | 413 if pos.y < self.upperleft.y: self.upperleft.y = pos.y |
449 self.lowerright.x = pos.x | 414 elif pos.y > self.lowerright.y: self.lowerright.y = pos.y |
450 if pos.y < self.upperleft.y: | |
451 self.upperleft.y = pos.y | |
452 elif pos.y > self.lowerright.y: | |
453 self.lowerright.y = pos.y | |
454 | 415 |
455 #if this point doens't end the line | 416 #if this point doens't end the line |
456 #add a new point into the line string | 417 #add a new point into the line string |
457 if not self.polyline_end_check( pos ): | 418 if not self.polyline_end_check( pos ): |
458 if self.drawing == True: | 419 if self.drawing == True: |
467 self.lowerright.x = pos.x | 428 self.lowerright.x = pos.x |
468 self.lowerright.y = pos.y | 429 self.lowerright.y = pos.y |
469 self.drawing = True | 430 self.drawing = True |
470 else: #end of line. Send and reset vars for next line | 431 else: #end of line. Send and reset vars for next line |
471 self.drawing = False | 432 self.drawing = False |
472 if self.polypoints < 2: | 433 if self.polypoints < 2: pass |
473 #not enough points to form a line. Ignore line | |
474 pass | |
475 else: | 434 else: |
476 #have enough points to create valid line | 435 #have enough points to create valid line |
477 #check to role to make sure user can draw at all.... | 436 #check to role to make sure user can draw at all.... |
478 session = self.canvas.frame.session | 437 session = self.canvas.frame.session |
479 if (session.my_role() != session.ROLE_GM) and (session.my_role()!=session.ROLE_PLAYER) and (session.use_roles()): | 438 if (session.my_role() != session.ROLE_GM) and (session.my_role()!=session.ROLE_PLAYER) and (session.use_roles()): |
480 open_rpg.get_component("chat").InfoPost("You must be either a player or GM to use this feature") | 439 open_rpg.get_component("chat").InfoPost("You must be either a player or GM to use this feature") |
481 self.canvas.Refresh(False) | 440 self.canvas.Refresh(False) |
482 else: | 441 else: line = self.canvas.layers['whiteboard'].add_line(self.line_string,self.upperleft,self.lowerright) |
483 #user allowed to draw on whiteboard.. send polyline | |
484 line = self.canvas.layers['whiteboard'].add_line(self.line_string,self.upperleft,self.lowerright) | |
485 #resetting variables for next line | 442 #resetting variables for next line |
486 self.upperleft.x = self.upperleft.y = 0 | 443 self.upperleft.x = self.upperleft.y = 0 |
487 self.lowerright.x = self.lowerright.y = 0 | 444 self.lowerright.x = self.lowerright.y = 0 |
488 self.polypoints = 0 | 445 self.polypoints = 0 |
489 self.line_string = "0,0;" | 446 self.line_string = "0,0;" |
491 # Polyline Last Point | 448 # Polyline Last Point |
492 # adds a final point to the polyline and ends it | 449 # adds a final point to the polyline and ends it |
493 # 05-09-2003 Snowdog | 450 # 05-09-2003 Snowdog |
494 def polyline_last_point(self, evt): | 451 def polyline_last_point(self, evt): |
495 #if we haven't started a line already. Ignore the click | 452 #if we haven't started a line already. Ignore the click |
496 if self.drawing != True: | 453 if self.drawing != True: return |
497 return | |
498 scale = self.canvas.layers['grid'].mapscale | 454 scale = self.canvas.layers['grid'].mapscale |
499 dc = wx.ClientDC( self.canvas ) | 455 dc = wx.ClientDC( self.canvas ) |
500 self.canvas.PrepareDC( dc ) | 456 self.canvas.PrepareDC( dc ) |
501 dc.SetUserScale(scale,scale) | 457 dc.SetUserScale(scale,scale) |
502 pos = evt.GetLogicalPosition(dc) | 458 pos = evt.GetLogicalPosition(dc) |
503 #reset the bounding points | 459 #reset the bounding points |
504 if pos.x < self.upperleft.x: | 460 if pos.x < self.upperleft.x: self.upperleft.x = pos.x |
505 self.upperleft.x = pos.x | 461 elif pos.x > self.lowerright.x: self.lowerright.x = pos.x |
506 elif pos.x > self.lowerright.x: | 462 if pos.y < self.upperleft.y: self.upperleft.y = pos.y |
507 self.lowerright.x = pos.x | 463 elif pos.y > self.lowerright.y: self.lowerright.y = pos.y |
508 if pos.y < self.upperleft.y: | |
509 self.upperleft.y = pos.y | |
510 elif pos.y > self.lowerright.y: | |
511 self.lowerright.y = pos.y | |
512 self.polypoints += 1 #add one to the point counter. | 464 self.polypoints += 1 #add one to the point counter. |
513 self.line_string += `pos.x` + "," + `pos.y` + ";" | 465 self.line_string += `pos.x` + "," + `pos.y` + ";" |
514 self.canvas.layers['whiteboard'].draw_working_line(dc,self.line_string) | 466 self.canvas.layers['whiteboard'].draw_working_line(dc,self.line_string) |
515 #end of line. Send and reset vars for next line | 467 #end of line. Send and reset vars for next line |
516 self.drawing = False | 468 self.drawing = False |
517 if self.polypoints < 2: | 469 if self.polypoints < 2: pass |
518 #not enough points to form a line. Ignore line | |
519 pass | |
520 else: | 470 else: |
521 #have enough points to create valid line | 471 #have enough points to create valid line |
522 #check to role to make sure user can draw at all.... | 472 #check to role to make sure user can draw at all.... |
523 session = self.canvas.frame.session | 473 session = self.canvas.frame.session |
524 if (session.my_role() != session.ROLE_GM) and (session.my_role()!=session.ROLE_PLAYER) and (session.use_roles()): | 474 if (session.my_role() != session.ROLE_GM) and (session.my_role()!=session.ROLE_PLAYER) and (session.use_roles()): |
525 open_rpg.get_component("chat").InfoPost("You must be either a player or GM to use this feature") | 475 open_rpg.get_component("chat").InfoPost("You must be either a player or GM to use this feature") |
526 self.canvas.Refresh(False) | 476 self.canvas.Refresh(False) |
527 else: | 477 else: line = self.canvas.layers['whiteboard'].add_line(self.line_string,self.upperleft,self.lowerright) |
528 #user allowed to draw on whiteboard.. send polyline | |
529 line = self.canvas.layers['whiteboard'].add_line(self.line_string,self.upperleft,self.lowerright) | |
530 #resetting variables for next line | 478 #resetting variables for next line |
531 self.upperleft.x = self.upperleft.y = 0 | 479 self.upperleft.x = self.upperleft.y = 0 |
532 self.lowerright.x = self.lowerright.y = 0 | 480 self.lowerright.x = self.lowerright.y = 0 |
533 self.lastpoint = None #becuase the end check function is not called we must force its lastpoint var to None again | 481 self.lastpoint = None #becuase the end check function is not called we must force its lastpoint var to None again |
534 self.polypoints = 0 | 482 self.polypoints = 0 |
546 # the original freeform version is. A line with fewer than 2 points should be ignored | 494 # the original freeform version is. A line with fewer than 2 points should be ignored |
547 x_in = y_in = 0 | 495 x_in = y_in = 0 |
548 tol = 5 | 496 tol = 5 |
549 | 497 |
550 #first point check | 498 #first point check |
551 if type(self.lastpoint) == type(None): | 499 if type(self.lastpoint) == type(None): self.lastpoint = wx.Point(pos.x,pos.y); return 0 #not end of line |
552 self.lastpoint = wx.Point(pos.x,pos.y) | 500 if ((self.lastpoint.x -tol) <= pos.x <= (self.lastpoint.x)): x_in = 1 |
553 return 0 #not end of line | 501 if ((self.lastpoint.y -tol) <= pos.y <= (self.lastpoint.y)): y_in = 1 |
554 if ((self.lastpoint.x -tol) <= pos.x <= (self.lastpoint.x)): | 502 if x_in and y_in: self.lastpoint = None; return 1 |
555 x_in = 1 | |
556 if ((self.lastpoint.y -tol) <= pos.y <= (self.lastpoint.y)): | |
557 y_in = 1 | |
558 if x_in and y_in: | |
559 #point within tolerance. End line | |
560 self.lastpoint = None | |
561 return 1 | |
562 #if we've reached here the point is NOT a terminal point. Reset the lastpoint and return False | 503 #if we've reached here the point is NOT a terminal point. Reset the lastpoint and return False |
563 self.lastpoint.x = pos.x | 504 self.lastpoint.x = pos.x |
564 self.lastpoint.y = pos.y | 505 self.lastpoint.y = pos.y |
565 return 0 | 506 return 0 |
566 | 507 |
567 # Polyline Preview | 508 # Polyline Preview |
568 # display a temporary/momentary line to the user | 509 # display a temporary/momentary line to the user |
569 # from the last point to mouse position | 510 # from the last point to mouse position |
570 # 05-09-2003 Snowdog | 511 # 05-09-2003 Snowdog |
571 def polyline_preview(self, evt): | 512 def polyline_preview(self, evt): |
572 if self.drawing != True: | 513 if self.drawing != True: return |
573 #not enough points to form a line. Ignore line | 514 if self.live_refresh.GetValue() == 0: return |
574 return | |
575 if self.live_refresh.GetValue() == 0: | |
576 #not using live redraw | |
577 return | |
578 scale = self.canvas.layers['grid'].mapscale | 515 scale = self.canvas.layers['grid'].mapscale |
579 dc = wx.ClientDC( self.canvas ) | 516 dc = wx.ClientDC( self.canvas ) |
580 self.canvas.PrepareDC( dc ) | 517 self.canvas.PrepareDC( dc ) |
581 dc.SetUserScale(scale,scale) | 518 dc.SetUserScale(scale,scale) |
582 pos = evt.GetLogicalPosition(dc) | 519 pos = evt.GetLogicalPosition(dc) |
583 | 520 |
584 #reset the bounding points | 521 #reset the bounding points |
585 if pos.x < self.upperleft.x: | 522 if pos.x < self.upperleft.x: self.upperleft.x = pos.x |
586 self.upperleft.x = pos.x | 523 elif pos.x > self.lowerright.x: self.lowerright.x = pos.x |
587 elif pos.x > self.lowerright.x: | 524 if pos.y < self.upperleft.y: self.upperleft.y = pos.y |
588 self.lowerright.x = pos.x | 525 elif pos.y > self.lowerright.y: self.lowerright.y = pos.y |
589 if pos.y < self.upperleft.y: | |
590 self.upperleft.y = pos.y | |
591 elif pos.y > self.lowerright.y: | |
592 self.lowerright.y = pos.y | |
593 | 526 |
594 #redraw the line with a line connected to the cursor | 527 #redraw the line with a line connected to the cursor |
595 temp_string = self.line_string | 528 temp_string = self.line_string |
596 temp_string += `pos.x` + "," + `pos.y` + ";" | 529 temp_string += `pos.x` + "," + `pos.y` + ";" |
597 self.canvas.layers['whiteboard'].draw_working_line(dc,temp_string) | 530 self.canvas.layers['whiteboard'].draw_working_line(dc,temp_string) |
606 scale = self.canvas.layers['grid'].mapscale | 539 scale = self.canvas.layers['grid'].mapscale |
607 dc = wx.ClientDC( self.canvas ) | 540 dc = wx.ClientDC( self.canvas ) |
608 self.canvas.PrepareDC( dc ) | 541 self.canvas.PrepareDC( dc ) |
609 dc.SetUserScale(scale,scale) | 542 dc.SetUserScale(scale,scale) |
610 pos = evt.GetLogicalPosition(dc) | 543 pos = evt.GetLogicalPosition(dc) |
611 if pos.x < self.upperleft.x: | 544 if pos.x < self.upperleft.x: self.upperleft.x = pos.x |
612 self.upperleft.x = pos.x | 545 elif pos.x > self.lowerright.x: self.lowerright.x = pos.x |
613 elif pos.x > self.lowerright.x: | 546 if pos.y < self.upperleft.y: self.upperleft.y = pos.y |
614 self.lowerright.x = pos.x | 547 elif pos.y > self.lowerright.y: self.lowerright.y = pos.y |
615 if pos.y < self.upperleft.y: | |
616 self.upperleft.y = pos.y | |
617 elif pos.y > self.lowerright.y: | |
618 self.lowerright.y = pos.y | |
619 if evt.m_leftDown: | 548 if evt.m_leftDown: |
620 if self.drawing == True: | 549 if self.drawing == True: |
621 self.line_string += `pos.x` + "," + `pos.y` + ";" | 550 self.line_string += `pos.x` + "," + `pos.y` + ";" |
622 self.canvas.layers['whiteboard'].draw_working_line(dc,self.line_string) | 551 self.canvas.layers['whiteboard'].draw_working_line(dc,self.line_string) |
623 else: | 552 else: |
663 self.canvas.PrepareDC( dc ) | 592 self.canvas.PrepareDC( dc ) |
664 dc.SetUserScale(scale,scale) | 593 dc.SetUserScale(scale,scale) |
665 pos = evt.GetLogicalPosition(dc) | 594 pos = evt.GetLogicalPosition(dc) |
666 test_text = self.canvas.layers['whiteboard'].hit_test_text(pos,dc) | 595 test_text = self.canvas.layers['whiteboard'].hit_test_text(pos,dc) |
667 if len(test_text) > 0: | 596 if len(test_text) > 0: |
668 if len(test_text) > 1: | 597 if len(test_text) > 1: self.do_text_menu('left', test_text) |
669 self.do_text_menu('left', test_text) | |
670 else: | 598 else: |
671 self.text_selected_item = test_text[0] | 599 self.text_selected_item = test_text[0] |
672 self.text_selected_item.selected = True | 600 self.text_selected_item.selected = True |
673 self.canvas.Refresh(True) | 601 self.canvas.Refresh(True) |
674 else: | 602 else: |
675 if self.text_selected_item == None: | 603 if self.text_selected_item == None: |
676 dlg = wx.TextEntryDialog(self,"Text to add to whiteboard", caption="Enter text",defaultValue=" ") | 604 dlg = wx.TextEntryDialog(self,"Text to add to whiteboard", caption="Enter text",defaultValue=" ") |
677 if dlg.ShowModal() == wx.ID_OK: | 605 if dlg.ShowModal() == wx.ID_OK: |
678 text_string = dlg.GetValue() | 606 text_string = dlg.GetValue() |
679 self.canvas.layers['whiteboard'].add_text(text_string,pos, self.style, self.pointsize, self.weight, self.canvas.layers['whiteboard'].color) | 607 self.canvas.layers['whiteboard'].add_text(text_string,pos, self.style, |
608 self.pointsize, self.weight, self.canvas.layers['whiteboard'].color) | |
680 else: | 609 else: |
681 self.text_selected_item.posx = pos.x | 610 self.text_selected_item.posx = pos.x |
682 self.text_selected_item.posy = pos.y | 611 self.text_selected_item.posy = pos.y |
683 self.text_selected_item.isUpdated = True | 612 self.text_selected_item.isUpdated = True |
684 self.text_to_xml() | 613 self.text_to_xml() |
693 self.canvas.Refresh(False) | 622 self.canvas.Refresh(False) |
694 return | 623 return |
695 pos = evt.GetLogicalPosition(dc) | 624 pos = evt.GetLogicalPosition(dc) |
696 test_text = self.canvas.layers['whiteboard'].hit_test_text(pos, dc) | 625 test_text = self.canvas.layers['whiteboard'].hit_test_text(pos, dc) |
697 if len(test_text) > 0: | 626 if len(test_text) > 0: |
698 if len(test_text) > 1: | 627 if len(test_text) > 1: self.do_text_menu('right', test_text) |
699 self.do_text_menu('right', test_text) | |
700 else: | 628 else: |
701 self.text_selected_item = test_text[0] | 629 self.text_selected_item = test_text[0] |
702 self.do_text_menu('right') | 630 self.do_text_menu('right') |
703 | 631 |
704 def on_start_cone(self, evt): | 632 def on_start_cone(self, evt): |
728 self.canvas.PrepareDC( dc ) | 656 self.canvas.PrepareDC( dc ) |
729 dc.SetUserScale(scale,scale) | 657 dc.SetUserScale(scale,scale) |
730 pos = evt.GetLogicalPosition(dc) | 658 pos = evt.GetLogicalPosition(dc) |
731 pos2 = self.get_snapped_to_logical_pos(evt) | 659 pos2 = self.get_snapped_to_logical_pos(evt) |
732 size = self.canvas.layers['grid'].unit_size #60 | 660 size = self.canvas.layers['grid'].unit_size #60 |
733 if abs(pos.x-pos2.x)<=size/10 and abs(pos.y-pos2.y)<=size/10: | 661 if abs(pos.x-pos2.x)<=size/10 and abs(pos.y-pos2.y)<=size/10: pos = pos2 |
734 pos = pos2 | |
735 radius = int(int(self.radius.GetValue())/5) | 662 radius = int(int(self.radius.GetValue())/5) |
736 curve = self.calculate_circle(self.cone_start, radius, size) | 663 curve = self.calculate_circle(self.cone_start, radius, size) |
737 edge1 = [] | 664 edge1 = [] |
738 edge2 = [] | 665 edge2 = [] |
739 horizontal_inc = wx.Point(size,0) | 666 horizontal_inc = wx.Point(size,0) |
740 if pos.x <= self.cone_start.x: | 667 if pos.x <= self.cone_start.x: horizontal_inc = wx.Point(-size,0) |
741 horizontal_inc = wx.Point(-size,0) | |
742 vertical_inc = wx.Point(0,size) | 668 vertical_inc = wx.Point(0,size) |
743 if pos.y <= self.cone_start.y: | 669 if pos.y <= self.cone_start.y: vertical_inc = wx.Point(0,-size) |
744 vertical_inc = wx.Point(0,-size) | |
745 x_diff = float(pos.x - self.cone_start.x) | 670 x_diff = float(pos.x - self.cone_start.x) |
746 y_diff = float(pos.y - self.cone_start.y) | 671 y_diff = float(pos.y - self.cone_start.y) |
747 ratio = float(1) | 672 ratio = float(1) |
748 if abs(x_diff) <= abs(y_diff): | 673 if abs(x_diff) <= abs(y_diff): ratio = x_diff / y_diff |
749 ratio = x_diff / y_diff | |
750 elif abs(y_diff) < abs(x_diff): | 674 elif abs(y_diff) < abs(x_diff): |
751 ratio = -(y_diff / x_diff) | 675 ratio = -(y_diff / x_diff) |
752 horizontal_inc,vertical_inc = vertical_inc,horizontal_inc #swap | 676 horizontal_inc,vertical_inc = vertical_inc,horizontal_inc #swap |
753 horizontal_rotated = wx.Point(-horizontal_inc.y, horizontal_inc.x) | 677 horizontal_rotated = wx.Point(-horizontal_inc.y, horizontal_inc.x) |
754 vertical_rotated = wx.Point(-vertical_inc.y, vertical_inc.x) | 678 vertical_rotated = wx.Point(-vertical_inc.y, vertical_inc.x) |
815 pos = wx.Point(self.cone_start.x+x_diff, self.cone_start.y+y_diff) | 739 pos = wx.Point(self.cone_start.x+x_diff, self.cone_start.y+y_diff) |
816 qos = wx.Point(self.cone_start.x-y_diff, self.cone_start.y+x_diff)# 90 degree rotation | 740 qos = wx.Point(self.cone_start.x-y_diff, self.cone_start.y+x_diff)# 90 degree rotation |
817 curve = `pos.x`+","+`pos.y`+";" + curve + `qos.x`+","+`qos.y`+";" | 741 curve = `pos.x`+","+`pos.y`+";" + curve + `qos.x`+","+`qos.y`+";" |
818 if(self.temp_circle): | 742 if(self.temp_circle): |
819 self.canvas.layers['whiteboard'].del_temp_line(self.temp_circle) | 743 self.canvas.layers['whiteboard'].del_temp_line(self.temp_circle) |
820 if self.selected == self.temp_circle: | 744 if self.selected == self.temp_circle: self.selected = None |
821 self.selected = None | |
822 self.temp_circle = self.canvas.layers['whiteboard'].add_temp_line(curve) | 745 self.temp_circle = self.canvas.layers['whiteboard'].add_temp_line(curve) |
823 self.canvas.Refresh(True) | 746 self.canvas.Refresh(True) |
824 | 747 |
825 def draw_temporary_circle(self, evt): | 748 def draw_temporary_circle(self, evt): |
826 session = self.canvas.frame.session | 749 session = self.canvas.frame.session |