diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 3d3ad7b..4d79148 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -936,6 +936,7 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height, (GB_map_type_t) self.tilemapMapButton.indexOfSelectedItem, (GB_tileset_type_t) self.TilemapSetButton.indexOfSelectedItem); + self.tilemapImageView.scrollRect = NSMakeRect(gb.io_registers[GB_IO_SCX], gb.io_registers[GB_IO_SCY], 160, 144); self.tilemapImageView.image = [Document imageFromData:data width:256 height:256 scale:1.0]; self.tilemapImageView.layer.magnificationFilter = kCAFilterNearest; } @@ -1192,6 +1193,11 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height, } } +- (IBAction)toggleScrollingDisplay:(NSButton *)sender +{ + self.tilemapImageView.displayScrollRect = sender.state; +} + - (IBAction)vramTabChanged:(NSSegmentedControl *)sender { [self.vramTabView selectTabViewItemAtIndex:[sender selectedSegment]]; diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib index 88c5275..d558216 100644 --- a/Cocoa/Document.xib +++ b/Cocoa/Document.xib @@ -1,8 +1,8 @@ - + - + @@ -83,9 +83,9 @@ - + - + @@ -109,7 +109,7 @@ - + @@ -133,9 +133,9 @@ - + - + @@ -163,9 +163,9 @@ - + - + @@ -243,7 +243,7 @@ - + @@ -260,7 +260,7 @@ - + @@ -285,7 +285,7 @@ - + @@ -298,7 +298,7 @@ - + @@ -377,6 +377,17 @@ + @@ -612,7 +623,7 @@ - + diff --git a/Cocoa/GBImageView.h b/Cocoa/GBImageView.h index 22a8829..d5ee534 100644 --- a/Cocoa/GBImageView.h +++ b/Cocoa/GBImageView.h @@ -11,7 +11,9 @@ @interface GBImageView : NSImageView @property (nonatomic) NSArray *horizontalGrids; @property (nonatomic) NSArray *verticalGrids; -@property (weak) IBOutlet id delegate; +@property (nonatomic) bool displayScrollRect; +@property NSRect scrollRect; +@property (weak) IBOutlet id delegate; @end @protocol GBImageViewDelegate diff --git a/Cocoa/GBImageView.m b/Cocoa/GBImageView.m index 674d4b2..973625e 100644 --- a/Cocoa/GBImageView.m +++ b/Cocoa/GBImageView.m @@ -25,8 +25,8 @@ [conf.color set]; for (CGFloat y = conf.size * y_ratio; y < self.frame.size.height; y += conf.size * y_ratio) { NSBezierPath *line = [NSBezierPath bezierPath]; - [line moveToPoint:NSMakePoint(0, y + 0.5)]; - [line lineToPoint:NSMakePoint(self.frame.size.width, y + 0.5)]; + [line moveToPoint:NSMakePoint(0, y - 0.5)]; + [line lineToPoint:NSMakePoint(self.frame.size.width, y - 0.5)]; [line setLineWidth:1.0]; [line stroke]; } @@ -42,6 +42,35 @@ [line stroke]; } } + + if (self.displayScrollRect) { + NSBezierPath *path = [NSBezierPath bezierPathWithRect:CGRectInfinite]; + for (unsigned x = 0; x < 2; x++) { + for (unsigned y = 0; y < 2; y++) { + NSRect rect = self.scrollRect; + rect.origin.x *= x_ratio; + rect.origin.y *= y_ratio; + rect.size.width *= x_ratio; + rect.size.height *= y_ratio; + rect.origin.y = self.frame.size.height - rect.origin.y - rect.size.height; + + rect.origin.x -= self.frame.size.width * x; + rect.origin.y += self.frame.size.height * y; + + + NSBezierPath *subpath = [NSBezierPath bezierPathWithRect:rect]; + [path appendBezierPath:subpath]; + } + } + [path setWindingRule:NSEvenOddWindingRule]; + [path setLineWidth:4.0]; + [path setLineJoinStyle:NSRoundLineJoinStyle]; + [[NSColor colorWithWhite:0.2 alpha:0.5] set]; + [path fill]; + [path addClip]; + [[NSColor colorWithWhite:0.0 alpha:0.6] set]; + [path stroke]; + } } - (void)setHorizontalGrids:(NSArray *)horizontalGrids @@ -56,6 +85,12 @@ [self setNeedsDisplay]; } +- (void)setDisplayScrollRect:(bool)displayScrollRect +{ + self->_displayScrollRect = displayScrollRect; + [self setNeedsDisplay]; +} + - (void)updateTrackingAreas { if(trackingArea != nil) {