remove unneeded view subclasses
no doubt, more deletes will follow... goodbye old friends BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1740383002 TBR= Review URL: https://codereview.chromium.org/1740383002
This commit is contained in:
parent
afaf496910
commit
6b2af12a39
@ -42,7 +42,6 @@
|
||||
'../include/views/SkTouchGesture.h',
|
||||
'../include/views/SkView.h',
|
||||
'../include/views/SkViewInflate.h',
|
||||
'../include/views/SkWidget.h',
|
||||
'../include/views/SkWindow.h',
|
||||
|
||||
'../src/views/SkBGViewArtist.cpp',
|
||||
@ -50,7 +49,6 @@
|
||||
'../src/views/SkEventSink.cpp',
|
||||
'../src/views/SkOSMenu.cpp',
|
||||
'../src/views/SkParsePaint.cpp',
|
||||
'../src/views/SkProgressView.cpp',
|
||||
'../src/views/SkStackViewLayout.cpp',
|
||||
'../src/views/SkTagList.cpp',
|
||||
'../src/views/SkTagList.h',
|
||||
@ -59,7 +57,6 @@
|
||||
'../src/views/SkViewInflate.cpp',
|
||||
'../src/views/SkViewPriv.cpp',
|
||||
'../src/views/SkViewPriv.h',
|
||||
'../src/views/SkWidgets.cpp',
|
||||
'../src/views/SkWindow.cpp',
|
||||
|
||||
# Unix
|
||||
|
@ -1,411 +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 SkWidget_DEFINED
|
||||
#define SkWidget_DEFINED
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkDOM.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkString.h"
|
||||
#include "SkTextBox.h"
|
||||
#include "SkView.h"
|
||||
|
||||
class SkEvent;
|
||||
class SkInterpolator;
|
||||
class SkShader;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkWidget : public SkView {
|
||||
public:
|
||||
SkWidget(uint32_t flags = 0) : SkView(flags | kFocusable_Mask | kEnabled_Mask) {}
|
||||
|
||||
/** Call this to post the widget's event to its listeners */
|
||||
void postWidgetEvent();
|
||||
|
||||
static void Init();
|
||||
static void Term();
|
||||
protected:
|
||||
// override to add slots to an event before posting
|
||||
virtual void prepareWidgetEvent(SkEvent*);
|
||||
virtual void onEnabledChange();
|
||||
|
||||
// <event ...> to initialize the event from XML
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
|
||||
|
||||
private:
|
||||
SkEvent fEvent;
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkHasLabelWidget : public SkWidget {
|
||||
public:
|
||||
SkHasLabelWidget(uint32_t flags = 0) : SkWidget(flags) {}
|
||||
|
||||
size_t getLabel(SkString* label = NULL) const;
|
||||
size_t getLabel(char lable[] = NULL) const;
|
||||
void setLabel(const SkString&);
|
||||
void setLabel(const char label[]);
|
||||
void setLabel(const char label[], size_t len);
|
||||
|
||||
protected:
|
||||
// called when the label changes
|
||||
virtual void onLabelChange();
|
||||
|
||||
// overrides
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
SkString fLabel;
|
||||
typedef SkWidget INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkButtonWidget : public SkHasLabelWidget {
|
||||
public:
|
||||
SkButtonWidget(uint32_t flags = 0) : SkHasLabelWidget(flags), fState(kOff_State) {}
|
||||
|
||||
enum State {
|
||||
kOff_State, //!< XML: buttonState="off"
|
||||
kOn_State, //!< XML: buttonState="on"
|
||||
kUnknown_State //!< XML: buttonState="unknown"
|
||||
};
|
||||
State getButtonState() const { return fState; }
|
||||
void setButtonState(State);
|
||||
|
||||
protected:
|
||||
/** called when the label changes. default behavior is to inval the widget */
|
||||
virtual void onButtonStateChange();
|
||||
|
||||
// overrides
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
State fState;
|
||||
typedef SkHasLabelWidget INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkPushButtonWidget : public SkButtonWidget {
|
||||
public:
|
||||
SkPushButtonWidget(uint32_t flags = 0) : SkButtonWidget(flags) {}
|
||||
|
||||
protected:
|
||||
bool onEvent(const SkEvent&) override;
|
||||
void onDraw(SkCanvas*) override;
|
||||
Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override;
|
||||
bool onClick(Click* click) override;
|
||||
|
||||
private:
|
||||
typedef SkButtonWidget INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkCheckBoxWidget : public SkButtonWidget {
|
||||
public:
|
||||
SkCheckBoxWidget(uint32_t flags = 0);
|
||||
|
||||
protected:
|
||||
virtual bool onEvent(const SkEvent&);
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
typedef SkButtonWidget INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkStaticTextView : public SkView {
|
||||
public:
|
||||
SkStaticTextView(uint32_t flags = 0);
|
||||
virtual ~SkStaticTextView();
|
||||
|
||||
enum Mode {
|
||||
kFixedSize_Mode,
|
||||
kAutoWidth_Mode,
|
||||
kAutoHeight_Mode,
|
||||
|
||||
kModeCount
|
||||
};
|
||||
Mode getMode() const { return (Mode)fMode; }
|
||||
void setMode(Mode);
|
||||
|
||||
SkTextBox::SpacingAlign getSpacingAlign() const { return (SkTextBox::SpacingAlign)fSpacingAlign; }
|
||||
void setSpacingAlign(SkTextBox::SpacingAlign);
|
||||
|
||||
void getMargin(SkPoint* margin) const;
|
||||
void setMargin(SkScalar dx, SkScalar dy);
|
||||
|
||||
size_t getText(SkString* text = NULL) const;
|
||||
size_t getText(char text[] = NULL) const;
|
||||
void setText(const SkString&);
|
||||
void setText(const char text[]);
|
||||
void setText(const char text[], size_t len);
|
||||
|
||||
void getPaint(SkPaint*) const;
|
||||
void setPaint(const SkPaint&);
|
||||
|
||||
protected:
|
||||
// overrides
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
SkPoint fMargin;
|
||||
SkString fText;
|
||||
SkPaint fPaint;
|
||||
uint8_t fMode;
|
||||
uint8_t fSpacingAlign;
|
||||
|
||||
void computeSize();
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkBitmapView : public SkView {
|
||||
public:
|
||||
SkBitmapView(uint32_t flags = 0);
|
||||
virtual ~SkBitmapView();
|
||||
|
||||
bool getBitmap(SkBitmap*) const;
|
||||
void setBitmap(const SkBitmap*, bool viewOwnsPixels);
|
||||
bool loadBitmapFromFile(const char path[]);
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM&, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
SkBitmap fBitmap;
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkHasLabelView : public SkView {
|
||||
public:
|
||||
void getLabel(SkString*) const;
|
||||
void setLabel(const SkString&);
|
||||
void setLabel(const char label[]);
|
||||
|
||||
protected:
|
||||
SkString fLabel;
|
||||
|
||||
// called when the label changes
|
||||
virtual void onLabelChange();
|
||||
|
||||
// overrides
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkPushButtonView : public SkHasLabelView {
|
||||
public:
|
||||
SkPushButtonView(uint32_t flags = 0);
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkCheckBoxView : public SkHasLabelView {
|
||||
public:
|
||||
SkCheckBoxView(uint32_t flags = 0);
|
||||
|
||||
enum State {
|
||||
kOff_State,
|
||||
kOn_State,
|
||||
kMaybe_State
|
||||
};
|
||||
State getState() const { return fState; }
|
||||
void setState(State);
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
|
||||
|
||||
private:
|
||||
State fState;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkProgressView : public SkView {
|
||||
public:
|
||||
SkProgressView(uint32_t flags = 0);
|
||||
virtual ~SkProgressView();
|
||||
|
||||
uint16_t getValue() const { return fValue; }
|
||||
uint16_t getMax() const { return fMax; }
|
||||
|
||||
void setMax(U16CPU max);
|
||||
void setValue(U16CPU value);
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
|
||||
|
||||
private:
|
||||
uint16_t fValue, fMax;
|
||||
SkShader* fOnShader, *fOffShader;
|
||||
SkInterpolator* fInterp;
|
||||
bool fDoInterp;
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkListSource : public SkEventSink {
|
||||
public:
|
||||
virtual int countRows() = 0;
|
||||
virtual void getRow(int index, SkString* left, SkString* right) = 0;
|
||||
virtual SkEvent* getEvent(int index);
|
||||
|
||||
static SkListSource* CreateFromDir(const char path[], const char suffix[],
|
||||
const char targetPrefix[]);
|
||||
static SkListSource* CreateFromDOM(const SkDOM& dom, const SkDOM::Node* node);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkListView : public SkView {
|
||||
public:
|
||||
SkListView(uint32_t flags = 0);
|
||||
virtual ~SkListView();
|
||||
|
||||
SkScalar getRowHeight() const { return fRowHeight; }
|
||||
void setRowHeight(SkScalar);
|
||||
|
||||
/** Return the index of the selected row, or -1 if none
|
||||
*/
|
||||
int getSelection() const { return fCurrIndex; }
|
||||
/** Set the index of the selected row, or -1 for none
|
||||
*/
|
||||
void setSelection(int);
|
||||
|
||||
void moveSelectionUp();
|
||||
void moveSelectionDown();
|
||||
|
||||
enum Attr {
|
||||
kBG_Attr,
|
||||
kNormalText_Attr,
|
||||
kHiliteText_Attr,
|
||||
kHiliteCell_Attr,
|
||||
kAttrCount
|
||||
};
|
||||
SkPaint& paint(Attr);
|
||||
|
||||
SkListSource* getListSource() const { return fSource; }
|
||||
SkListSource* setListSource(SkListSource*);
|
||||
|
||||
#if 0
|
||||
enum Action {
|
||||
kSelectionChange_Action,
|
||||
kSelectionPicked_Action,
|
||||
kActionCount
|
||||
};
|
||||
/** If event is not null, it is retained by the view, and a copy
|
||||
of the event will be posted to its listeners when the specified
|
||||
action occurs. If event is null, then no event will be posted for
|
||||
the specified action.
|
||||
*/
|
||||
void setActionEvent(Action, SkEvent* event);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onSizeChange();
|
||||
virtual bool onEvent(const SkEvent&);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
|
||||
|
||||
private:
|
||||
SkPaint fPaint[kAttrCount];
|
||||
SkListSource* fSource;
|
||||
SkScalar fRowHeight;
|
||||
int fCurrIndex; // logical index
|
||||
int fScrollIndex; // logical index of top-most visible row
|
||||
int fVisibleRowCount;
|
||||
SkString* fStrCache;
|
||||
|
||||
void dirtyStrCache();
|
||||
void ensureStrCache(int visibleCount);
|
||||
|
||||
int logicalToVisualIndex(int index) const { return index - fScrollIndex; }
|
||||
void invalSelection();
|
||||
bool getRowRect(int index, SkRect*) const;
|
||||
void ensureSelectionIsVisible();
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkGridView : public SkView {
|
||||
public:
|
||||
SkGridView(uint32_t flags = 0);
|
||||
virtual ~SkGridView();
|
||||
|
||||
void getCellSize(SkPoint*) const;
|
||||
void setCellSize(SkScalar x, SkScalar y);
|
||||
|
||||
/** Return the index of the selected item, or -1 if none
|
||||
*/
|
||||
int getSelection() const { return fCurrIndex; }
|
||||
/** Set the index of the selected row, or -1 for none
|
||||
*/
|
||||
void setSelection(int);
|
||||
|
||||
void moveSelectionUp();
|
||||
void moveSelectionDown();
|
||||
|
||||
enum Attr {
|
||||
kBG_Attr,
|
||||
kHiliteCell_Attr,
|
||||
kAttrCount
|
||||
};
|
||||
SkPaint& paint(Attr);
|
||||
|
||||
SkListSource* getListSource() const { return fSource; }
|
||||
SkListSource* setListSource(SkListSource*);
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
virtual void onSizeChange();
|
||||
virtual bool onEvent(const SkEvent&);
|
||||
virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
|
||||
|
||||
private:
|
||||
SkView* fScrollBar;
|
||||
SkPaint fPaint[kAttrCount];
|
||||
SkListSource* fSource;
|
||||
int fCurrIndex; // logical index
|
||||
|
||||
SkPoint fCellSize;
|
||||
SkIPoint fVisibleCount;
|
||||
|
||||
int logicalToVisualIndex(int index) const { return index; }
|
||||
void invalSelection();
|
||||
bool getCellRect(int index, SkRect*) const;
|
||||
void ensureSelectionIsVisible();
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,132 +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 "SkWidget.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkShader.h"
|
||||
#include "SkInterpolator.h"
|
||||
#include "SkTime.h"
|
||||
|
||||
SkProgressView::SkProgressView(uint32_t flags) : SkView(flags), fOnShader(nullptr), fOffShader(nullptr)
|
||||
{
|
||||
fValue = 0;
|
||||
fMax = 0;
|
||||
fInterp = nullptr;
|
||||
fDoInterp = false;
|
||||
}
|
||||
|
||||
SkProgressView::~SkProgressView()
|
||||
{
|
||||
delete fInterp;
|
||||
SkSafeUnref(fOnShader);
|
||||
SkSafeUnref(fOffShader);
|
||||
}
|
||||
|
||||
void SkProgressView::setMax(U16CPU max)
|
||||
{
|
||||
if (fMax != max)
|
||||
{
|
||||
fMax = SkToU16(max);
|
||||
if (fValue > 0)
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SkProgressView::setValue(U16CPU value)
|
||||
{
|
||||
if (fValue != value)
|
||||
{
|
||||
if (fDoInterp)
|
||||
{
|
||||
if (fInterp)
|
||||
delete fInterp;
|
||||
fInterp = new SkInterpolator(1, 2);
|
||||
SkScalar x = (SkScalar)(fValue << 8);
|
||||
fInterp->setKeyFrame(0, SkTime::GetMSecs(), &x, 0);
|
||||
x = (SkScalar)(value << 8);
|
||||
fInterp->setKeyFrame(1, SkTime::GetMSecs() + 333, &x);
|
||||
}
|
||||
fValue = SkToU16(value);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SkProgressView::onDraw(SkCanvas* canvas)
|
||||
{
|
||||
if (fMax == 0)
|
||||
return;
|
||||
|
||||
SkFixed percent;
|
||||
|
||||
if (fInterp)
|
||||
{
|
||||
SkScalar x;
|
||||
if (fInterp->timeToValues(SkTime::GetMSecs(), &x) == SkInterpolator::kFreezeEnd_Result)
|
||||
{
|
||||
delete fInterp;
|
||||
fInterp = nullptr;
|
||||
}
|
||||
percent = (SkFixed)x; // now its 16.8
|
||||
percent = SkMax32(0, SkMin32(percent, fMax << 8)); // now its pinned
|
||||
percent = SkFixedDiv(percent, fMax << 8); // now its 0.16
|
||||
this->inval(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
U16CPU value = SkMax32(0, SkMin32(fValue, fMax));
|
||||
percent = SkFixedDiv(value, fMax);
|
||||
}
|
||||
|
||||
|
||||
SkRect r;
|
||||
SkPaint p;
|
||||
|
||||
r.set(0, 0, this->width(), this->height());
|
||||
p.setAntiAlias(true);
|
||||
|
||||
r.fRight = r.fLeft + SkScalarMul(r.width(), SkFixedToScalar(percent));
|
||||
p.setStyle(SkPaint::kFill_Style);
|
||||
|
||||
p.setColor(SK_ColorDKGRAY);
|
||||
p.setShader(fOnShader);
|
||||
canvas->drawRect(r, p);
|
||||
|
||||
p.setColor(SK_ColorWHITE);
|
||||
p.setShader(fOffShader);
|
||||
r.fLeft = r.fRight;
|
||||
r.fRight = this->width() - SK_Scalar1;
|
||||
if (r.width() > 0)
|
||||
canvas->drawRect(r, p);
|
||||
}
|
||||
|
||||
#include "SkImageDecoder.h"
|
||||
|
||||
static SkShader* inflate_shader(const char file[])
|
||||
{
|
||||
SkBitmap bm;
|
||||
|
||||
return SkImageDecoder::DecodeFile(file, &bm) ?
|
||||
SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode) :
|
||||
nullptr;
|
||||
}
|
||||
|
||||
void SkProgressView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
this->INHERITED::onInflate(dom, node);
|
||||
|
||||
const char* s;
|
||||
|
||||
SkASSERT(fOnShader == nullptr);
|
||||
SkASSERT(fOffShader == nullptr);
|
||||
|
||||
if ((s = dom.findAttr(node, "src-on")) != nullptr)
|
||||
fOnShader = inflate_shader(s);
|
||||
if ((s = dom.findAttr(node, "src-off")) != nullptr)
|
||||
fOffShader = inflate_shader(s);
|
||||
(void)dom.findBool(node, "do-interp", &fDoInterp);
|
||||
}
|
@ -1,562 +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 "SkWidget.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkKey.h"
|
||||
#include "SkParsePaint.h"
|
||||
#include "SkSystemEventTypes.h"
|
||||
#include "SkTextBox.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
static void assert_no_attr(const SkDOM& dom, const SkDOM::Node* node, const char attr[])
|
||||
{
|
||||
const char* value = dom.findAttr(node, attr);
|
||||
if (value)
|
||||
SkDebugf("unknown attribute %s=\"%s\"\n", attr, value);
|
||||
}
|
||||
#else
|
||||
#define assert_no_attr(dom, node, attr)
|
||||
#endif
|
||||
|
||||
#include "SkAnimator.h"
|
||||
#include "SkTime.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum SkinType {
|
||||
kPushButton_SkinType,
|
||||
kStaticText_SkinType,
|
||||
|
||||
kSkinTypeCount
|
||||
};
|
||||
|
||||
struct SkinSuite {
|
||||
SkinSuite();
|
||||
~SkinSuite()
|
||||
{
|
||||
for (int i = 0; i < kSkinTypeCount; i++)
|
||||
delete fAnimators[i];
|
||||
}
|
||||
|
||||
SkAnimator* get(SkinType);
|
||||
|
||||
private:
|
||||
SkAnimator* fAnimators[kSkinTypeCount];
|
||||
};
|
||||
|
||||
SkinSuite::SkinSuite()
|
||||
{
|
||||
static const char kSkinPath[] = "skins/";
|
||||
|
||||
static const char* gSkinNames[] = {
|
||||
"pushbutton_skin.xml",
|
||||
"statictext_skin.xml"
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < SK_ARRAY_COUNT(gSkinNames); i++)
|
||||
{
|
||||
size_t len = strlen(gSkinNames[i]);
|
||||
SkString path(sizeof(kSkinPath) - 1 + len);
|
||||
|
||||
memcpy(path.writable_str(), kSkinPath, sizeof(kSkinPath) - 1);
|
||||
memcpy(path.writable_str() + sizeof(kSkinPath) - 1, gSkinNames[i], len);
|
||||
|
||||
fAnimators[i] = new SkAnimator;
|
||||
if (!fAnimators[i]->decodeURI(path.c_str()))
|
||||
{
|
||||
delete fAnimators[i];
|
||||
fAnimators[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SkAnimator* SkinSuite::get(SkinType st)
|
||||
{
|
||||
SkASSERT((unsigned)st < kSkinTypeCount);
|
||||
return fAnimators[st];
|
||||
}
|
||||
|
||||
static SkinSuite* gSkinSuite;
|
||||
|
||||
static SkAnimator* get_skin_animator(SkinType st)
|
||||
{
|
||||
#if 0
|
||||
if (gSkinSuite == nullptr)
|
||||
gSkinSuite = new SkinSuite;
|
||||
return gSkinSuite->get(st);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkWidget::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void SkWidget::Term()
|
||||
{
|
||||
delete gSkinSuite;
|
||||
}
|
||||
|
||||
void SkWidget::onEnabledChange()
|
||||
{
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void SkWidget::postWidgetEvent()
|
||||
{
|
||||
if (!fEvent.isType("") && this->hasListeners())
|
||||
{
|
||||
this->prepareWidgetEvent(&fEvent);
|
||||
this->postToListeners(fEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void SkWidget::prepareWidgetEvent(SkEvent*)
|
||||
{
|
||||
// override in subclass to add any additional fields before posting
|
||||
}
|
||||
|
||||
void SkWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
this->INHERITED::onInflate(dom, node);
|
||||
|
||||
if ((node = dom.getFirstChild(node, "event")) != nullptr)
|
||||
fEvent.inflate(dom, node);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
size_t SkHasLabelWidget::getLabel(SkString* str) const
|
||||
{
|
||||
if (str)
|
||||
*str = fLabel;
|
||||
return fLabel.size();
|
||||
}
|
||||
|
||||
size_t SkHasLabelWidget::getLabel(char buffer[]) const
|
||||
{
|
||||
if (buffer)
|
||||
memcpy(buffer, fLabel.c_str(), fLabel.size());
|
||||
return fLabel.size();
|
||||
}
|
||||
|
||||
void SkHasLabelWidget::setLabel(const SkString& str)
|
||||
{
|
||||
this->setLabel(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
void SkHasLabelWidget::setLabel(const char label[])
|
||||
{
|
||||
this->setLabel(label, strlen(label));
|
||||
}
|
||||
|
||||
void SkHasLabelWidget::setLabel(const char label[], size_t len)
|
||||
{
|
||||
if (!fLabel.equals(label, len))
|
||||
{
|
||||
fLabel.set(label, len);
|
||||
this->onLabelChange();
|
||||
}
|
||||
}
|
||||
|
||||
void SkHasLabelWidget::onLabelChange()
|
||||
{
|
||||
// override in subclass
|
||||
}
|
||||
|
||||
void SkHasLabelWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
this->INHERITED::onInflate(dom, node);
|
||||
|
||||
const char* text = dom.findAttr(node, "label");
|
||||
if (text)
|
||||
this->setLabel(text);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkButtonWidget::setButtonState(State state)
|
||||
{
|
||||
if (fState != state)
|
||||
{
|
||||
fState = state;
|
||||
this->onButtonStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
void SkButtonWidget::onButtonStateChange()
|
||||
{
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void SkButtonWidget::onInflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
this->INHERITED::onInflate(dom, node);
|
||||
|
||||
int index;
|
||||
if ((index = dom.findList(node, "buttonState", "off,on,unknown")) >= 0)
|
||||
this->setButtonState((State)index);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SkPushButtonWidget::onEvent(const SkEvent& evt)
|
||||
{
|
||||
if (evt.isType(SK_EventType_Key) && evt.getFast32() == kOK_SkKey)
|
||||
{
|
||||
this->postWidgetEvent();
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onEvent(evt);
|
||||
}
|
||||
|
||||
static const char* computeAnimatorState(int enabled, int focused, SkButtonWidget::State state)
|
||||
{
|
||||
if (!enabled)
|
||||
return "disabled";
|
||||
if (state == SkButtonWidget::kOn_State)
|
||||
{
|
||||
SkASSERT(focused);
|
||||
return "enabled-pressed";
|
||||
}
|
||||
if (focused)
|
||||
return "enabled-focused";
|
||||
return "enabled";
|
||||
}
|
||||
|
||||
#include "SkBlurMask.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkEmbossMaskFilter.h"
|
||||
|
||||
static void create_emboss(SkPaint* paint, SkScalar radius, bool focus, bool pressed)
|
||||
{
|
||||
SkEmbossMaskFilter::Light light;
|
||||
|
||||
light.fDirection[0] = SK_Scalar1/2;
|
||||
light.fDirection[1] = SK_Scalar1/2;
|
||||
light.fDirection[2] = SK_Scalar1/3;
|
||||
light.fAmbient = 0x48;
|
||||
light.fSpecular = 0x80;
|
||||
|
||||
if (pressed)
|
||||
{
|
||||
light.fDirection[0] = -light.fDirection[0];
|
||||
light.fDirection[1] = -light.fDirection[1];
|
||||
}
|
||||
if (focus)
|
||||
light.fDirection[2] += SK_Scalar1/4;
|
||||
|
||||
SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(radius);
|
||||
paint->setMaskFilter(new SkEmbossMaskFilter(sigma, light))->unref();
|
||||
}
|
||||
|
||||
void SkPushButtonWidget::onDraw(SkCanvas* canvas)
|
||||
{
|
||||
this->INHERITED::onDraw(canvas);
|
||||
|
||||
SkString label;
|
||||
this->getLabel(&label);
|
||||
|
||||
SkAnimator* anim = get_skin_animator(kPushButton_SkinType);
|
||||
|
||||
if (anim)
|
||||
{
|
||||
SkEvent evt("user");
|
||||
|
||||
evt.setString("id", "prime");
|
||||
evt.setScalar("prime-width", this->width());
|
||||
evt.setScalar("prime-height", this->height());
|
||||
evt.setString("prime-text", label);
|
||||
evt.setString("prime-state", computeAnimatorState(this->isEnabled(), this->hasFocus(), this->getButtonState()));
|
||||
|
||||
(void)anim->doUserEvent(evt);
|
||||
SkPaint paint;
|
||||
anim->draw(canvas, &paint, SkTime::GetMSecs());
|
||||
}
|
||||
else
|
||||
{
|
||||
SkRect r;
|
||||
SkPaint p;
|
||||
|
||||
r.set(0, 0, this->width(), this->height());
|
||||
p.setAntiAliasOn(true);
|
||||
p.setColor(SK_ColorBLUE);
|
||||
create_emboss(&p, SkIntToScalar(12)/5, this->hasFocus(), this->getButtonState() == kOn_State);
|
||||
canvas->drawRoundRect(r, SkScalarHalf(this->height()), SkScalarHalf(this->height()), p);
|
||||
p.setMaskFilter(nullptr);
|
||||
|
||||
p.setTextAlign(SkPaint::kCenter_Align);
|
||||
|
||||
SkTextBox box;
|
||||
box.setMode(SkTextBox::kOneLine_Mode);
|
||||
box.setSpacingAlign(SkTextBox::kCenter_SpacingAlign);
|
||||
box.setBox(0, 0, this->width(), this->height());
|
||||
|
||||
// if (this->getButtonState() == kOn_State)
|
||||
// p.setColor(SK_ColorRED);
|
||||
// else
|
||||
p.setColor(SK_ColorWHITE);
|
||||
|
||||
box.draw(canvas, label.c_str(), label.size(), p);
|
||||
}
|
||||
}
|
||||
|
||||
SkView::Click* SkPushButtonWidget::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi)
|
||||
{
|
||||
this->acceptFocus();
|
||||
return new Click(this);
|
||||
}
|
||||
|
||||
bool SkPushButtonWidget::onClick(Click* click)
|
||||
{
|
||||
SkRect r;
|
||||
State state = kOff_State;
|
||||
|
||||
this->getLocalBounds(&r);
|
||||
if (r.contains(click->fCurr))
|
||||
{
|
||||
if (click->fState == Click::kUp_State)
|
||||
this->postWidgetEvent();
|
||||
else
|
||||
state = kOn_State;
|
||||
}
|
||||
this->setButtonState(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkStaticTextView::SkStaticTextView(U32 flags) : SkView(flags)
|
||||
{
|
||||
fMargin.set(0, 0);
|
||||
fMode = kFixedSize_Mode;
|
||||
fSpacingAlign = SkTextBox::kStart_SpacingAlign;
|
||||
}
|
||||
|
||||
SkStaticTextView::~SkStaticTextView()
|
||||
{
|
||||
}
|
||||
|
||||
void SkStaticTextView::computeSize()
|
||||
{
|
||||
if (fMode == kAutoWidth_Mode)
|
||||
{
|
||||
SkScalar width = fPaint.measureText(fText.c_str(), fText.size(), nullptr, nullptr);
|
||||
this->setWidth(width + fMargin.fX * 2);
|
||||
}
|
||||
else if (fMode == kAutoHeight_Mode)
|
||||
{
|
||||
SkScalar width = this->width() - fMargin.fX * 2;
|
||||
int lines = width > 0 ? SkTextLineBreaker::CountLines(fText.c_str(), fText.size(), fPaint, width) : 0;
|
||||
|
||||
SkScalar before, after;
|
||||
(void)fPaint.measureText(0, nullptr, &before, &after);
|
||||
|
||||
this->setHeight(lines * (after - before) + fMargin.fY * 2);
|
||||
}
|
||||
}
|
||||
|
||||
void SkStaticTextView::setMode(Mode mode)
|
||||
{
|
||||
SkASSERT((unsigned)mode < kModeCount);
|
||||
|
||||
if (fMode != mode)
|
||||
{
|
||||
fMode = SkToU8(mode);
|
||||
this->computeSize();
|
||||
}
|
||||
}
|
||||
|
||||
void SkStaticTextView::setSpacingAlign(SkTextBox::SpacingAlign align)
|
||||
{
|
||||
fSpacingAlign = SkToU8(align);
|
||||
this->inval(nullptr);
|
||||
}
|
||||
|
||||
void SkStaticTextView::getMargin(SkPoint* margin) const
|
||||
{
|
||||
if (margin)
|
||||
*margin = fMargin;
|
||||
}
|
||||
|
||||
void SkStaticTextView::setMargin(SkScalar dx, SkScalar dy)
|
||||
{
|
||||
if (fMargin.fX != dx || fMargin.fY != dy)
|
||||
{
|
||||
fMargin.set(dx, dy);
|
||||
this->computeSize();
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
size_t SkStaticTextView::getText(SkString* text) const
|
||||
{
|
||||
if (text)
|
||||
*text = fText;
|
||||
return fText.size();
|
||||
}
|
||||
|
||||
size_t SkStaticTextView::getText(char text[]) const
|
||||
{
|
||||
if (text)
|
||||
memcpy(text, fText.c_str(), fText.size());
|
||||
return fText.size();
|
||||
}
|
||||
|
||||
void SkStaticTextView::setText(const SkString& text)
|
||||
{
|
||||
this->setText(text.c_str(), text.size());
|
||||
}
|
||||
|
||||
void SkStaticTextView::setText(const char text[])
|
||||
{
|
||||
this->setText(text, strlen(text));
|
||||
}
|
||||
|
||||
void SkStaticTextView::setText(const char text[], size_t len)
|
||||
{
|
||||
if (!fText.equals(text, len))
|
||||
{
|
||||
fText.set(text, len);
|
||||
this->computeSize();
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SkStaticTextView::getPaint(SkPaint* paint) const
|
||||
{
|
||||
if (paint)
|
||||
*paint = fPaint;
|
||||
}
|
||||
|
||||
void SkStaticTextView::setPaint(const SkPaint& paint)
|
||||
{
|
||||
if (fPaint != paint)
|
||||
{
|
||||
fPaint = paint;
|
||||
this->computeSize();
|
||||
this->inval(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SkStaticTextView::onDraw(SkCanvas* canvas)
|
||||
{
|
||||
this->INHERITED::onDraw(canvas);
|
||||
|
||||
if (fText.isEmpty())
|
||||
return;
|
||||
|
||||
SkTextBox box;
|
||||
|
||||
box.setMode(fMode == kAutoWidth_Mode ? SkTextBox::kOneLine_Mode : SkTextBox::kLineBreak_Mode);
|
||||
box.setSpacingAlign(this->getSpacingAlign());
|
||||
box.setBox(fMargin.fX, fMargin.fY, this->width() - fMargin.fX, this->height() - fMargin.fY);
|
||||
box.draw(canvas, fText.c_str(), fText.size(), fPaint);
|
||||
}
|
||||
|
||||
void SkStaticTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
this->INHERITED::onInflate(dom, node);
|
||||
|
||||
int index;
|
||||
if ((index = dom.findList(node, "mode", "fixed,auto-width,auto-height")) >= 0)
|
||||
this->setMode((Mode)index);
|
||||
else
|
||||
assert_no_attr(dom, node, "mode");
|
||||
|
||||
if ((index = dom.findList(node, "spacing-align", "start,center,end")) >= 0)
|
||||
this->setSpacingAlign((SkTextBox::SpacingAlign)index);
|
||||
else
|
||||
assert_no_attr(dom, node, "mode");
|
||||
|
||||
SkScalar s[2];
|
||||
if (dom.findScalars(node, "margin", s, 2))
|
||||
this->setMargin(s[0], s[1]);
|
||||
else
|
||||
assert_no_attr(dom, node, "margin");
|
||||
|
||||
const char* text = dom.findAttr(node, "text");
|
||||
if (text)
|
||||
this->setText(text);
|
||||
|
||||
if ((node = dom.getFirstChild(node, "paint")) != nullptr)
|
||||
SkPaint_Inflate(&fPaint, dom, node);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkImageDecoder.h"
|
||||
|
||||
SkBitmapView::SkBitmapView(U32 flags) : SkView(flags)
|
||||
{
|
||||
}
|
||||
|
||||
SkBitmapView::~SkBitmapView()
|
||||
{
|
||||
}
|
||||
|
||||
bool SkBitmapView::getBitmap(SkBitmap* bitmap) const
|
||||
{
|
||||
if (bitmap)
|
||||
*bitmap = fBitmap;
|
||||
return fBitmap.colorType() != kUnknown_SkColorType;
|
||||
}
|
||||
|
||||
void SkBitmapView::setBitmap(const SkBitmap* bitmap, bool viewOwnsPixels)
|
||||
{
|
||||
if (bitmap)
|
||||
{
|
||||
fBitmap = *bitmap;
|
||||
fBitmap.setOwnsPixels(viewOwnsPixels);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkBitmapView::loadBitmapFromFile(const char path[])
|
||||
{
|
||||
SkBitmap bitmap;
|
||||
|
||||
if (SkImageDecoder::DecodeFile(path, &bitmap))
|
||||
{
|
||||
this->setBitmap(&bitmap, true);
|
||||
bitmap.setOwnsPixels(false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkBitmapView::onDraw(SkCanvas* canvas)
|
||||
{
|
||||
if (fBitmap.colorType() != kUnknown_SkColorType &&
|
||||
fBitmap.width() && fBitmap.height())
|
||||
{
|
||||
SkAutoCanvasRestore restore(canvas, true);
|
||||
SkPaint p;
|
||||
|
||||
p.setFilterType(SkPaint::kBilinear_FilterType);
|
||||
canvas->scale( this->width() / fBitmap.width(),
|
||||
this->height() / fBitmap.height(),
|
||||
0, 0);
|
||||
canvas->drawBitmap(fBitmap, 0, 0, p);
|
||||
}
|
||||
}
|
||||
|
||||
void SkBitmapView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
|
||||
{
|
||||
this->INHERITED::onInflate(dom, node);
|
||||
|
||||
const char* src = dom.findAttr(node, "src");
|
||||
if (src)
|
||||
(void)this->loadBitmapFromFile(src);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user