Skip to content

Commit

Permalink
Added menu item for bitmap zoom factor
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcmullen committed Feb 2, 2016
1 parent b511833 commit 7b0f651
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
10 changes: 10 additions & 0 deletions omnivore/tasks/hex_edit/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
11 changes: 11 additions & 0 deletions omnivore/tasks/hex_edit/hex_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class HexEditor(FrameworkEditor):

bitmap_width = Int

bitmap_zoom = Int

playfield_colors = Any

color_standard = Enum(0, 1)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions omnivore/tasks/hex_edit/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def get_common_ViewConfigGroup(self):
SMenu(
Group(
BitmapWidthAction(),
BitmapZoomAction(),
id="a1", separator=True),
id='FontChoiceSubmenu2a2', separator=True, name="Bitmap"),
SMenu(
Expand Down
25 changes: 18 additions & 7 deletions omnivore/utils/wx/bitviewscroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 7b0f651

Please sign in to comment.