From cebd7a0c23e6b32471687d1715bbf25fc08faf67 Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Wed, 30 Aug 2000 18:26:49 +0000 Subject: [PATCH] Scratch that. Start again. Removed all the _clipped functions. Added imlib_context_set_cliprect(int x, int y, int w, int h) and a corresponding _get_cliprect. Set width to 0 to disable clipping (default). Just use the normal _draw_ functions and it'll do the Right thing. SVN revision: 3278 --- src/Imlib2.h | 28 ++++++------ src/api.c | 115 ++++++++++++++++++++++++++++--------------------- src/rgbadraw.c | 40 +++++++++++++++++ src/rgbadraw.h | 36 ++++++++++++++++ test/main.c | 59 +++++++++++++------------ 5 files changed, 189 insertions(+), 89 deletions(-) diff --git a/src/Imlib2.h b/src/Imlib2.h index 893c576..8e0bf94 100644 --- a/src/Imlib2.h +++ b/src/Imlib2.h @@ -17,7 +17,14 @@ typedef void * Imlib_Color_Range; typedef void * Imlib_Filter; typedef struct _imlib_border Imlib_Border; typedef struct _imlib_color Imlib_Color; -typedef struct _imlib_rectangle Imlib_Rectangle; +typedef void * ImlibPolygon; + +enum _imlib_polytype +{ + POLY_OPEN, + POLY_CLOSED, + POLY_FILLED +}; enum _imlib_operation { @@ -69,11 +76,6 @@ struct _imlib_color int alpha, red, green, blue; }; -struct _imlib_rectangle -{ - int x, y, width, height; -}; - typedef int (*Imlib_Progress_Function)(Imlib_Image im, char percent, int update_x, int update_y, int update_w, int update_h); @@ -102,6 +104,7 @@ void imlib_context_set_color_range(Imlib_Color_Range color_range); void imlib_context_set_progress_function(Imlib_Progress_Function progress_function); void imlib_context_set_progress_granularity(char progress_granularity); void imlib_context_set_image(Imlib_Image image); +void imlib_context_set_cliprect(int x, int y, int w, int h); Display *imlib_context_get_display(void); void imlib_context_set_visual(Visual *visual); @@ -124,6 +127,7 @@ Imlib_Color_Range imlib_context_get_color_range(void); Imlib_Progress_Function imlib_context_get_progress_function(void); char imlib_context_get_progress_granularity(void); Imlib_Image imlib_context_get_image(void); +void imlib_context_get_cliprect(int *x, int *y, int *w, int *h); int imlib_get_cache_size(void); void imlib_set_cache_size(int bytes); @@ -233,20 +237,18 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin, int ymax, int *clip_x0, int *clip_y0, int *clip_x1, int *clip_y1); Imlib_Updates imlib_image_draw_line(int x1, int y1, int x2, int y2, char make_updates); -/* draw line clipped into rectangle - results in no draw if line is not inside - * rectangle */ -Imlib_Updates imlib_image_draw_line_clipped(int x1, int y1, int x2, int y2, int clip_xmin, int clip_xmax, int clip_ymin, int clip_ymax, char make_updates); void imlib_image_draw_rectangle(int x, int y, int width, int height); -void -imlib_image_draw_rectangle_clipped(int x, int y, int width, int height, - int clip_xmin, int clip_xmax, int clip_ymin, - int clip_ymax); void imlib_image_fill_rectangle(int x, int y, int width, int height); void imlib_image_copy_alpha_to_image(Imlib_Image image_source, int x, int y); void imlib_image_copy_alpha_rectangle_to_image(Imlib_Image image_source, int x, int y, int width, int height, int destination_x, int destination_y); void imlib_image_scroll_rect(int x, int y, int width, int height, int delta_x, int delta_y); void imlib_image_copy_rect(int x, int y, int width, int height, int new_x,int new_y); +/* polygons */ +ImlibPolygon imlib_polygon_new(int type); +void imlib_polygon_free(ImlibPolygon poly); +void imlib_polygon_add_point(ImlibPolygon poly, int x, int y); + Imlib_Color_Range imlib_create_color_range(void); void imlib_free_color_range(void); void imlib_add_color_to_color_range(int distance_away); diff --git a/src/api.c b/src/api.c index 433dc49..c3c85c5 100644 --- a/src/api.c +++ b/src/api.c @@ -86,8 +86,26 @@ static Imlib_Progress_Function ctxt_progress_func = NULL; static char ctxt_progress_granularity = 0; static char ctxt_dither_mask = 0; static Imlib_Filter ctxt_filter = NULL; +static Imlib_Rectangle ctxt_cliprect = {0,0,0,0}; /* context setting/getting functions */ + +void imlib_context_set_cliprect(int x, int y, int w, int h) +{ + ctxt_cliprect.x = x; + ctxt_cliprect.y = y; + ctxt_cliprect.w = w; + ctxt_cliprect.h = h; +} + +void imlib_context_get_cliprect(int *x, int *y, int *w, int *h) +{ + *x = ctxt_cliprect.x; + *y = ctxt_cliprect.y; + *w = ctxt_cliprect.w; + *h = ctxt_cliprect.h; +} + void imlib_context_set_display(Display * display) { @@ -2032,39 +2050,29 @@ Imlib_Updates imlib_image_draw_line(int x1, int y1, int x2, int y2, return NULL; __imlib_DirtyImage(im); __imlib_DirtyPixmapsForImage(im); + if(ctxt_cliprect.w) + { + return (Imlib_Updates) __imlib_draw_line_clipped(im, x1, y1, x2, y2, + ctxt_cliprect.x, + ctxt_cliprect.x + ctxt_cliprect.w, + ctxt_cliprect.y, + ctxt_cliprect.y + ctxt_cliprect.h, + (DATA8) ctxt_color.red, + (DATA8) ctxt_color.green, + (DATA8) ctxt_color.blue, + (DATA8) ctxt_color.alpha, + ctxt_operation, + (char)make_updates); + } + else + { return (Imlib_Updates) __imlib_draw_line(im, x1, y1, x2, y2, (DATA8) ctxt_color.red, (DATA8) ctxt_color.green, (DATA8) ctxt_color.blue, (DATA8) ctxt_color.alpha, ctxt_operation, (char)make_updates); -} - -Imlib_Updates imlib_image_draw_line_clipped(int x1, int y1, int x2, int y2, - int clip_xmin, int clip_xmax, - int clip_ymin, int clip_ymax, - char make_updates) -{ - ImlibImage *im; - - CHECK_PARAM_POINTER_RETURN("imlib_image_draw_line_clipped", "image", - ctxt_image, NULL); - CAST_IMAGE(im, ctxt_image); - if ((!(im->data)) && (im->loader) && (im->loader->load)) - im->loader->load(im, NULL, 0, 1); - if (!(im->data)) - return NULL; - __imlib_DirtyImage(im); - __imlib_DirtyPixmapsForImage(im); - return (Imlib_Updates) __imlib_draw_line_clipped(im, x1, y1, x2, y2, - clip_xmin, clip_xmax, - clip_ymin, clip_ymax, - (DATA8) ctxt_color.red, - (DATA8) ctxt_color.green, - (DATA8) ctxt_color.blue, - (DATA8) ctxt_color.alpha, - ctxt_operation, - (char)make_updates); + } } void @@ -2080,29 +2088,22 @@ imlib_image_draw_rectangle(int x, int y, int width, int height) return; __imlib_DirtyImage(im); __imlib_DirtyPixmapsForImage(im); - __imlib_draw_box(im, x, y, width, height, ctxt_color.red, ctxt_color.green, - ctxt_color.blue, ctxt_color.alpha, ctxt_operation); -} - -void -imlib_image_draw_rectangle_clipped(int x, int y, int width, int height, - int clip_xmin, int clip_xmax, int clip_ymin, - int clip_ymax) -{ - ImlibImage *im; - - CHECK_PARAM_POINTER("imlib_image_draw_rectangle", "image", ctxt_image); - CAST_IMAGE(im, ctxt_image); - if ((!(im->data)) && (im->loader) && (im->loader->load)) - im->loader->load(im, NULL, 0, 1); - if (!(im->data)) - return; - __imlib_DirtyImage(im); - __imlib_DirtyPixmapsForImage(im); - __imlib_draw_box_clipped(im, x, y, width, height, clip_xmin, clip_xmax, - clip_ymin, clip_ymax, ctxt_color.red, + if(ctxt_cliprect.w) + { + __imlib_draw_box_clipped(im, x, y, width, height, + ctxt_cliprect.x, + ctxt_cliprect.x + ctxt_cliprect.w, + ctxt_cliprect.y, + ctxt_cliprect.y + ctxt_cliprect.h, + ctxt_color.red, ctxt_color.green, ctxt_color.blue, ctxt_color.alpha, ctxt_operation); + } + else + { + __imlib_draw_box(im, x, y, width, height, ctxt_color.red, ctxt_color.green, + ctxt_color.blue, ctxt_color.alpha, ctxt_operation); + } } void @@ -2701,3 +2702,21 @@ imlib_apply_filter(char *script, ...) __imlib_script_parse(im, script, param_list); va_end(param_list); } + +ImlibPolygon imlib_polygon_new(int type) +{ + return (ImlibPolygon)__imlib_polygon_new(type); +} + +void imlib_polygon_add_point(ImlibPolygon poly, int x, int y) +{ + CHECK_PARAM_POINTER("imlib_polygon_add_point", "polygon", poly); + __imlib_polygon_add_point(poly, x, y); +} + +void imlib_polygon_free(ImlibPolygon poly) +{ + CHECK_PARAM_POINTER("imlib_polygon_free", "polygon", poly); + __imlib_polygon_free(poly); +} + diff --git a/src/rgbadraw.c b/src/rgbadraw.c index 74dbf63..2604f5f 100644 --- a/src/rgbadraw.c +++ b/src/rgbadraw.c @@ -1626,3 +1626,43 @@ __imlib_comp_outcode(double x, double y, double xmin, double xmax, double ymin, code |= LEFT; return code; } + +ImlibPoly __imlib_polygon_new(int type) +{ + ImlibPoly poly; + poly = malloc(sizeof(_ImlibPoly)); + if(!poly) + return NULL; + memset(poly, 0, sizeof(_ImlibPoly)); + switch(type) + { + case P_OPEN: + break; + case P_CLOSED: + poly->closed = 1; + break; + case P_FILLED: + poly->filled = 1; + break; + default: + break; + } + return poly; +} + +void __imlib_polygon_add_point(ImlibPoly poly, int x, int y) +{ + poly->pointcount++; + if(!poly->points) + poly->points = malloc(sizeof(ImlibPoint)); + else + poly->points = realloc(poly->points, (poly->pointcount * sizeof(ImlibPoint))); + poly->points[poly->pointcount - 1].x = x; + poly->points[poly->pointcount - 1].y = y; +} + +void __imlib_polygon_free(ImlibPoly poly) +{ + free(poly->points); + free(poly); +} diff --git a/src/rgbadraw.h b/src/rgbadraw.h index 2ecb90b..53bc65c 100644 --- a/src/rgbadraw.h +++ b/src/rgbadraw.h @@ -1,6 +1,42 @@ #ifndef __RGBADRAW #define __RGBADRAW 1 +typedef struct _imlib_point ImlibPoint; + +struct _imlib_point +{ + int x,y; +}; + +typedef struct _imlib_rectangle Imlib_Rectangle; + +struct _imlib_rectangle +{ + int x,y,w,h; +}; + + +enum __imlib_polytype +{ + P_OPEN, + P_CLOSED, + P_FILLED +}; + +typedef struct _imlib_polygon _ImlibPoly; +typedef _ImlibPoly * ImlibPoly; + +struct _imlib_polygon +{ + unsigned char closed, filled; + ImlibPoint *points; + int pointcount; + DATA8 r,g,b,a; +}; + +void __imlib_polygon_free(ImlibPoly poly); +void __imlib_polygon_add_point(ImlibPoly poly, int x, int y); +ImlibPoly __imlib_polygon_new(int type); typedef unsigned int ImlibOutCode; enum diff --git a/test/main.c b/test/main.c index 62addcb..4912bc7 100644 --- a/test/main.c +++ b/test/main.c @@ -763,54 +763,57 @@ int main (int argc, char **argv) up = imlib_updates_append_updates(up, uu); /* test line clipping */ + imlib_context_set_cliprect(0,0,0,0); imlib_image_draw_rectangle(50,50,100,100); up = imlib_update_append_rect(up, 50,50,100,100); imlib_context_set_color(255, 255, 255, 255); + uu = imlib_image_draw_line(0, 0, 200, 200, 1); up = imlib_updates_append_updates(up, uu); - imlib_context_set_color(255, 55, 55, 255); - uu = imlib_image_draw_line_clipped(0, 0, 200, 200, 50, 150, 50, 150, 1); - up = imlib_updates_append_updates(up, uu); - - imlib_context_set_color(255, 255, 255, 255); + uu = imlib_image_draw_line(305, 25, 20, 200, 1); up = imlib_updates_append_updates(up, uu); - imlib_context_set_color(255, 55, 55, 255); - uu = imlib_image_draw_line_clipped(305, 25, 20, 200, 50, 150, 50, 150, 1); - up = imlib_updates_append_updates(up, uu); - - imlib_context_set_color(255, 255, 255, 255); + uu = imlib_image_draw_line(100, 5, 100, 205, 1); up = imlib_updates_append_updates(up, uu); - imlib_context_set_color(255, 55, 55, 255); - uu = imlib_image_draw_line_clipped(100, 5, 100, 205, 50, 150, 50, 150, 1); - up = imlib_updates_append_updates(up, uu); - imlib_context_set_color(255, 255, 255, 255); uu = imlib_image_draw_line(275, 5, 20, 100, 1); up = imlib_updates_append_updates(up, uu); - imlib_context_set_color(255, 55, 55, 255); - uu = imlib_image_draw_line_clipped(275, 5, 20, 100, 50, 150, 50, 150, 1); + + + imlib_context_set_color(255, 55, 55, 255); + imlib_context_set_cliprect(50,50,100,100); + + uu = imlib_image_draw_line(0, 0, 200, 200,1); + up = imlib_updates_append_updates(up, uu); + + uu = imlib_image_draw_line(305, 25, 20, 200,1); up = imlib_updates_append_updates(up, uu); + uu = imlib_image_draw_line(100, 5, 100, 205,1); + up = imlib_updates_append_updates(up, uu); + + uu = imlib_image_draw_line(275, 5, 20, 100,1); + up = imlib_updates_append_updates(up, uu); + + /* test rectangle clipping */ imlib_context_set_color(255, 255, 255, 255); - imlib_image_draw_rectangle(70,90,20,20); - imlib_context_set_color(255, 55, 55, 255); - imlib_image_draw_rectangle_clipped(70,90,20,20,50, 150, 50, 150); - up = imlib_update_append_rect(up, 70,90,20,20); - - imlib_context_set_color(255, 255, 255, 255); - imlib_image_draw_rectangle(115,70,60,30); - imlib_context_set_color(255, 55, 55, 255); - imlib_image_draw_rectangle_clipped(115,70,60,30,50, 150, 50, 150); - up = imlib_update_append_rect(up, 115,70,60,30); + imlib_context_set_cliprect(0,0,0,0); - imlib_context_set_color(255, 255, 255, 255); + imlib_image_draw_rectangle(70,90,20,20); + imlib_image_draw_rectangle(115,70,60,30); imlib_image_draw_rectangle(30,120,50,50); + imlib_context_set_color(255, 55, 55, 255); - imlib_image_draw_rectangle_clipped(30,120,50,50,50, 150, 50, 150); + imlib_context_set_cliprect(50,50,100,100); + + imlib_image_draw_rectangle(70,90,20,20); + up = imlib_update_append_rect(up, 70,90,20,20); + imlib_image_draw_rectangle(115,70,60,30); + up = imlib_update_append_rect(up, 115,70,60,30); + imlib_image_draw_rectangle(30,120,50,50); up = imlib_update_append_rect(up, 30,120,50,50); }