yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 1 | #import <UIKit/UIKit.h> |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 2 | #include "SkCanvas.h" |
yangsu@google.com | 2e20c24 | 2011-07-07 19:26:42 +0000 | [diff] [blame] | 3 | #include "SkGraphics.h" |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 4 | #import "SkEventNotifier.h" |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 5 | #include "SkOSMenu.h" |
| 6 | #include "SkTime.h" |
yangsu@google.com | 2e20c24 | 2011-07-07 19:26:42 +0000 | [diff] [blame] | 7 | #include "SkTypes.h" |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 8 | #import "SkUIView.h" |
yangsu@google.com | 2e20c24 | 2011-07-07 19:26:42 +0000 | [diff] [blame] | 9 | #include "SkWindow.h" |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 10 | |
| 11 | #define kINVAL_UIVIEW_EventType "inval-uiview" |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 12 | |
| 13 | SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { |
| 14 | fInvalEventIsPending = false; |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 15 | fNotifier = [[SkEventNotifier alloc] init]; |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 16 | } |
| 17 | SkOSWindow::~SkOSWindow() { |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 18 | [(SkEventNotifier*)fNotifier release]; |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | void SkOSWindow::onHandleInval(const SkIRect& r) { |
| 22 | if (!fInvalEventIsPending) { |
| 23 | fInvalEventIsPending = true; |
| 24 | (new SkEvent(kINVAL_UIVIEW_EventType))->post(this->getSinkID()); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | bool SkOSWindow::onEvent(const SkEvent& evt) { |
| 29 | if (evt.isType(kINVAL_UIVIEW_EventType)) { |
| 30 | fInvalEventIsPending = false; |
| 31 | const SkIRect& r = this->getDirtyBounds(); |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 32 | [(SkUIView*)fHWND postInvalWithRect:&r]; |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 33 | return true; |
| 34 | } |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 35 | if ([(SkUIView*)fHWND onHandleEvent:evt]) { |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 36 | return true; |
| 37 | } |
yangsu@google.com | 2e20c24 | 2011-07-07 19:26:42 +0000 | [diff] [blame] | 38 | return this->INHERITED::onEvent(evt); |
| 39 | } |
| 40 | |
| 41 | bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner) { |
| 42 | return this->INHERITED::onDispatchClick(x, y, state, owner); |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void SkOSWindow::onSetTitle(const char title[]) { |
yangsu@google.com | c5aeccd | 2011-07-17 14:42:08 +0000 | [diff] [blame] | 46 | [(SkUIView*)fHWND setSkTitle:title]; |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 47 | } |
| 48 | |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 49 | void SkOSWindow::onAddMenu(const SkOSMenu* menu) { |
| 50 | [(SkUIView*)fHWND onAddMenu:menu]; |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 51 | } |
| 52 | |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 53 | void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) { |
| 54 | [(SkUIView*)fHWND onUpdateMenu:menu]; |
| 55 | } |
yangsu@google.com | 2e20c24 | 2011-07-07 19:26:42 +0000 | [diff] [blame] | 56 | |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 57 | bool SkOSWindow::attachGL() { |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 58 | bool success = true; |
| 59 | return success; |
| 60 | } |
| 61 | |
yangsu@google.com | e938b19 | 2011-08-02 13:23:15 +0000 | [diff] [blame^] | 62 | void SkOSWindow::detachGL() {} |
yangsu@google.com | 1a2b4c1 | 2011-06-24 17:20:50 +0000 | [diff] [blame] | 63 | |
| 64 | void SkOSWindow::presentGL() { |
| 65 | glFlush(); |
| 66 | } |