From 7b0f651df7c7d1a136956b987629673745b4c0a0 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Tue, 2 Feb 2016 14:43:01 -0800 Subject: [PATCH] Added menu item for bitmap zoom factor --- omnivore/tasks/hex_edit/actions.py | 10 ++++++++++ omnivore/tasks/hex_edit/hex_editor.py | 11 +++++++++++ omnivore/tasks/hex_edit/task.py | 1 + omnivore/utils/wx/bitviewscroller.py | 25 ++++++++++++++++++------- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/omnivore/tasks/hex_edit/actions.py b/omnivore/tasks/hex_edit/actions.py index a9dced20..f31c938d 100644 --- a/omnivore/tasks/hex_edit/actions.py +++ b/omnivore/tasks/hex_edit/actions.py @@ -105,6 +105,16 @@ def perform(self, event): wx.CallAfter(e.set_bitmap_width, width) +class BitmapZoomAction(EditorAction): + name = "Bitmap Zoom" + + def perform(self, event): + e = self.active_editor + width = prompt_for_hex(e.window.control, 'Enter new pixel zoom factor', 'Set Bitmap Zoom', e.bitmap_zoom) + if width is not None and width > 0: + wx.CallAfter(e.set_bitmap_zoom, width) + + class FontMappingWidthAction(EditorAction): name = "Map Width" diff --git a/omnivore/tasks/hex_edit/hex_editor.py b/omnivore/tasks/hex_edit/hex_editor.py index 090ff505..de57793b 100644 --- a/omnivore/tasks/hex_edit/hex_editor.py +++ b/omnivore/tasks/hex_edit/hex_editor.py @@ -55,6 +55,8 @@ class HexEditor(FrameworkEditor): bitmap_width = Int + bitmap_zoom = Int + playfield_colors = Any color_standard = Enum(0, 1) @@ -126,6 +128,9 @@ def _map_width_default(self): def _bitmap_width_default(self): return 1 + def _bitmap_zoom_default(self): + return 5 + def _playfield_colors_default(self): return colors.powerup_colors() @@ -265,6 +270,12 @@ def set_bitmap_width(self, width=None): self.bitmap_width = width self.bitmap.recalc_view() + def set_bitmap_zoom(self, zoom=None): + if zoom is None: + zoom = self.bitmap_zoom + self.bitmap_zoom = zoom + self.bitmap.recalc_view() + def update_fonts(self): self.font_map.Refresh() pane = self.window.get_dock_pane('hex_edit.font_map') diff --git a/omnivore/tasks/hex_edit/task.py b/omnivore/tasks/hex_edit/task.py index 1f2b8b9b..39089ea9 100644 --- a/omnivore/tasks/hex_edit/task.py +++ b/omnivore/tasks/hex_edit/task.py @@ -172,6 +172,7 @@ def get_common_ViewConfigGroup(self): SMenu( Group( BitmapWidthAction(), + BitmapZoomAction(), id="a1", separator=True), id='FontChoiceSubmenu2a2', separator=True, name="Bitmap"), SMenu( diff --git a/omnivore/utils/wx/bitviewscroller.py b/omnivore/utils/wx/bitviewscroller.py index 4e60bce9..6a4a4df0 100644 --- a/omnivore/utils/wx/bitviewscroller.py +++ b/omnivore/utils/wx/bitviewscroller.py @@ -116,6 +116,7 @@ def recalc_view(self): self.set_colors() self.set_font() self.update_bytes_per_row() + self.update_zoom() self.set_scale() def refresh_view(self): @@ -133,17 +134,20 @@ def set_font(self): pass def zoom_in(self, zoom=1): - self.zoom += zoom - if self.zoom > self.max_zoom: - self.zoom = self.max_zoom + self.set_zoom(self.zoom + zoom) self.set_scale() def zoom_out(self, zoom=1): - self.zoom -= zoom - if self.zoom < self.min_zoom: - self.zoom = self.min_zoom + self.set_zoom(self.zoom - zoom) self.set_scale() + def set_zoom(self, zoom): + if zoom > self.max_zoom: + zoom = self.max_zoom + elif zoom < self.min_zoom: + zoom = self.min_zoom + self.zoom = zoom + def get_zoom_factors(self): return self.zoom, self.zoom @@ -262,6 +266,9 @@ def calc_image_size(self): def update_bytes_per_row(self): pass + def update_zoom(self): + pass + def set_scale(self): """Creates new image at specified zoom factor. @@ -523,6 +530,10 @@ class BitmapScroller(BitviewScroller): def update_bytes_per_row(self): self.bytes_per_row = self.editor.bitmap_width + def update_zoom(self): + self.set_zoom(self.editor.bitmap_zoom) + self.editor.bitmap_zoom = self.zoom + def event_coords_to_byte(self, evt): if self.end_byte is None: # end_byte is a proxy for the image being loaded return 0, 0, False @@ -675,7 +686,7 @@ def get_image_multi(self, sr, nr, count, bytes, style): def get_popup_actions(self): actions = BitviewScroller.get_popup_actions(self) - actions.extend([None, BitmapWidthAction]) + actions.extend([None, BitmapWidthAction, BitmapZoomAction]) return actions