| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "SkCanvas.h" | 7 #include "SkCanvas.h" |
| 8 #include "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
| 9 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 protected: | 62 protected: |
| 63 virtual void onDraw(SkCanvas* canvas) { | 63 virtual void onDraw(SkCanvas* canvas) { |
| 64 canvas->drawColor(0xFFFFFFFF); | 64 canvas->drawColor(0xFFFFFFFF); |
| 65 SkPaint p; | 65 SkPaint p; |
| 66 p.setTextSize(20); | 66 p.setTextSize(20); |
| 67 p.setAntiAlias(true); | 67 p.setAntiAlias(true); |
| 68 canvas->drawText("Hello World!", 13, 50, 30, p); | 68 canvas->drawText("Hello World!", 13, 50, 30, p); |
| 69 // SkRect r = {50, 50, 80, 80}; | 69 // SkRect r = {50, 50, 80, 80}; |
| 70 p.setColor(0xAA11EEAA); | 70 p.setColor(0xAA11EEAA); |
| 71 // canvas->drawRect(r, p); | 71 // canvas->drawRect(r, p); |
| 72 | 72 |
| 73 SkRect result; | 73 SkRect result; |
| 74 SkPath path; | 74 SkPath path; |
| 75 path.moveTo(0, 0); | 75 path.moveTo(0, 0); |
| 76 path.lineTo(1, 1); | 76 path.lineTo(1, 1); |
| 77 path.lineTo(1, 8); | 77 path.lineTo(1, 8); |
| 78 path.lineTo(0, 9); | 78 path.lineTo(0, 9); |
| 79 SkASSERT(path.hasRectangularInterior(&result)); | 79 SkASSERT(path.hasRectangularInterior(&result)); |
| 80 | 80 |
| 81 path.reset(); | 81 path.reset(); |
| 82 path.addRect(10, 10, 100, 100, SkPath::kCW_Direction); | 82 path.addRect(10, 10, 100, 100, SkPath::kCW_Direction); |
| 83 path.addRect(20, 20, 50, 50, SkPath::kCW_Direction); | 83 path.addRect(20, 20, 50, 50, SkPath::kCW_Direction); |
| 84 path.addRect(50, 50, 90, 90, SkPath::kCCW_Direction); | 84 path.addRect(50, 50, 90, 90, SkPath::kCCW_Direction); |
| 85 p.setColor(0xAA335577); | 85 p.setColor(0xAA335577); |
| 86 canvas->drawPath(path, p); | 86 canvas->drawPath(path, p); |
| 87 SkASSERT(!path.hasRectangularInterior(NULL)); | 87 SkASSERT(!path.hasRectangularInterior(NULL)); |
| 88 path.reset(); | 88 path.reset(); |
| 89 path.addRect(10, 10, 100, 100, SkPath::kCW_Direction); | 89 path.addRect(10, 10, 100, 100, SkPath::kCW_Direction); |
| 90 path.addRect(20, 20, 80, 80, SkPath::kCW_Direction); | 90 path.addRect(20, 20, 80, 80, SkPath::kCW_Direction); |
| 91 SkRect expected = {20, 20, 80, 80}; | 91 SkRect expected = {20, 20, 80, 80}; |
| 92 SkASSERT(path.hasRectangularInterior(&result)); | 92 SkASSERT(path.hasRectangularInterior(&result)); |
| 93 SkASSERT(result == expected); | 93 SkASSERT(result == expected); |
| 94 | 94 |
| 95 } | 95 } |
| 96 private: | 96 private: |
| 97 typedef SkView INHERITED; | 97 typedef SkView INHERITED; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 void application_init(); | 100 void application_init(); |
| 101 void application_term(); | 101 void application_term(); |
| 102 | 102 |
| 103 static int showPathContour(SkPath::Iter& iter) { | 103 static int showPathContour(SkPath::Iter& iter) { |
| 104 uint8_t verb; | 104 uint8_t verb; |
| 105 SkPoint pts[4]; | 105 SkPoint pts[4]; |
| 106 int moves = 0; | 106 int moves = 0; |
| 107 bool waitForClose = false; | 107 bool waitForClose = false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 pointsMin = points; | 187 pointsMin = points; |
| 188 } | 188 } |
| 189 if (pointsMax < points) { | 189 if (pointsMax < points) { |
| 190 pointsMax = points; | 190 pointsMax = points; |
| 191 } | 191 } |
| 192 SkDebugf("no interior bounds\n"); | 192 SkDebugf("no interior bounds\n"); |
| 193 } | 193 } |
| 194 path.hasRectangularInterior(©); | 194 path.hasRectangularInterior(©); |
| 195 SkDebugf("</div>\n\n"); | 195 SkDebugf("</div>\n\n"); |
| 196 } | 196 } |
| 197 | 197 |
| 198 virtual void drawPosTextH(const void* text, size_t byteLength, | 198 virtual void drawPosTextH(const void* text, size_t byteLength, |
| 199 const SkScalar xpos[], SkScalar constY, | 199 const SkScalar xpos[], SkScalar constY, |
| 200 const SkPaint& paint) { | 200 const SkPaint& paint) { |
| 201 } | 201 } |
| 202 | 202 |
| 203 public: | 203 public: |
| 204 void divName(const SkString& str, bool only) { | 204 void divName(const SkString& str, bool only) { |
| 205 filename = str; | 205 filename = str; |
| 206 char* chars = filename.writable_str(); | 206 char* chars = filename.writable_str(); |
| 207 while (*chars) { | 207 while (*chars) { |
| 208 if (*chars == '.' || *chars == '-') *chars = '_'; | 208 if (*chars == '.' || *chars == '-') *chars = '_'; |
| 209 chars++; | 209 chars++; |
| 210 } | 210 } |
| 211 count = 0; | 211 count = 0; |
| 212 nameonly = only; | 212 nameonly = only; |
| 213 } | 213 } |
| 214 | 214 |
| 215 void init() { | 215 void init() { |
| 216 pointsMin = verbsMin = SK_MaxS32; | 216 pointsMin = verbsMin = SK_MaxS32; |
| 217 pointsMax = verbsMax = SK_MinS32; | 217 pointsMax = verbsMax = SK_MinS32; |
| 218 rectPointsMin = rectVerbsMin = SK_MaxS32; | 218 rectPointsMin = rectVerbsMin = SK_MaxS32; |
| 219 rectPointsMax = rectVerbsMax = SK_MinS32; | 219 rectPointsMax = rectVerbsMax = SK_MinS32; |
| 220 } | 220 } |
| 221 | 221 |
| 222 SkString filename; | 222 SkString filename; |
| 223 int count; | 223 int count; |
| 224 bool nameonly; | 224 bool nameonly; |
| 225 int pointsMin; | 225 int pointsMin; |
| 226 int pointsMax; | 226 int pointsMax; |
| 227 int verbsMin; | 227 int verbsMin; |
| 228 int verbsMax; | 228 int verbsMax; |
| 229 int rectPointsMin; | 229 int rectPointsMin; |
| 230 int rectPointsMax; | 230 int rectPointsMax; |
| 231 int rectVerbsMin; | 231 int rectVerbsMin; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 SkDebugf("points min=%d max=%d verbs min=%d max=%d\n", canvas.pointsMin, can
vas.pointsMax, | 273 SkDebugf("points min=%d max=%d verbs min=%d max=%d\n", canvas.pointsMin, can
vas.pointsMax, |
| 274 canvas.verbsMin, canvas.verbsMax); | 274 canvas.verbsMin, canvas.verbsMax); |
| 275 SkDebugf("rect points min=%d max=%d verbs min=%d max=%d\n", canvas.rectPoint
sMin, canvas.rectPointsMax, | 275 SkDebugf("rect points min=%d max=%d verbs min=%d max=%d\n", canvas.rectPoint
sMin, canvas.rectPointsMax, |
| 276 canvas.rectVerbsMin, canvas.rectVerbsMax); | 276 canvas.rectVerbsMin, canvas.rectVerbsMax); |
| 277 | 277 |
| 278 SkDebugf("\n"); | 278 SkDebugf("\n"); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void application_term() { | 281 void application_term() { |
| 282 SkGraphics::Term(); | |
| 283 SkEvent::Term(); | 282 SkEvent::Term(); |
| 284 } | 283 } |
| 285 | 284 |
| 286 class FillLayout : public SkView::Layout { | 285 class FillLayout : public SkView::Layout { |
| 287 protected: | 286 protected: |
| 288 virtual void onLayoutChildren(SkView* parent) { | 287 virtual void onLayoutChildren(SkView* parent) { |
| 289 SkView* view = SkView::F2BIter(parent).next(); | 288 SkView* view = SkView::F2BIter(parent).next(); |
| 290 view->setSize(parent->width(), parent->height()); | 289 view->setSize(parent->width(), parent->height()); |
| 291 } | 290 } |
| 292 }; | 291 }; |
| 293 | 292 |
| 294 #import "SimpleApp.h" | 293 #import "SimpleApp.h" |
| 295 @implementation SimpleNSView | 294 @implementation SimpleNSView |
| 296 | 295 |
| 297 - (id)initWithDefaults { | 296 - (id)initWithDefaults { |
| 298 if ((self = [super initWithDefaults])) { | 297 if ((self = [super initWithDefaults])) { |
| 299 fWind = new SkOSWindow(self); | 298 fWind = new SkOSWindow(self); |
| 300 fWind->setLayout(new FillLayout, false); | 299 fWind->setLayout(new FillLayout, false); |
| 301 fWind->attachChildToFront(new SkSampleView)->unref(); | 300 fWind->attachChildToFront(new SkSampleView)->unref(); |
| 302 } | 301 } |
| 303 return self; | 302 return self; |
| 304 } | 303 } |
| 305 | 304 |
| 306 - (void)drawRect:(NSRect)dirtyRect { | 305 - (void)drawRect:(NSRect)dirtyRect { |
| 307 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphic
sPort]; | 306 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphic
sPort]; |
| 308 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0); | 307 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0); |
| 309 } | 308 } |
| 310 | 309 |
| 311 @end | 310 @end |
| OLD | NEW |