2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SampleCode_DEFINED
|
|
|
|
#define SampleCode_DEFINED
|
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
#include "SkColor.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkEvent.h"
|
2010-12-20 18:26:13 +00:00
|
|
|
#include "SkKey.h"
|
2011-04-22 01:59:09 +00:00
|
|
|
#include "SkView.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SampleCode {
|
|
|
|
public:
|
2010-12-20 18:26:13 +00:00
|
|
|
static bool KeyQ(const SkEvent&, SkKey* outKey);
|
|
|
|
static bool CharQ(const SkEvent&, SkUnichar* outUni);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
static bool TitleQ(const SkEvent&);
|
|
|
|
static void TitleR(SkEvent*, const char title[]);
|
|
|
|
|
|
|
|
static bool PrefSizeQ(const SkEvent&);
|
|
|
|
static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height);
|
2010-12-20 18:26:13 +00:00
|
|
|
|
|
|
|
static bool FastTextQ(const SkEvent&);
|
|
|
|
|
2009-11-23 21:07:51 +00:00
|
|
|
static SkMSec GetAnimTime();
|
2010-12-20 18:26:13 +00:00
|
|
|
static SkMSec GetAnimTimeDelta();
|
|
|
|
static SkScalar GetAnimSecondsDelta();
|
2009-11-23 21:07:51 +00:00
|
|
|
static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0);
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef SkView* (*SkViewFactory)();
|
|
|
|
|
|
|
|
class SkViewRegister : SkNoncopyable {
|
|
|
|
public:
|
2009-06-11 12:26:47 +00:00
|
|
|
explicit SkViewRegister(SkViewFactory);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
static const SkViewRegister* Head() { return gHead; }
|
|
|
|
|
|
|
|
SkViewRegister* next() const { return fChain; }
|
|
|
|
SkViewFactory factory() const { return fFact; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkViewFactory fFact;
|
|
|
|
SkViewRegister* fChain;
|
|
|
|
|
|
|
|
static SkViewRegister* gHead;
|
|
|
|
};
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class SampleView : public SkView {
|
|
|
|
public:
|
2011-04-22 14:10:48 +00:00
|
|
|
SampleView() : fRepeatCount(1), fBGColor(SK_ColorWHITE) {}
|
2011-04-22 01:59:09 +00:00
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
void setBGColor(SkColor color) { fBGColor = color; }
|
|
|
|
|
|
|
|
static bool SetRepeatDraw(SkView*, int count);
|
2011-04-22 01:59:09 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onDrawBackground(SkCanvas*);
|
|
|
|
virtual void onDrawContent(SkCanvas*) = 0;
|
|
|
|
|
|
|
|
// overrides
|
|
|
|
virtual bool onEvent(const SkEvent& evt);
|
|
|
|
virtual bool onQuery(SkEvent* evt);
|
|
|
|
virtual void onDraw(SkCanvas*);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int fRepeatCount;
|
2011-04-22 14:10:48 +00:00
|
|
|
SkColor fBGColor;
|
2011-04-22 01:59:09 +00:00
|
|
|
|
|
|
|
typedef SkView INHERITED;
|
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|
|
|
|
|