Delete even more unused views code
Bug: skia: Change-Id: I41480aa89dfcd8cb7e016e477cbabe354f35ce8a Reviewed-on: https://skia-review.googlesource.com/75480 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
3f67914c01
commit
ede860e91c
@ -8,8 +8,6 @@ _samplecode = get_path_info("../samplecode", "abspath")
|
||||
|
||||
samples_sources = [
|
||||
"$_samplecode/ClockFaceView.cpp",
|
||||
"$_samplecode/GMSampleView.cpp",
|
||||
"$_samplecode/OverView.cpp",
|
||||
"$_samplecode/PerlinPatch.cpp",
|
||||
"$_samplecode/Sample2PtRadial.cpp",
|
||||
"$_samplecode/SampleAAClip.cpp",
|
||||
|
@ -11,11 +11,6 @@
|
||||
#include "SkMetaData.h"
|
||||
#include "SkString.h"
|
||||
|
||||
class SkDOM;
|
||||
struct SkDOMNode;
|
||||
|
||||
#include "../private/SkLeanWindows.h"
|
||||
|
||||
/** Unique 32bit id used to identify an instance of SkEventSink. When events are
|
||||
posted, they are posted to a specific sinkID. When it is time to dispatch the
|
||||
event, the sinkID is used to find the specific SkEventSink object. If it is found,
|
||||
@ -143,11 +138,6 @@ public:
|
||||
/** Return the underlying metadata object */
|
||||
const SkMetaData& getMetaData() const { return fMeta; }
|
||||
|
||||
/** Call this to initialize the event from the specified XML node */
|
||||
void inflate(const SkDOM&, const SkDOMNode*);
|
||||
|
||||
SkDEBUGCODE(void dump(const char title[] = nullptr);)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
@ -155,10 +145,6 @@ private:
|
||||
mutable char* fType; // may be characters with low bit set to know that it is not a pointer
|
||||
uint32_t f32;
|
||||
|
||||
// these are for our implementation of the event queue
|
||||
SkMSec fTime;
|
||||
SkEvent* fNextEvent; // either in the delay or normal event queue
|
||||
|
||||
void initialize(const char* type, size_t typeLen);
|
||||
};
|
||||
|
||||
|
@ -12,46 +12,6 @@
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
enum SkKey {
|
||||
//reordering these to match android.app.KeyEvent
|
||||
kNONE_SkKey, //corresponds to android's UNKNOWN
|
||||
|
||||
kLeftSoftKey_SkKey,
|
||||
kRightSoftKey_SkKey,
|
||||
|
||||
kHome_SkKey, //!< the home key - added to match android
|
||||
kBack_SkKey, //!< (CLR)
|
||||
kSend_SkKey, //!< the green (talk) key
|
||||
kEnd_SkKey, //!< the red key
|
||||
|
||||
k0_SkKey,
|
||||
k1_SkKey,
|
||||
k2_SkKey,
|
||||
k3_SkKey,
|
||||
k4_SkKey,
|
||||
k5_SkKey,
|
||||
k6_SkKey,
|
||||
k7_SkKey,
|
||||
k8_SkKey,
|
||||
k9_SkKey,
|
||||
kStar_SkKey, //!< the * key
|
||||
kHash_SkKey, //!< the # key
|
||||
|
||||
kUp_SkKey,
|
||||
kDown_SkKey,
|
||||
kLeft_SkKey,
|
||||
kRight_SkKey,
|
||||
|
||||
kOK_SkKey, //!< the center key
|
||||
|
||||
kVolUp_SkKey, //!< volume up - match android
|
||||
kVolDown_SkKey, //!< volume down - same
|
||||
kPower_SkKey, //!< power button - same
|
||||
kCamera_SkKey, //!< camera - same
|
||||
|
||||
kSkKeyCount
|
||||
};
|
||||
|
||||
enum SkModifierKeys {
|
||||
kShift_SkModifierKey = 1 << 0,
|
||||
kControl_SkModifierKey = 1 << 1,
|
||||
|
@ -1,25 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SkSystemEventTypes_DEFINED
|
||||
#define SkSystemEventTypes_DEFINED
|
||||
|
||||
/*
|
||||
The goal of these strings is two-fold:
|
||||
1) make funny strings (containing at least one char < 32) to avoid colliding with "user" strings
|
||||
2) keep them <= 4 bytes, so we can avoid an allocation in SkEvent::setType()
|
||||
*/
|
||||
#define SK_EventType_Delay "\xd" "lay"
|
||||
#define SK_EventType_Inval "nv" "\xa" "l"
|
||||
#define SK_EventType_Key "key" "\x1"
|
||||
#define SK_EventType_OnEnd "on" "\xe" "n"
|
||||
#define SK_EventType_Unichar "\xc" "har"
|
||||
#define SK_EventType_KeyUp "key" "\xf"
|
||||
|
||||
#endif
|
@ -16,9 +16,6 @@
|
||||
#include "SkMetaData.h"
|
||||
|
||||
class SkCanvas;
|
||||
class SkLayerView;
|
||||
class SkDOM;
|
||||
struct SkDOMNode;
|
||||
|
||||
/** \class SkView
|
||||
|
||||
@ -79,62 +76,10 @@ public:
|
||||
void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); }
|
||||
void setWidth(SkScalar width) { this->setSize(width, fHeight); }
|
||||
void setHeight(SkScalar height) { this->setSize(fWidth, height); }
|
||||
/** Return a rectangle set to [0, 0, width, height] */
|
||||
void getLocalBounds(SkRect* bounds) const;
|
||||
|
||||
/** Loc - the view's offset with respect to its parent in its view hiearchy.
|
||||
NOTE: For more complex transforms, use Local Matrix. The tranformations
|
||||
are applied in the following order:
|
||||
canvas->translate(fLoc.fX, fLoc.fY);
|
||||
canvas->concat(fMatrix);
|
||||
*/
|
||||
/** Return the view's left edge */
|
||||
SkScalar locX() const { return fLoc.fX; }
|
||||
/** Return the view's top edge */
|
||||
SkScalar locY() const { return fLoc.fY; }
|
||||
/** Set the view's left and top edge. This does not affect the view's size */
|
||||
void setLoc(SkScalar x, SkScalar y);
|
||||
void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); }
|
||||
void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); }
|
||||
void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); }
|
||||
|
||||
/** Local Matrix - matrix used to tranform the view with respect to its
|
||||
parent in its view hiearchy. Use setLocalMatrix to apply matrix
|
||||
transformations to the current view and in turn affect its children.
|
||||
NOTE: For simple offsets, use Loc. The transformations are applied in
|
||||
the following order:
|
||||
canvas->translate(fLoc.fX, fLoc.fY);
|
||||
canvas->concat(fMatrix);
|
||||
*/
|
||||
const SkMatrix& getLocalMatrix() const { return fMatrix; }
|
||||
void setLocalMatrix(const SkMatrix& matrix);
|
||||
|
||||
/** Offset (move) the view by the specified dx and dy. This does not affect the view's size */
|
||||
void offset(SkScalar dx, SkScalar dy);
|
||||
|
||||
/** Call this to have the view draw into the specified canvas. */
|
||||
virtual void draw(SkCanvas* canvas);
|
||||
|
||||
/** Call this to invalidate part of all of a view, requesting that the view's
|
||||
draw method be called. The rectangle parameter specifies the part of the view
|
||||
that should be redrawn. If it is null, it specifies the entire view bounds.
|
||||
*/
|
||||
void inval(SkRect* rectOrNull);
|
||||
|
||||
// Focus management
|
||||
|
||||
SkView* getFocusView() const;
|
||||
bool hasFocus() const;
|
||||
|
||||
enum FocusDirection {
|
||||
kNext_FocusDirection,
|
||||
kPrev_FocusDirection,
|
||||
|
||||
kFocusDirectionCount
|
||||
};
|
||||
bool acceptFocus();
|
||||
SkView* moveFocus(FocusDirection);
|
||||
|
||||
// Click handling
|
||||
|
||||
class Click {
|
||||
@ -142,11 +87,6 @@ public:
|
||||
Click(SkView* target);
|
||||
virtual ~Click();
|
||||
|
||||
const char* getType() const { return fType; }
|
||||
bool isType(const char type[]) const;
|
||||
void setType(const char type[]); // does NOT make a copy of the string
|
||||
void copyType(const char type[]); // makes a copy of the string
|
||||
|
||||
enum State {
|
||||
kDown_State,
|
||||
kMoved_State,
|
||||
@ -155,16 +95,11 @@ public:
|
||||
SkPoint fOrig, fPrev, fCurr;
|
||||
SkIPoint fIOrig, fIPrev, fICurr;
|
||||
State fState;
|
||||
void* fOwner;
|
||||
unsigned fModifierKeys;
|
||||
|
||||
SkMetaData fMeta;
|
||||
private:
|
||||
SkEventSinkID fTargetID;
|
||||
char* fType;
|
||||
bool fWeOwnTheType;
|
||||
|
||||
void resetType();
|
||||
|
||||
friend class SkView;
|
||||
};
|
||||
@ -174,163 +109,23 @@ public:
|
||||
static void DoClickMoved(Click*, int x, int y, unsigned modi);
|
||||
static void DoClickUp(Click*, int x, int y, unsigned modi);
|
||||
|
||||
/** Send the event to the view's parent, and its parent etc. until one of them
|
||||
returns true from its onEvent call. This view is returned. If no parent handles
|
||||
the event, null is returned.
|
||||
*/
|
||||
SkView* sendEventToParents(const SkEvent&);
|
||||
/** Send the query to the view's parent, and its parent etc. until one of them
|
||||
returns true from its onQuery call. This view is returned. If no parent handles
|
||||
the query, null is returned.
|
||||
*/
|
||||
SkView* sendQueryToParents(SkEvent*);
|
||||
|
||||
// View hierarchy management
|
||||
|
||||
/** Return the view's parent, or null if it has none. This does not affect the parent's reference count. */
|
||||
SkView* getParent() const { return fParent; }
|
||||
SkView* attachChildToFront(SkView* child);
|
||||
/** Attach the child view to this view, and increment the child's reference count. The child view is added
|
||||
such that it will be drawn before all other child views.
|
||||
The child view parameter is returned.
|
||||
*/
|
||||
SkView* attachChildToBack(SkView* child);
|
||||
/** If the view has a parent, detach the view from its parent and decrement the view's reference count.
|
||||
If the parent was the only owner of the view, this will cause the view to be deleted.
|
||||
*/
|
||||
void detachFromParent();
|
||||
/** Attach the child view to this view, and increment the child's reference count. The child view is added
|
||||
such that it will be drawn after all other child views.
|
||||
The child view parameter is returned.
|
||||
*/
|
||||
/** Detach all child views from this view. */
|
||||
void detachAllChildren();
|
||||
|
||||
/** Convert the specified point from global coordinates into view-local coordinates
|
||||
* Return true on success; false on failure
|
||||
*/
|
||||
bool globalToLocal(SkPoint* pt) const {
|
||||
if (pt) {
|
||||
return this->globalToLocal(pt->fX, pt->fY, pt);
|
||||
}
|
||||
return true; // nothing to do so return true
|
||||
}
|
||||
/** Convert the specified x,y from global coordinates into view-local coordinates, returning
|
||||
the answer in the local parameter.
|
||||
*/
|
||||
bool globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const;
|
||||
|
||||
/** \class F2BIter
|
||||
|
||||
Iterator that will return each of this view's children, in
|
||||
front-to-back order (the order used for clicking). The first
|
||||
call to next() returns the front-most child view. When
|
||||
next() returns null, there are no more child views.
|
||||
*/
|
||||
class F2BIter {
|
||||
public:
|
||||
F2BIter(const SkView* parent);
|
||||
SkView* next();
|
||||
private:
|
||||
SkView* fFirstChild, *fChild;
|
||||
};
|
||||
|
||||
/** \class B2FIter
|
||||
|
||||
Iterator that will return each of this view's children, in
|
||||
back-to-front order (the order they are drawn). The first
|
||||
call to next() returns the back-most child view. When
|
||||
next() returns null, there are no more child views.
|
||||
*/
|
||||
class B2FIter {
|
||||
public:
|
||||
B2FIter(const SkView* parent);
|
||||
SkView* next();
|
||||
private:
|
||||
SkView* fFirstChild, *fChild;
|
||||
};
|
||||
|
||||
/** Call this to initialize this view based on the specified XML node
|
||||
*/
|
||||
void inflate(const SkDOM& dom, const SkDOMNode* node);
|
||||
|
||||
SkDEBUGCODE(void dump(bool recurse) const;)
|
||||
|
||||
protected:
|
||||
/** Override this to draw inside the view. Be sure to call the inherited version too */
|
||||
virtual void onDraw(SkCanvas*);
|
||||
/** Override this to be notified when the view's size changes. Be sure to call the inherited version too */
|
||||
virtual void onSizeChange();
|
||||
/** Override this if you want to handle an inval request from this view or one of its children.
|
||||
Tyically this is only overridden by the by the "window". If your subclass does handle the
|
||||
request, return true so the request will not continue to propogate to the parent.
|
||||
*/
|
||||
virtual bool handleInval(const SkRect*);
|
||||
//! called once before all of the children are drawn (or clipped/translated)
|
||||
virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; }
|
||||
//! called once after all of the children are drawn (or clipped/translated)
|
||||
virtual void afterChildren(SkCanvas*) {}
|
||||
|
||||
//! called right before this child's onDraw is called
|
||||
virtual void beforeChild(SkView* /*child*/, SkCanvas*) {}
|
||||
//! called right after this child's onDraw is called
|
||||
virtual void afterChild(SkView* /*child*/, SkCanvas*) {}
|
||||
|
||||
/** Override this if you might handle the click
|
||||
*/
|
||||
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi);
|
||||
/** Override this to decide if your children are targets for a click.
|
||||
The default returns true, in which case your children views will be
|
||||
candidates for onFindClickHandler. Returning false wil skip the children
|
||||
and just call your onFindClickHandler.
|
||||
*/
|
||||
virtual bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi);
|
||||
/** Override this to track clicks, returning true as long as you want to track
|
||||
the pen/mouse.
|
||||
*/
|
||||
virtual bool onClick(Click*);
|
||||
/** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOMNode* node);
|
||||
/** Override this if you want to perform post initialization work based on the ID dictionary built
|
||||
during XML parsing. Be sure to call the inherited version too.
|
||||
*/
|
||||
|
||||
public:
|
||||
#ifdef SK_DEBUG
|
||||
void validate() const;
|
||||
#else
|
||||
void validate() const {}
|
||||
#endif
|
||||
// default action is to inval the view
|
||||
virtual void onFocusChange(bool gainFocusP);
|
||||
|
||||
protected:
|
||||
|
||||
// override these if you're acting as a layer/host
|
||||
virtual bool onGetFocusView(SkView**) const { return false; }
|
||||
virtual bool onSetFocusView(SkView*) { return false; }
|
||||
|
||||
private:
|
||||
SkScalar fWidth, fHeight;
|
||||
SkMatrix fMatrix;
|
||||
SkPoint fLoc;
|
||||
SkView* fParent;
|
||||
SkView* fFirstChild;
|
||||
SkView* fNextSibling;
|
||||
SkView* fPrevSibling;
|
||||
uint8_t fFlags;
|
||||
uint8_t fContainsFocus;
|
||||
|
||||
friend class B2FIter;
|
||||
friend class F2BIter;
|
||||
|
||||
friend class SkLayerView;
|
||||
|
||||
bool setFocusView(SkView* fvOrNull);
|
||||
SkView* acceptFocus(FocusDirection);
|
||||
void detachFromParent_NoLayout();
|
||||
/** Compute the matrix to transform view-local coordinates into global ones */
|
||||
void localToGlobal(SkMatrix* matrix) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -207,7 +207,6 @@ protected:
|
||||
fInterp = 0;
|
||||
fDx = -fDx;
|
||||
}
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "GMSampleView.h"
|
||||
#include "SkData.h"
|
||||
|
||||
GMSampleView::GMSampleView(GM* gm) : fShowSize(false), fGM(gm) {}
|
||||
|
||||
GMSampleView::~GMSampleView() {
|
||||
delete fGM;
|
||||
}
|
||||
|
||||
SkEvent* GMSampleView::NewShowSizeEvt(bool doShowSize) {
|
||||
SkEvent* evt = new SkEvent("GMSampleView::showSize");
|
||||
evt->setFast32(doShowSize);
|
||||
return evt;
|
||||
}
|
||||
|
||||
bool GMSampleView::onQuery(SkEvent* evt) {
|
||||
if (SampleCode::TitleQ(*evt)) {
|
||||
SkString name("GM:");
|
||||
name.append(fGM->getName());
|
||||
SampleCode::TitleR(evt, name.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
if (fGM->handleKey(uni)) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
bool GMSampleView::onEvent(const SkEvent& evt) {
|
||||
if (evt.isType("GMSampleView::showSize")) {
|
||||
fShowSize = SkToBool(evt.getFast32());
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onEvent(evt);
|
||||
}
|
||||
|
||||
#include "SkPicture.h"
|
||||
static sk_sp<SkPicture> round_trip_serialize(SkPicture* src) {
|
||||
return SkPicture::MakeFromData(src->serialize().get());
|
||||
}
|
||||
|
||||
#include "SkPictureRecorder.h"
|
||||
void GMSampleView::onDrawContent(SkCanvas* canvas) {
|
||||
SkPictureRecorder recorder;
|
||||
SkCanvas* origCanvas = canvas;
|
||||
|
||||
if (false) {
|
||||
SkISize size = fGM->getISize();
|
||||
canvas = recorder.beginRecording(SkRect::MakeIWH(size.width(), size.height()));
|
||||
}
|
||||
|
||||
{
|
||||
SkAutoCanvasRestore acr(canvas, fShowSize);
|
||||
fGM->drawContent(canvas);
|
||||
}
|
||||
|
||||
if (origCanvas != canvas) {
|
||||
sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
|
||||
if (false) {
|
||||
pic = round_trip_serialize(pic.get());
|
||||
}
|
||||
origCanvas->drawPicture(pic);
|
||||
canvas = origCanvas;
|
||||
}
|
||||
|
||||
if (fShowSize) {
|
||||
SkISize size = fGM->getISize();
|
||||
SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
|
||||
SkIntToScalar(size.height()));
|
||||
SkPaint paint;
|
||||
paint.setColor(0x40FF8833);
|
||||
canvas->drawRect(r, paint);
|
||||
}
|
||||
}
|
||||
|
||||
void GMSampleView::onDrawBackground(SkCanvas* canvas) {
|
||||
fGM->drawBackground(canvas);
|
||||
}
|
||||
|
||||
bool GMSampleView::onAnimate(const SkAnimTimer& timer) {
|
||||
return fGM->animate(timer);
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GMSampleView_DEFINED
|
||||
#define GMSampleView_DEFINED
|
||||
|
||||
#include "SampleCode.h"
|
||||
#include "gm.h"
|
||||
|
||||
class GMSampleView : public SampleView {
|
||||
private:
|
||||
bool fShowSize;
|
||||
typedef skiagm::GM GM;
|
||||
|
||||
public:
|
||||
GMSampleView(GM*);
|
||||
~GMSampleView() override;
|
||||
|
||||
static SkEvent* NewShowSizeEvt(bool doShowSize);
|
||||
|
||||
protected:
|
||||
bool onQuery(SkEvent*) override;
|
||||
bool onEvent(const SkEvent&) override;
|
||||
void onDrawContent(SkCanvas*) override;
|
||||
void onDrawBackground(SkCanvas*) override;
|
||||
bool onAnimate(const SkAnimTimer&) override;
|
||||
|
||||
private:
|
||||
GM* fGM;
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "OverView.h"
|
||||
#include "SampleCode.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkView.h"
|
||||
|
||||
static const char gIsOverview[] = "is-overview";
|
||||
|
||||
static int to_lower(int c) {
|
||||
if ('A' <= c && c <= 'Z') {
|
||||
c = c - 'A' + 'a';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static void make_lc(SkString* str) {
|
||||
char* ptr = str->writable_str();
|
||||
while (*ptr) {
|
||||
*ptr = to_lower(*ptr);
|
||||
ptr += 1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool case_insensitive_find(const SkString& base, const SkString& sub) {
|
||||
SkString lcBase(base);
|
||||
SkString lcSub(sub);
|
||||
make_lc(&lcBase);
|
||||
make_lc(&lcSub);
|
||||
return lcBase.find(lcSub.c_str()) >= 0;
|
||||
}
|
||||
|
||||
static bool draw_this_name(const SkString& name, const SkString& filter) {
|
||||
if (filter.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return case_insensitive_find(name, filter);
|
||||
}
|
||||
|
||||
class OverView : public SkView {
|
||||
public:
|
||||
OverView(int count, const SkViewFactory* factories[]);
|
||||
~OverView() override;
|
||||
|
||||
protected:
|
||||
bool onEvent(const SkEvent&) override;
|
||||
bool onQuery(SkEvent* evt) override {
|
||||
if (SampleCode::TitleQ(*evt)) {
|
||||
SampleCode::TitleR(evt, "Overview");
|
||||
return true;
|
||||
}
|
||||
if (evt->isType(gIsOverview)) {
|
||||
return true;
|
||||
}
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
if (uni >= ' ') {
|
||||
fMatchStr.appendUnichar(uni);
|
||||
}
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override;
|
||||
|
||||
bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
Click* onFindClickHandler(SkScalar cx, SkScalar cy, unsigned modi) override {
|
||||
const SkRect crect = SkRect::MakeXYWH(cx - 0.5f, cy - 0.5f, 1, 1);
|
||||
SkPoint loc = this->start();
|
||||
for (int i = 0; i < fCount; ++i) {
|
||||
if (draw_this_name(fNames[i], fMatchStr)) {
|
||||
if (this->bounds(loc).intersects(crect)) {
|
||||
SkEvent evt("set-curr-index");
|
||||
evt.setFast32(i);
|
||||
this->sendEventToParents(evt);
|
||||
break;
|
||||
}
|
||||
this->next(&loc);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
int fCount;
|
||||
const SkViewFactory** fFactories;
|
||||
SkString* fNames;
|
||||
SkString fMatchStr;
|
||||
SkPaint fNamePaint;
|
||||
SkPaint::FontMetrics fNameMetrics;
|
||||
SkScalar fNameW;
|
||||
SkScalar fNameH;
|
||||
|
||||
SkRect bounds(const SkPoint& loc) const {
|
||||
return SkRect::MakeXYWH(loc.x(), loc.y() + fNameMetrics.fAscent, fNameW, fNameH);
|
||||
}
|
||||
|
||||
SkPoint start() const {
|
||||
return SkPoint::Make(10, -fNameMetrics.fTop);
|
||||
}
|
||||
|
||||
void next(SkPoint* loc) const {
|
||||
loc->fY += fNameH;
|
||||
if (loc->fY > this->height() - fNameMetrics.fBottom) {
|
||||
loc->fY = -fNameMetrics.fTop;
|
||||
loc->fX += fNameW;
|
||||
}
|
||||
}
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
SkView* create_overview(int count, const SkViewFactory* factories[]) {
|
||||
return new OverView(count, factories);
|
||||
}
|
||||
|
||||
bool is_overview(SkView* view) {
|
||||
SkEvent isOverview(gIsOverview);
|
||||
return view->doQuery(&isOverview);
|
||||
}
|
||||
|
||||
OverView::OverView(int count, const SkViewFactory* factories[]) {
|
||||
fCount = count;
|
||||
fFactories = factories;
|
||||
|
||||
fNames = new SkString[count];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkView* view = (*fFactories[i])();
|
||||
if (view) {
|
||||
(void)SampleCode::RequestTitle(view, &fNames[i]);
|
||||
if (0 == fNames[i].find("GM:")) {
|
||||
fNames[i].remove(0, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fNamePaint.setAntiAlias(true);
|
||||
fNamePaint.setTextSize(12);
|
||||
fNameW = 160;
|
||||
fNameH = fNamePaint.getFontMetrics(&fNameMetrics);
|
||||
}
|
||||
|
||||
OverView::~OverView() {
|
||||
delete[] fNames;
|
||||
}
|
||||
|
||||
bool OverView::onEvent(const SkEvent& evt) {
|
||||
return this->INHERITED::onEvent(evt);
|
||||
}
|
||||
|
||||
void OverView::onDraw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setColor(0xFFF8F8F8);
|
||||
canvas->drawPaint(paint);
|
||||
|
||||
SkPoint loc = this->start();
|
||||
for (int i = 0; i < fCount; ++i) {
|
||||
if (draw_this_name(fNames[i], fMatchStr)) {
|
||||
canvas->drawRect(this->bounds(loc), paint);
|
||||
canvas->drawString(fNames[i], loc.x(), loc.y(), fNamePaint);
|
||||
this->next(&loc);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SAMPLECODE_OVERVIEW_H_
|
||||
#define SAMPLECODE_OVERVIEW_H_
|
||||
|
||||
class SkView;
|
||||
class SkViewFactory;
|
||||
|
||||
SkView* create_overview(int, const SkViewFactory*[]);
|
||||
|
||||
bool is_overview(SkView* view);
|
||||
|
||||
#endif // SAMPLECODE_OVERVIEW_H_
|
@ -119,7 +119,7 @@ protected:
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
switch (uni) {
|
||||
case 'g': fShowGrid = !fShowGrid; this->inval(nullptr); return true;
|
||||
case 'g': fShowGrid = !fShowGrid; return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -207,7 +207,6 @@ protected:
|
||||
fTexScale += yDiff / 10.0f;
|
||||
fTexScale = SkTMax(0.1f, SkTMin(20.f, fTexScale));
|
||||
}
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -883,7 +883,6 @@ public:
|
||||
|
||||
bool constructPath() {
|
||||
construct_path(fPath);
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -909,7 +908,6 @@ public:
|
||||
PathUndo* next = fUndo->fNext;
|
||||
delete fUndo;
|
||||
fUndo = next;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -932,7 +930,6 @@ public:
|
||||
|
||||
bool hideAll() {
|
||||
fHideAll ^= true;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -991,7 +988,6 @@ public:
|
||||
matrix.setScale(1.f / 1.5f, 1.f / 1.5f, bounds.centerX(), bounds.centerY());
|
||||
fPath.transform(matrix);
|
||||
validatePath();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1007,7 +1003,6 @@ public:
|
||||
SkScalar offsetY = (this->height() - bounds.height()) / 2 - bounds.fTop;
|
||||
fPath.offset(offsetX, offsetY);
|
||||
validatePath();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1017,7 +1012,6 @@ public:
|
||||
matrix.setScale(1.5f, 1.5f, bounds.centerX(), bounds.centerY());
|
||||
fPath.transform(matrix);
|
||||
validatePath();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1038,7 +1032,6 @@ public:
|
||||
|
||||
bool showLegend() {
|
||||
fShowLegend ^= true;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1670,7 +1663,6 @@ public:
|
||||
SkIntToScalar(click->fICurr.fY - click->fIPrev.fY));
|
||||
set_path_pt(fActivePt, pt, &fPath);
|
||||
validatePath();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
case MyClick::kPathType:
|
||||
@ -1678,7 +1670,6 @@ public:
|
||||
fPath.offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX),
|
||||
SkIntToScalar(click->fICurr.fY - click->fIPrev.fY));
|
||||
validatePath();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case MyClick::kVerbType: {
|
||||
fActiveVerb = myClick->verbHit();
|
||||
@ -1790,7 +1781,6 @@ public:
|
||||
break;
|
||||
}
|
||||
setControlButtonsPos();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,6 @@ protected:
|
||||
|
||||
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) {
|
||||
fClickPt.set(x, y);
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,6 @@ protected:
|
||||
break;
|
||||
}
|
||||
if (handled) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkRandom.h"
|
||||
#include "SkSystemEventTypes.h"
|
||||
#include "SkTime.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "Timer.h"
|
||||
|
@ -196,12 +196,6 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
// fSweep += SK_Scalar1;
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
private:
|
||||
SkScalar fSweep;
|
||||
|
||||
|
@ -223,7 +223,7 @@ protected:
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
switch (uni) {
|
||||
case 'C': fDrawable->toggleUseColors(); this->inval(nullptr); return true;
|
||||
case 'C': fDrawable->toggleUseColors(); return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ private:
|
||||
|
||||
void updateAndInval() {
|
||||
this->updateGpuData();
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void updateGpuData();
|
||||
|
@ -164,7 +164,6 @@ protected:
|
||||
}
|
||||
|
||||
fShift += kShiftPerFrame;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -79,8 +79,6 @@ protected:
|
||||
// now "fling" a random amount
|
||||
fIndex += fRand.nextRangeU(5, 20);
|
||||
fIndex %= fBlobs.count();
|
||||
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -141,17 +141,17 @@ protected:
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
switch (uni) {
|
||||
case '1': fGeom = kRect_Geometry; this->inval(nullptr); return true;
|
||||
case '2': fGeom = kRRect_Geometry; this->inval(nullptr); return true;
|
||||
case '3': fGeom = kCircle_Geometry; this->inval(nullptr); return true;
|
||||
case '4': fGeom = kConvexPath_Geometry; this->inval(nullptr); return true;
|
||||
case '5': fGeom = kConcavePath_Geometry; this->inval(nullptr); return true;
|
||||
case '6': fGeom = kRectAndRect_Geometry; this->inval(nullptr); return true;
|
||||
case '7': fGeom = kRectAndRRect_Geometry; this->inval(nullptr); return true;
|
||||
case '8': fGeom = kRectAndConvex_Geometry; this->inval(nullptr); return true;
|
||||
case '9': fGeom = kRectAndConcave_Geometry; this->inval(nullptr); return true;
|
||||
case 'f': fSign = -fSign; this->inval(nullptr); return true;
|
||||
case 't': fClipFirst = !fClipFirst; this->inval(nullptr); return true;
|
||||
case '1': fGeom = kRect_Geometry; return true;
|
||||
case '2': fGeom = kRRect_Geometry; return true;
|
||||
case '3': fGeom = kCircle_Geometry; return true;
|
||||
case '4': fGeom = kConvexPath_Geometry; return true;
|
||||
case '5': fGeom = kConcavePath_Geometry; return true;
|
||||
case '6': fGeom = kRectAndRect_Geometry; return true;
|
||||
case '7': fGeom = kRectAndRRect_Geometry; return true;
|
||||
case '8': fGeom = kRectAndConvex_Geometry; return true;
|
||||
case '9': fGeom = kRectAndConcave_Geometry; return true;
|
||||
case 'f': fSign = -fSign; return true;
|
||||
case 't': fClipFirst = !fClipFirst; return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -239,8 +239,6 @@ protected:
|
||||
int saveCount = canvas->save();
|
||||
this->drawGeometry(canvas, offset, false);
|
||||
canvas->restoreToCount(saveCount);
|
||||
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
SkMSec GetMSecs() const {
|
||||
|
@ -26,16 +26,6 @@ bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SampleCode::KeyQ(const SkEvent& evt, SkKey* outKey) {
|
||||
if (evt.isType(gKeyEvtName, sizeof(gKeyEvtName) - 1)) {
|
||||
if (outKey) {
|
||||
*outKey = (SkKey)evt.getFast32();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SampleCode::TitleQ(const SkEvent& evt) {
|
||||
return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1);
|
||||
}
|
||||
@ -54,22 +44,6 @@ bool SampleCode::RequestTitle(SkView* view, SkString* title) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SampleCode::PrefSizeQ(const SkEvent& evt) {
|
||||
return evt.isType(gPrefSizeEvtName, sizeof(gPrefSizeEvtName) - 1);
|
||||
}
|
||||
|
||||
void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) {
|
||||
SkASSERT(evt && PrefSizeQ(*evt));
|
||||
SkScalar size[2];
|
||||
size[0] = width;
|
||||
size[1] = height;
|
||||
evt->setScalars(gPrefSizeEvtName, 2, size);
|
||||
}
|
||||
|
||||
bool SampleCode::FastTextQ(const SkEvent& evt) {
|
||||
return evt.isType(gFastTextEvtName, sizeof(gFastTextEvtName) - 1);
|
||||
}
|
||||
|
||||
SkViewRegister* SkViewRegister::gHead;
|
||||
SkViewRegister::SkViewRegister(SkViewFactory* fact) : fFact(fact) {
|
||||
fFact->ref();
|
||||
@ -87,48 +61,21 @@ SkView* SkFuncViewFactory::operator() () const {
|
||||
return (*fCreateFunc)();
|
||||
}
|
||||
|
||||
#include "GMSampleView.h"
|
||||
|
||||
SkGMSampleViewFactory::SkGMSampleViewFactory(GMFactoryFunc func)
|
||||
: fFunc(func) {
|
||||
}
|
||||
|
||||
SkView* SkGMSampleViewFactory::operator() () const {
|
||||
skiagm::GM* gm = fFunc(nullptr);
|
||||
gm->setMode(skiagm::GM::kSample_Mode);
|
||||
return new GMSampleView(gm);
|
||||
}
|
||||
|
||||
SkViewRegister::SkViewRegister(SkViewCreateFunc func) {
|
||||
fFact = new SkFuncViewFactory(func);
|
||||
fChain = gHead;
|
||||
gHead = this;
|
||||
}
|
||||
|
||||
SkViewRegister::SkViewRegister(GMFactoryFunc func) {
|
||||
fFact = new SkGMSampleViewFactory(func);
|
||||
fChain = gHead;
|
||||
gHead = this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char is_sample_view_tag[] = "sample-is-sample-view";
|
||||
static const char repeat_count_tag[] = "sample-set-repeat-count";
|
||||
|
||||
bool SampleView::IsSampleView(SkView* view) {
|
||||
SkEvent evt(is_sample_view_tag);
|
||||
return view->doQuery(&evt);
|
||||
}
|
||||
|
||||
bool SampleView::onEvent(const SkEvent& evt) {
|
||||
if (evt.isType(repeat_count_tag)) {
|
||||
fRepeatCount = evt.getFast32();
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onEvent(evt);
|
||||
}
|
||||
|
||||
bool SampleView::onQuery(SkEvent* evt) {
|
||||
if (evt->isType(is_sample_view_tag)) {
|
||||
return true;
|
||||
@ -143,16 +90,14 @@ void SampleView::onDraw(SkCanvas* canvas) {
|
||||
}
|
||||
this->onDrawBackground(canvas);
|
||||
|
||||
for (int i = 0; i < fRepeatCount; i++) {
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
this->onDrawContent(canvas);
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
this->onDrawContent(canvas);
|
||||
#if SK_SUPPORT_GPU
|
||||
// Ensure the GrContext doesn't combine GrDrawOps across draw loops.
|
||||
if (GrContext* context = canvas->getGrContext()) {
|
||||
context->flush();
|
||||
}
|
||||
#endif
|
||||
// Ensure the GrContext doesn't combine GrDrawOps across draw loops.
|
||||
if (GrContext* context = canvas->getGrContext()) {
|
||||
context->flush();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SampleView::onDrawBackground(SkCanvas* canvas) {
|
||||
|
@ -10,40 +10,25 @@
|
||||
|
||||
#include "SkColor.h"
|
||||
#include "SkEvent.h"
|
||||
#include "SkKey.h"
|
||||
#include "SkView.h"
|
||||
|
||||
class GrContext;
|
||||
class SkAnimTimer;
|
||||
|
||||
#define DEF_SAMPLE(code) \
|
||||
static SkView* SK_MACRO_APPEND_LINE(F_)() { code } \
|
||||
static SkViewRegister SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
|
||||
|
||||
#define MAX_ZOOM_LEVEL 8
|
||||
#define MIN_ZOOM_LEVEL -8
|
||||
|
||||
static const char gCharEvtName[] = "SampleCode_Char_Event";
|
||||
static const char gKeyEvtName[] = "SampleCode_Key_Event";
|
||||
static const char gTitleEvtName[] = "SampleCode_Title_Event";
|
||||
static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event";
|
||||
static const char gFastTextEvtName[] = "SampleCode_FastText_Event";
|
||||
static const char gUpdateWindowTitleEvtName[] = "SampleCode_UpdateWindowTitle";
|
||||
|
||||
class SampleCode {
|
||||
public:
|
||||
static bool KeyQ(const SkEvent&, SkKey* outKey);
|
||||
static bool CharQ(const SkEvent&, SkUnichar* outUni);
|
||||
|
||||
static bool TitleQ(const SkEvent&);
|
||||
static void TitleR(SkEvent*, const char title[]);
|
||||
static bool RequestTitle(SkView* view, SkString* title);
|
||||
|
||||
static bool PrefSizeQ(const SkEvent&);
|
||||
static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height);
|
||||
|
||||
static bool FastTextQ(const SkEvent&);
|
||||
|
||||
friend class SampleWindow;
|
||||
};
|
||||
|
||||
@ -67,29 +52,10 @@ private:
|
||||
SkViewCreateFunc fCreateFunc;
|
||||
};
|
||||
|
||||
namespace skiagm {
|
||||
class GM;
|
||||
}
|
||||
|
||||
// factory function that creates a skiagm::GM
|
||||
typedef skiagm::GM* (*GMFactoryFunc)(void*);
|
||||
|
||||
// Takes a GM factory function and implements the SkViewFactory interface
|
||||
// by making the GM and wrapping it in a GMSampleView. GMSampleView bridges
|
||||
// the SampleView interface to skiagm::GM.
|
||||
class SkGMSampleViewFactory : public SkViewFactory {
|
||||
public:
|
||||
SkGMSampleViewFactory(GMFactoryFunc func);
|
||||
SkView* operator() () const override;
|
||||
private:
|
||||
GMFactoryFunc fFunc;
|
||||
};
|
||||
|
||||
class SkViewRegister : public SkRefCnt {
|
||||
public:
|
||||
explicit SkViewRegister(SkViewFactory*);
|
||||
explicit SkViewRegister(SkViewCreateFunc);
|
||||
explicit SkViewRegister(GMFactoryFunc);
|
||||
|
||||
~SkViewRegister() {
|
||||
fFact->unref();
|
||||
@ -113,7 +79,6 @@ class SampleView : public SkView {
|
||||
public:
|
||||
SampleView()
|
||||
: fBGColor(SK_ColorWHITE)
|
||||
, fRepeatCount(1)
|
||||
, fHaveCalledOnceBeforeDraw(false)
|
||||
{}
|
||||
|
||||
@ -129,14 +94,12 @@ protected:
|
||||
virtual void onOnceBeforeDraw() {}
|
||||
|
||||
// overrides
|
||||
virtual bool onEvent(const SkEvent& evt);
|
||||
virtual bool onQuery(SkEvent* evt);
|
||||
virtual void onDraw(SkCanvas*);
|
||||
|
||||
SkColor fBGColor;
|
||||
|
||||
private:
|
||||
int fRepeatCount;
|
||||
bool fHaveCalledOnceBeforeDraw;
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
@ -134,12 +134,6 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
|
||||
unsigned modi) {
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
@ -159,7 +159,6 @@ protected:
|
||||
draw_sweep(canvas, fBM.width()>>2, fBM.height()>>2, fAngle);
|
||||
|
||||
fAngle += SK_Scalar1/2;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -379,7 +379,6 @@ public:
|
||||
|
||||
void setStyle(FatBits::Style s) {
|
||||
fFB.setStyle(s);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -393,19 +392,15 @@ protected:
|
||||
switch (uni) {
|
||||
case 'c':
|
||||
fFB.setUseClip(!fFB.getUseClip());
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'r':
|
||||
fIsRect = !fIsRect;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'o':
|
||||
fFB.toggleRectAsOval();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'x':
|
||||
fFB.setGrid(!fFB.getGrid());
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 's':
|
||||
if (FatBits::kStroke_Style == fFB.getStyle()) {
|
||||
@ -419,32 +414,25 @@ protected:
|
||||
SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap,
|
||||
};
|
||||
fFB.fStrokeCap = caps[(fFB.fStrokeCap + 1) % 3];
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
} break;
|
||||
case 'a':
|
||||
fFB.setAA(!fFB.getAA());
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'w':
|
||||
fFB.setShowSkeleton(!fFB.getShowSkeleton());
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'g':
|
||||
fFB.togglePixelColors();
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 't':
|
||||
fFB.setTriangle(!fFB.getTriangle());
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case '-':
|
||||
fFB.fStrokeWidth -= 0.125f;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case '=':
|
||||
fFB.fStrokeWidth += 0.125f;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -503,7 +491,6 @@ protected:
|
||||
fPts[1].offset(dx, dy);
|
||||
fPts[2].offset(dx, dy);
|
||||
}
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -805,7 +805,6 @@ protected:
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
do_fuzz(canvas);
|
||||
this->inval(0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -175,11 +175,11 @@ protected:
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
switch (uni) {
|
||||
case '1': fAngle.inc(-ANGLE_DELTA); this->inval(nullptr); return true;
|
||||
case '2': fAngle.inc( ANGLE_DELTA); this->inval(nullptr); return true;
|
||||
case '3': fScale.inc(-SCALE_DELTA); this->inval(nullptr); return true;
|
||||
case '4': fScale.inc( SCALE_DELTA); this->inval(nullptr); return true;
|
||||
case '5': fShowFatBits = !fShowFatBits; this->inval(nullptr); return true;
|
||||
case '1': fAngle.inc(-ANGLE_DELTA); return true;
|
||||
case '2': fAngle.inc( ANGLE_DELTA); return true;
|
||||
case '3': fScale.inc(-SCALE_DELTA); return true;
|
||||
case '4': fScale.inc( SCALE_DELTA); return true;
|
||||
case '5': fShowFatBits = !fShowFatBits; return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -296,11 +296,6 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool handleKey(SkKey key) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
@ -380,7 +380,6 @@ protected:
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
do_fuzz(canvas);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -160,7 +160,6 @@ protected:
|
||||
if (false) { // avoid bit rot, suppress warning
|
||||
test_alphagradients(canvas);
|
||||
}
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -171,7 +171,6 @@ protected:
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->inval(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,6 @@ protected:
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
fDoAA = !fDoAA;
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@ protected:
|
||||
canvas->drawBitmap( fBM, 100, 100, &paint );
|
||||
canvas->restore();
|
||||
canvas->drawString(text, 100, 400, paint );
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "SkTime.h"
|
||||
#include "SkTypeface.h"
|
||||
#include "SkUtils.h"
|
||||
#include "SkKey.h"
|
||||
#include "SkDrawFilter.h"
|
||||
#include "SkClipOpPriv.h"
|
||||
|
||||
@ -191,21 +190,6 @@ protected:
|
||||
test_fade(canvas);
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
this->inval(nullptr);
|
||||
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
return this->INHERITED::onClick(click);
|
||||
}
|
||||
|
||||
virtual bool handleKey(SkKey) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
@ -271,12 +255,10 @@ protected:
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
this->inval(nullptr);
|
||||
return new Click(this);
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
this->inval(nullptr);
|
||||
fCenter = click->fCurr;
|
||||
return this->INHERITED::onClick(click);
|
||||
}
|
||||
|
@ -94,7 +94,6 @@ protected:
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
||||
fAlpha = SkScalarRoundToInt(y);
|
||||
this->inval(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
private:
|
||||
|
@ -62,7 +62,6 @@ protected:
|
||||
canvas->drawRect(rect, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -322,7 +322,6 @@ protected:
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
fPts[((PtClick*)click)->fIndex].set(click->fCurr.fX - DX, click->fCurr.fY - DY);
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,6 @@ protected:
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
fShowHairline = !fShowHairline;
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
@ -248,7 +247,6 @@ public:
|
||||
|
||||
void toggle(bool& value) {
|
||||
value = !value;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -298,7 +296,6 @@ protected:
|
||||
if (click->fMeta.findS32("index", &index)) {
|
||||
SkASSERT((unsigned)index < N);
|
||||
fPts[index] = click->fCurr;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -364,12 +361,10 @@ public:
|
||||
|
||||
void toggle(bool& value) {
|
||||
value = !value;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void toggle3(int& value) {
|
||||
value = (value + 1) % 3;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -388,8 +383,8 @@ protected:
|
||||
case '4': this->toggle3(fJoinType); return true;
|
||||
case '5': this->toggle3(fCapType); return true;
|
||||
case '6': this->toggle(fClosed); return true;
|
||||
case '-': fWidth -= 5; this->inval(nullptr); return true;
|
||||
case '=': fWidth += 5; this->inval(nullptr); return true;
|
||||
case '-': fWidth -= 5; return true;
|
||||
case '=': fWidth += 5; return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -435,7 +430,6 @@ protected:
|
||||
if (click->fMeta.findS32("index", &index)) {
|
||||
SkASSERT((unsigned)index < N);
|
||||
fPts[index] = click->fCurr;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -61,7 +61,6 @@ protected:
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
fCenter.set(click->fCurr.fX, click->fCurr.fY);
|
||||
this->inval(nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -307,7 +306,6 @@ protected:
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
((MyClick*)click)->handleMove();
|
||||
this->inval(nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,6 @@ private:
|
||||
} else {
|
||||
fTrail.push_back('X');
|
||||
}
|
||||
this->inval(nullptr);
|
||||
}
|
||||
return true;
|
||||
case 'x':
|
||||
@ -104,7 +103,6 @@ private:
|
||||
fTossedPaths.reset(fPaths.begin() + midpt, fPaths.count() - midpt);
|
||||
fPaths.resize_back(midpt);
|
||||
fTrail.push_back('x');
|
||||
this->inval(nullptr);
|
||||
}
|
||||
return true;
|
||||
case 'Z': {
|
||||
@ -117,7 +115,6 @@ private:
|
||||
ch = fTrail.back();
|
||||
fTrail.pop_back();
|
||||
} while (ch != 'x');
|
||||
this->inval(nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -686,7 +686,6 @@ protected:
|
||||
path_fuzz_stroker(&offscreen, fIndex += 100);
|
||||
canvas->drawBitmap(offscreen, 0, 0);
|
||||
}
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -43,27 +43,21 @@ class OverstrokeView : public SampleView {
|
||||
switch (uni) {
|
||||
case ',':
|
||||
fStroke += 1.0;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case '.':
|
||||
fStroke -= 1.0;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'x':
|
||||
fPathType = (fPathType + 1) % 4;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'c':
|
||||
fClosePath = !fClosePath;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'f':
|
||||
fDrawFillPath = !fDrawFillPath;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
case 'D':
|
||||
fDumpHex = !fDumpHex;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
|
@ -58,7 +58,6 @@ public:
|
||||
if (SampleCode::CharQ(*evt, &unichar)) {
|
||||
if (unichar == 'X') {
|
||||
fDoClip = !fDoClip;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,6 @@ protected:
|
||||
default:
|
||||
fText.appendUnichar(uni);
|
||||
}
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
@ -697,7 +696,6 @@ protected:
|
||||
draw_button(canvas, fRRectButton);
|
||||
draw_button(canvas, fCircleButton);
|
||||
draw_button(canvas, fTextButton);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
class MyClick : public Click {
|
||||
@ -771,7 +769,6 @@ protected:
|
||||
if (index < (int) SK_ARRAY_COUNT(fPts)) {
|
||||
fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX),
|
||||
SkIntToScalar(click->fICurr.fY - click->fIPrev.fY));
|
||||
this->inval(nullptr);
|
||||
} else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) {
|
||||
fWeight = MapScreenYtoValue(click->fICurr.fY, fWeightControl, 0, 5);
|
||||
} else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) {
|
||||
|
@ -126,8 +126,6 @@ protected:
|
||||
|
||||
str.printf("Press \'h\' to toggle rects");
|
||||
canvas->drawString(str, 50, kHeight + 150, blackBigFont);
|
||||
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -395,7 +395,6 @@ protected:
|
||||
bool onClick(Click* click) override {
|
||||
fRect.offset(click->fICurr.fX - click->fIPrev.fX,
|
||||
click->fICurr.fY - click->fIPrev.fY);
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "SkView.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkShader.h"
|
||||
#include "SkKey.h"
|
||||
|
||||
static void make_bitmap(SkBitmap* bm) {
|
||||
const int W = 100;
|
||||
@ -64,21 +63,6 @@ protected:
|
||||
canvas->drawPaint(paint);
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
this->inval(nullptr);
|
||||
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
return this->INHERITED::onClick(click);
|
||||
}
|
||||
|
||||
virtual bool handleKey(SkKey) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
@ -100,15 +100,6 @@ protected:
|
||||
canvas->drawRect(r, paint);
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
return this->INHERITED::onClick(click);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
@ -89,7 +89,6 @@ protected:
|
||||
break;
|
||||
}
|
||||
if (handled) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ protected:
|
||||
break;
|
||||
}
|
||||
if (handled) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,6 @@ protected:
|
||||
break;
|
||||
}
|
||||
if (handled) {
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -151,8 +151,6 @@ protected:
|
||||
canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint);
|
||||
paint.setColor(SK_ColorWHITE);
|
||||
canvas->drawString(outString, 5, 15, paint);
|
||||
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -702,7 +702,6 @@ protected:
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
||||
this->init();
|
||||
fIndex = (fIndex + 1) % SK_ARRAY_COUNT(gProc);
|
||||
this->inval(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,6 @@ protected:
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
||||
fAngle = x/width();
|
||||
this->inval(nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
private:
|
||||
|
@ -205,11 +205,6 @@ protected:
|
||||
drawSet(canvas, &paint);
|
||||
}
|
||||
|
||||
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
|
||||
unsigned modi) override {
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
private:
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
@ -100,7 +100,6 @@ protected:
|
||||
|
||||
fCurPos.fX += fHorizontalVelocity;
|
||||
fCurPos.fY += fVerticalVelocity;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -148,7 +148,6 @@ protected:
|
||||
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
|
||||
unsigned modi) override {
|
||||
fClickX = x;
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,6 @@ protected:
|
||||
y = 255;
|
||||
}
|
||||
fByte = y;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "SkTextBox.h"
|
||||
#include "SkOSFile.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkKey.h"
|
||||
|
||||
extern void skia_set_text_gamma(float blackGamma, float whiteGamma);
|
||||
|
||||
|
@ -143,21 +143,13 @@ protected:
|
||||
|
||||
canvas->translate(SkIntToScalar(-275), SkIntToScalar(250));
|
||||
textPathMatrix(canvas);
|
||||
|
||||
if (REPEAT_COUNT > 1)
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
fHints += 1;
|
||||
this->inval(nullptr);
|
||||
return this->INHERITED::onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
return this->INHERITED::onClick(click);
|
||||
}
|
||||
|
||||
private:
|
||||
int fHints;
|
||||
typedef SampleView INHERITED;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "SkOSPath.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkString.h"
|
||||
#include "SkSystemEventTypes.h"
|
||||
#include "SkTypes.h"
|
||||
#include "SkUtils.h"
|
||||
#include "SkView.h"
|
||||
@ -164,7 +163,6 @@ private:
|
||||
return;
|
||||
}
|
||||
fDecodeSucceeded = decode_file(fCurrFile.c_str(), &fBitmap, kN32_SkColorType, !fPremul);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void togglePremul() {
|
||||
|
@ -113,7 +113,6 @@ protected:
|
||||
bool onClick(Click* click) override {
|
||||
// fCurrX = click->fICurr.fX;
|
||||
// fCurrY = click->fICurr.fY;
|
||||
this->inval(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -32,64 +32,36 @@ const int N_Modes = SK_ARRAY_COUNT(gModes);
|
||||
|
||||
static SkRandom gRand;
|
||||
|
||||
class PushButtonWig : public SkView {
|
||||
struct ModeButton {
|
||||
SkString fLabel;
|
||||
SkColor fColor;
|
||||
uint32_t fFast32;
|
||||
SkRect fRect;
|
||||
|
||||
public:
|
||||
PushButtonWig(const char label[], uint32_t fast) : fLabel(label) {
|
||||
void init(const char label[], const SkRect& rect) {
|
||||
fLabel = label;
|
||||
fRect = rect;
|
||||
fColor = (gRand.nextU() & 0x7F7F7F7F) | SkColorSetARGB(0xFF, 0, 0, 0x80);
|
||||
fFast32 = fast;
|
||||
}
|
||||
|
||||
void postWidgetEvent() {
|
||||
SkEvent evt;
|
||||
evt.setType("push-button");
|
||||
evt.setFast32(fFast32);
|
||||
evt.setString("label", fLabel.c_str());
|
||||
this->sendEventToParents(evt);
|
||||
}
|
||||
|
||||
protected:
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkRect r;
|
||||
this->getLocalBounds(&r);
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColor(fColor);
|
||||
canvas->drawRoundRect(r, 8, 8, paint);
|
||||
canvas->drawRoundRect(fRect, 8, 8, paint);
|
||||
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
paint.setTextSize(16);
|
||||
paint.setTextAlign(SkPaint::kCenter_Align);
|
||||
paint.setLCDRenderText(true);
|
||||
canvas->drawString(fLabel, r.centerX(), r.fTop + 0.68f * r.height(), paint);
|
||||
canvas->drawString(fLabel, fRect.centerX(), fRect.fTop + 0.68f * fRect.height(), paint);
|
||||
}
|
||||
|
||||
Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
||||
return new Click(this);
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
SkRect target = SkRect::MakeXYWH(click->fCurr.x() - 1, click->fCurr.y() - 1, 3, 3);
|
||||
SkRect r;
|
||||
this->getLocalBounds(&r);
|
||||
if (r.intersects(target)) {
|
||||
fColor = SkColorSetA(fColor, 0x99);
|
||||
} else {
|
||||
fColor = SkColorSetA(fColor, 0xFF);
|
||||
}
|
||||
this->inval(nullptr);
|
||||
|
||||
if (click->fState == SkView::Click::kUp_State) {
|
||||
this->postWidgetEvent();
|
||||
}
|
||||
return true;
|
||||
bool hitTest(SkScalar x, SkScalar y) {
|
||||
return fRect.intersects(x - 1, y - 1, x + 1, y + 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ModeDrawable : public SkDrawable {
|
||||
public:
|
||||
ModeDrawable() : fMode(SkBlendMode::kSrcOver), fLoc(SkPoint::Make(0, 0)) {}
|
||||
@ -136,6 +108,7 @@ class XferDemo : public SampleView {
|
||||
};
|
||||
|
||||
SkRect fModeRect[N_Modes];
|
||||
ModeButton fModeButtons[N_Modes];
|
||||
sk_sp<CircDrawable> fDrs[N];
|
||||
CircDrawable* fSelected;
|
||||
|
||||
@ -143,12 +116,7 @@ class XferDemo : public SampleView {
|
||||
SkScalar x = 10;
|
||||
SkScalar y = 10;
|
||||
for (int i = 0; i < N_Modes; ++i) {
|
||||
sk_sp<SkView> v(new PushButtonWig(SkBlendMode_Name(gModes[i]), (int)gModes[i]));
|
||||
v->setSize(70, 25);
|
||||
v->setLoc(x, y);
|
||||
v->setVisibleP(true);
|
||||
v->setEnabledP(true);
|
||||
this->attachChildToFront(v.get());
|
||||
fModeButtons[i].init(SkBlendMode_Name(gModes[i]), SkRect::MakeXYWH(x, y, 70, 25));
|
||||
fModeRect[i] = SkRect::MakeXYWH(x, y + 28, 70, 2);
|
||||
x += 80;
|
||||
}
|
||||
@ -168,17 +136,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
bool onEvent(const SkEvent& evt) override {
|
||||
if (evt.isType("push-button")) {
|
||||
if (fSelected) {
|
||||
fSelected->fMode = (SkBlendMode)evt.getFast32();
|
||||
this->inval(nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onEvent(evt);
|
||||
}
|
||||
|
||||
bool onQuery(SkEvent* evt) override {
|
||||
if (SampleCode::TitleQ(*evt)) {
|
||||
SampleCode::TitleR(evt, "XferDemo");
|
||||
@ -188,6 +145,10 @@ protected:
|
||||
}
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
for (int i = 0; i < N_Modes; ++i) {
|
||||
fModeButtons[i].draw(canvas);
|
||||
}
|
||||
|
||||
SkPaint paint;
|
||||
if (fSelected) {
|
||||
for (int i = 0; i < N_Modes; ++i) {
|
||||
@ -206,6 +167,14 @@ protected:
|
||||
}
|
||||
|
||||
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
||||
// Check mode buttons first
|
||||
for (int i = 0; i < N_Modes; ++i) {
|
||||
if (fModeButtons[i].hitTest(x, y)) {
|
||||
Click* click = new Click(this);
|
||||
click->fMeta.setS32("mode", i);
|
||||
return click;
|
||||
}
|
||||
}
|
||||
fSelected = nullptr;
|
||||
for (int i = N - 1; i >= 0; --i) {
|
||||
if (fDrs[i]->hitTest(x, y)) {
|
||||
@ -213,14 +182,19 @@ protected:
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->inval(nullptr);
|
||||
return fSelected ? new Click(this) : nullptr;
|
||||
}
|
||||
|
||||
bool onClick(Click* click) override {
|
||||
fSelected->fLoc.fX += click->fCurr.fX - click->fPrev.fX;
|
||||
fSelected->fLoc.fY += click->fCurr.fY - click->fPrev.fY;
|
||||
this->inval(nullptr);
|
||||
int32_t mode;
|
||||
if (click->fMeta.findS32("mode", &mode)) {
|
||||
if (fSelected && Click::kUp_State == click->fState) {
|
||||
fSelected->fMode = gModes[mode];
|
||||
}
|
||||
} else {
|
||||
fSelected->fLoc.fX += click->fCurr.fX - click->fPrev.fX;
|
||||
fSelected->fLoc.fY += click->fCurr.fY - click->fPrev.fY;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5,18 +5,12 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "SkDOM.h"
|
||||
#include "SkEvent.h"
|
||||
|
||||
void SkEvent::initialize(const char* type, size_t typeLen) {
|
||||
fType = nullptr;
|
||||
setType(type, typeLen);
|
||||
f32 = 0;
|
||||
#ifdef SK_DEBUG
|
||||
fTime = 0;
|
||||
fNextEvent = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
SkEvent::SkEvent()
|
||||
@ -113,132 +107,3 @@ void SkEvent::setType(const SkString& type)
|
||||
{
|
||||
setType(type.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkParse.h"
|
||||
|
||||
void SkEvent::inflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
const char* name = dom.findAttr(node, "type");
|
||||
if (name)
|
||||
this->setType(name);
|
||||
|
||||
const char* value;
|
||||
if ((value = dom.findAttr(node, "fast32")) != nullptr)
|
||||
{
|
||||
int32_t n;
|
||||
if (SkParse::FindS32(value, &n))
|
||||
this->setFast32(n);
|
||||
}
|
||||
|
||||
for (node = dom.getFirstChild(node); node; node = dom.getNextSibling(node))
|
||||
{
|
||||
if (strcmp(dom.getName(node), "data"))
|
||||
{
|
||||
SkDEBUGCODE(SkDebugf("SkEvent::inflate unrecognized subelement <%s>\n", dom.getName(node));)
|
||||
continue;
|
||||
}
|
||||
|
||||
name = dom.findAttr(node, "name");
|
||||
if (name == nullptr)
|
||||
{
|
||||
SkDEBUGCODE(SkDebugf("SkEvent::inflate missing required \"name\" attribute in <data> subelement\n");)
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((value = dom.findAttr(node, "s32")) != nullptr)
|
||||
{
|
||||
int32_t n;
|
||||
if (SkParse::FindS32(value, &n))
|
||||
this->setS32(name, n);
|
||||
}
|
||||
else if ((value = dom.findAttr(node, "scalar")) != nullptr)
|
||||
{
|
||||
SkScalar x;
|
||||
if (SkParse::FindScalar(value, &x))
|
||||
this->setScalar(name, x);
|
||||
}
|
||||
else if ((value = dom.findAttr(node, "string")) != nullptr)
|
||||
this->setString(name, value);
|
||||
#ifdef SK_DEBUG
|
||||
else
|
||||
{
|
||||
SkDebugf("SkEvent::inflate <data name=\"%s\"> subelement missing required type attribute [S32 | scalar | string]\n", name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
|
||||
#ifndef SkScalarToFloat
|
||||
#define SkScalarToFloat(x) ((x) / 65536.f)
|
||||
#endif
|
||||
|
||||
void SkEvent::dump(const char title[])
|
||||
{
|
||||
if (title)
|
||||
SkDebugf("%s ", title);
|
||||
|
||||
SkString etype;
|
||||
this->getType(&etype);
|
||||
SkDebugf("event<%s> fast32=%d", etype.c_str(), this->getFast32());
|
||||
|
||||
const SkMetaData& md = this->getMetaData();
|
||||
SkMetaData::Iter iter(md);
|
||||
SkMetaData::Type mtype;
|
||||
int count;
|
||||
const char* name;
|
||||
|
||||
while ((name = iter.next(&mtype, &count)) != nullptr)
|
||||
{
|
||||
SkASSERT(count > 0);
|
||||
|
||||
SkDebugf(" <%s>=", name);
|
||||
switch (mtype) {
|
||||
case SkMetaData::kS32_Type: // vector version???
|
||||
{
|
||||
int32_t value;
|
||||
md.findS32(name, &value);
|
||||
SkDebugf("%d ", value);
|
||||
}
|
||||
break;
|
||||
case SkMetaData::kScalar_Type:
|
||||
{
|
||||
const SkScalar* values = md.findScalars(name, &count, nullptr);
|
||||
SkDebugf("%f", SkScalarToFloat(values[0]));
|
||||
for (int i = 1; i < count; i++)
|
||||
SkDebugf(", %f", SkScalarToFloat(values[i]));
|
||||
SkDebugf(" ");
|
||||
}
|
||||
break;
|
||||
case SkMetaData::kString_Type:
|
||||
{
|
||||
const char* value = md.findString(name);
|
||||
SkASSERT(value);
|
||||
SkDebugf("<%s> ", value);
|
||||
}
|
||||
break;
|
||||
case SkMetaData::kPtr_Type: // vector version???
|
||||
{
|
||||
void* value;
|
||||
md.findPtr(name, &value);
|
||||
SkDebugf("%p ", value);
|
||||
}
|
||||
break;
|
||||
case SkMetaData::kBool_Type: // vector version???
|
||||
{
|
||||
bool value;
|
||||
md.findBool(name, &value);
|
||||
SkDebugf("%s ", value ? "true" : "false");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
SkDEBUGFAIL("unknown metadata type returned from iterator");
|
||||
break;
|
||||
}
|
||||
}
|
||||
SkDebugf("\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "SkView.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDOM.h"
|
||||
|
||||
static inline uint32_t SkSetClearShift(uint32_t bits, bool cond, unsigned shift) {
|
||||
SkASSERT((int)cond == 0 || (int)cond == 1);
|
||||
@ -18,29 +17,13 @@ static inline uint32_t SkSetClearShift(uint32_t bits, bool cond, unsigned shift)
|
||||
|
||||
SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) {
|
||||
fWidth = fHeight = 0;
|
||||
fLoc.set(0, 0);
|
||||
fParent = fFirstChild = fNextSibling = fPrevSibling = nullptr;
|
||||
fMatrix.setIdentity();
|
||||
fContainsFocus = 0;
|
||||
}
|
||||
|
||||
SkView::~SkView() {
|
||||
this->detachAllChildren();
|
||||
}
|
||||
SkView::~SkView() {}
|
||||
|
||||
void SkView::setFlags(uint32_t flags) {
|
||||
SkASSERT((flags & ~kAllFlagMasks) == 0);
|
||||
|
||||
uint32_t diff = fFlags ^ flags;
|
||||
|
||||
if (diff & kVisible_Mask)
|
||||
this->inval(nullptr);
|
||||
|
||||
fFlags = SkToU8(flags);
|
||||
|
||||
if (diff & kVisible_Mask) {
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SkView::setVisibleP(bool pred) {
|
||||
@ -65,37 +48,16 @@ void SkView::setSize(SkScalar width, SkScalar height) {
|
||||
|
||||
if (fWidth != width || fHeight != height)
|
||||
{
|
||||
this->inval(nullptr);
|
||||
fWidth = width;
|
||||
fHeight = height;
|
||||
this->inval(nullptr);
|
||||
this->onSizeChange();
|
||||
}
|
||||
}
|
||||
|
||||
void SkView::setLoc(SkScalar x, SkScalar y) {
|
||||
if (fLoc.fX != x || fLoc.fY != y) {
|
||||
this->inval(nullptr);
|
||||
fLoc.set(x, y);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SkView::offset(SkScalar dx, SkScalar dy) {
|
||||
if (dx || dy)
|
||||
this->setLoc(fLoc.fX + dx, fLoc.fY + dy);
|
||||
}
|
||||
|
||||
void SkView::setLocalMatrix(const SkMatrix& matrix) {
|
||||
this->inval(nullptr);
|
||||
fMatrix = matrix;
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void SkView::draw(SkCanvas* canvas) {
|
||||
if (fWidth && fHeight && this->isVisible()) {
|
||||
SkRect r;
|
||||
r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight);
|
||||
r.set(0, 0, fWidth, fHeight);
|
||||
if (this->isClipToBounds() && canvas->quickReject(r)) {
|
||||
return;
|
||||
}
|
||||
@ -106,269 +68,26 @@ void SkView::draw(SkCanvas* canvas) {
|
||||
canvas->clipRect(r);
|
||||
}
|
||||
|
||||
canvas->translate(fLoc.fX, fLoc.fY);
|
||||
canvas->concat(fMatrix);
|
||||
|
||||
if (fParent) {
|
||||
fParent->beforeChild(this, canvas);
|
||||
}
|
||||
|
||||
int sc = canvas->save();
|
||||
this->onDraw(canvas);
|
||||
canvas->restoreToCount(sc);
|
||||
|
||||
if (fParent) {
|
||||
fParent->afterChild(this, canvas);
|
||||
}
|
||||
|
||||
B2FIter iter(this);
|
||||
SkView* child;
|
||||
|
||||
SkCanvas* childCanvas = this->beforeChildren(canvas);
|
||||
|
||||
while ((child = iter.next()) != nullptr)
|
||||
child->draw(childCanvas);
|
||||
|
||||
this->afterChildren(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
void SkView::inval(SkRect* rect) {
|
||||
SkView* view = this;
|
||||
SkRect storage;
|
||||
|
||||
for (;;) {
|
||||
if (!view->isVisible()) {
|
||||
return;
|
||||
}
|
||||
if (view->isClipToBounds()) {
|
||||
SkRect bounds;
|
||||
view->getLocalBounds(&bounds);
|
||||
if (rect && !bounds.intersect(*rect)) {
|
||||
return;
|
||||
}
|
||||
storage = bounds;
|
||||
rect = &storage;
|
||||
}
|
||||
if (view->handleInval(rect)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkView* parent = view->fParent;
|
||||
if (parent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rect) {
|
||||
rect->offset(view->fLoc.fX, view->fLoc.fY);
|
||||
}
|
||||
view = parent;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SkView::setFocusView(SkView* fv) {
|
||||
SkView* view = this;
|
||||
|
||||
do {
|
||||
if (view->onSetFocusView(fv)) {
|
||||
return true;
|
||||
}
|
||||
} while ((view = view->fParent) != nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
SkView* SkView::getFocusView() const {
|
||||
SkView* focus = nullptr;
|
||||
const SkView* view = this;
|
||||
do {
|
||||
if (view->onGetFocusView(&focus)) {
|
||||
break;
|
||||
}
|
||||
} while ((view = view->fParent) != nullptr);
|
||||
return focus;
|
||||
}
|
||||
|
||||
bool SkView::hasFocus() const {
|
||||
return this == this->getFocusView();
|
||||
}
|
||||
|
||||
bool SkView::acceptFocus() {
|
||||
return this->isFocusable() && this->setFocusView(this);
|
||||
}
|
||||
|
||||
/*
|
||||
Try to give focus to this view, or its children
|
||||
*/
|
||||
SkView* SkView::acceptFocus(FocusDirection dir) {
|
||||
if (dir == kNext_FocusDirection) {
|
||||
if (this->acceptFocus()) {
|
||||
return this;
|
||||
}
|
||||
B2FIter iter(this);
|
||||
SkView* child, *focus;
|
||||
while ((child = iter.next()) != nullptr) {
|
||||
if ((focus = child->acceptFocus(dir)) != nullptr) {
|
||||
return focus;
|
||||
}
|
||||
}
|
||||
} else { // prev
|
||||
F2BIter iter(this);
|
||||
SkView* child, *focus;
|
||||
while ((child = iter.next()) != nullptr) {
|
||||
if ((focus = child->acceptFocus(dir)) != nullptr) {
|
||||
return focus;
|
||||
}
|
||||
}
|
||||
if (this->acceptFocus()) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkView* SkView::moveFocus(FocusDirection dir) {
|
||||
SkView* focus = this->getFocusView();
|
||||
|
||||
if (focus == nullptr) { // start with the root
|
||||
focus = this;
|
||||
while (focus->fParent) {
|
||||
focus = focus->fParent;
|
||||
}
|
||||
}
|
||||
|
||||
SkView* child, *parent;
|
||||
|
||||
if (dir == kNext_FocusDirection) {
|
||||
parent = focus;
|
||||
child = focus->fFirstChild;
|
||||
if (child)
|
||||
goto FIRST_CHILD;
|
||||
else
|
||||
goto NEXT_SIB;
|
||||
|
||||
do {
|
||||
while (child != parent->fFirstChild) {
|
||||
FIRST_CHILD:
|
||||
if ((focus = child->acceptFocus(dir)) != nullptr)
|
||||
return focus;
|
||||
child = child->fNextSibling;
|
||||
}
|
||||
NEXT_SIB:
|
||||
child = parent->fNextSibling;
|
||||
parent = parent->fParent;
|
||||
} while (parent != nullptr);
|
||||
} else { // prevfocus
|
||||
parent = focus->fParent;
|
||||
if (parent == nullptr) { // we're the root
|
||||
return focus->acceptFocus(dir);
|
||||
} else {
|
||||
child = focus;
|
||||
while (parent) {
|
||||
while (child != parent->fFirstChild) {
|
||||
child = child->fPrevSibling;
|
||||
if ((focus = child->acceptFocus(dir)) != nullptr) {
|
||||
return focus;
|
||||
}
|
||||
}
|
||||
if (parent->acceptFocus()) {
|
||||
return parent;
|
||||
}
|
||||
child = parent;
|
||||
parent = parent->fParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SkView::onFocusChange(bool gainFocusP) {
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkView::Click::Click(SkView* target) {
|
||||
SkASSERT(target);
|
||||
fTargetID = target->getSinkID();
|
||||
fType = nullptr;
|
||||
fWeOwnTheType = false;
|
||||
fOwner = nullptr;
|
||||
}
|
||||
|
||||
SkView::Click::~Click() {
|
||||
this->resetType();
|
||||
}
|
||||
|
||||
void SkView::Click::resetType() {
|
||||
if (fWeOwnTheType) {
|
||||
sk_free(fType);
|
||||
fWeOwnTheType = false;
|
||||
}
|
||||
fType = nullptr;
|
||||
}
|
||||
|
||||
bool SkView::Click::isType(const char type[]) const {
|
||||
const char* t = fType;
|
||||
|
||||
if (type == t) {
|
||||
return true;
|
||||
}
|
||||
if (type == nullptr) {
|
||||
type = "";
|
||||
}
|
||||
if (t == nullptr) {
|
||||
t = "";
|
||||
}
|
||||
return !strcmp(t, type);
|
||||
}
|
||||
|
||||
void SkView::Click::setType(const char type[]) {
|
||||
this->resetType();
|
||||
fType = (char*)type;
|
||||
}
|
||||
|
||||
void SkView::Click::copyType(const char type[]) {
|
||||
if (fType != type) {
|
||||
this->resetType();
|
||||
if (type) {
|
||||
size_t len = strlen(type) + 1;
|
||||
fType = (char*)sk_malloc_throw(len);
|
||||
memcpy(fType, type, len);
|
||||
fWeOwnTheType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
SkView::Click::~Click() {}
|
||||
|
||||
SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) {
|
||||
if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->onSendClickToChildren(x, y, modi)) {
|
||||
F2BIter iter(this);
|
||||
SkView* child;
|
||||
|
||||
while ((child = iter.next()) != nullptr) {
|
||||
SkPoint p;
|
||||
#if 0
|
||||
if (!child->globalToLocal(x, y, &p)) {
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
// the above seems broken, so just respecting fLoc for now <reed>
|
||||
p.set(x - child->fLoc.x(), y - child->fLoc.y());
|
||||
#endif
|
||||
|
||||
Click* click = child->findClickHandler(p.fX, p.fY, modi);
|
||||
|
||||
if (click) {
|
||||
return click;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this->onFindClickHandler(x, y, modi);
|
||||
}
|
||||
|
||||
@ -384,10 +103,6 @@ void SkView::DoClickDown(Click* click, int x, int y, unsigned modi) {
|
||||
click->fICurr = click->fIPrev = click->fIOrig;
|
||||
|
||||
click->fOrig.iset(x, y);
|
||||
if (!target->globalToLocal(&click->fOrig)) {
|
||||
// no history to let us recover from this failure
|
||||
return;
|
||||
}
|
||||
click->fPrev = click->fCurr = click->fOrig;
|
||||
|
||||
click->fState = Click::kDown_State;
|
||||
@ -408,10 +123,6 @@ void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) {
|
||||
|
||||
click->fPrev = click->fCurr;
|
||||
click->fCurr.iset(x, y);
|
||||
if (!target->globalToLocal(&click->fCurr)) {
|
||||
// on failure pretend the mouse didn't move
|
||||
click->fCurr = click->fPrev;
|
||||
}
|
||||
|
||||
click->fState = Click::kMoved_State;
|
||||
click->fModifierKeys = modi;
|
||||
@ -431,10 +142,6 @@ void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) {
|
||||
|
||||
click->fPrev = click->fCurr;
|
||||
click->fCurr.iset(x, y);
|
||||
if (!target->globalToLocal(&click->fCurr)) {
|
||||
// on failure pretend the mouse didn't move
|
||||
click->fCurr = click->fPrev;
|
||||
}
|
||||
|
||||
click->fState = Click::kUp_State;
|
||||
click->fModifierKeys = modi;
|
||||
@ -447,10 +154,6 @@ void SkView::onDraw(SkCanvas* canvas) {}
|
||||
|
||||
void SkView::onSizeChange() {}
|
||||
|
||||
bool SkView::onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) {
|
||||
return true;
|
||||
}
|
||||
|
||||
SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -458,323 +161,3 @@ SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi)
|
||||
bool SkView::onClick(Click*) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkView::handleInval(const SkRect*) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkView::getLocalBounds(SkRect* bounds) const {
|
||||
if (bounds) {
|
||||
bounds->set(0, 0, fWidth, fHeight);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkView::detachFromParent_NoLayout() {
|
||||
this->validate();
|
||||
if (fParent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fContainsFocus) {
|
||||
(void)this->setFocusView(nullptr);
|
||||
}
|
||||
|
||||
this->inval(nullptr);
|
||||
|
||||
SkView* next = nullptr;
|
||||
|
||||
if (fNextSibling != this) { // do we have any siblings
|
||||
fNextSibling->fPrevSibling = fPrevSibling;
|
||||
fPrevSibling->fNextSibling = fNextSibling;
|
||||
next = fNextSibling;
|
||||
}
|
||||
|
||||
if (fParent->fFirstChild == this) {
|
||||
fParent->fFirstChild = next;
|
||||
}
|
||||
|
||||
fParent = fNextSibling = fPrevSibling = nullptr;
|
||||
|
||||
this->validate();
|
||||
this->unref();
|
||||
}
|
||||
|
||||
void SkView::detachFromParent() {
|
||||
this->validate();
|
||||
SkView* parent = fParent;
|
||||
|
||||
if (parent) {
|
||||
this->detachFromParent_NoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
SkView* SkView::attachChildToBack(SkView* child) {
|
||||
this->validate();
|
||||
SkASSERT(child != this);
|
||||
|
||||
if (child == nullptr || fFirstChild == child)
|
||||
goto DONE;
|
||||
|
||||
child->ref();
|
||||
child->detachFromParent_NoLayout();
|
||||
|
||||
if (fFirstChild == nullptr) {
|
||||
child->fNextSibling = child;
|
||||
child->fPrevSibling = child;
|
||||
} else {
|
||||
child->fNextSibling = fFirstChild;
|
||||
child->fPrevSibling = fFirstChild->fPrevSibling;
|
||||
fFirstChild->fPrevSibling->fNextSibling = child;
|
||||
fFirstChild->fPrevSibling = child;
|
||||
}
|
||||
|
||||
fFirstChild = child;
|
||||
child->fParent = this;
|
||||
child->inval(nullptr);
|
||||
|
||||
this->validate();
|
||||
DONE:
|
||||
return child;
|
||||
}
|
||||
|
||||
SkView* SkView::attachChildToFront(SkView* child) {
|
||||
this->validate();
|
||||
SkASSERT(child != this);
|
||||
|
||||
if (child == nullptr || (fFirstChild && fFirstChild->fPrevSibling == child))
|
||||
goto DONE;
|
||||
|
||||
child->ref();
|
||||
child->detachFromParent_NoLayout();
|
||||
|
||||
if (fFirstChild == nullptr) {
|
||||
fFirstChild = child;
|
||||
child->fNextSibling = child;
|
||||
child->fPrevSibling = child;
|
||||
} else {
|
||||
child->fNextSibling = fFirstChild;
|
||||
child->fPrevSibling = fFirstChild->fPrevSibling;
|
||||
fFirstChild->fPrevSibling->fNextSibling = child;
|
||||
fFirstChild->fPrevSibling = child;
|
||||
}
|
||||
|
||||
child->fParent = this;
|
||||
child->inval(nullptr);
|
||||
|
||||
this->validate();
|
||||
DONE:
|
||||
return child;
|
||||
}
|
||||
|
||||
void SkView::detachAllChildren() {
|
||||
this->validate();
|
||||
while (fFirstChild)
|
||||
fFirstChild->detachFromParent_NoLayout();
|
||||
}
|
||||
|
||||
void SkView::localToGlobal(SkMatrix* matrix) const {
|
||||
if (matrix) {
|
||||
matrix->reset();
|
||||
const SkView* view = this;
|
||||
while (view)
|
||||
{
|
||||
matrix->preConcat(view->getLocalMatrix());
|
||||
matrix->preTranslate(-view->fLoc.fX, -view->fLoc.fY);
|
||||
view = view->fParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const {
|
||||
if (local) {
|
||||
SkMatrix m;
|
||||
this->localToGlobal(&m);
|
||||
if (!m.invert(&m)) {
|
||||
return false;
|
||||
}
|
||||
SkPoint p;
|
||||
m.mapXY(x, y, &p);
|
||||
local->set(p.fX, p.fY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Even if the subclass overrides onInflate, they should always be
|
||||
sure to call the inherited method, so that we get called.
|
||||
*/
|
||||
void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node) {
|
||||
SkScalar x, y;
|
||||
|
||||
x = this->locX();
|
||||
y = this->locY();
|
||||
(void)dom.findScalar(node, "x", &x);
|
||||
(void)dom.findScalar(node, "y", &y);
|
||||
this->setLoc(x, y);
|
||||
|
||||
x = this->width();
|
||||
y = this->height();
|
||||
(void)dom.findScalar(node, "width", &x);
|
||||
(void)dom.findScalar(node, "height", &y);
|
||||
this->setSize(x, y);
|
||||
|
||||
// inflate the flags
|
||||
|
||||
static const char* gFlagNames[] = {
|
||||
"visible", "enabled", "focusable", "flexH", "flexV"
|
||||
};
|
||||
SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount);
|
||||
|
||||
bool b;
|
||||
uint32_t flags = this->getFlags();
|
||||
for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++) {
|
||||
if (dom.findBool(node, gFlagNames[i], &b)) {
|
||||
flags = SkSetClearShift(flags, b, i);
|
||||
}
|
||||
}
|
||||
this->setFlags(flags);
|
||||
}
|
||||
|
||||
void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node) {
|
||||
this->onInflate(dom, node);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
SkView* SkView::sendEventToParents(const SkEvent& evt) {
|
||||
SkView* parent = fParent;
|
||||
|
||||
while (parent) {
|
||||
if (parent->doEvent(evt)) {
|
||||
return parent;
|
||||
}
|
||||
parent = parent->fParent;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkView* SkView::sendQueryToParents(SkEvent* evt) {
|
||||
SkView* parent = fParent;
|
||||
|
||||
while (parent) {
|
||||
if (parent->doQuery(evt)) {
|
||||
return parent;
|
||||
}
|
||||
parent = parent->fParent;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
SkView::F2BIter::F2BIter(const SkView* parent) {
|
||||
fFirstChild = parent ? parent->fFirstChild : nullptr;
|
||||
fChild = fFirstChild ? fFirstChild->fPrevSibling : nullptr;
|
||||
}
|
||||
|
||||
SkView* SkView::F2BIter::next() {
|
||||
SkView* curr = fChild;
|
||||
|
||||
if (fChild) {
|
||||
if (fChild == fFirstChild) {
|
||||
fChild = nullptr;
|
||||
} else {
|
||||
fChild = fChild->fPrevSibling;
|
||||
}
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
SkView::B2FIter::B2FIter(const SkView* parent) {
|
||||
fFirstChild = parent ? parent->fFirstChild : nullptr;
|
||||
fChild = fFirstChild;
|
||||
}
|
||||
|
||||
SkView* SkView::B2FIter::next() {
|
||||
SkView* curr = fChild;
|
||||
|
||||
if (fChild) {
|
||||
SkView* next = fChild->fNextSibling;
|
||||
if (next == fFirstChild)
|
||||
next = nullptr;
|
||||
fChild = next;
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
|
||||
void SkView::validate() const {
|
||||
// SkASSERT(this->getRefCnt() > 0 && this->getRefCnt() < 100);
|
||||
if (fParent) {
|
||||
SkASSERT(fNextSibling);
|
||||
SkASSERT(fPrevSibling);
|
||||
} else {
|
||||
bool nextNull = nullptr == fNextSibling;
|
||||
bool prevNull = nullptr == fNextSibling;
|
||||
SkASSERT(nextNull == prevNull);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void show_if_nonzero(const char name[], SkScalar value) {
|
||||
if (value) {
|
||||
SkDebugf("%s=\"%g\"", name, value/65536.);
|
||||
}
|
||||
}
|
||||
|
||||
static void tab(int level) {
|
||||
for (int i = 0; i < level; i++) {
|
||||
SkDebugf(" ");
|
||||
}
|
||||
}
|
||||
|
||||
static void dumpview(const SkView* view, int level, bool recurse) {
|
||||
tab(level);
|
||||
|
||||
SkDebugf("<view");
|
||||
show_if_nonzero(" x", view->locX());
|
||||
show_if_nonzero(" y", view->locY());
|
||||
show_if_nonzero(" width", view->width());
|
||||
show_if_nonzero(" height", view->height());
|
||||
|
||||
if (recurse) {
|
||||
SkView::B2FIter iter(view);
|
||||
SkView* child;
|
||||
bool noChildren = true;
|
||||
|
||||
while ((child = iter.next()) != nullptr) {
|
||||
if (noChildren) {
|
||||
SkDebugf(">\n");
|
||||
}
|
||||
noChildren = false;
|
||||
dumpview(child, level + 1, true);
|
||||
}
|
||||
|
||||
if (!noChildren) {
|
||||
tab(level);
|
||||
SkDebugf("</view>\n");
|
||||
} else {
|
||||
goto ONELINER;
|
||||
}
|
||||
} else {
|
||||
ONELINER:
|
||||
SkDebugf(" />\n");
|
||||
}
|
||||
}
|
||||
|
||||
void SkView::dump(bool recurse) const {
|
||||
dumpview(this, 0, recurse);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkCommonFlags.h"
|
||||
#include "SkKey.h"
|
||||
#include "SkOSFile.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user