update to SampleView

git-svn-id: http://skia.googlecode.com/svn/trunk@1460 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-06-01 12:42:36 +00:00
parent e5ff439066
commit 81e3d7f794
12 changed files with 46 additions and 236 deletions

View File

@ -1477,8 +1477,6 @@ void SimplePC::notifyWritten(size_t bytes) {
void SampleView::onDraw(SkCanvas* canvas) {
this->onDrawBackground(canvas);
#ifdef TEST_GPIPE
SimplePC controller(canvas);
SkGPipeWriter writer;
@ -1489,6 +1487,8 @@ void SampleView::onDraw(SkCanvas* canvas) {
}
#endif
this->onDrawBackground(canvas);
for (int i = 0; i < fRepeatCount; i++) {
SkAutoCanvasRestore acr(canvas, true);
this->onDrawContent(canvas);

View File

@ -34,8 +34,7 @@ static const Setting gSettings[] = {
{ ONE, true, true }
};
static void doMeasure(SkCanvas* canvas, const SkPaint& paint, const char text[])
{
static void doMeasure(SkCanvas* canvas, const SkPaint& paint, const char text[]) {
SkScalar dy = paint.getFontMetrics(NULL);
size_t len = strlen(text);
@ -80,55 +79,33 @@ static void doMeasure(SkCanvas* canvas, const SkPaint& paint, const char text[])
}
}
class MeasureView : public SkView {
class MeasureView : public SampleView {
public:
SkPaint fPaint;
MeasureView()
{
MeasureView() {
fPaint.setAntiAlias(true);
fPaint.setTextSize(SkIntToScalar(64));
this->setBGColor(0xFFDDDDDD);
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt)
{
if (SampleCode::TitleQ(*evt))
{
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Measure");
return true;
}
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas)
{
canvas->drawColor(0xFFDDDDDD);
}
virtual void onDraw(SkCanvas* canvas)
{
this->drawBG(canvas);
virtual void onDrawContent(SkCanvas* canvas) {
canvas->translate(fPaint.getTextSize(), fPaint.getTextSize());
doMeasure(canvas, fPaint, "Hamburgefons");
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y)
{
// fSweep += SK_Scalar1;
this->inval(NULL);
return this->INHERITED::onFindClickHandler(x, y);
}
virtual bool onClick(Click* click)
{
return this->INHERITED::onClick(click);
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -6,7 +6,7 @@
#include "SkPaint.h"
#include "SkUnPreMultiply.h"
class NinePatchView : public SkView {
class NinePatchView : public SampleView {
public:
SkBitmap fBM;
@ -34,7 +34,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
virtual void onDrawBackground(SkCanvas* canvas) {
SkPaint p;
p.setDither(true);
p.setColor(0xFF909090);
@ -69,11 +69,7 @@ protected:
}
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
// canvas->scale(1.5f, 1.5f);
virtual void onDrawContent(SkCanvas* canvas) {
canvas->drawBitmap(fBM, 0, 0);
SkIRect margins;
@ -108,7 +104,7 @@ protected:
}
private:
SkScalar fX, fY;
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -5,7 +5,7 @@
static const int kILimit = 101;
static const SkScalar kLimit = SK_Scalar1 * kILimit;
class OvalTestView : public SkView {
class OvalTestView : public SampleView {
public:
SkSize fSize;
SkPMColor fInsideColor; // signals an interior pixel that was not set
@ -20,6 +20,8 @@ public:
fInsideColor = SkPreMultiplyColor(SK_ColorRED);
fOutsideColor = SkPreMultiplyColor(SK_ColorGREEN);
this->setBGColor(0xFFDDDDDD);
}
protected:
@ -32,10 +34,6 @@ protected:
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(0xFFDDDDDD);
}
void drawOval() {
SkCanvas canvas(fBitmap);
SkPaint p;
@ -72,9 +70,7 @@ protected:
return flatc + buldgec;
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
virtual void onDrawContent(SkCanvas* canvas) {
this->drawOval();
int flatCount, buldgeCount;
this->checkOval(&flatCount, &buldgeCount);
@ -104,7 +100,7 @@ protected:
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -70,7 +70,7 @@ static void TestOverflowHitTest() {
#endif
}
class OverflowView : public SkView {
class OverflowView : public SampleView {
public:
OverflowView() {}
@ -84,19 +84,13 @@ protected:
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(SK_ColorWHITE);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
virtual void onDrawContent(SkCanvas* canvas) {
DrawRoundRect();
TestOverflowHitTest();
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -90,7 +90,7 @@ static const SkBitmap::Config gConfigs[] = {
#endif
};
class PageFlipView : public SkView {
class PageFlipView : public SampleView {
public:
enum { N = SK_ARRAY_COUNT(gConfigs) };
@ -115,6 +115,7 @@ public:
status = pthread_create(&fThreads[i], &attr, draw_proc, &fBitmaps[i]);
SkASSERT(0 == status);
}
this->setBGColor(0xFFDDDDDD);
}
virtual ~PageFlipView() {
@ -135,15 +136,8 @@ protected:
}
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(0xFFDDDDDD);
// canvas->drawColor(SK_ColorWHITE);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
virtual void onDrawContent(SkCanvas* canvas) {
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(10);
for (int i = 0; i < N; i++) {
@ -163,7 +157,7 @@ protected:
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -14,58 +14,7 @@
#include "SkTime.h"
#include "SkTypeface.h"
#if 0
static void CFString2SkString(CFStringRef ref, SkString* str) {
str->reset();
int count = CFStringGetLength(ref);
for (int i = 0; i < count; i++) {
SkString tmp;
UniChar c = CFStringGetCharacterAtIndex(ref, i);
tmp.setUTF16(&c, 1);
str->append(tmp);
}
}
static size_t get_table_size(ATSFontRef font, uint32_t tableTag) {
ByteCount size;
OSStatus status = ATSFontGetTable(font, tableTag, 0, 0, NULL, &size);
if (status) {
SkDebugf("*** ATSFontGetTable returned %d\n", status);
size = -1;
}
return size;
}
static void test_ats() {
OSStatus status;
ATSFontIterator iter;
status = ATSFontIteratorCreate(kATSFontContextLocal, NULL, NULL,
kATSOptionFlagsUnRestrictedScope, &iter);
for (int index = 0;; index++) {
ATSFontRef fontRef;
status = ATSFontIteratorNext(iter, &fontRef);
if (status) {
break;
}
CFStringRef name;
SkString str;
ATSFontGetName(fontRef, kATSOptionFlagsDefault, &name);
CFString2SkString(name, &str);
if (str.size() > 0 && str.c_str()[0] != '.') {
SkDebugf("[%3d] font %x cmap %d 'name' %d <%s>\n", index, fontRef,
get_table_size(fontRef, 'cmap'),
get_table_size(fontRef, 'name'),
str.c_str());
}
CFRelease(name);
}
ATSFontIteratorRelease(&iter);
}
#endif
class PathClipView : public SkView {
class PathClipView : public SampleView {
public:
SkRect fOval;
SkPoint fCenter;
@ -89,13 +38,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(SK_ColorWHITE);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
virtual void onDrawContent(SkCanvas* canvas) {
SkRect oval = fOval;
oval.offset(fCenter.fX - oval.centerX(), fCenter.fY - oval.centerY());
@ -131,7 +74,7 @@ protected:
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -35,9 +35,11 @@ static void make_paint(SkPaint* paint, SkShader::TileMode tm) {
paint->setShader(shader)->unref();
}
class RepeatTileView : public SkView {
class RepeatTileView : public SampleView {
public:
RepeatTileView() {}
RepeatTileView() {
this->setBGColor(SK_ColorGRAY);
}
protected:
// overrides from SkEventSink
@ -49,13 +51,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(SK_ColorGRAY);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
virtual void onDrawContent(SkCanvas* canvas) {
SkPaint paint;
make_paint(&paint, SkShader::kRepeat_TileMode);
@ -80,7 +76,7 @@ protected:
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -1,82 +0,0 @@
#include "SampleCode.h"
#include "SkView.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkImageDecoder.h"
#include "SkPath.h"
#include "SkRandom.h"
#include "SkRegion.h"
#include "SkShader.h"
#include "SkUtils.h"
#include "SkXfermode.h"
#include "SkColorPriv.h"
#include "SkColorFilter.h"
#include "SkTime.h"
#include "SkTypeface.h"
#include "SkTextBox.h"
#include "SkOSFile.h"
#include "SkStream.h"
#include "SkSVGParser.h"
class SVGView : public SkView {
public:
SVGView() {
SkXMLParserError err;
SkFILEStream stream("/testsvg2.svg");
SkSVGParser parser(&err);
if (parser.parse(stream)) {
const char* text = parser.getFinal();
SkFILEWStream output("/testanim.txt");
output.write(text, strlen(text));
}
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SkString str("SVG");
SampleCode::TitleR(evt, str.c_str());
return true;
}
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(SK_ColorWHITE);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
return new Click(this);
}
virtual bool onClick(Click* click) {
int y = click->fICurr.fY;
if (y < 0) {
y = 0;
} else if (y > 255) {
y = 255;
}
fByte = y;
this->inval(NULL);
return true;
}
private:
int fByte;
typedef SkView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new SVGView; }
static SkViewRegister reg(MyFactory);

View File

@ -749,7 +749,7 @@ static const SlideProc gProc[] = {
texteffect_slide
};
class SlideView : public SkView {
class SlideView : public SampleView {
int fIndex;
public:
SlideView() {
@ -770,6 +770,7 @@ public:
str.printf("/skimages/slide_%d.png", i);
SkImageEncoder::EncodeFile(str.c_str(), bm, SkImageEncoder::kPNG_Type, 100);
}
this->setBGColor(BG_COLOR);
}
protected:
@ -782,8 +783,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
virtual void onDraw(SkCanvas* canvas) {
canvas->drawColor(BG_COLOR);
virtual void onDrawContent(SkCanvas* canvas) {
gProc[fIndex](canvas);
}
@ -794,7 +794,7 @@ protected:
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -88,7 +88,7 @@ static const struct {
{ SkPaint::kStrokeAndFill_Style, SkPaint::kMiter_Join, 10 },
};
class StrokePathView : public SkView {
class StrokePathView : public SampleView {
SkScalar fWidth;
SkPath fPath;
public:
@ -111,6 +111,8 @@ public:
scale_to_width(&fPath, fWidth);
const SkRect& bounds = fPath.getBounds();
fPath.offset(-bounds.fLeft, -bounds.fTop);
this->setBGColor(0xFFDDDDDD);
}
protected:
@ -123,10 +125,6 @@ protected:
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(0xFFDDDDDD);
}
SkRandom rand;
void drawSet(SkCanvas* canvas, SkPaint* paint) {
@ -141,9 +139,7 @@ protected:
}
}
virtual void onDraw(SkCanvas* canvas) {
drawBG(canvas);
//return;
virtual void onDrawContent(SkCanvas* canvas) {
test_huge_stroke(canvas); return;
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
@ -211,7 +207,7 @@ protected:
return this->INHERITED::onFindClickHandler(x, y);
}
private:
typedef SkView INHERITED;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -1,4 +1,4 @@
#include "SampleCode.h"
utils#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"