Previous 199869 Revisions Next

r35194 Sunday 22nd February, 2015 at 01:34:36 UTC by Vasantha Crabb
More minor improvements to Cocoa debugger (nw)
[src/osd/modules/debugger/osx]debugview.h debugview.m

trunk/src/osd/modules/debugger/osx/debugview.h
r243705r243706
2323   running_machine   *machine;
2424   debug_view      *view;
2525
26   INT32         totalWidth, totalHeight, originLeft, originTop;
26   INT32         totalWidth, totalHeight, originTop;
2727
2828   NSFont         *font;
2929   CGFloat         fontWidth, fontHeight, fontAscent;
r243705r243706
5151- (IBAction)copyVisible:(id)sender;
5252- (IBAction)paste:(id)sender;
5353
54- (void)viewBoundsDidChange:(NSNotification *)notification;
55
5456- (void)windowDidBecomeKey:(NSNotification *)notification;
5557- (void)windowDidResignKey:(NSNotification *)notification;
5658
trunk/src/osd/modules/debugger/osx/debugview.m
r243705r243706
165165
166166
167167- (void)recomputeVisible {
168   if ([self window] != nil)
169   {
170      // this gets all the lines that are at least partially visible
171      debug_view_xy origin(0, 0), size(totalWidth, totalHeight);
172      [self convertBounds:[self visibleRect] toFirstAffectedLine:&origin.y count:&size.y];
168   // this gets all the lines that are at least partially visible
169   debug_view_xy origin(0, 0), size(totalWidth, totalHeight);
170   [self convertBounds:[self visibleRect] toFirstAffectedLine:&origin.y count:&size.y];
173171
174      // tell them what we think
175      view->set_visible_size(size);
176      view->set_visible_position(origin);
177      originLeft = origin.x;
178      originTop = origin.y;
179   }
172   // tell the underlying view how much real estate is available
173   view->set_visible_size(size);
174   view->set_visible_position(origin);
175   originTop = origin.y;
180176}
181177
182178
183179- (void)typeCharacterAndScrollToCursor:(char)ch {
184   if (view->cursor_supported())
180   debug_view_xy const oldPos = view->cursor_position();
181   view->process_char(ch);
182   if (view->cursor_supported() && view->cursor_visible())
185183   {
186      debug_view_xy const oldPos = view->cursor_position();
187      view->process_char(ch);
188184      debug_view_xy const newPos = view->cursor_position();
189185      if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y))
190186      {
r243705r243706
194190                                     fontWidth,
195191                                     fontHeight)];
196192      }
197   } else {
198      view->process_char(ch);
199193   }
200194}
201195
r243705r243706
216210      return nil;
217211   }
218212   totalWidth = totalHeight = 0;
219   originLeft = originTop = 0;
213   originTop = 0;
220214
221215   text = [[NSTextStorage alloc] init];
222216   textContainer = [[NSTextContainer alloc] init];
r243705r243706
261255   debug_view_xy const newOrigin = view->visible_position();
262256   if (newOrigin.y != originTop)
263257   {
264      [self scrollPoint:NSMakePoint([self visibleRect].origin.x, newOrigin.y * fontHeight)];
258      NSRect const visible = [self visibleRect];
259      NSPoint scroll = NSMakePoint(visible.origin.x, newOrigin.y * fontHeight);
260      if ((newOrigin.y + view->visible_size().y) == totalHeight)
261         scroll.y += (view->visible_size().y * fontHeight) - visible.size.height;
262      [self scrollPoint:scroll];
265263      originTop = newOrigin.y;
266264   }
267265
268   // recompute the visible area and mark as dirty
269   [self recomputeVisible];
266   // mark as dirty
270267   [self setNeedsDisplay:YES];
271268}
272269
r243705r243706
389386   NSData *const data = [[board stringForType:avail] dataUsingEncoding:NSASCIIStringEncoding
390387                                       allowLossyConversion:YES];
391388   char const *const bytes = (char const *)[data bytes];
389   debug_view_xy const oldPos = view->cursor_position();
392390   for (NSUInteger i = 0, l = [data length]; i < l; i++)
393391      view->process_char(bytes[i]);
392   if (view->cursor_supported() && view->cursor_visible())
393   {
394      debug_view_xy const newPos = view->cursor_position();
395      if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y))
396      {
397         // FIXME - use proper font metrics
398         [self scrollRectToVisible:NSMakeRect((newPos.x * fontWidth) + [textContainer lineFragmentPadding],
399                                     newPos.y * fontHeight,
400                                     fontWidth,
401                                     fontHeight)];
402      }
403   }
394404}
395405
396406
407- (void)viewBoundsDidChange:(NSNotification *)notification {
408   NSView *const changed = [notification object];
409   if (changed == [[self enclosingScrollView] contentView])
410      [self recomputeVisible];
411}
412
413
397414- (void)windowDidBecomeKey:(NSNotification *)notification {
398   NSWindow *win = [notification object];
415   NSWindow *const win = [notification object];
399416   if ((win == [self window]) && ([win firstResponder] == self) && view->cursor_supported())
400417      [self setNeedsDisplay:YES];
401418}
402419
403420
404421- (void)windowDidResignKey:(NSNotification *)notification {
405   NSWindow *win = [notification object];
422   NSWindow *const win = [notification object];
406423   if ((win == [self window]) && ([win firstResponder] == self) && view->cursor_supported())
407424      [self setNeedsDisplay:YES];
408425}
r243705r243706
429446
430447
431448- (BOOL)becomeFirstResponder {
432   if (view->cursor_supported()) {
449   if (view->cursor_supported())
450   {
433451      debug_view_xy pos;
434452      view->set_cursor_visible(true);
435453      pos = view->cursor_position();
436454      [self scrollRectToVisible:NSMakeRect((pos.x * fontWidth) + [textContainer lineFragmentPadding], pos.y * fontHeight, fontWidth, fontHeight)]; // FIXME: metrics
437455      [self setNeedsDisplay:YES];
438456      return [super becomeFirstResponder];
439   } else {
457   }
458   else
459   {
440460      return NO;
441461   }
442462}
r243705r243706
450470
451471
452472- (void)viewDidMoveToSuperview {
453   [[self enclosingScrollView] setLineScroll:fontHeight];
454473   [super viewDidMoveToSuperview];
474
475   [[NSNotificationCenter defaultCenter] removeObserver:self
476                                       name:NSViewBoundsDidChangeNotification
477                                      object:nil];
478
479   NSScrollView *const scroller = [self enclosingScrollView];
480   if (scroller != nil)
481   {
482      [scroller setLineScroll:fontHeight];
483      [[scroller contentView] setPostsBoundsChangedNotifications:YES];
484      [[NSNotificationCenter defaultCenter] addObserver:self
485                                     selector:@selector(viewBoundsDidChange:)
486                                        name:NSViewBoundsDidChangeNotification
487                                       object:[scroller contentView]];
488   }
455489}
456490
457491
458492- (void)viewDidMoveToWindow {
459   [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidBecomeKeyNotification object:nil];
460   [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResignKeyNotification object:nil];
461   if ([self window] != nil) {
493   [super viewDidMoveToWindow];
494
495   [[NSNotificationCenter defaultCenter] removeObserver:self
496                                       name:NSWindowDidBecomeKeyNotification
497                                      object:nil];
498   [[NSNotificationCenter defaultCenter] removeObserver:self
499                                       name:NSWindowDidResignKeyNotification
500                                      object:nil];
501
502   if ([self window] != nil)
503   {
462504      [[NSNotificationCenter defaultCenter] addObserver:self
463505                                     selector:@selector(windowDidBecomeKey:)
464506                                        name:NSWindowDidBecomeKeyNotification
r243705r243706
467509                                     selector:@selector(windowDidResignKey:)
468510                                        name:NSWindowDidResignKeyNotification
469511                                       object:[self window]];
470      [self recomputeVisible];
512      [self setNeedsDisplay:YES];
471513   }
472514}
473515
r243705r243706
483525
484526
485527- (void)drawRect:(NSRect)dirtyRect {
486   INT32 position, clip;
487
488   // work out how much we need to draw
528   // work out what's available
489529   [self recomputeVisible];
490530   debug_view_xy const origin = view->visible_position();
491531   debug_view_xy const size = view->visible_size();
532
533   // work out how much we need to draw
534   INT32 position, clip;
492535   [self convertBounds:dirtyRect toFirstAffectedLine:&position count:&clip];
493536
494537   // this gets the text for the whole visible area
r243705r243706
500543   for (UINT32 row = position; row < position + clip; row++, data += size.x)
501544   {
502545      if ((row < origin.y) || (row >= origin.y + size.y))
546      {
547         [DefaultBackground set];
548         [NSBezierPath fillRect:NSMakeRect(0,
549                                   row * fontHeight,
550                                   [self bounds].size.width,
551                                   fontHeight)];
503552         continue;
553      }
504554
505555      // render entire lines to get character alignment right
506556      int         attr = -1;


Previous 199869 Revisions Next


© 1997-2024 The MAME Team