2011-07-28 18:26:00 +04: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 19:06:10 +04: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 22:45:38 +03:00
|
|
|
void reset() {
|
|
|
|
fReg = GMRegistry::Head();
|
|
|
|
}
|
|
|
|
|
2009-09-23 19:06:10 +04: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 09:58:58 +04:00
|
|
|
class GMView : public SampleView {
|
2009-09-23 19:06:10 +04:00
|
|
|
Iter fIter;
|
|
|
|
GM* fGM;
|
|
|
|
public:
|
|
|
|
GMView() {
|
|
|
|
fGM = fIter.next();
|
2011-01-11 22:45:38 +03:00
|
|
|
this->postNextGM();
|
2011-05-11 09:58:58 +04:00
|
|
|
|
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2009-09-23 19:06:10 +04:00
|
|
|
}
|
2011-05-31 19:35:54 +04:00
|
|
|
|
|
|
|
virtual ~GMView() {
|
|
|
|
delete fGM;
|
|
|
|
}
|
|
|
|
|
2009-09-23 19:06:10 +04: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 22:45:38 +03: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 09:58:58 +04:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2009-09-23 19:06:10 +04:00
|
|
|
fGM->draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-01-11 22:45:38 +03:00
|
|
|
void postNextGM() {
|
2011-08-04 17:50:17 +04:00
|
|
|
(new SkEvent("next-gm", this->getSinkID()))->postDelay(1500);
|
2011-01-11 22:45:38 +03:00
|
|
|
}
|
|
|
|
|
2011-05-11 09:58:58 +04:00
|
|
|
typedef SampleView INHERITED;
|
2009-09-23 19:06:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new GMView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|
|
|
|
|
2010-12-20 21:26:13 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
using namespace skiagm;
|
|
|
|
|
|
|
|
GM::GM() {}
|
|
|
|
GM::~GM() {}
|
|
|
|
|
|
|
|
void GM::draw(SkCanvas* canvas) {
|
|
|
|
this->onDraw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
|