Skip to content

Commit

Permalink
Simplifications for plugdata drawing mechanism, fixed iolet position …
Browse files Browse the repository at this point in the history
…offset when zoomed in pd-vanilla
  • Loading branch information
timothyschoen committed Feb 28, 2024
1 parent f1dcfde commit 5c65e09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion pdlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ static int pdlua_object_new(lua_State *L)
#else
// NULL until plugdata overrides them with something useful
o->gfx.plugdata_draw_callback = NULL;
o->gfx.plugdata_callback_target = NULL;
#endif

lua_pushlightuserdata(L, o);
Expand Down
1 change: 0 additions & 1 deletion pdlua.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ typedef struct _pdlua_gfx
char current_color[8]; // Keep track of current color
#else
void(*plugdata_draw_callback)(void*, t_symbol*, int, t_atom*); // Callback to perform drawing in plugdata
void* plugdata_callback_target; // Pointer to plugdata object, the target for our draw callback
#endif

// Size variables
Expand Down
12 changes: 8 additions & 4 deletions pdlua_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ static int get_size(lua_State* L)
// Wrapper around draw callback to plugdata
static inline void plugdata_draw(t_pdlua* obj, t_symbol* sym, int argc, t_atom* argv)
{
if(obj->gfx.plugdata_callback_target) {
obj->gfx.plugdata_draw_callback(obj->gfx.plugdata_callback_target, sym, argc, argv);
if(obj->gfx.plugdata_draw_callback) {
obj->gfx.plugdata_draw_callback(obj, sym, argc, argv);
}
}

Expand Down Expand Up @@ -637,9 +637,11 @@ static void gfx_displace(t_pdlua *x, t_glist *glist, int dx, int dy)
sys_vgui(".x%lx.c move .x%lx %d %d\n", glist_getcanvas(x->canvas), (long)x, dx, dy);
canvas_fixlinesfor(glist, (t_text*)x);

int scale = glist_getzoom(glist_getcanvas(x->canvas));

int xpos = text_xpix((t_object*)x, x->canvas);
int ypos = text_ypix((t_object*)x, x->canvas);
glist_drawiofor(glist_getcanvas(x->canvas), (t_object*)x, 0, x->gfx.object_tag, xpos, ypos, xpos + x->gfx.width, ypos + x->gfx.height);
glist_drawiofor(x->canvas, (t_object*)x, 0, x->gfx.object_tag, xpos, ypos, xpos + (x->gfx.width * scale), ypos + (x->gfx.height * scale));
}

static const char* register_drawing(t_pdlua *object)
Expand Down Expand Up @@ -710,10 +712,12 @@ static int end_paint(lua_State* L) {
t_canvas *cnv = glist_getcanvas(obj->canvas);
t_pdlua_gfx *gfx = &obj->gfx;

int scale = glist_getzoom(glist_getcanvas(obj->canvas));

// Draw iolets on top
int xpos = text_xpix((t_object*)obj, obj->canvas);
int ypos = text_ypix((t_object*)obj, obj->canvas);
glist_drawiofor(glist_getcanvas(obj->canvas), (t_object*)obj, 1, gfx->object_tag, xpos, ypos, xpos + gfx->width, ypos + gfx->height);
glist_drawiofor(glist_getcanvas(obj->canvas), (t_object*)obj, 1, gfx->object_tag, xpos, ypos, xpos + (x->gfx.width * scale), ypos + (x->gfx.height * scale));

if(!gfx->first_draw && gfx->order_tag[0] != '\0') {
// Move everything to below the order marker, to make sure redrawn stuff isn't always on top
Expand Down

0 comments on commit 5c65e09

Please sign in to comment.