trunk/src/osd/modules/debugger/osx/debugview.m
| r243698 | r243699 | |
| 31 | 31 | static NSColor *InactiveSelectedBackground; |
| 32 | 32 | static NSColor *InactiveSelectedCurrentBackground; |
| 33 | 33 | |
| 34 | static NSCharacterSet *NonWhiteCharacters; |
| 34 | 35 | |
| 36 | |
| 35 | 37 | static void debugwin_view_update(debug_view &view, void *osdprivate) |
| 36 | 38 | { |
| 37 | 39 | [(MAMEDebugView *)osdprivate update]; |
| r243698 | r243699 | |
| 57 | 59 | SelectedCurrentBackground = [[NSColor colorWithCalibratedRed:0.875 green:0.625 blue:0.875 alpha:1.0] retain]; |
| 58 | 60 | InactiveSelectedBackground = [[NSColor colorWithCalibratedWhite:0.875 alpha:1.0] retain]; |
| 59 | 61 | InactiveSelectedCurrentBackground = [[NSColor colorWithCalibratedRed:0.875 green:0.5 blue:0.625 alpha:1.0] retain]; |
| 62 | |
| 63 | NonWhiteCharacters = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet]; |
| 60 | 64 | } |
| 61 | 65 | |
| 62 | 66 | |
| r243698 | r243699 | |
| 317 | 321 | |
| 318 | 322 | for (UINT32 row = 0; row < size.y; row++, data += size.x) |
| 319 | 323 | { |
| 324 | // add content for the line and set colours |
| 320 | 325 | int attr = -1; |
| 321 | | NSUInteger start = [text length], length = 0; |
| 326 | NSUInteger start = [text length], length = start; |
| 322 | 327 | for (UINT32 col = 0; col < size.x; col++) |
| 323 | 328 | { |
| 324 | 329 | [[text mutableString] appendFormat:@"%c", data[col].byte]; |
| r243698 | r243699 | |
| 336 | 341 | attr = data[col].attrib & ~DCA_SELECTED; |
| 337 | 342 | length = [text length]; |
| 338 | 343 | } |
| 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 |
| 349 | 360 | [[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]; |
| 350 | 368 | } |
| 351 | 369 | |
| 370 | // set the font and send it to the pasteboard |
| 352 | 371 | NSRange const run = NSMakeRange(0, [text length]); |
| 353 | 372 | [text addAttribute:NSFontAttributeName value:font range:run]; |
| 354 | 373 | NSPasteboard *const board = [NSPasteboard generalPasteboard]; |
| r243698 | r243699 | |
| 458 | 477 | } |
| 459 | 478 | |
| 460 | 479 | |
| 480 | - (BOOL)isOpaque { |
| 481 | return YES; |
| 482 | } |
| 483 | |
| 484 | |
| 461 | 485 | - (void)drawRect:(NSRect)dirtyRect { |
| 462 | 486 | INT32 position, clip; |
| 463 | 487 | |
| r243698 | r243699 | |
| 495 | 519 | range:run]; |
| 496 | 520 | NSRange const glyphs = [layoutManager glyphRangeForCharacterRange:run |
| 497 | 521 | 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 | } |
| 500 | 529 | [[self backgroundForAttribute:attr] set]; |
| 501 | 530 | [NSBezierPath fillRect:NSMakeRect(box.origin.x, |
| 502 | 531 | row * fontHeight, |
| r243698 | r243699 | |
| 507 | 536 | attr = data[col - origin.x].attrib; |
| 508 | 537 | length = [text length]; |
| 509 | 538 | } |
| 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)]; |
| 529 | 558 | [layoutManager drawGlyphsForGlyphRange:[layoutManager glyphRangeForTextContainer:textContainer] |
| 530 | 559 | atPoint:NSMakePoint(0, row * fontHeight)]; |
| 531 | 560 | [text deleteCharactersInRange:NSMakeRange(0, length)]; |