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.
|
|
|
|
*/
|
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"
|
2011-08-02 13:39:12 +00:00
|
|
|
class SkOSMenu;
|
2011-07-06 13:59:47 +00:00
|
|
|
class GrContext;
|
|
|
|
|
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[]);
|
2011-08-08 15:37:23 +00:00
|
|
|
static bool RequestTitle(SkView* view, SkString* title);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
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);
|
2011-07-06 13:59:47 +00:00
|
|
|
|
|
|
|
static GrContext* GetGr();
|
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-08-26 13:19:39 +00:00
|
|
|
SampleView() : fRepeatCount(1), fBGColor(SK_ColorWHITE) {
|
2011-05-11 05:58:58 +00:00
|
|
|
fUsePipe = false;
|
|
|
|
}
|
2011-04-22 01:59:09 +00:00
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
void setBGColor(SkColor color) { fBGColor = color; }
|
|
|
|
|
2011-05-12 22:08:24 +00:00
|
|
|
static bool IsSampleView(SkView*);
|
2011-04-22 14:10:48 +00:00
|
|
|
static bool SetRepeatDraw(SkView*, int count);
|
2011-05-11 05:58:58 +00:00
|
|
|
static bool SetUsePipe(SkView*, bool);
|
2011-08-02 13:39:12 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
/**
|
|
|
|
* Call this to request menu items from a SampleView.
|
|
|
|
* Subclassing notes: A subclass of SampleView can overwrite this method
|
|
|
|
* to add new items of various types to the menu and change its title.
|
|
|
|
* The events attached to any new menu items must be handled in its onEvent
|
|
|
|
* method. See SkOSMenu.h for helper functions.
|
|
|
|
*/
|
|
|
|
virtual void requestMenu(SkOSMenu* menu) {}
|
2011-04-22 01:59:09 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onDrawBackground(SkCanvas*);
|
|
|
|
virtual void onDrawContent(SkCanvas*) = 0;
|
2011-08-02 13:39:12 +00:00
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
// overrides
|
|
|
|
virtual bool onEvent(const SkEvent& evt);
|
|
|
|
virtual bool onQuery(SkEvent* evt);
|
2011-08-08 15:37:23 +00:00
|
|
|
virtual void draw(SkCanvas*);
|
2011-04-22 01:59:09 +00:00
|
|
|
virtual void onDraw(SkCanvas*);
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
bool fUsePipe;
|
|
|
|
SkColor fBGColor;
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
private:
|
|
|
|
int fRepeatCount;
|
2011-05-11 05:58:58 +00:00
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
typedef SkView INHERITED;
|
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|
|
|
|
|