| yangsu@google.com | a8a42e2 | 2011-06-16 20:49:55 +0000 | [diff] [blame^] | 1 | #import "SkDebugger.h" |
| 2 | @implementation SkDebugger |
| 3 | -(void) installSkViews { |
| 4 | |
| 5 | float width = [self frame].size.width; |
| 6 | float height = [self frame].size.height; |
| 7 | float commandListW = 200; |
| 8 | float infoPanelH = 150.0; |
| 9 | fCommand = new SkCommandListView; |
| 10 | fCommand->setSize(commandListW, height); |
| 11 | fCommand->setVisibleP(true); |
| 12 | |
| 13 | fInfo = new SkInfoPanelView; |
| 14 | fInfo->setSize(width - commandListW, infoPanelH); |
| 15 | fInfo->setVisibleP(true); |
| 16 | |
| 17 | fContent = new SkContentView(fCommand->getSinkID(), |
| 18 | fInfo->getSinkID()); |
| 19 | fContent->setSize(width - commandListW, height - infoPanelH); |
| 20 | fContent->setVisibleP(true); |
| 21 | |
| 22 | [fInfoView addSkView:fInfo]; |
| 23 | [fCommandView addSkView:fCommand]; |
| 24 | [fContentView addSkView:fContent]; |
| 25 | |
| 26 | fInfo->unref(); |
| 27 | fCommand->unref(); |
| 28 | fContent->unref(); |
| 29 | } |
| 30 | |
| 31 | - (void)loadFile:(NSString *)filename { |
| 32 | fCommand->reinit(); |
| 33 | fContent->reinit([filename UTF8String]); |
| 34 | } |
| 35 | |
| 36 | - (void)keyDown:(NSEvent *)event { |
| 37 | // arrow keys have this mask |
| 38 | if ([event modifierFlags] & NSNumericPadKeyMask) { |
| 39 | NSString *theArrow = [event charactersIgnoringModifiers]; |
| 40 | if ( [theArrow length] == 0 ) |
| 41 | return; // reject dead keys |
| 42 | if ( [theArrow length] == 1 ) { |
| 43 | switch ([theArrow characterAtIndex:0]) { |
| 44 | case NSLeftArrowFunctionKey: |
| 45 | fContent->goToAtom(fCommand->prevItem()); |
| 46 | break; |
| 47 | case NSRightArrowFunctionKey: |
| 48 | fContent->goToAtom(fCommand->nextItem()); |
| 49 | break; |
| 50 | case NSUpArrowFunctionKey: |
| 51 | fContent->goToAtom(fCommand->scrollUp()); |
| 52 | break; |
| 53 | case NSDownArrowFunctionKey: |
| 54 | fContent->goToAtom(fCommand->scrollDown()); |
| 55 | break; |
| 56 | default: |
| 57 | [super keyDown:event]; |
| 58 | } |
| 59 | return; |
| 60 | } |
| 61 | } |
| 62 | else {//normal keys |
| 63 | switch ([[event characters] characterAtIndex:0]) { |
| 64 | case 'c': |
| 65 | fContent->toggleClip(); |
| 66 | break; |
| 67 | case 'e': |
| 68 | fCommand->toggleCentered(); |
| 69 | break; |
| 70 | default: |
| 71 | [super keyDown:event]; |
| 72 | } |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | [super keyDown:event]; |
| 77 | } |
| 78 | |
| 79 | - (void)mouseDown:(NSEvent *)event { |
| 80 | if ([event clickCount] > 1) { |
| 81 | [fContentView resetTransformations]; |
| 82 | [fContentView setNeedsDisplay:YES]; |
| 83 | } |
| 84 | else { |
| 85 | NSPoint p = [event locationInWindow]; |
| 86 | NSRect commandRect = [fCommandView convertRectToBase:[fCommandView bounds]]; |
| 87 | if ([fCommandView mouse:p inRect:commandRect]) { |
| 88 | NSPoint mouseLocInView = [fCommandView convertPoint:p fromView:nil]; |
| 89 | fContent->goToAtom(fCommand->selectHighlight(mouseLocInView.y)); |
| 90 | } |
| 91 | } |
| 92 | [super mouseDown:event]; |
| 93 | } |
| 94 | |
| 95 | - (void)mouseDragged:(NSEvent *)event { |
| 96 | NSPoint p = [event locationInWindow]; |
| 97 | NSRect contentRect = [fContentView convertRectToBase:[fContentView bounds]]; |
| 98 | NSRect commandRect = [fCommandView convertRectToBase:[fCommandView bounds]]; |
| 99 | if ([fContentView mouse:p inRect:contentRect]) { |
| 100 | fContentView.offset = NSMakePoint(fContentView.offset.x + [event deltaX], |
| 101 | fContentView.offset.y + [event deltaY]); |
| 102 | [fContentView setNeedsDisplay:YES]; |
| 103 | } |
| 104 | [super mouseDragged:event]; |
| 105 | } |
| 106 | |
| 107 | - (void)magnifyWithEvent:(NSEvent *)event { |
| 108 | if ([fContentView mouse:[event locationInWindow] |
| 109 | inRect:[fContentView convertRectToBase:[fContentView bounds]]]) { |
| 110 | fContentView.center = [fContentView convertPoint:[event locationInWindow] |
| 111 | fromView:nil]; |
| 112 | fContentView.scale = fContentView.scale * ([event magnification] + 1.0); |
| 113 | [fContentView setNeedsDisplay:YES]; |
| 114 | } |
| 115 | [super magnifyWithEvent:event]; |
| 116 | } |
| 117 | |
| 118 | - (void)rotateWithEvent:(NSEvent *)event { |
| 119 | if ([fContentView mouse:[event locationInWindow] |
| 120 | inRect:[fContentView convertRectToBase:[fContentView bounds]]]) { |
| 121 | fContentView.center = [fContentView convertPoint:[event locationInWindow] |
| 122 | fromView:nil]; |
| 123 | fContentView.rotation = fContentView.rotation - [event rotation]; |
| 124 | [fContentView setNeedsDisplay:YES]; |
| 125 | } |
| 126 | [super rotateWithEvent:event]; |
| 127 | } |
| 128 | |
| 129 | - (void)scrollWheel:(NSEvent *)event { |
| 130 | NSPoint p = [event locationInWindow]; |
| 131 | NSRect contentRect = [fContentView convertRectToBase:[fContentView bounds]]; |
| 132 | NSRect commandRect = [fCommandView convertRectToBase:[fCommandView bounds]]; |
| 133 | if ([fContentView mouse:p inRect:contentRect]) { |
| 134 | fContentView.center = [fContentView convertPoint:[event locationInWindow] |
| 135 | fromView:nil]; |
| 136 | if ([event deltaY] > 0) { |
| 137 | fContentView.scale = fContentView.scale * (1.05); |
| 138 | } |
| 139 | if ([event deltaY] < 0) { |
| 140 | fContentView.scale = fContentView.scale * (0.95); |
| 141 | } |
| 142 | [fContentView setNeedsDisplay:YES]; |
| 143 | } |
| 144 | if ([fCommandView mouse:p inRect:commandRect]) { |
| 145 | if ([event deltaY] > 0) { |
| 146 | fContent->goToAtom(fCommand->scrollUp()); |
| 147 | } |
| 148 | if ([event deltaY] < 0) { |
| 149 | fContent->goToAtom(fCommand->scrollDown()); |
| 150 | } |
| 151 | } |
| 152 | [super scrollWheel:event]; |
| 153 | } |
| 154 | @end |