Skip to content

Commit

Permalink
Added menu item for char map zoom
Browse files Browse the repository at this point in the history
* added sync between the bitview classes and the editors, particularly for zoom which can be controlled directly by the mouse wheel
  • Loading branch information
robmcmullen committed Feb 2, 2016
1 parent 7b0f651 commit afea601
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 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 @@ -125,6 +125,16 @@ def perform(self, event):
wx.CallAfter(e.set_map_width, width)


class FontMappingZoomAction(EditorAction):
name = "Map Zoom"

def perform(self, event):
e = self.active_editor
width = prompt_for_hex(e.window.control, 'Enter new pixel zoom factor', 'Set Map Zoom', e.map_zoom)
if width is not None and width > 0:
wx.CallAfter(e.set_map_zoom, width)


class AnticColorAction(EditorAction):
name = 'Choose Colors...'

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 @@ -53,6 +53,8 @@ class HexEditor(FrameworkEditor):

map_width = Int

map_zoom = Int

bitmap_width = Int

bitmap_zoom = Int
Expand Down Expand Up @@ -125,6 +127,9 @@ def _antic_font_mapping_default(self):
def _map_width_default(self):
return 8 # ATASCII

def _map_zoom_default(self):
return 2

def _bitmap_width_default(self):
return 1

Expand Down Expand Up @@ -325,6 +330,12 @@ def set_map_width(self, width=None):
self.map_width = width
self.font_map.recalc_view()

def set_map_zoom(self, zoom=None):
if zoom is None:
zoom = self.map_zoom
self.map_zoom = zoom
self.font_map.recalc_view()

def load_font(self, filename):
try:
fh = open(filename, 'rb')
Expand Down
23 changes: 21 additions & 2 deletions omnivore/utils/wx/bitviewscroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def refresh_view(self):
else:
self.Refresh()

def sync_settings(self):
e = self.editor
if e is not None:
self.sync_to_editor(e)

def sync_to_editor(self, e):
pass

def set_colors(self):
pass

Expand All @@ -147,6 +155,7 @@ def set_zoom(self, zoom):
elif zoom < self.min_zoom:
zoom = self.min_zoom
self.zoom = zoom
self.sync_settings()

def get_zoom_factors(self):
return self.zoom, self.zoom
Expand Down Expand Up @@ -532,7 +541,10 @@ def update_bytes_per_row(self):

def update_zoom(self):
self.set_zoom(self.editor.bitmap_zoom)
self.editor.bitmap_zoom = self.zoom

def sync_to_editor(self, e):
e.bitmap_zoom = self.zoom
e.bitmap_width = self.bytes_per_row

def event_coords_to_byte(self, evt):
if self.end_byte is None: # end_byte is a proxy for the image being loaded
Expand Down Expand Up @@ -714,6 +726,13 @@ def is_ready_to_render(self):
def update_bytes_per_row(self):
self.bytes_per_row = self.editor.map_width

def update_zoom(self):
self.set_zoom(self.editor.map_zoom)

def sync_to_editor(self, e):
e.map_zoom = self.zoom
e.map_width = self.bytes_per_row

def calc_scale_from_bytes(self):
self.total_rows = (self.bytes.size + self.bytes_per_row - 1) / self.bytes_per_row
self.grid_width = int(8 * self.bytes_per_row)
Expand Down Expand Up @@ -876,7 +895,7 @@ def event_coords_to_byte(self, evt):

def get_popup_actions(self):
actions = BitviewScroller.get_popup_actions(self)
actions.extend([None, FontMappingWidthAction, None])
actions.extend([None, FontMappingWidthAction, FontMappingZoomAction, None])
actions.extend(self.task.get_font_mapping_actions())
return actions

Expand Down

0 comments on commit afea601

Please sign in to comment.