Previous 199869 Revisions Next

r35187 Saturday 21st February, 2015 at 22:28:43 UTC by Vasantha Crabb
Cocoa debugger: suppress trailing whitespace on copy, draw background to edge, more efficient drawing
[src/osd/modules/debugger/osx]debugview.m

trunk/src/osd/modules/debugger/osx/debugview.m
r243698r243699
3131static NSColor *InactiveSelectedBackground;
3232static NSColor *InactiveSelectedCurrentBackground;
3333
34static NSCharacterSet *NonWhiteCharacters;
3435
36
3537static void debugwin_view_update(debug_view &view, void *osdprivate)
3638{
3739   [(MAMEDebugView *)osdprivate update];
r243698r243699
5759   SelectedCurrentBackground = [[NSColor colorWithCalibratedRed:0.875 green:0.625 blue:0.875 alpha:1.0] retain];
5860   InactiveSelectedBackground = [[NSColor colorWithCalibratedWhite:0.875 alpha:1.0] retain];
5961   InactiveSelectedCurrentBackground = [[NSColor colorWithCalibratedRed:0.875 green:0.5 blue:0.625 alpha:1.0] retain];
62
63   NonWhiteCharacters = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet];
6064}
6165
6266
r243698r243699
317321
318322   for (UINT32 row = 0; row < size.y; row++, data += size.x)
319323   {
324      // add content for the line and set colours
320325      int         attr = -1;
321      NSUInteger   start = [text length], length = 0;
326      NSUInteger   start = [text length], length = start;
322327      for (UINT32 col = 0; col < size.x; col++)
323328      {
324329         [[text mutableString] appendFormat:@"%c", data[col].byte];
r243698r243699
336341         attr = data[col].attrib & ~DCA_SELECTED;
337342         length = [text length];
338343      }
339      if (start < length)
340      {
341         NSRange const run = NSMakeRange(start, length - start);
342         [text addAttribute:NSForegroundColorAttributeName
343                   value:[self foregroundForAttribute:attr]
344                   range:run];
345         [text addAttribute:NSBackgroundColorAttributeName
346                   value:[self backgroundForAttribute:attr]
347                   range:run];
348      }
344
345      // clean up trailing whitespace
346      NSRange trim = [[text string] rangeOfCharacterFromSet:NonWhiteCharacters
347                                         options:NSBackwardsSearch
348                                          range:NSMakeRange(start, length - start)];
349      if (trim.location != NSNotFound)
350         trim = [[text string] rangeOfComposedCharacterSequenceAtIndex:(trim.location + trim.length - 1)];
351      else if (start > 0)
352         trim = [[text string] rangeOfComposedCharacterSequenceAtIndex:(start - 1)];
353      else
354         trim = NSMakeRange(start, 0);
355      trim.location += trim.length;
356      trim.length = length - trim.location;
357      [text deleteCharactersInRange:trim];
358
359      // add the line ending and set colours
349360      [[text mutableString] appendString:@"\n"];
361      NSRange const run = NSMakeRange(start, [text length] - start);
362      [text addAttribute:NSForegroundColorAttributeName
363                value:[self foregroundForAttribute:attr]
364                range:run];
365      [text addAttribute:NSBackgroundColorAttributeName
366                value:[self backgroundForAttribute:attr]
367                range:run];
350368   }
351369
370   // set the font and send it to the pasteboard
352371   NSRange const run = NSMakeRange(0, [text length]);
353372   [text addAttribute:NSFontAttributeName value:font range:run];
354373   NSPasteboard *const board = [NSPasteboard generalPasteboard];
r243698r243699
458477}
459478
460479
480- (BOOL)isOpaque {
481   return YES;
482}
483
484
461485- (void)drawRect:(NSRect)dirtyRect {
462486   INT32 position, clip;
463487
r243698r243699
495519                      range:run];
496520            NSRange const glyphs = [layoutManager glyphRangeForCharacterRange:run
497521                                              actualCharacterRange:NULL];
498            NSRect const box = [layoutManager boundingRectForGlyphRange:glyphs
499                                             inTextContainer:textContainer];
522            NSRect box = [layoutManager boundingRectForGlyphRange:glyphs
523                                         inTextContainer:textContainer];
524            if (start == 0)
525            {
526               box.size.width += box.origin.x;
527               box.origin.x = 0;
528            }
500529            [[self backgroundForAttribute:attr] set];
501530            [NSBezierPath fillRect:NSMakeRect(box.origin.x,
502531                                      row * fontHeight,
r243698r243699
507536         attr = data[col - origin.x].attrib;
508537         length = [text length];
509538      }
510      if (start < length)
511      {
512         NSRange const run = NSMakeRange(start, length - start);
513         [text addAttribute:NSFontAttributeName
514                   value:font
515                   range:NSMakeRange(0, length)];
516         [text addAttribute:NSForegroundColorAttributeName
517                   value:[self foregroundForAttribute:attr]
518                   range:run];
519         NSRange const glyphs = [layoutManager glyphRangeForCharacterRange:run
520                                           actualCharacterRange:NULL];
521         NSRect const box = [layoutManager boundingRectForGlyphRange:glyphs
522                                          inTextContainer:textContainer];
523         [[self backgroundForAttribute:attr] set];
524         [NSBezierPath fillRect:NSMakeRect(box.origin.x,
525                                   row * fontHeight,
526                                   box.size.width,
527                                   fontHeight)];
528      }
539      NSRange const run = NSMakeRange(start, length - start);
540      [text addAttribute:NSFontAttributeName
541                value:font
542                range:NSMakeRange(0, length)];
543      [text addAttribute:NSForegroundColorAttributeName
544                value:[self foregroundForAttribute:attr]
545                range:run];
546      NSRange const glyphs = [layoutManager glyphRangeForCharacterRange:run
547                                        actualCharacterRange:NULL];
548      NSRect box = [layoutManager boundingRectForGlyphRange:glyphs
549                                   inTextContainer:textContainer];
550      if (start == 0)
551         box.origin.x = 0;
552      box.size.width = [self bounds].size.width - box.origin.x;
553      [[self backgroundForAttribute:attr] set];
554      [NSBezierPath fillRect:NSMakeRect(box.origin.x,
555                                row * fontHeight,
556                                box.size.width,
557                                fontHeight)];
529558      [layoutManager drawGlyphsForGlyphRange:[layoutManager glyphRangeForTextContainer:textContainer]
530559                              atPoint:NSMakePoint(0, row * fontHeight)];
531560      [text deleteCharactersInRange:NSMakeRange(0, length)];


Previous 199869 Revisions Next


© 1997-2024 The MAME Team