void area_changed(MyPaintTiledSurface *tiled_surface, int bb_x, int bb_y, int bb_w, int bb_h) { MyPaintPythonTiledSurface *self = (MyPaintPythonTiledSurface *)tiled_surface; ExpandRectToIncludePoint (&self->dirty_bbox, bb_x, bb_y); ExpandRectToIncludePoint (&self->dirty_bbox, bb_x+bb_w-1, bb_y+bb_h-1); }
// returns true if the surface was modified bool draw_dab (float x, float y, float radius, float color_r, float color_g, float color_b, float opaque, float hardness = 0.5, float color_a = 1.0, float aspect_ratio = 1.0, float angle = 0.0, float lock_alpha = 0.0 ) { opaque = CLAMP(opaque, 0.0, 1.0); hardness = CLAMP(hardness, 0.0, 1.0); lock_alpha = CLAMP(lock_alpha, 0.0, 1.0); if (radius < 0.1) return false; // don't bother with dabs smaller than 0.1 pixel if (hardness == 0.0) return false; // infintly small center point, fully transparent outside if (opaque == 0.0) return false; assert(atomic > 0); color_r = CLAMP(color_r, 0.0, 1.0); color_g = CLAMP(color_g, 0.0, 1.0); color_b = CLAMP(color_b, 0.0, 1.0); color_a = CLAMP(color_a, 0.0, 1.0); uint16_t color_r_ = color_r * (1<<15); uint16_t color_g_ = color_g * (1<<15); uint16_t color_b_ = color_b * (1<<15); // blending mode preparation float normal = 1.0; normal *= 1.0-lock_alpha; if (aspect_ratio<1.0) aspect_ratio=1.0; float r_fringe = radius + 1; int tx1 = floor(floor(x - r_fringe) / TILE_SIZE); int tx2 = floor(floor(x + r_fringe) / TILE_SIZE); int ty1 = floor(floor(y - r_fringe) / TILE_SIZE); int ty2 = floor(floor(y + r_fringe) / TILE_SIZE); int tx, ty; for (ty = ty1; ty <= ty2; ty++) { for (tx = tx1; tx <= tx2; tx++) { uint16_t * rgba_p = get_tile_memory(tx, ty, false); if (!rgba_p) { printf("Python exception during draw_dab()!\n"); return true; } // first, we calculate the mask (opacity for each pixel) static uint16_t mask[TILE_SIZE*TILE_SIZE+2*TILE_SIZE]; render_dab_mask(mask, x - tx*TILE_SIZE, y - ty*TILE_SIZE, radius, hardness, aspect_ratio, angle ); // second, we use the mask to stamp a dab for each activated blend mode if (normal) { if (color_a == 1.0) { draw_dab_pixels_BlendMode_Normal(mask, rgba_p, color_r_, color_g_, color_b_, normal*opaque*(1<<15)); } else { // normal case for brushes that use smudging (eg. watercolor) draw_dab_pixels_BlendMode_Normal_and_Eraser(mask, rgba_p, color_r_, color_g_, color_b_, color_a*(1<<15), normal*opaque*(1<<15)); } } if (lock_alpha) { draw_dab_pixels_BlendMode_LockAlpha(mask, rgba_p, color_r_, color_g_, color_b_, lock_alpha*opaque*(1<<15)); } } } { // expand the bounding box to include the region we just drawed int bb_x, bb_y, bb_w, bb_h; bb_x = floor (x - (radius+1)); bb_y = floor (y - (radius+1)); /* FIXME: think about it exactly */ bb_w = ceil (2*(radius+1)); bb_h = ceil (2*(radius+1)); ExpandRectToIncludePoint (&dirty_bbox, bb_x, bb_y); ExpandRectToIncludePoint (&dirty_bbox, bb_x+bb_w-1, bb_y+bb_h-1); } return true; }