News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Main Menu

Drawing a circle

Started by Rudolph, October 17, 2026, 05:40:14 PM

Previous topic - Next topic

Rudolph

I am re-visiting my circle function:
void EVE_widget_circle(const int16_t xc0, const int16_t yc0, const uint16_t radius, const uint16_t border, const uint32_t bgcolor)
{
    EVE_save_context();
    EVE_begin(EVE_POINTS);
    EVE_point_size(radius);
    EVE_vertex2f(xc0, yc0);
    EVE_color_rgb(bgcolor);
    EVE_point_size((uint16_t) (radius - border));
    EVE_vertex2f(xc0, yc0);
    EVE_end();
    EVE_restore_context();
}

While that is short and simple, it is a bit odd to use.
The inner area is not transparent, but filled with the provided color.
This is using 9 commands, so 36 bytes in the command-list.

Now I have this:
void EVE_widget_circle(const int16_t xc0, const int16_t yc0, const uint16_t radius, const uint16_t border)
{
    EVE_save_context();
    EVE_color_mask(0, 0, 0, 0);
    EVE_stencil_func(EVE_ALWAYS, 0x01, 0x01);
    EVE_stencil_op(EVE_REPLACE, EVE_REPLACE);
    EVE_point_size((uint16_t) (radius - border));
    EVE_begin(EVE_POINTS);
    EVE_vertex2f(xc0, yc0);
//    EVE_end();
    EVE_color_mask(1, 1, 1, 1);
    EVE_stencil_func(EVE_NOTEQUAL, 0x01, 0x01);
    EVE_stencil_op(EVE_KEEP, EVE_KEEP);
    EVE_point_size(radius);
//    EVE_begin(EVE_POINTS);
    EVE_vertex2f(xc0, yc0);
//    EVE_end();
    EVE_color_mask(0, 0, 0, 0);
    EVE_stencil_func(EVE_ALWAYS, 0x00, 0x01);
    EVE_stencil_op(EVE_REPLACE, EVE_REPLACE);
//    EVE_begin(EVE_POINTS);
    EVE_vertex2f(xc0, yc0);
    EVE_end();
    EVE_restore_context();
}

And this works fine, 18 commands, 72 bytes in the command-list.

At least in the EVE Emulator library I can do this:
EVE_color_rgb(BLACK);
EVE_cmd_text(40, 350, 31, 0, "The quick brown fox jumps...");

EVE_color_rgb(GREEN);
EVE_widget_circle(100,400, 50*16, 8*16);

EVE_color_rgb(RED);
EVE_widget_circle(150,400, 50*16, 8*16);

EVE_color_rgb(MAGENTA);
EVE_widget_circle(220,400, 50*16, 8*16);

I get three overlapping circles and the text underneath.

Hmm, yes, I am also using:
EVE_vertex_format(0);
But neither POINT_SIZE or LINE_WIDTH care about that.

What I am wondering now is, is there a way to do this more efficient?

For rectangles with transparent background I played with this in EVE Screen Editor:
SAVE_CONTEXT();
COLOR_MASK(0, 0, 0, 0);
STENCIL_FUNC(ALWAYS, 0x01, 0x01);
STENCIL_OP(REPLACE, REPLACE);
BEGIN(RECTS)
VERTEX2F(4100, 2100);
VERTEX2F(5900, 3900);
//END();
COLOR_MASK(1, 1, 1, 1);
STENCIL_FUNC(NOTEQUAL, 0x01, 0x01);
STENCIL_OP(KEEP, KEEP);
//BEGIN(RECTS)
VERTEX2F(4000, 2000);
VERTEX2F(6000, 4000);
//END();
COLOR_MASK(0, 0, 0, 0);
STENCIL_FUNC(ALWAYS, 0x00, 0x01);
STENCIL_OP(REPLACE, REPLACE);
//BEGIN(RECTS)
VERTEX2F(4000, 2000);
VERTEX2F(6000, 4000);
END();
RESTORE_CONTEXT();

Same principle, only not put into the final form.
The setting of color and line-width is deliberately left out, so you can have multiple
rectangles with only setting the color and line-width as needed.