Skip to content

Commit

Permalink
Moved bitmap and char width/zoom out of Machine and into control only
Browse files Browse the repository at this point in the history
* fixed width/zoom problems in some views
  • Loading branch information
robmcmullen committed Oct 18, 2017
1 parent 5cfef75 commit 148cbdc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 45 deletions.
24 changes: 0 additions & 24 deletions omnivore8bit/arch/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,8 @@ class Machine(HasTraits):

bitmap_renderer = Any(transient=True)

bitmap_bytes_per_row = Int(1)

bitmap_zoom = Int(5)

font_renderer = Any(transient=True)

font_bytes_per_row = Int(8)

font_zoom = Int(2)

font_mapping = Any(transient=True)

page_renderer = Any(transient=True)
Expand Down Expand Up @@ -374,14 +366,6 @@ def set_bitmap_renderer(self, renderer):
self.bitmap_renderer = renderer
self.bitmap_shape_change_event = True

def set_bitmap_bytes_per_row(self, value):
self.bitmap_bytes_per_row = value
self.bitmap_shape_change_event = True

def set_bitmap_zoom(self, value):
self.bitmap_zoom = value
self.bitmap_shape_change_event = True

def set_disassembler(self, disassembler):
self.disassembler = disassembler
self.disassembler_change_event = True
Expand Down Expand Up @@ -433,14 +417,6 @@ def set_font_mapping(self, font_mapping=None):
self.font_mapping = font_mapping
self.font_change_event = True

def set_font_bytes_per_row(self, value):
self.font_bytes_per_row = value
self.font_change_event = True

def set_font_zoom(self, value):
self.font_zoom = value
self.font_change_event = True

def get_antic_font(self, reverse=False):
return fonts.AnticFont(self, self.antic_font_data, self.font_renderer, self.antic_color_registers[4:9], reverse)

Expand Down
24 changes: 12 additions & 12 deletions omnivore8bit/byte_edit/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ class BitmapWidthAction(EditorAction):
def perform(self, event):
e = self.active_editor
v = e.focused_viewer
width = prompt_for_dec(e.window.control, 'Enter new bitmap width in bytes', 'Set Bitmap Width', v.machine.bitmap_bytes_per_row)
if width is not None and width > 0:
wx.CallAfter(v.machine.set_bitmap_bytes_per_row, width)
val = prompt_for_dec(e.window.control, 'Enter new bitmap width in bytes', 'Set Bitmap Width', v.width)
if val is not None and val > 0:
v.set_width(val)

@on_trait_change('active_editor.focused_viewer')
def _update_enabled(self):
Expand All @@ -392,9 +392,9 @@ class BitmapZoomAction(EditorAction):
def perform(self, event):
e = self.active_editor
v = e.focused_viewer
width = prompt_for_dec(e.window.control, 'Enter new pixel zoom factor', 'Set Bitmap Zoom', v.machine.bitmap_zoom)
if width is not None and width > 0:
wx.CallAfter(v.machine.set_bitmap_zoom, width)
val = prompt_for_dec(e.window.control, 'Enter new pixel zoom factor', 'Set Bitmap Zoom', v.zoom)
if val is not None and val > 0:
v.set_zoom(val)

@on_trait_change('active_editor.focused_viewer')
def _update_enabled(self):
Expand All @@ -410,9 +410,9 @@ class FontMappingWidthAction(EditorAction):
def perform(self, event):
e = self.active_editor
v = e.focused_viewer
width = prompt_for_dec(e.window.control, 'Enter new map width in bytes', 'Set Map Width', str(v.machine.font_bytes_per_row))
if width is not None and width > 0:
wx.CallAfter(v.machine.set_font_bytes_per_row, width)
val = prompt_for_dec(e.window.control, 'Enter new map width in bytes', 'Set Map Width', v.width)
if val is not None and val > 0:
v.set_width(val)

@on_trait_change('active_editor.focused_viewer')
def _update_enabled(self):
Expand All @@ -429,9 +429,9 @@ class FontMappingZoomAction(EditorAction):
def perform(self, event):
e = self.active_editor
v = e.focused_viewer
width = prompt_for_dec(e.window.control, 'Enter new pixel zoom factor', 'Set Map Zoom', v.machine.font_zoom)
if width is not None and width > 0:
wx.CallAfter(v.machine.set_font_zoom, width)
val = prompt_for_dec(e.window.control, 'Enter new pixel zoom factor', 'Set Map Zoom', v.zoom)
if val is not None and val > 0:
v.set_zoom(val)

@on_trait_change('active_editor.focused_viewer')
def _update_enabled(self):
Expand Down
9 changes: 0 additions & 9 deletions omnivore8bit/ui/bitviewscroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,6 @@ def on_char_hook(self, evt):
class BitmapScroller(BitviewScroller):
short_name = "bitmap"

def update_bytes_per_row(self):
BitviewScroller.update_bytes_per_row(self)
m = self.segment_viewer.machine
self.bytes_per_row = m.bitmap_renderer.validate_bytes_per_row(m.bitmap_bytes_per_row)

# def sync_to_editor(self, e):
# e.bitmap_zoom = self.zoom
# e.bitmap_width = self.bytes_per_row
Expand Down Expand Up @@ -652,10 +647,6 @@ def update(self, event):
def is_ready_to_render(self):
return self.font is not None

def update_bytes_per_row(self):
BitviewScroller.update_bytes_per_row(self)
self.bytes_per_row = self.segment_viewer.machine.font_bytes_per_row

def sync_to_editor(self, e):
e.map_zoom = self.zoom
e.map_width = self.bytes_per_row
Expand Down
22 changes: 22 additions & 0 deletions omnivore8bit/viewers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid

import wx
import wx.lib.agw.aui as aui

from traits.api import Any, Bool, Int, Str, List, Dict, Event, Enum, Instance, File, Unicode, Property, on_trait_change, HasTraits, Undefined
Expand Down Expand Up @@ -149,6 +150,27 @@ def get_extra_segment_savers(self, segment):
"""
return []

##### view settings

@property
def width(self):
return self.control.bytes_per_row

def set_width(self, width):
self.control.bytes_per_row = self.validate_width(width)
wx.CallAfter(self.control.recalc_view)

def validate_width(self, width):
return width

@property
def zoom(self):
return self.control.zoom

def set_zoom(self, zoom):
self.control.zoom = zoom
wx.CallAfter(self.control.recalc_view)

##### Selections

def highlight_selected_ranges(self):
Expand Down
4 changes: 4 additions & 0 deletions omnivore8bit/viewers/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def update_bitmap(self, evt):
if evt is not Undefined:
self.control.refresh_view()

def validate_width(self, width):
return self.machine.bitmap_renderer.validate_bytes_per_row(width)


class MemoryMapViewer(BitmapViewer):
name = "memmap"

Expand Down

0 comments on commit 148cbdc

Please sign in to comment.