From 3047ba4982151f6ac4a9790e25848625559f7079 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 23 Feb 2015 01:25:45 +1100 Subject: [PATCH] Add a whole line scroll mode to make breakpoints/watchpoints header work nicely --- .../modules/debugger/osx/breakpointsview.m | 2 +- src/osd/modules/debugger/osx/consoleview.m | 2 +- src/osd/modules/debugger/osx/debugview.h | 3 +- src/osd/modules/debugger/osx/debugview.m | 43 +++++++++++++------ .../modules/debugger/osx/disassemblyview.m | 2 +- src/osd/modules/debugger/osx/errorlogview.m | 2 +- src/osd/modules/debugger/osx/memoryview.m | 2 +- src/osd/modules/debugger/osx/registersview.m | 2 +- .../modules/debugger/osx/watchpointsview.m | 2 +- 9 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/osd/modules/debugger/osx/breakpointsview.m b/src/osd/modules/debugger/osx/breakpointsview.m index 97545370955..46f58eac29b 100644 --- a/src/osd/modules/debugger/osx/breakpointsview.m +++ b/src/osd/modules/debugger/osx/breakpointsview.m @@ -17,7 +17,7 @@ @implementation MAMEBreakpointsView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_BREAK_POINTS machine:m])) + if (!(self = [super initWithFrame:f type:DVT_BREAK_POINTS machine:m wholeLineScroll:YES])) return nil; return self; } diff --git a/src/osd/modules/debugger/osx/consoleview.m b/src/osd/modules/debugger/osx/consoleview.m index 3e2e29b9202..afa6c826199 100644 --- a/src/osd/modules/debugger/osx/consoleview.m +++ b/src/osd/modules/debugger/osx/consoleview.m @@ -17,7 +17,7 @@ @implementation MAMEConsoleView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_CONSOLE machine:m])) + if (!(self = [super initWithFrame:f type:DVT_CONSOLE machine:m wholeLineScroll:NO])) return nil; return self; } diff --git a/src/osd/modules/debugger/osx/debugview.h b/src/osd/modules/debugger/osx/debugview.h index 12bfa3c3ca7..b76e4633f38 100644 --- a/src/osd/modules/debugger/osx/debugview.h +++ b/src/osd/modules/debugger/osx/debugview.h @@ -22,6 +22,7 @@ int type; running_machine *machine; debug_view *view; + BOOL wholeLineScroll; INT32 totalWidth, totalHeight, originTop; @@ -35,7 +36,7 @@ + (NSFont *)defaultFont; -- (id)initWithFrame:(NSRect)f type:(debug_view_type)t machine:(running_machine &)m; +- (id)initWithFrame:(NSRect)f type:(debug_view_type)t machine:(running_machine &)m wholeLineScroll:(BOOL)w; - (void)update; diff --git a/src/osd/modules/debugger/osx/debugview.m b/src/osd/modules/debugger/osx/debugview.m index eda265db976..6ed888fd53d 100644 --- a/src/osd/modules/debugger/osx/debugview.m +++ b/src/osd/modules/debugger/osx/debugview.m @@ -168,6 +168,7 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) // this gets all the lines that are at least partially visible debug_view_xy origin(0, 0), size(totalWidth, totalHeight); [self convertBounds:[self visibleRect] toFirstAffectedLine:&origin.y count:&size.y]; + size.y = MIN(size.y, totalHeight - origin.y); // tell the underlying view how much real estate is available view->set_visible_size(size); @@ -196,9 +197,12 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) - (void)adjustSizeAndRecomputeVisible { NSSize const clip = [[[self enclosingScrollView] contentView] bounds].size; - NSSize const content = NSMakeSize((fontWidth * totalWidth) + (2 * [textContainer lineFragmentPadding]), - fontHeight * totalHeight); - [self setFrameSize:NSMakeSize(MAX(clip.width, content.width), MAX(clip.height, content.height))]; + NSSize content = NSMakeSize((fontWidth * totalWidth) + (2 * [textContainer lineFragmentPadding]), + fontHeight * totalHeight); + if (wholeLineScroll) + content.height += (fontHeight * 2) - 1; + [self setFrameSize:NSMakeSize(ceil(MAX(clip.width, content.width)), + ceil(MAX(clip.height, content.height)))]; [self recomputeVisible]; } @@ -208,7 +212,7 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) } -- (id)initWithFrame:(NSRect)f type:(debug_view_type)t machine:(running_machine &)m { +- (id)initWithFrame:(NSRect)f type:(debug_view_type)t machine:(running_machine &)m wholeLineScroll:(BOOL)w { if (!(self = [super initWithFrame:f])) return nil; type = t; @@ -218,7 +222,10 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) [self release]; return nil; } - totalWidth = totalHeight = 0; + wholeLineScroll = w; + debug_view_xy const size = view->total_size(); + totalWidth = size.x; + totalHeight = size.y; originTop = 0; text = [[NSTextStorage alloc] init]; @@ -258,10 +265,12 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) if (scroller) { NSSize const clip = [[scroller contentView] bounds].size; - NSSize const content = NSMakeSize((fontWidth * newSize.x) + (2 * [textContainer lineFragmentPadding]), - fontHeight * newSize.y); - [self setFrameSize:NSMakeSize(MAX(clip.width, content.width), MAX(clip.height, content.height))]; - [self recomputeVisible]; + NSSize content = NSMakeSize((fontWidth * newSize.x) + (2 * [textContainer lineFragmentPadding]), + fontHeight * newSize.y); + if (wholeLineScroll) + content.height += (fontHeight * 2) - 1; + [self setFrameSize:NSMakeSize(ceil(MAX(clip.width, content.width)), + ceil(MAX(clip.height, content.height)))]; } totalWidth = newSize.x; totalHeight = newSize.y; @@ -273,8 +282,6 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) { NSRect const visible = [self visibleRect]; NSPoint scroll = NSMakePoint(visible.origin.x, newOrigin.y * fontHeight); - if ((newOrigin.y + view->visible_size().y) == totalHeight) - scroll.y += (view->visible_size().y * fontHeight) - visible.size.height; [self scrollPoint:scroll]; originTop = newOrigin.y; } @@ -287,7 +294,7 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) - (NSSize)maximumFrameSize { debug_view_xy const max = view->total_size(); return NSMakeSize(ceil((max.x * fontWidth) + (2 * [textContainer lineFragmentPadding])), - ceil(max.y * fontHeight)); + ceil((max.y + (wholeLineScroll ? 1 : 0)) * fontHeight)); } @@ -519,6 +526,7 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) selector:@selector(viewFrameDidChange:) name:NSViewFrameDidChangeNotification object:[scroller contentView]]; + [self adjustSizeAndRecomputeVisible]; } } @@ -558,6 +566,17 @@ static void debugwin_view_update(debug_view &view, void *osdprivate) } +- (NSRect)adjustScroll:(NSRect)proposedVisibleRect { + if (wholeLineScroll) + { + CGFloat const clamp = [self bounds].size.height - fontHeight - proposedVisibleRect.size.height; + proposedVisibleRect.origin.y = MIN(proposedVisibleRect.origin.y, MAX(clamp, 0)); + proposedVisibleRect.origin.y -= fmod(proposedVisibleRect.origin.y, fontHeight); + } + return proposedVisibleRect; +} + + - (void)drawRect:(NSRect)dirtyRect { // work out what's available [self recomputeVisible]; diff --git a/src/osd/modules/debugger/osx/disassemblyview.m b/src/osd/modules/debugger/osx/disassemblyview.m index 0be36d9f5f9..55ecb5f50ac 100644 --- a/src/osd/modules/debugger/osx/disassemblyview.m +++ b/src/osd/modules/debugger/osx/disassemblyview.m @@ -17,7 +17,7 @@ @implementation MAMEDisassemblyView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_DISASSEMBLY machine:m])) + if (!(self = [super initWithFrame:f type:DVT_DISASSEMBLY machine:m wholeLineScroll:NO])) return nil; return self; } diff --git a/src/osd/modules/debugger/osx/errorlogview.m b/src/osd/modules/debugger/osx/errorlogview.m index 80380bc1e16..102065009ea 100644 --- a/src/osd/modules/debugger/osx/errorlogview.m +++ b/src/osd/modules/debugger/osx/errorlogview.m @@ -17,7 +17,7 @@ @implementation MAMEErrorLogView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_LOG machine:m])) + if (!(self = [super initWithFrame:f type:DVT_LOG machine:m wholeLineScroll:NO])) return nil; return self; } diff --git a/src/osd/modules/debugger/osx/memoryview.m b/src/osd/modules/debugger/osx/memoryview.m index 0cb1a7f55d9..e90095292a4 100644 --- a/src/osd/modules/debugger/osx/memoryview.m +++ b/src/osd/modules/debugger/osx/memoryview.m @@ -18,7 +18,7 @@ @implementation MAMEMemoryView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_MEMORY machine:m])) + if (!(self = [super initWithFrame:f type:DVT_MEMORY machine:m wholeLineScroll:NO])) return nil; return self; } diff --git a/src/osd/modules/debugger/osx/registersview.m b/src/osd/modules/debugger/osx/registersview.m index 50191b4c9a5..e02bd9cd7a6 100644 --- a/src/osd/modules/debugger/osx/registersview.m +++ b/src/osd/modules/debugger/osx/registersview.m @@ -18,7 +18,7 @@ @implementation MAMERegistersView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_STATE machine:m])) + if (!(self = [super initWithFrame:f type:DVT_STATE machine:m wholeLineScroll:NO])) return nil; return self; } diff --git a/src/osd/modules/debugger/osx/watchpointsview.m b/src/osd/modules/debugger/osx/watchpointsview.m index 0b1ab9ae39c..ae726d0f0d0 100644 --- a/src/osd/modules/debugger/osx/watchpointsview.m +++ b/src/osd/modules/debugger/osx/watchpointsview.m @@ -17,7 +17,7 @@ @implementation MAMEWatchpointsView - (id)initWithFrame:(NSRect)f machine:(running_machine &)m { - if (!(self = [super initWithFrame:f type:DVT_WATCH_POINTS machine:m])) + if (!(self = [super initWithFrame:f type:DVT_WATCH_POINTS machine:m wholeLineScroll:YES])) return nil; return self; }