Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion samples/HierarchySample/src/Square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void Square::setup(int size)
mHighlightColor = ci::Color(ci::CM_HSV, 1 - hue, 1, 1);

mShape->setFillColor(mColor);
mShape->setStrokeColor(ci::Color::black());
mShape->setStrokeEnabled(true);
addChild(mShape);

// Connect to mouse events
Expand Down Expand Up @@ -107,4 +109,4 @@ void Square::highlightChildren(bool isHighlighted)
child->setDrawBounds(false);
}
}
}
}
3 changes: 2 additions & 1 deletion src/poScene/poNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace po { namespace scene {
, mFillEnabled(true)
, mStrokeColor(255, 255, 255)
, mStrokeEnabled(false)
, mStrokeSize(2.f)
, mPixelSnapping(false)
, mUpdatePositionFromAnim(false)
, mUpdateScaleFromAnim(false)
Expand Down Expand Up @@ -783,4 +784,4 @@ namespace po { namespace scene {
return false;
}

} } // namespace po::scene
} } // namespace po::scene
7 changes: 6 additions & 1 deletion src/poScene/poNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,14 @@ namespace po { namespace scene {
Node &setStrokeColor(float r, float g, float b) { mStrokeColor = ci::Color(r, g, b); return *this;}
//! Enable or disable the stroke
Node &setStrokeEnabled(bool enabled) { mStrokeEnabled = enabled; return *this; };
//! Set the stroke size with a pixel amount
Node &setStrokeSize(float size) { mStrokeSize = size; return *this; }
//! Get stroke enabled
bool getStrokeEnabled() { return mStrokeEnabled; }
//! Get the stroke color
ci::Color getStrokeColor() { return mStrokeColor; }
//! Set the stroke color (convenience method)
float &getStrokeSize() { return mStrokeSize; }

// Caching/FBO
// Nodes can be cached to an FBO. This is generally useful when applying a shader to a whole node,
Expand Down Expand Up @@ -511,6 +515,7 @@ namespace po { namespace scene {
ci::Color mFillColor;
ci::Color mStrokeColor;
bool mFillEnabled, mStrokeEnabled;
float mStrokeSize;
float mAlpha, mAppliedAlpha;
MatrixOrder mMatrixOrder;

Expand Down Expand Up @@ -611,4 +616,4 @@ namespace po { namespace scene {

};

} } // namespace po::scene
} } // namespace po::scene
24 changes: 21 additions & 3 deletions src/poScene/poShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ namespace po { namespace scene {

void Shape::draw()
{
if(getStrokeEnabled()) {
ci::Rectf b = getBounds();
float s = getStrokeSize();
ci::vec2 scale =
ci::vec2((b.getWidth() + s * 2.f) / b.getWidth(), (b.getHeight() + s * 2.f) / b.getHeight());

ci::gl::color(ci::Color(getStrokeColor()));
// Scale up by 2 times stroke size pixels.
ci::gl::scale(scale);

// Translate it so that the main shape is centered.
ci::gl::translate(-s, -s);
ci::gl::ScopedGlslProg shaderScp( ci::gl::getStockShader( ci::gl::ShaderDef().color()));
ci::gl::draw(mVboMesh);

// Remember to scale and translate back before drawing the main shape.
ci::gl::scale(ci::vec2(1.0f) / scale);
ci::gl::translate(s, s);
}

//Draw fill
if (getFillEnabled()) {
ci::gl::enableAlphaBlending();
Expand All @@ -189,8 +209,6 @@ namespace po { namespace scene {
ci::gl::draw(mVboMesh);
}
}

// TODO: Draw stroke
}


Expand Down Expand Up @@ -306,4 +324,4 @@ namespace po { namespace scene {
return mBounds;
}

} } // namespace po::scene
} } // namespace po::scene