Simple example showing how to operator<< overloads to construct a complicated path and to fill it with a custom fill rule.
#include <iostream>
#include "initialization.hpp"
{
public:
ExampleFillRule(void):
m_winding_value(0),
m_fill_equal(false)
{}
virtual
bool
{
return (m_fill_equal) ?
m_winding_value == winding_number :
m_winding_value != winding_number;
}
int m_winding_value;
bool m_fill_equal;
};
class ExamplePath2:public Initialization
{
public:
ExamplePath2(DemoRunner *runner, int argc, char **argv);
virtual
void
draw_frame(void) override;
virtual
void
handle_event(const SDL_Event &ev) override;
private:
ExampleFillRule m_example_fill_rule;
};
ExamplePath2::
ExamplePath2(DemoRunner *runner, int argc, char **argv):
Initialization(runner, argc, argv)
{
m_path.approximate_bounding_box(&m_path_bounds);
std::cout << "Press space to toggle fill rule comparison operator between equal and not equal\n"
<< "Press any other key to increment the winding comparison value\n";
}
void
ExamplePath2::
draw_frame(void)
{
float stroke_width, border;
m_surface_gl->viewport(vwp);
stroke_width = 8.0f;
border = 3.0f * stroke_width;
m_painter->shear(scale.
x(), scale.
y());
m_painter->translate(translate);
.color(1.0f, 0.0f, 0.0f, 1.0f),
m_path, m_example_fill_rule);
.color(1.0f, 0.6f, 0.0f, 0.8f),
.width(stroke_width),
m_path,
m_painter->end();
fastuidraw_glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
fastuidraw_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_surface_gl->blit_surface(GL_NEAREST);
}
void
ExamplePath2::
handle_event(const SDL_Event &ev)
{
switch (ev.type)
{
case SDL_KEYDOWN:
switch (ev.key.keysym.sym)
{
case SDLK_SPACE:
m_example_fill_rule.m_fill_equal = !m_example_fill_rule.m_fill_equal;
std::cout << "Winding comparison operator set to ";
if (m_example_fill_rule.m_fill_equal)
{
std::cout << "equality.\n";
}
else
{
std::cout << "inequality.\n";
}
break;
default:
++m_example_fill_rule.m_winding_value;
if (m_example_fill_rule.m_winding_value > 3)
{
m_example_fill_rule.m_winding_value = -1;
}
std::cout << "Winding reference value set to "
<< m_example_fill_rule.m_winding_value
<< "\n";
}
break;
}
Initialization::handle_event(ev);
}
int
main(int argc, char **argv)
{
DemoRunner demo;
return demo.main<ExamplePath2>(argc, argv);
}