use statictextviews to display coordinates in unitmapper
git-svn-id: http://skia.googlecode.com/svn/trunk@491 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
4526a847da
commit
562ea92179
@ -6,9 +6,39 @@
|
||||
#include "SkUnitMappers.h"
|
||||
#include "SkCubicInterval.h"
|
||||
|
||||
#include "SkWidgetViews.h"
|
||||
|
||||
static SkStaticTextView* make_textview(SkView* parent,
|
||||
const SkRect& bounds,
|
||||
const SkPaint& paint) {
|
||||
SkStaticTextView* view = new SkStaticTextView;
|
||||
view->setMode(SkStaticTextView::kFixedSize_Mode);
|
||||
view->setPaint(paint);
|
||||
view->setVisibleP(true);
|
||||
view->setSize(bounds.width(), bounds.height());
|
||||
view->setLoc(bounds.fLeft, bounds.fTop);
|
||||
parent->attachChildToFront(view)->unref();
|
||||
return view;
|
||||
}
|
||||
|
||||
static void set_scalar(SkStaticTextView* view, SkScalar value) {
|
||||
SkString str;
|
||||
str.appendScalar(value);
|
||||
view->setText(str);
|
||||
}
|
||||
|
||||
class UnitMapperView : public SkView {
|
||||
SkPoint fPts[4];
|
||||
SkMatrix fMatrix;
|
||||
SkStaticTextView* fViews[4];
|
||||
|
||||
void setViews() {
|
||||
set_scalar(fViews[0], fPts[1].fX);
|
||||
set_scalar(fViews[1], fPts[1].fY);
|
||||
set_scalar(fViews[2], fPts[2].fX);
|
||||
set_scalar(fViews[3], fPts[2].fY);
|
||||
}
|
||||
|
||||
public:
|
||||
UnitMapperView() {
|
||||
fPts[0].set(0, 0);
|
||||
@ -18,6 +48,19 @@ public:
|
||||
|
||||
fMatrix.setScale(SK_Scalar1 * 200, -SK_Scalar1 * 200);
|
||||
fMatrix.postTranslate(SkIntToScalar(100), SkIntToScalar(300));
|
||||
|
||||
SkRect r = {
|
||||
SkIntToScalar(350), SkIntToScalar(100),
|
||||
SkIntToScalar(500), SkIntToScalar(130)
|
||||
};
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(SkIntToScalar(25));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
fViews[i] = make_textview(this, r, paint);
|
||||
r.offset(0, r.height());
|
||||
}
|
||||
this->setViews();
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -80,26 +123,27 @@ protected:
|
||||
return pt;
|
||||
}
|
||||
|
||||
SkPoint* hittest(SkScalar x, SkScalar y) {
|
||||
int hittest(SkScalar x, SkScalar y) {
|
||||
SkPoint target = { x, y };
|
||||
SkPoint pts[2] = { fPts[1], fPts[2] };
|
||||
fMatrix.mapPoints(pts, 2);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (SkPoint::Distance(pts[i], target) < SkIntToScalar(4)) {
|
||||
return &fPts[i + 1];
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
|
||||
fDragPt = hittest(x, y);
|
||||
return fDragPt ? new Click(this) : NULL;
|
||||
fDragIndex = hittest(x, y);
|
||||
return fDragIndex >= 0 ? new Click(this) : NULL;
|
||||
}
|
||||
|
||||
virtual bool onClick(Click* click) {
|
||||
if (fDragPt) {
|
||||
*fDragPt = invertPt(click->fCurr.fX, click->fCurr.fY);
|
||||
if (fDragIndex >= 0) {
|
||||
fPts[fDragIndex] = invertPt(click->fCurr.fX, click->fCurr.fY);
|
||||
this->setViews();
|
||||
this->inval(NULL);
|
||||
return true;
|
||||
}
|
||||
@ -107,7 +151,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
SkPoint* fDragPt;
|
||||
int fDragIndex;
|
||||
|
||||
typedef SkView INHERITED;
|
||||
};
|
||||
|
@ -98,7 +98,11 @@ void SkView::draw(SkCanvas* canvas)
|
||||
if (fParent) {
|
||||
fParent->beforeChild(this, canvas);
|
||||
}
|
||||
|
||||
int sc = canvas->save();
|
||||
this->onDraw(canvas);
|
||||
canvas->restoreToCount(sc);
|
||||
|
||||
if (fParent) {
|
||||
fParent->afterChild(this, canvas);
|
||||
}
|
||||
|
@ -348,171 +348,6 @@ private:
|
||||
typedef SkButtonView INHERITED;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SkTextBox.h"
|
||||
|
||||
SkStaticTextView::SkStaticTextView()
|
||||
{
|
||||
fMargin.set(0, 0);
|
||||
fMode = kFixedSize_Mode;
|
||||
fSpacingAlign = SkTextBox::kStart_SpacingAlign;
|
||||
|
||||
init_skin_paint(kStaticText_SkinEnum, &fPaint);
|
||||
}
|
||||
|
||||
SkStaticTextView::~SkStaticTextView()
|
||||
{
|
||||
}
|
||||
|
||||
void SkStaticTextView::computeSize()
|
||||
{
|
||||
if (fMode == kAutoWidth_Mode)
|
||||
{
|
||||
SkScalar width = fPaint.measureText(fText.c_str(), fText.size());
|
||||
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;
|
||||
|
||||
this->setHeight(lines * fPaint.getFontSpacing() + 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(NULL);
|
||||
}
|
||||
|
||||
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(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
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[])
|
||||
{
|
||||
if (text == NULL)
|
||||
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(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
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(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
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, "spacing-align");
|
||||
|
||||
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")) != NULL &&
|
||||
(node = dom.getFirstChild(node, "screenplay")) != NULL)
|
||||
{
|
||||
inflate_paint(dom, node, &fPaint);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
0001FB9A110E362F00C1D647 /* SkTextureCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0001FB93110E362F00C1D647 /* SkTextureCache.cpp */; };
|
||||
000630AD10F4E8F000BC2C23 /* SampleText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 000630AC10F4E8EF00BC2C23 /* SampleText.cpp */; };
|
||||
001B871E1042184D00C84ED4 /* Forth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 001B871D1042184D00C84ED4 /* Forth.cpp */; };
|
||||
0021F3A21120B29C0062682F /* SkStaticTextView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0021F3A11120B29C0062682F /* SkStaticTextView.cpp */; };
|
||||
0021F3D31120B61F0062682F /* SampleUnitMapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00995E1510A079D80054AD6D /* SampleUnitMapper.cpp */; };
|
||||
00244D1B10642BBA00B8F4D8 /* SampleStrokePath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0009E21F1057E96800B0DE6F /* SampleStrokePath.cpp */; };
|
||||
00244D97106A539500B8F4D8 /* SampleXfermodes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007A7CB20F01658C00A2D6EE /* SampleXfermodes.cpp */; };
|
||||
00244DBB106A61B700B8F4D8 /* SampleGM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00244DBA106A61B700B8F4D8 /* SampleGM.cpp */; };
|
||||
@ -44,6 +46,7 @@
|
||||
00281D071084ED1200BCCB06 /* SkXMLParser_expat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00281D061084ED1200BCCB06 /* SkXMLParser_expat.cpp */; };
|
||||
0028847B0EFAB46A0083E387 /* libcore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 002884510EFAA35C0083E387 /* libcore.a */; };
|
||||
002884BD0EFAB6A30083E387 /* libmaccore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 002884BC0EFAB69F0083E387 /* libmaccore.a */; };
|
||||
003EE652111239D5001AB759 /* SampleWarp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 003EE651111239D5001AB759 /* SampleWarp.cpp */; };
|
||||
0041CDDB0F00975E00695E8C /* SampleImageDir.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CDDA0F00975E00695E8C /* SampleImageDir.cpp */; };
|
||||
0041CDF30F009ED100695E8C /* SkImageRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CDF20F009ED100695E8C /* SkImageRef.cpp */; };
|
||||
0041CDF60F009EED00695E8C /* SkImageRef_GlobalPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0041CDF50F009EED00695E8C /* SkImageRef_GlobalPool.cpp */; };
|
||||
@ -95,7 +98,6 @@
|
||||
00EB4593104DBB18002B413E /* ForthTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00EB4592104DBB18002B413E /* ForthTests.cpp */; };
|
||||
00ED55F3104A10EB00F51FF8 /* StdWords.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00ED55F2104A10EB00F51FF8 /* StdWords.cpp */; };
|
||||
00F0441010B447160049C54C /* SamplePathClip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007C785D0F3B4C230004B142 /* SamplePathClip.cpp */; };
|
||||
00F0442210B44AFB0049C54C /* SampleUnitMapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00995E1510A079D80054AD6D /* SampleUnitMapper.cpp */; };
|
||||
00F0444C10B4569B0049C54C /* SampleLineClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00F042D410B1CE990049C54C /* SampleLineClipper.cpp */; };
|
||||
00F45DDC10CE94CE00ABEA26 /* SampleTypeface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007A7CB00F01658C00A2D6EE /* SampleTypeface.cpp */; };
|
||||
0156F80407C56A3000C6122B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0156F80307C56A3000C6122B /* Foundation.framework */; };
|
||||
@ -198,6 +200,7 @@
|
||||
000630AC10F4E8EF00BC2C23 /* SampleText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleText.cpp; path = ../../samplecode/SampleText.cpp; sourceTree = SOURCE_ROOT; };
|
||||
0009E21F1057E96800B0DE6F /* SampleStrokePath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleStrokePath.cpp; path = ../../samplecode/SampleStrokePath.cpp; sourceTree = SOURCE_ROOT; };
|
||||
001B871D1042184D00C84ED4 /* Forth.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Forth.cpp; path = ../../forth/Forth.cpp; sourceTree = SOURCE_ROOT; };
|
||||
0021F3A11120B29C0062682F /* SkStaticTextView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkStaticTextView.cpp; path = ../../src/views/SkStaticTextView.cpp; sourceTree = SOURCE_ROOT; };
|
||||
00244DBA106A61B700B8F4D8 /* SampleGM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleGM.cpp; path = ../../samplecode/SampleGM.cpp; sourceTree = SOURCE_ROOT; };
|
||||
00244DC7106A630100B8F4D8 /* bitmapfilters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bitmapfilters.cpp; path = ../../gm/bitmapfilters.cpp; sourceTree = SOURCE_ROOT; };
|
||||
00244DC8106A630100B8F4D8 /* filltypes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = filltypes.cpp; path = ../../gm/filltypes.cpp; sourceTree = SOURCE_ROOT; };
|
||||
@ -213,6 +216,7 @@
|
||||
002884490EFAA35C0083E387 /* core.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = core.xcodeproj; path = ../core/core.xcodeproj; sourceTree = SOURCE_ROOT; };
|
||||
002884B40EFAB69F0083E387 /* maccore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = maccore.xcodeproj; path = ../maccore/maccore.xcodeproj; sourceTree = SOURCE_ROOT; };
|
||||
003145310FB9B48F00B10956 /* SampleShapes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleShapes.cpp; path = ../../samplecode/SampleShapes.cpp; sourceTree = SOURCE_ROOT; };
|
||||
003EE651111239D5001AB759 /* SampleWarp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleWarp.cpp; path = ../../samplecode/SampleWarp.cpp; sourceTree = SOURCE_ROOT; };
|
||||
0041CDDA0F00975E00695E8C /* SampleImageDir.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleImageDir.cpp; path = ../../samplecode/SampleImageDir.cpp; sourceTree = SOURCE_ROOT; };
|
||||
0041CDF20F009ED100695E8C /* SkImageRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkImageRef.cpp; path = ../../src/images/SkImageRef.cpp; sourceTree = SOURCE_ROOT; };
|
||||
0041CDF50F009EED00695E8C /* SkImageRef_GlobalPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkImageRef_GlobalPool.cpp; path = ../../src/images/SkImageRef_GlobalPool.cpp; sourceTree = SOURCE_ROOT; };
|
||||
@ -314,6 +318,7 @@
|
||||
00003C610EFC2287000FF73A /* samples */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
003EE651111239D5001AB759 /* SampleWarp.cpp */,
|
||||
000630AC10F4E8EF00BC2C23 /* SampleText.cpp */,
|
||||
00281C771083CFA100BCCB06 /* SampleAnimator.cpp */,
|
||||
0086CBF010A8661F00C8BF27 /* SampleAvoid.cpp */,
|
||||
@ -397,6 +402,7 @@
|
||||
00003C710EFC22CE000FF73A /* SkView.cpp */,
|
||||
00003C720EFC22CE000FF73A /* SkViewPriv.cpp */,
|
||||
00003C730EFC22CE000FF73A /* SkWindow.cpp */,
|
||||
0021F3A11120B29C0062682F /* SkStaticTextView.cpp */,
|
||||
);
|
||||
name = views;
|
||||
sourceTree = "<group>";
|
||||
@ -729,7 +735,6 @@
|
||||
0086CBF110A8661F00C8BF27 /* SampleAvoid.cpp in Sources */,
|
||||
0086CC1C10A9B6A600C8BF27 /* SamplePicture.cpp in Sources */,
|
||||
00F0441010B447160049C54C /* SamplePathClip.cpp in Sources */,
|
||||
00F0442210B44AFB0049C54C /* SampleUnitMapper.cpp in Sources */,
|
||||
00F0444C10B4569B0049C54C /* SampleLineClipper.cpp in Sources */,
|
||||
00575A1810BB02CF00A43B94 /* SampleEffects.cpp in Sources */,
|
||||
00575A3B10BB05FE00A43B94 /* SampleArc.cpp in Sources */,
|
||||
@ -747,6 +752,9 @@
|
||||
0001FB98110E362F00C1D647 /* SkGLState.cpp in Sources */,
|
||||
0001FB99110E362F00C1D647 /* SkGLTextCache.cpp in Sources */,
|
||||
0001FB9A110E362F00C1D647 /* SkTextureCache.cpp in Sources */,
|
||||
003EE652111239D5001AB759 /* SampleWarp.cpp in Sources */,
|
||||
0021F3A21120B29C0062682F /* SkStaticTextView.cpp in Sources */,
|
||||
0021F3D31120B61F0062682F /* SampleUnitMapper.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user