yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 1 | #import "SkUIView.h" |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 2 | #include "SkCanvas.h" |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 3 | #include "SkCGUtils.h" |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 4 | @implementation SkUIView |
| 5 | |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 6 | @synthesize fWind, fTitleItem, fOptionsDelegate; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 7 | |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 8 | - (id)initWithDefaults { |
| 9 | fWind = NULL; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 10 | return self; |
| 11 | } |
| 12 | |
| 13 | - (id)initWithCoder:(NSCoder*)coder { |
| 14 | if ((self = [super initWithCoder:coder])) { |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 15 | self = [self initWithDefaults]; |
| 16 | [self setUpWindow]; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 17 | } |
| 18 | return self; |
| 19 | } |
| 20 | |
| 21 | - (id)initWithFrame:(CGRect)frame { |
| 22 | if (self = [super initWithFrame:frame]) { |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 23 | self = [self initWithDefaults]; |
| 24 | [self setUpWindow]; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 25 | } |
| 26 | return self; |
| 27 | } |
| 28 | |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 29 | - (void)setUpWindow { |
| 30 | if (NULL != fWind) { |
| 31 | fWind->setVisibleP(true); |
commit-bot@chromium.org | b45c56e | 2014-02-18 23:32:05 +0000 | [diff] [blame^] | 32 | fWind->resize(self.frame.size.width, self.frame.size.height, |
| 33 | kPMColor_SkColorType); |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 37 | - (void)dealloc { |
| 38 | delete fWind; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 39 | [fTitleItem release]; |
| 40 | [super dealloc]; |
| 41 | } |
yangsu@google.com | 2ba30c0 | 2011-07-19 15:17:44 +0000 | [diff] [blame] | 42 | |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 43 | - (void)forceRedraw { |
| 44 | [self drawInRaster]; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 45 | } |
| 46 | |
yangsu@google.com | 2ba30c0 | 2011-07-19 15:17:44 +0000 | [diff] [blame] | 47 | - (void)drawInRaster { |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 48 | SkCanvas canvas(fWind->getBitmap()); |
| 49 | fWind->draw(&canvas); |
yangsu@google.com | 2ba30c0 | 2011-07-19 15:17:44 +0000 | [diff] [blame] | 50 | CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 51 | self.layer.contents = (id)cgimage; |
yangsu@google.com | 2ba30c0 | 2011-07-19 15:17:44 +0000 | [diff] [blame] | 52 | CGImageRelease(cgimage); |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 53 | } |
yangsu@google.com | 2ba30c0 | 2011-07-19 15:17:44 +0000 | [diff] [blame] | 54 | |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 55 | //Gesture Handlers |
| 56 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
| 57 | for (UITouch *touch in touches) { |
| 58 | CGPoint loc = [touch locationInView:self]; |
| 59 | fWind->handleClick(loc.x, loc.y, SkView::Click::kDown_State, touch); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
| 64 | for (UITouch *touch in touches) { |
| 65 | CGPoint loc = [touch locationInView:self]; |
| 66 | fWind->handleClick(loc.x, loc.y, SkView::Click::kMoved_State, touch); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
| 71 | for (UITouch *touch in touches) { |
| 72 | CGPoint loc = [touch locationInView:self]; |
| 73 | fWind->handleClick(loc.x, loc.y, SkView::Click::kUp_State, touch); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
| 78 | for (UITouch *touch in touches) { |
| 79 | CGPoint loc = [touch locationInView:self]; |
| 80 | fWind->handleClick(loc.x, loc.y, SkView::Click::kUp_State, touch); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /////////////////////////////////////////////////////////////////////////////// |
| 85 | |
| 86 | - (void)setSkTitle:(const char *)title { |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 87 | if (fTitleItem) { |
| 88 | fTitleItem.title = [NSString stringWithUTF8String:title]; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | - (BOOL)onHandleEvent:(const SkEvent&)evt { |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 93 | return false; |
| 94 | } |
| 95 | |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 96 | - (void)getAttachmentInfo:(SkOSWindow::AttachmentInfo*)info { |
| 97 | // we don't have a GL context. |
| 98 | info->fSampleCount = 0; |
| 99 | info->fStencilBits = 0; |
| 100 | } |
| 101 | |
yangsu@google.com | 5987045 | 2011-08-02 13:20:22 +0000 | [diff] [blame] | 102 | #include "SkOSMenu.h" |
| 103 | - (void)onAddMenu:(const SkOSMenu*)menu { |
| 104 | [self.fOptionsDelegate view:self didAddMenu:menu]; |
| 105 | } |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 106 | - (void)onUpdateMenu:(SkOSMenu*)menu { |
yangsu@google.com | 5987045 | 2011-08-02 13:20:22 +0000 | [diff] [blame] | 107 | [self.fOptionsDelegate view:self didUpdateMenu:menu]; |
| 108 | } |
| 109 | |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 110 | - (void)postInvalWithRect:(const SkIRect*)r { |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 111 | [self performSelector:@selector(drawInRaster) withObject:nil afterDelay:0]; |
| 112 | [self setNeedsDisplay]; |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | @end |