2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-09-23 15:06:10 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
using namespace skiagm;
|
|
|
|
|
|
|
|
// need to explicitly declare this, or we get some weird infinite loop llist
|
|
|
|
template GMRegistry* GMRegistry::gHead;
|
|
|
|
|
|
|
|
class Iter {
|
|
|
|
public:
|
|
|
|
Iter() {
|
|
|
|
fReg = GMRegistry::Head();
|
|
|
|
}
|
|
|
|
|
2011-01-11 19:45:38 +00:00
|
|
|
void reset() {
|
|
|
|
fReg = GMRegistry::Head();
|
|
|
|
}
|
|
|
|
|
2009-09-23 15:06:10 +00:00
|
|
|
GM* next() {
|
|
|
|
if (fReg) {
|
|
|
|
GMRegistry::Factory fact = fReg->factory();
|
|
|
|
fReg = fReg->next();
|
|
|
|
return fact(0);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Count() {
|
|
|
|
const GMRegistry* reg = GMRegistry::Head();
|
|
|
|
int count = 0;
|
|
|
|
while (reg) {
|
|
|
|
count += 1;
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const GMRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-11 05:58:58 +00:00
|
|
|
class GMView : public SampleView {
|
2009-09-23 15:06:10 +00:00
|
|
|
Iter fIter;
|
|
|
|
GM* fGM;
|
|
|
|
public:
|
|
|
|
GMView() {
|
|
|
|
fGM = fIter.next();
|
2011-01-11 19:45:38 +00:00
|
|
|
this->postNextGM();
|
2011-05-11 05:58:58 +00:00
|
|
|
|
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2009-09-23 15:06:10 +00:00
|
|
|
}
|
2011-05-31 15:35:54 +00:00
|
|
|
|
|
|
|
virtual ~GMView() {
|
|
|
|
delete fGM;
|
|
|
|
}
|
|
|
|
|
2009-09-23 15:06:10 +00:00
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "GM");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2011-01-11 19:45:38 +00:00
|
|
|
virtual bool onEvent(const SkEvent& evt) {
|
|
|
|
if (evt.isType("next-gm")) {
|
|
|
|
delete fGM;
|
|
|
|
if (!(fGM = fIter.next())) {
|
|
|
|
fIter.reset();
|
|
|
|
fGM = fIter.next();
|
|
|
|
}
|
|
|
|
this->inval(NULL);
|
|
|
|
this->postNextGM();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
2011-05-11 05:58:58 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2009-09-23 15:06:10 +00:00
|
|
|
fGM->draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-01-11 19:45:38 +00:00
|
|
|
void postNextGM() {
|
2011-08-04 13:50:17 +00:00
|
|
|
(new SkEvent("next-gm", this->getSinkID()))->postDelay(1500);
|
2011-01-11 19:45:38 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 05:58:58 +00:00
|
|
|
typedef SampleView INHERITED;
|
2009-09-23 15:06:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new GMView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
using namespace skiagm;
|
|
|
|
|
|
|
|
GM::GM() {}
|
|
|
|
GM::~GM() {}
|
|
|
|
|
|
|
|
void GM::draw(SkCanvas* canvas) {
|
|
|
|
this->onDraw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
|