I want to make a simple paint type application which would have two panels"
- Painting area
- Panel containing set of colors.
I need to know how can I set up panels in Openframeworks.
I want to make a simple paint type application which would have two panels"
I need to know how can I set up panels in Openframeworks.
While ofxGui
offers “panels”, I don’t think it will do exactly what you want by default.
I would recommend making a small class that contains an ofRectangle
and an ofColor
. It might also have a method called draw()
that draws a rectangle filled with the color at the right location on screen.
Then I would create an instance of that class (perhaps you might call it MyPaletteColor
) with the position/size (represented by the ofRectangle
) and color (represented by the ofColor
) that describe their locations in a paint panel. You might store the collection of objects in a std::vector<MyPaletteColor>
. Then you’ll need to keep track of a few variables like bool isPainting;
and ofColor currentPaintingColor;
.
Then during each ofApp::update()
loop I would look at where the mouse cursor is on screen. If isPainting
is true
, and the mouse is being dragged (i.e. the mouse is down), then keep painting with the current color. If isPainting
is true
and the mouse is released, then you set isPainting
to false
. If isPainting
is false
and the mouse is pressed, then you have to make a decision. If the mouse button was pressed while it was on top of one of your MyPaletteColor
instances (you’ll need to cycle through your std::vector
and ask each instance’s ofRectangle
if your mouseX
and mouseY
isInside()
), then you will set currentPaintingColor
to the color of the MyPaletteColor
instance that you just clicked. else the mouse must have been pressed somewhere on the painting canvas (the simple interpretation) and you should set isPainting
to true
and begin painting until the mouse is released (at which time you’ll set isPainting
back to false
).
Then you can repeat the process.
Thank you so much.
My pleasure. Just share your project when you’re done!