trunk/src/osd/modules/debugger/osx/debugconsole.m
| r243713 | r243714 | |
| 45 | 45 | // create the register view |
| 46 | 46 | regView = [[MAMERegistersView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine]; |
| 47 | 47 | regScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 48 | | [regScroll setDrawsBackground:YES]; |
| 49 | 48 | [regScroll setHasHorizontalScroller:YES]; |
| 50 | 49 | [regScroll setHasVerticalScroller:YES]; |
| 51 | 50 | [regScroll setAutohidesScrollers:YES]; |
| r243713 | r243714 | |
| 57 | 56 | dasmView = [[MAMEDisassemblyView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine]; |
| 58 | 57 | [dasmView setExpression:@"curpc"]; |
| 59 | 58 | dasmScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 60 | | [dasmScroll setDrawsBackground:YES]; |
| 61 | 59 | [dasmScroll setHasHorizontalScroller:YES]; |
| 62 | 60 | [dasmScroll setHasVerticalScroller:YES]; |
| 63 | 61 | [dasmScroll setAutohidesScrollers:YES]; |
| r243713 | r243714 | |
| 68 | 66 | // create the console view |
| 69 | 67 | consoleView = [[MAMEConsoleView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine]; |
| 70 | 68 | consoleScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 71 | | [consoleScroll setDrawsBackground:YES]; |
| 72 | 69 | [consoleScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 73 | 70 | [consoleScroll setHasHorizontalScroller:YES]; |
| 74 | 71 | [consoleScroll setHasVerticalScroller:YES]; |
trunk/src/osd/modules/debugger/osx/debugview.m
| r243713 | r243714 | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
| 197 | - (void)adjustSizeAndRecomputeVisible { |
| 198 | NSSize const clip = [[[self enclosingScrollView] contentView] bounds].size; |
| 199 | NSSize const content = NSMakeSize((fontWidth * totalWidth) + (2 * [textContainer lineFragmentPadding]), |
| 200 | fontHeight * totalHeight); |
| 201 | [self setFrameSize:NSMakeSize(MAX(clip.width, content.width), MAX(clip.height, content.height))]; |
| 202 | [self recomputeVisible]; |
| 203 | } |
| 204 | |
| 205 | |
| 197 | 206 | + (NSFont *)defaultFont { |
| 198 | 207 | return [NSFont userFixedPitchFontOfSize:0]; |
| 199 | 208 | } |
| r243713 | r243714 | |
| 245 | 254 | BOOL const resized = (newSize.x != totalWidth) || (newSize.y != totalHeight); |
| 246 | 255 | if (resized) |
| 247 | 256 | { |
| 248 | | [self setFrameSize:NSMakeSize((fontWidth * newSize.x) + (2 * [textContainer lineFragmentPadding]), |
| 249 | | fontHeight * newSize.y)]; |
| 257 | NSScrollView *const scroller = [self enclosingScrollView]; |
| 258 | if (scroller) |
| 259 | { |
| 260 | NSSize const clip = [[scroller contentView] bounds].size; |
| 261 | NSSize const content = NSMakeSize((fontWidth * newSize.x) + (2 * [textContainer lineFragmentPadding]), |
| 262 | fontHeight * newSize.y); |
| 263 | [self setFrameSize:NSMakeSize(MAX(clip.width, content.width), MAX(clip.height, content.height))]; |
| 264 | [self recomputeVisible]; |
| 265 | } |
| 250 | 266 | totalWidth = newSize.x; |
| 251 | 267 | totalHeight = newSize.y; |
| 252 | 268 | } |
| r243713 | r243714 | |
| 407 | 423 | - (void)viewBoundsDidChange:(NSNotification *)notification { |
| 408 | 424 | NSView *const changed = [notification object]; |
| 409 | 425 | if (changed == [[self enclosingScrollView] contentView]) |
| 410 | | [self recomputeVisible]; |
| 426 | [self adjustSizeAndRecomputeVisible]; |
| 411 | 427 | } |
| 412 | 428 | |
| 413 | 429 | |
| 430 | - (void)viewFrameDidChange:(NSNotification *)notification { |
| 431 | NSView *const changed = [notification object]; |
| 432 | if (changed == [[self enclosingScrollView] contentView]) |
| 433 | [self adjustSizeAndRecomputeVisible]; |
| 434 | } |
| 435 | |
| 436 | |
| 414 | 437 | - (void)windowDidBecomeKey:(NSNotification *)notification { |
| 415 | 438 | NSWindow *const win = [notification object]; |
| 416 | 439 | if ((win == [self window]) && ([win firstResponder] == self) && view->cursor_supported()) |
| r243713 | r243714 | |
| 451 | 474 | debug_view_xy pos; |
| 452 | 475 | view->set_cursor_visible(true); |
| 453 | 476 | pos = view->cursor_position(); |
| 454 | | [self scrollRectToVisible:NSMakeRect((pos.x * fontWidth) + [textContainer lineFragmentPadding], pos.y * fontHeight, fontWidth, fontHeight)]; // FIXME: metrics |
| 477 | [self scrollRectToVisible:NSMakeRect((pos.x * fontWidth) + [textContainer lineFragmentPadding], |
| 478 | pos.y * fontHeight, |
| 479 | fontWidth, |
| 480 | fontHeight)]; // FIXME: metrics |
| 455 | 481 | [self setNeedsDisplay:YES]; |
| 456 | 482 | return [super becomeFirstResponder]; |
| 457 | 483 | } |
| r243713 | r243714 | |
| 475 | 501 | [[NSNotificationCenter defaultCenter] removeObserver:self |
| 476 | 502 | name:NSViewBoundsDidChangeNotification |
| 477 | 503 | object:nil]; |
| 504 | [[NSNotificationCenter defaultCenter] removeObserver:self |
| 505 | name:NSViewFrameDidChangeNotification |
| 506 | object:nil]; |
| 478 | 507 | |
| 479 | 508 | NSScrollView *const scroller = [self enclosingScrollView]; |
| 480 | 509 | if (scroller != nil) |
| 481 | 510 | { |
| 482 | 511 | [scroller setLineScroll:fontHeight]; |
| 483 | 512 | [[scroller contentView] setPostsBoundsChangedNotifications:YES]; |
| 513 | [[scroller contentView] setPostsFrameChangedNotifications:YES]; |
| 484 | 514 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 485 | 515 | selector:@selector(viewBoundsDidChange:) |
| 486 | 516 | name:NSViewBoundsDidChangeNotification |
| 487 | 517 | object:[scroller contentView]]; |
| 518 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 519 | selector:@selector(viewFrameDidChange:) |
| 520 | name:NSViewFrameDidChangeNotification |
| 521 | object:[scroller contentView]]; |
| 488 | 522 | } |
| 489 | 523 | } |
| 490 | 524 | |
| r243713 | r243714 | |
| 531 | 565 | debug_view_xy const size = view->visible_size(); |
| 532 | 566 | |
| 533 | 567 | // work out how much we need to draw |
| 534 | | INT32 position, clip; |
| 535 | | [self convertBounds:dirtyRect toFirstAffectedLine:&position count:&clip]; |
| 568 | INT32 row, clip; |
| 569 | [self convertBounds:dirtyRect toFirstAffectedLine:&row count:&clip]; |
| 570 | clip += row; |
| 571 | row = MAX(row, origin.y); |
| 572 | clip = MIN(clip, origin.y + size.y); |
| 536 | 573 | |
| 537 | 574 | // this gets the text for the whole visible area |
| 538 | 575 | debug_view_char const *data = view->viewdata(); |
| 539 | 576 | if (!data) |
| 540 | 577 | return; |
| 541 | 578 | |
| 542 | | data += ((position - origin.y) * size.x); |
| 543 | | for (UINT32 row = position; row < position + clip; row++, data += size.x) |
| 579 | // clear any space above the available content |
| 580 | data += ((row - origin.y) * size.x); |
| 581 | if (dirtyRect.origin.y < (row * fontHeight)) |
| 544 | 582 | { |
| 545 | | 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)]; |
| 552 | | continue; |
| 553 | | } |
| 583 | [DefaultBackground set]; |
| 584 | [NSBezierPath fillRect:NSMakeRect(0, |
| 585 | dirtyRect.origin.y, |
| 586 | [self bounds].size.width, |
| 587 | (row * fontHeight) - dirtyRect.origin.y)]; |
| 588 | } |
| 554 | 589 | |
| 555 | | // render entire lines to get character alignment right |
| 590 | // render entire lines to get character alignment right |
| 591 | for ( ; row < clip; row++, data += size.x) |
| 592 | { |
| 556 | 593 | int attr = -1; |
| 557 | 594 | NSUInteger start = 0, length = 0; |
| 558 | 595 | for (UINT32 col = origin.x; col < origin.x + size.x; col++) |
| r243713 | r243714 | |
| 599 | 636 | inTextContainer:textContainer]; |
| 600 | 637 | if (start == 0) |
| 601 | 638 | box.origin.x = 0; |
| 602 | | box.size.width = [self bounds].size.width - box.origin.x; |
| 639 | box.size.width = MAX([self bounds].size.width - box.origin.x, 0); |
| 603 | 640 | [[self backgroundForAttribute:attr] set]; |
| 604 | 641 | [NSBezierPath fillRect:NSMakeRect(box.origin.x, |
| 605 | 642 | row * fontHeight, |
| r243713 | r243714 | |
| 609 | 646 | atPoint:NSMakePoint(0, row * fontHeight)]; |
| 610 | 647 | [text deleteCharactersInRange:NSMakeRange(0, length)]; |
| 611 | 648 | } |
| 649 | |
| 650 | // clear any space below the available content |
| 651 | if ((dirtyRect.origin.y + dirtyRect.size.height) > (row * fontHeight)) |
| 652 | { |
| 653 | [DefaultBackground set]; |
| 654 | [NSBezierPath fillRect:NSMakeRect(0, |
| 655 | row * fontHeight, |
| 656 | [self bounds].size.width, |
| 657 | (dirtyRect.origin.y + dirtyRect.size.height) - (row * fontHeight))]; |
| 658 | } |
| 612 | 659 | } |
| 613 | 660 | |
| 614 | 661 | |