cc65 / cc65

cc65 - a freeware C compiler for 6502 based systems
https://cc65.github.io
zlib License
2.33k stars 435 forks source link

Suggestion: Adding line with callback functions to TGI #2373

Open rharper-trailcon opened 10 months ago

rharper-trailcon commented 10 months ago

It would be useful to have a way to control individual points when drawing a line. In the proposed TGI line drawing functions below, the callbacks would be called prior to plotting each point, and if true is returned, the point is plotted, otherwise it isn't. It also provides a means to adjust the color of the point on the fly. Currently, the only way to do this to create your own line drawing function.

void tgi_linewithcallback(int x1, int y1, int x2, int y2, bool *callback(int x, int y, unsigned char *color));
void tgi_linetowithcallback(int x, int y, bool *callback(int x, int y, unsigned char *color));

Uses:

Sample:

bool fancy_line_callback(int x, int y, unsigned char *color) {
    /* Just "even" points for dot-dot-dot pattern */
    if (x % 2 || y % 2)
        return false;
    /* Sixteen color "gradient" */
    *color = ((x ^ y) >> 1) & 0xF;
    return true;
}

void draw_fancy_x() {
    tgi_linewithcallback(20, 20, 110, 110, fancy_line_callback);
    tgi_linewithcallback(20, 110, 110, 20, fancy_line_callback);
};
colinleroy commented 10 months ago

That would be fancy, as you say, but I'm not sure it would be feasible: some of the platforms implementations use ROM calls (at least apple2) Also, it would be really slow...