OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkWidget.h" | 8 #include "SkWidget.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkKey.h" | 10 #include "SkKey.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 size_t len = strlen(gSkinNames[i]); | 65 size_t len = strlen(gSkinNames[i]); |
66 SkString path(sizeof(kSkinPath) - 1 + len); | 66 SkString path(sizeof(kSkinPath) - 1 + len); |
67 | 67 |
68 memcpy(path.writable_str(), kSkinPath, sizeof(kSkinPath) - 1); | 68 memcpy(path.writable_str(), kSkinPath, sizeof(kSkinPath) - 1); |
69 memcpy(path.writable_str() + sizeof(kSkinPath) - 1, gSkinNames[i], len); | 69 memcpy(path.writable_str() + sizeof(kSkinPath) - 1, gSkinNames[i], len); |
70 | 70 |
71 fAnimators[i] = new SkAnimator; | 71 fAnimators[i] = new SkAnimator; |
72 if (!fAnimators[i]->decodeURI(path.c_str())) | 72 if (!fAnimators[i]->decodeURI(path.c_str())) |
73 { | 73 { |
74 delete fAnimators[i]; | 74 delete fAnimators[i]; |
75 fAnimators[i] = NULL; | 75 fAnimators[i] = nullptr; |
76 } | 76 } |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 SkAnimator* SkinSuite::get(SkinType st) | 80 SkAnimator* SkinSuite::get(SkinType st) |
81 { | 81 { |
82 SkASSERT((unsigned)st < kSkinTypeCount); | 82 SkASSERT((unsigned)st < kSkinTypeCount); |
83 return fAnimators[st]; | 83 return fAnimators[st]; |
84 } | 84 } |
85 | 85 |
86 static SkinSuite* gSkinSuite; | 86 static SkinSuite* gSkinSuite; |
87 | 87 |
88 static SkAnimator* get_skin_animator(SkinType st) | 88 static SkAnimator* get_skin_animator(SkinType st) |
89 { | 89 { |
90 #if 0 | 90 #if 0 |
91 if (gSkinSuite == NULL) | 91 if (gSkinSuite == nullptr) |
92 gSkinSuite = new SkinSuite; | 92 gSkinSuite = new SkinSuite; |
93 return gSkinSuite->get(st); | 93 return gSkinSuite->get(st); |
94 #else | 94 #else |
95 return NULL; | 95 return nullptr; |
96 #endif | 96 #endif |
97 } | 97 } |
98 | 98 |
99 /////////////////////////////////////////////////////////////////////////////// | 99 /////////////////////////////////////////////////////////////////////////////// |
100 | 100 |
101 void SkWidget::Init() | 101 void SkWidget::Init() |
102 { | 102 { |
103 } | 103 } |
104 | 104 |
105 void SkWidget::Term() | 105 void SkWidget::Term() |
106 { | 106 { |
107 delete gSkinSuite; | 107 delete gSkinSuite; |
108 } | 108 } |
109 | 109 |
110 void SkWidget::onEnabledChange() | 110 void SkWidget::onEnabledChange() |
111 { | 111 { |
112 this->inval(NULL); | 112 this->inval(nullptr); |
113 } | 113 } |
114 | 114 |
115 void SkWidget::postWidgetEvent() | 115 void SkWidget::postWidgetEvent() |
116 { | 116 { |
117 if (!fEvent.isType("") && this->hasListeners()) | 117 if (!fEvent.isType("") && this->hasListeners()) |
118 { | 118 { |
119 this->prepareWidgetEvent(&fEvent); | 119 this->prepareWidgetEvent(&fEvent); |
120 this->postToListeners(fEvent); | 120 this->postToListeners(fEvent); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void SkWidget::prepareWidgetEvent(SkEvent*) | 124 void SkWidget::prepareWidgetEvent(SkEvent*) |
125 { | 125 { |
126 // override in subclass to add any additional fields before posting | 126 // override in subclass to add any additional fields before posting |
127 } | 127 } |
128 | 128 |
129 void SkWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node) | 129 void SkWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
130 { | 130 { |
131 this->INHERITED::onInflate(dom, node); | 131 this->INHERITED::onInflate(dom, node); |
132 | 132 |
133 if ((node = dom.getFirstChild(node, "event")) != NULL) | 133 if ((node = dom.getFirstChild(node, "event")) != nullptr) |
134 fEvent.inflate(dom, node); | 134 fEvent.inflate(dom, node); |
135 } | 135 } |
136 | 136 |
137 /////////////////////////////////////////////////////////////////////////////// | 137 /////////////////////////////////////////////////////////////////////////////// |
138 | 138 |
139 size_t SkHasLabelWidget::getLabel(SkString* str) const | 139 size_t SkHasLabelWidget::getLabel(SkString* str) const |
140 { | 140 { |
141 if (str) | 141 if (str) |
142 *str = fLabel; | 142 *str = fLabel; |
143 return fLabel.size(); | 143 return fLabel.size(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 { | 189 { |
190 if (fState != state) | 190 if (fState != state) |
191 { | 191 { |
192 fState = state; | 192 fState = state; |
193 this->onButtonStateChange(); | 193 this->onButtonStateChange(); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 void SkButtonWidget::onButtonStateChange() | 197 void SkButtonWidget::onButtonStateChange() |
198 { | 198 { |
199 this->inval(NULL); | 199 this->inval(nullptr); |
200 } | 200 } |
201 | 201 |
202 void SkButtonWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node) | 202 void SkButtonWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
203 { | 203 { |
204 this->INHERITED::onInflate(dom, node); | 204 this->INHERITED::onInflate(dom, node); |
205 | 205 |
206 int index; | 206 int index; |
207 if ((index = dom.findList(node, "buttonState", "off,on,unknown")) >= 0) | 207 if ((index = dom.findList(node, "buttonState", "off,on,unknown")) >= 0) |
208 this->setButtonState((State)index); | 208 this->setButtonState((State)index); |
209 } | 209 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 else | 286 else |
287 { | 287 { |
288 SkRect r; | 288 SkRect r; |
289 SkPaint p; | 289 SkPaint p; |
290 | 290 |
291 r.set(0, 0, this->width(), this->height()); | 291 r.set(0, 0, this->width(), this->height()); |
292 p.setAntiAliasOn(true); | 292 p.setAntiAliasOn(true); |
293 p.setColor(SK_ColorBLUE); | 293 p.setColor(SK_ColorBLUE); |
294 create_emboss(&p, SkIntToScalar(12)/5, this->hasFocus(), this->getButton
State() == kOn_State); | 294 create_emboss(&p, SkIntToScalar(12)/5, this->hasFocus(), this->getButton
State() == kOn_State); |
295 canvas->drawRoundRect(r, SkScalarHalf(this->height()), SkScalarHalf(this
->height()), p); | 295 canvas->drawRoundRect(r, SkScalarHalf(this->height()), SkScalarHalf(this
->height()), p); |
296 p.setMaskFilter(NULL); | 296 p.setMaskFilter(nullptr); |
297 | 297 |
298 p.setTextAlign(SkPaint::kCenter_Align); | 298 p.setTextAlign(SkPaint::kCenter_Align); |
299 | 299 |
300 SkTextBox box; | 300 SkTextBox box; |
301 box.setMode(SkTextBox::kOneLine_Mode); | 301 box.setMode(SkTextBox::kOneLine_Mode); |
302 box.setSpacingAlign(SkTextBox::kCenter_SpacingAlign); | 302 box.setSpacingAlign(SkTextBox::kCenter_SpacingAlign); |
303 box.setBox(0, 0, this->width(), this->height()); | 303 box.setBox(0, 0, this->width(), this->height()); |
304 | 304 |
305 // if (this->getButtonState() == kOn_State) | 305 // if (this->getButtonState() == kOn_State) |
306 // p.setColor(SK_ColorRED); | 306 // p.setColor(SK_ColorRED); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 344 } |
345 | 345 |
346 SkStaticTextView::~SkStaticTextView() | 346 SkStaticTextView::~SkStaticTextView() |
347 { | 347 { |
348 } | 348 } |
349 | 349 |
350 void SkStaticTextView::computeSize() | 350 void SkStaticTextView::computeSize() |
351 { | 351 { |
352 if (fMode == kAutoWidth_Mode) | 352 if (fMode == kAutoWidth_Mode) |
353 { | 353 { |
354 SkScalar width = fPaint.measureText(fText.c_str(), fText.size(), NULL, N
ULL); | 354 SkScalar width = fPaint.measureText(fText.c_str(), fText.size(), nullptr
, nullptr); |
355 this->setWidth(width + fMargin.fX * 2); | 355 this->setWidth(width + fMargin.fX * 2); |
356 } | 356 } |
357 else if (fMode == kAutoHeight_Mode) | 357 else if (fMode == kAutoHeight_Mode) |
358 { | 358 { |
359 SkScalar width = this->width() - fMargin.fX * 2; | 359 SkScalar width = this->width() - fMargin.fX * 2; |
360 int lines = width > 0 ? SkTextLineBreaker::CountLines(fText.c_str(), fTe
xt.size(), fPaint, width) : 0; | 360 int lines = width > 0 ? SkTextLineBreaker::CountLines(fText.c_str(), fTe
xt.size(), fPaint, width) : 0; |
361 | 361 |
362 SkScalar before, after; | 362 SkScalar before, after; |
363 (void)fPaint.measureText(0, NULL, &before, &after); | 363 (void)fPaint.measureText(0, nullptr, &before, &after); |
364 | 364 |
365 this->setHeight(lines * (after - before) + fMargin.fY * 2); | 365 this->setHeight(lines * (after - before) + fMargin.fY * 2); |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 void SkStaticTextView::setMode(Mode mode) | 369 void SkStaticTextView::setMode(Mode mode) |
370 { | 370 { |
371 SkASSERT((unsigned)mode < kModeCount); | 371 SkASSERT((unsigned)mode < kModeCount); |
372 | 372 |
373 if (fMode != mode) | 373 if (fMode != mode) |
374 { | 374 { |
375 fMode = SkToU8(mode); | 375 fMode = SkToU8(mode); |
376 this->computeSize(); | 376 this->computeSize(); |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 void SkStaticTextView::setSpacingAlign(SkTextBox::SpacingAlign align) | 380 void SkStaticTextView::setSpacingAlign(SkTextBox::SpacingAlign align) |
381 { | 381 { |
382 fSpacingAlign = SkToU8(align); | 382 fSpacingAlign = SkToU8(align); |
383 this->inval(NULL); | 383 this->inval(nullptr); |
384 } | 384 } |
385 | 385 |
386 void SkStaticTextView::getMargin(SkPoint* margin) const | 386 void SkStaticTextView::getMargin(SkPoint* margin) const |
387 { | 387 { |
388 if (margin) | 388 if (margin) |
389 *margin = fMargin; | 389 *margin = fMargin; |
390 } | 390 } |
391 | 391 |
392 void SkStaticTextView::setMargin(SkScalar dx, SkScalar dy) | 392 void SkStaticTextView::setMargin(SkScalar dx, SkScalar dy) |
393 { | 393 { |
394 if (fMargin.fX != dx || fMargin.fY != dy) | 394 if (fMargin.fX != dx || fMargin.fY != dy) |
395 { | 395 { |
396 fMargin.set(dx, dy); | 396 fMargin.set(dx, dy); |
397 this->computeSize(); | 397 this->computeSize(); |
398 this->inval(NULL); | 398 this->inval(nullptr); |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 size_t SkStaticTextView::getText(SkString* text) const | 402 size_t SkStaticTextView::getText(SkString* text) const |
403 { | 403 { |
404 if (text) | 404 if (text) |
405 *text = fText; | 405 *text = fText; |
406 return fText.size(); | 406 return fText.size(); |
407 } | 407 } |
408 | 408 |
(...skipping 13 matching lines...) Expand all Loading... |
422 { | 422 { |
423 this->setText(text, strlen(text)); | 423 this->setText(text, strlen(text)); |
424 } | 424 } |
425 | 425 |
426 void SkStaticTextView::setText(const char text[], size_t len) | 426 void SkStaticTextView::setText(const char text[], size_t len) |
427 { | 427 { |
428 if (!fText.equals(text, len)) | 428 if (!fText.equals(text, len)) |
429 { | 429 { |
430 fText.set(text, len); | 430 fText.set(text, len); |
431 this->computeSize(); | 431 this->computeSize(); |
432 this->inval(NULL); | 432 this->inval(nullptr); |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 void SkStaticTextView::getPaint(SkPaint* paint) const | 436 void SkStaticTextView::getPaint(SkPaint* paint) const |
437 { | 437 { |
438 if (paint) | 438 if (paint) |
439 *paint = fPaint; | 439 *paint = fPaint; |
440 } | 440 } |
441 | 441 |
442 void SkStaticTextView::setPaint(const SkPaint& paint) | 442 void SkStaticTextView::setPaint(const SkPaint& paint) |
443 { | 443 { |
444 if (fPaint != paint) | 444 if (fPaint != paint) |
445 { | 445 { |
446 fPaint = paint; | 446 fPaint = paint; |
447 this->computeSize(); | 447 this->computeSize(); |
448 this->inval(NULL); | 448 this->inval(nullptr); |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 void SkStaticTextView::onDraw(SkCanvas* canvas) | 452 void SkStaticTextView::onDraw(SkCanvas* canvas) |
453 { | 453 { |
454 this->INHERITED::onDraw(canvas); | 454 this->INHERITED::onDraw(canvas); |
455 | 455 |
456 if (fText.isEmpty()) | 456 if (fText.isEmpty()) |
457 return; | 457 return; |
458 | 458 |
(...skipping 23 matching lines...) Expand all Loading... |
482 SkScalar s[2]; | 482 SkScalar s[2]; |
483 if (dom.findScalars(node, "margin", s, 2)) | 483 if (dom.findScalars(node, "margin", s, 2)) |
484 this->setMargin(s[0], s[1]); | 484 this->setMargin(s[0], s[1]); |
485 else | 485 else |
486 assert_no_attr(dom, node, "margin"); | 486 assert_no_attr(dom, node, "margin"); |
487 | 487 |
488 const char* text = dom.findAttr(node, "text"); | 488 const char* text = dom.findAttr(node, "text"); |
489 if (text) | 489 if (text) |
490 this->setText(text); | 490 this->setText(text); |
491 | 491 |
492 if ((node = dom.getFirstChild(node, "paint")) != NULL) | 492 if ((node = dom.getFirstChild(node, "paint")) != nullptr) |
493 SkPaint_Inflate(&fPaint, dom, node); | 493 SkPaint_Inflate(&fPaint, dom, node); |
494 } | 494 } |
495 | 495 |
496 ////////////////////////////////////////////////////////////////////////////////
///////////////////// | 496 ////////////////////////////////////////////////////////////////////////////////
///////////////////// |
497 | 497 |
498 #include "SkImageDecoder.h" | 498 #include "SkImageDecoder.h" |
499 | 499 |
500 SkBitmapView::SkBitmapView(U32 flags) : SkView(flags) | 500 SkBitmapView::SkBitmapView(U32 flags) : SkView(flags) |
501 { | 501 { |
502 } | 502 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 void SkBitmapView::onInflate(const SkDOM& dom, const SkDOM::Node* node) | 553 void SkBitmapView::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
554 { | 554 { |
555 this->INHERITED::onInflate(dom, node); | 555 this->INHERITED::onInflate(dom, node); |
556 | 556 |
557 const char* src = dom.findAttr(node, "src"); | 557 const char* src = dom.findAttr(node, "src"); |
558 if (src) | 558 if (src) |
559 (void)this->loadBitmapFromFile(src); | 559 (void)this->loadBitmapFromFile(src); |
560 } | 560 } |
561 | 561 |
562 #endif | 562 #endif |
OLD | NEW |