Mercurial > traipse_dev
comparison orpg/mapper/base_handler.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 | 0b8b7e3ed78d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: mapper/whiteboard_hander.py | |
21 # Author: OpenRPG Team | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: base_handler.py,v 1.20 2007/11/04 17:32:25 digitalxero Exp $ | |
25 # | |
26 # Description: base layer handler. | |
27 # layer handlers are responsible for the GUI elements of the layer | |
28 # | |
29 __version__ = "$Id: base_handler.py,v 1.20 2007/11/04 17:32:25 digitalxero Exp $" | |
30 | |
31 | |
32 from orpg.orpg_windows import * | |
33 from orpg.orpgCore import open_rpg | |
34 | |
35 class base_layer_handler(wx.Panel): | |
36 | |
37 def __init__(self, parent, id, canvas): | |
38 wx.Panel.__init__(self, parent, id) | |
39 self.canvas = canvas | |
40 self.map_frame = self.canvas.frame | |
41 self.top_frame = self.canvas.frame.top_frame | |
42 self.chat = open_rpg.get_component("chat") | |
43 self.build_ctrls() | |
44 self.build_menu() | |
45 self.Bind(wx.EVT_SIZE, self.on_size) | |
46 self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick) | |
47 | |
48 def on_size(self,evt): | |
49 s = self.GetClientSizeTuple() | |
50 self.basesizer.SetDimension(0,0,s[0],s[1]) | |
51 | |
52 def build_ctrls(self): | |
53 self.basesizer = wx.BoxSizer(wx.HORIZONTAL) | |
54 self.sizer = wx.BoxSizer(wx.HORIZONTAL) | |
55 self.buttonsizer = wx.BoxSizer(wx.HORIZONTAL) | |
56 | |
57 self.zoom_in_button = createMaskedButton( self, orpg.dirpath.dir_struct["icon"]+'zoom_in.gif', "Zoom in from x1.0", wx.ID_ANY ) | |
58 self.zoom_out_button = createMaskedButton( self, orpg.dirpath.dir_struct["icon"]+'zoom_out.gif', "Zoom out from x1.0", wx.ID_ANY ) | |
59 props = createMaskedButton( self, orpg.dirpath.dir_struct["icon"]+'compass.gif', 'Edit map properties', wx.ID_ANY ) | |
60 mapopen = createMaskedButton( self, orpg.dirpath.dir_struct["icon"]+'open.bmp', 'Load a map', wx.ID_ANY, '#c0c0c0', wx.BITMAP_TYPE_BMP ) | |
61 mapsave = createMaskedButton( self, orpg.dirpath.dir_struct["icon"]+'save.bmp', 'Save the map', wx.ID_ANY, '#c0c0c0', wx.BITMAP_TYPE_BMP ) | |
62 self.buttonsizer.Add(self.zoom_in_button, 0, wx.EXPAND ) | |
63 self.buttonsizer.Add(self.zoom_out_button, 0, wx.EXPAND ) | |
64 self.buttonsizer.Add(props, 0, wx.EXPAND ) | |
65 self.buttonsizer.Add(mapopen, 0, wx.EXPAND ) | |
66 self.buttonsizer.Add(mapsave, 0, wx.EXPAND ) | |
67 self.SetSizer(self.basesizer) | |
68 self.SetAutoLayout(True) | |
69 self.Fit() | |
70 self.basesizer.Add( self.sizer, 1, wx.EXPAND) | |
71 self.basesizer.Add( self.buttonsizer, 0, wx.ALIGN_RIGHT) | |
72 self.Bind(wx.EVT_BUTTON, self.canvas.on_zoom_in, self.zoom_in_button) | |
73 self.Bind(wx.EVT_BUTTON, self.canvas.on_zoom_out, self.zoom_out_button) | |
74 self.Bind(wx.EVT_BUTTON, self.map_frame.on_open, mapopen) | |
75 self.Bind(wx.EVT_BUTTON, self.map_frame.on_save, mapsave) | |
76 self.Bind(wx.EVT_BUTTON, self.canvas.on_prop, props) | |
77 | |
78 def build_menu(self,label = "Map"): | |
79 "Menu is built based on the type of grid (rectangle or hex) we have in use." | |
80 # do main menu | |
81 main_menu = wx.Menu(label) # create a menu resource | |
82 main_menu.SetTitle(label) | |
83 item = wx.MenuItem(main_menu, wx.ID_ANY, "&Load Map", "Load Map") | |
84 self.canvas.Bind(wx.EVT_MENU, self.map_frame.on_open, item) | |
85 main_menu.AppendItem(item) | |
86 item = wx.MenuItem(main_menu, wx.ID_ANY, "&Save Map", "Save Map") | |
87 self.canvas.Bind(wx.EVT_MENU, self.map_frame.on_save, item) | |
88 main_menu.AppendItem(item) | |
89 item = wx.MenuItem(main_menu, wx.ID_ANY, "Save as JPG", "Save as JPG") | |
90 self.canvas.Bind(wx.EVT_MENU, self.on_save_map_jpg, item) | |
91 main_menu.AppendItem(item) | |
92 main_menu.AppendSeparator() | |
93 item = wx.MenuItem(main_menu, wx.ID_ANY, "&Properties", "Properties") | |
94 self.canvas.Bind(wx.EVT_MENU, self.canvas.on_prop, item) | |
95 main_menu.AppendItem(item) | |
96 self.main_menu = main_menu | |
97 | |
98 def on_save_map_jpg(self, evt): | |
99 directory = orpg.dirpath.dir_struct["user"] | |
100 if directory == None: | |
101 directory = "" | |
102 d = wx.FileDialog(self.GetParent(), "Save map as a jpg", directory, "", "*.jpg", wx.SAVE) | |
103 if d.ShowModal() != wx.ID_OK: | |
104 return | |
105 filename = d.GetPath() | |
106 width = self.canvas.size[0] | |
107 height = self.canvas.size[1] | |
108 dc = wx.MemoryDC() | |
109 bitmap = wx.EmptyBitmap(width+1, height+1) | |
110 dc.SelectObject(bitmap) | |
111 dc.SetPen(wx.TRANSPARENT_PEN) | |
112 dc.SetBrush(wx.Brush(self.canvas.GetBackgroundColour(), wx.SOLID)) | |
113 dc.DrawRectangle(0,0,width+1, height+1) | |
114 self.canvas.layers['bg'].layerDraw(dc, 1, [0,0], self.canvas.size) | |
115 self.canvas.layers['grid'].layerDraw(dc, [0,0], self.canvas.size) | |
116 self.canvas.layers['miniatures'].layerDraw(dc, [0,0], self.canvas.size) | |
117 self.canvas.layers['whiteboard'].layerDraw(dc) | |
118 self.canvas.layers['fog'].layerDraw(dc, [0,0], self.canvas.size) | |
119 image = bitmap.ConvertToImage() | |
120 image.SaveFile(filename, wx.BITMAP_TYPE_JPEG) | |
121 | |
122 def do_map_board_menu(self,pos): | |
123 self.canvas.PopupMenu(self.main_menu,pos) | |
124 | |
125 def on_right_down(self,evt): | |
126 self.do_map_board_menu(evt.GetPosition()) | |
127 | |
128 def on_left_down(self,evt): | |
129 pass | |
130 | |
131 def on_left_up(self,evt): | |
132 pass | |
133 | |
134 #added to base layer by Snowdog 5/03 | |
135 def on_left_dclick(self,evt): | |
136 pass | |
137 | |
138 def on_motion(self,evt): | |
139 pass | |
140 | |
141 def update_info(self): | |
142 pass |