float_shape_t *make_shape_from_pixbuf(GdkPixbuf *pixbuf) { float_shape_t *s = alloc_shape(); s->x = 0; s->y = 0; s->pixbuf = pixbuf; s->width = gdk_pixbuf_get_width(pixbuf); s->height = gdk_pixbuf_get_height(pixbuf); s->window = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_decorated(GTK_WINDOW(s->window), FALSE); gtk_window_set_title(GTK_WINDOW(s->window), "shape"); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(s->window), TRUE); gtk_window_set_keep_above(GTK_WINDOW(s->window), TRUE); s->image = gtk_image_new_from_pixbuf(pixbuf); gtk_container_add(GTK_CONTAINER(s->window), s->image); get_alpha_mask(s); gtk_widget_shape_combine_mask(s->window, s->mask_bitmap, 0, 0); g_signal_connect(G_OBJECT(s->window), "destroy", G_CALLBACK(quit_callback), NULL); return s; }
/************************************************************************* ************************************************************************** #cat: shape_from_contour - Converts a contour list that has been determined #cat: to form a complete loop into a shape representation where #cat: the contour points on each contiguous scanline of the shape #cat: are stored in left-to-right order. Input: contour_x - x-coord list for loop's contour points contour_y - y-coord list for loop's contour points ncontour - number of points in contour Output: oshape - points to the resulting shape structure Return Code: Zero - shape successfully derived Negative - system error **************************************************************************/ int shape_from_contour(SHAPE **oshape, const int *contour_x, const int *contour_y, const int ncontour) { SHAPE *shape; ROW *row; int ret, i, xmin, ymin, xmax, ymax; /* Find xmin, ymin, xmax, ymax on contour. */ contour_limits(&xmin, &ymin, &xmax, &ymax, contour_x, contour_y, ncontour); /* Allocate and initialize a shape structure. */ if((ret = alloc_shape(&shape, xmin, ymin, xmax, ymax))) /* If system error, then return error code. */ return(ret); /* Foreach point on contour ... */ for(i = 0; i < ncontour; i++){ /* Add point to corresponding row. */ /* First set a pointer to the current row. We need to subtract */ /* ymin because the rows are indexed relative to the top-most */ /* scanline in the shape. */ row = shape->rows[contour_y[i]-ymin]; /* It is possible with complex shapes to reencounter points */ /* already visited on a contour, especially at "pinching" points */ /* along the contour. So we need to test to see if a point has */ /* already been stored in the row. If not in row list already ... */ if(in_int_list(contour_x[i], row->xs, row->npts) < 0){ /* If row is full ... */ if(row->npts >= row->alloc){ /* This should never happen becuase we have allocated */ /* based on shape bounding limits. */ fprintf(stderr, "ERROR : shape_from_contour : row overflow\n"); return(-260); } /* Assign the x-coord of the current contour point to the row */ /* and bump the row's point counter. All the contour points */ /* on the same row share the same y-coord. */ row->xs[row->npts++] = contour_x[i]; } /* Otherwise, point is already stored in row, so ignore. */ } /* Foreach row in the shape. */ for(i = 0; i < shape->nrows; i++) /* Sort row points increasing on their x-coord. */ sort_row_on_x(shape->rows[i]); /* Assign shape structure to output pointer. */ *oshape = shape; /* Return normally. */ return(0); }