reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
| 4 | #include "SkGradientShader.h" |
| 5 | #include "SkGraphics.h" |
| 6 | #include "SkImageDecoder.h" |
| 7 | #include "SkPath.h" |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 8 | #include "SkRegion.h" |
| 9 | #include "SkShader.h" |
| 10 | #include "SkUtils.h" |
| 11 | #include "SkXfermode.h" |
| 12 | #include "SkColorPriv.h" |
| 13 | #include "SkColorFilter.h" |
| 14 | #include "SkTime.h" |
| 15 | #include "SkTypeface.h" |
| 16 | |
reed@android.com | 54043a3 | 2009-03-05 14:14:49 +0000 | [diff] [blame] | 17 | #if 0 |
| 18 | static void CFString2SkString(CFStringRef ref, SkString* str) { |
| 19 | str->reset(); |
| 20 | int count = CFStringGetLength(ref); |
| 21 | for (int i = 0; i < count; i++) { |
| 22 | SkString tmp; |
| 23 | UniChar c = CFStringGetCharacterAtIndex(ref, i); |
| 24 | tmp.setUTF16(&c, 1); |
| 25 | str->append(tmp); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | static size_t get_table_size(ATSFontRef font, uint32_t tableTag) { |
| 30 | ByteCount size; |
| 31 | OSStatus status = ATSFontGetTable(font, tableTag, 0, 0, NULL, &size); |
| 32 | if (status) { |
| 33 | SkDebugf("*** ATSFontGetTable returned %d\n", status); |
| 34 | size = -1; |
| 35 | } |
| 36 | return size; |
| 37 | } |
| 38 | |
| 39 | static void test_ats() { |
| 40 | OSStatus status; |
| 41 | ATSFontIterator iter; |
| 42 | status = ATSFontIteratorCreate(kATSFontContextLocal, NULL, NULL, |
| 43 | kATSOptionFlagsUnRestrictedScope, &iter); |
| 44 | |
| 45 | for (int index = 0;; index++) { |
| 46 | ATSFontRef fontRef; |
| 47 | status = ATSFontIteratorNext(iter, &fontRef); |
| 48 | if (status) { |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | CFStringRef name; |
| 53 | SkString str; |
| 54 | ATSFontGetName(fontRef, kATSOptionFlagsDefault, &name); |
| 55 | CFString2SkString(name, &str); |
| 56 | if (str.size() > 0 && str.c_str()[0] != '.') { |
| 57 | SkDebugf("[%3d] font %x cmap %d 'name' %d <%s>\n", index, fontRef, |
| 58 | get_table_size(fontRef, 'cmap'), |
| 59 | get_table_size(fontRef, 'name'), |
| 60 | str.c_str()); |
| 61 | } |
| 62 | CFRelease(name); |
| 63 | } |
| 64 | ATSFontIteratorRelease(&iter); |
| 65 | } |
| 66 | #endif |
| 67 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 68 | class PathClipView : public SkView { |
| 69 | public: |
| 70 | SkRect fOval; |
| 71 | SkPoint fCenter; |
| 72 | |
| 73 | PathClipView() { |
| 74 | fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50)); |
| 75 | fCenter.set(SkIntToScalar(250), SkIntToScalar(250)); |
reed@android.com | 54043a3 | 2009-03-05 14:14:49 +0000 | [diff] [blame] | 76 | |
| 77 | // test_ats(); |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | virtual ~PathClipView() {} |
| 81 | |
| 82 | protected: |
| 83 | // overrides from SkEventSink |
| 84 | virtual bool onQuery(SkEvent* evt) { |
| 85 | if (SampleCode::TitleQ(*evt)) { |
| 86 | SampleCode::TitleR(evt, "PathClip"); |
| 87 | return true; |
| 88 | } |
| 89 | return this->INHERITED::onQuery(evt); |
| 90 | } |
| 91 | |
| 92 | void drawBG(SkCanvas* canvas) { |
| 93 | canvas->drawColor(SK_ColorWHITE); |
| 94 | } |
| 95 | |
| 96 | virtual void onDraw(SkCanvas* canvas) { |
| 97 | this->drawBG(canvas); |
| 98 | |
| 99 | SkRect oval = fOval; |
| 100 | oval.offset(fCenter.fX - oval.centerX(), fCenter.fY - oval.centerY()); |
| 101 | |
| 102 | SkPaint p; |
| 103 | p.setAntiAlias(true); |
| 104 | |
| 105 | p.setStyle(SkPaint::kStroke_Style); |
| 106 | canvas->drawOval(oval, p); |
| 107 | |
| 108 | SkRect r; |
| 109 | r.set(SkIntToScalar(200), SkIntToScalar(200), |
| 110 | SkIntToScalar(300), SkIntToScalar(300)); |
| 111 | canvas->clipRect(r); |
| 112 | |
| 113 | p.setStyle(SkPaint::kFill_Style); |
| 114 | p.setColor(SK_ColorRED); |
| 115 | canvas->drawRect(r, p); |
| 116 | |
| 117 | p.setColor(0x800000FF); |
| 118 | r.set(SkIntToScalar(150), SkIntToScalar(10), |
| 119 | SkIntToScalar(250), SkIntToScalar(400)); |
| 120 | canvas->drawOval(oval, p); |
| 121 | } |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame^] | 122 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 123 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame^] | 124 | return new Click(this); |
| 125 | } |
| 126 | |
| 127 | virtual bool onClick(Click* click) { |
| 128 | fCenter.set(click->fCurr.fX, click->fCurr.fY); |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 129 | this->inval(NULL); |
| 130 | return NULL; |
| 131 | } |
| 132 | |
| 133 | private: |
| 134 | typedef SkView INHERITED; |
| 135 | }; |
| 136 | |
| 137 | ////////////////////////////////////////////////////////////////////////////// |
| 138 | |
| 139 | static SkView* MyFactory() { return new PathClipView; } |
| 140 | static SkViewRegister reg(MyFactory); |
| 141 | |