comparison orpg/map/_object.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 from math import sqrt
2
3 import wx
4
5 import orpg.dirpath
6 from orpg.orpgCore import *
7 from orpg.tools.rgbhex import RGBHex
8
9 wxEVT_ENTER_OBJECT = wx.NewEventType()
10 wxEVT_LEAVE_OBJECT = wx.NewEventType()
11 wxEVT_SELECT_OBJECT = wx.NewEventType()
12 wxEVT_DESELECT_OBJECT = wx.NewEventType()
13 EVT_ENTER_OBJECT = wx.PyEventBinder(wxEVT_ENTER_OBJECT)
14 EVT_LEAVE_OBJECT = wx.PyEventBinder(wxEVT_LEAVE_OBJECT)
15 EVT_SELECT_OBJECT = wx.PyEventBinder(wxEVT_SELECT_OBJECT)
16 EVT_DESELECT_OBJECT = wx.PyEventBinder(wxEVT_DESELECT_OBJECT)
17
18 class ObjectEvent(wx.PyCommandEvent):
19 def __init__(self, eventType, object):
20 wx.PyCommandEvent.__init__(self, eventType)
21
22 self._object = object
23
24 self._eventType = eventType
25 self.notify = wx.NotifyEvent(eventType, -1)
26
27 def GetNotifyEvent(self):
28 return self.notify
29
30 def GetObject(self):
31 return self._object
32
33 def GetId(self):
34 return self._object.GetId()
35
36 class MapObject:
37 def __init__(self, **kwargs):
38 self.id = -1
39 self.start = wx.Point(0,0)
40 self.color = "#000000"
41 self.hcolor = "#ffffff"
42 self.lineWidth = 1
43 self.zOrder = 'front'
44 self.selected = False
45 self.inObject = False
46 self.highlighed = False
47 self.isshown = True
48 self.canvas = None
49 self.RGBHex = RGBHex()
50 self.trans = 1
51
52 for atter, value in kwargs.iteritems():
53 setattr(self, atter, value)
54
55 try:
56 if self.id == wx.ID_ANY:
57 self.id = wx.NewId()
58 except:
59 self.id = wx.NewId()
60
61 #Public Methods
62 def HitTest(self, pos):
63 if self.InObject(pos) and not self.inObject and not self.selected:
64 self.inObject = True
65 evt = ObjectEvent(wxEVT_ENTER_OBJECT, self)
66 self.canvas.GetEventHandler().ProcessEvent(evt)
67 elif not self.InObject(pos) and self.inObject and not self.selected:
68 self.inObject = False
69 evt = ObjectEvent(wxEVT_LEAVE_OBJECT, self)
70 self.canvas.GetEventHandler().ProcessEvent(evt)
71
72 def GetId(self):
73 return self.id
74
75 def IsShown(self):
76 return self.isshown
77
78 def Show(self, event=None, show=True):
79 self.isshown = show
80 self.Update(send=True, action="update")
81
82 def Hide(self, event=None):
83 self.isshown = False
84 self.Update(send=True, action="update")
85
86 def IsSelected(self):
87 return self.selected
88
89 def Select(self, select=True):
90 self.selected = select
91
92 if select:
93 evt = ObjectEvent(wxEVT_SELECT_OBJECT, self)
94 else:
95 evt = ObjectEvent(wxEVT_DESELECT_OBJECT, self)
96
97 self.canvas.GetEventHandler().ProcessEvent(evt)
98
99 def Deselect(self):
100 self.selected = False
101 evt = ObjectEvent(wxEVT_DESELECT_OBJECT, self)
102 self.canvas.GetEventHandler().ProcessEvent(evt)
103
104 def Update(self, send=False, action="update"):
105 self.canvas.UpdateMap()
106 if send:
107 self.canvas.session.send(self._toxml(action))
108
109 def GetName(self):
110 return 'ID: ' + str(self.id) + ' Color: ' + self.color
111
112 def InObject(self, pos):
113 pass
114
115 def Draw(self, dc):
116 if self.selected:
117 self.DrawSelected(dc)
118
119 def DrawSelected(self, dc):
120 pass
121
122 def Highlight(self):
123 self.highlighed = True
124 self.Update()
125
126 def UnHighlight(self):
127 self.highlighed = False
128 self.Update()
129
130 def OnLeftDown(self, pos):
131 if self.inObject and self.selected:
132 self.start = pos
133 self.Deselect()
134
135 elif self.inObject and not self.selected:
136 self.Select()
137
138 else:
139 self.start = pos
140
141 self.Update()
142
143 def OnMotion(self, pos):
144 cdc = wx.ClientDC(self.canvas)
145 self.canvas.PrepareDC(cdc)
146 dc = wx.GraphicsContext.Create(cdc)
147
148 if self.selected:
149 self.start = pos
150 self.Draw(dc)
151
152 def OnLeftUp(self, pos):
153 pass
154
155 def OnRightDown(self, pos):
156 pass
157
158 def OnLeftDClick(self, pos):
159 pass
160
161 def ShowProperties(self, event):
162 pass
163
164 def _toxml(self, action="update"):
165 return ''