static gboolean preview_expose(GtkWidget *widget, GdkEventExpose *event) { cairo_t *cr; gint width = preview_get_width (widget); gint height = preview_get_height (widget); cr = gdk_cairo_create (event->window); gdk_cairo_region (cr, event->region); cairo_clip (cr); cairo_set_line_width (cr, 1.); draw_grid (cr, width, height); draw_shapes (cr); if (_tmp_obj) { /* this is a bit of a hack */ gdouble dash = 4.; _tmp_obj->selected |= 4; cairo_set_source_rgb (cr, 1., 0., 1.); cairo_set_dash (cr, &dash, 1, dash); object_draw (_tmp_obj, cr); } cairo_destroy (cr); return FALSE; }
void draw_loop(const char *dir, int start_image_num, int num_images) { int key, i; IplImage *img; CvSize size = { IMAGE_WIDTH, IMAGE_HEIGHT }; img = cvCreateImage(size, IPL_DEPTH_8U, 1); //3); if (!img) return; for (i = start_image_num; i < start_image_num + num_images; i++) { draw_shapes(img); cvShowImage("shapegen", img); save_image(dir, img, i); if (dir) key = 0xff & cvWaitKey(500); else key = 0xff & cvWaitKey(0); if (key == ESCAPE_KEY) break; } cvReleaseImage(&img); }
//--------------------------------------------------------------------------------------- void GmoBox::on_draw(Drawer* pDrawer, RenderOptions& opt) { draw_border(pDrawer, opt); draw_shapes(pDrawer, opt); //draw contained boxes std::vector<GmoBox*>::iterator it; for (it=m_childBoxes.begin(); it != m_childBoxes.end(); ++it) (*it)->on_draw(pDrawer, opt); }
/* Generate a calibration image based on the average of some accumulated images. */ int generate_cal_image (const char *dir, int num_cal_images) { int key, i; CvScalar bkgd_color, one; IplImage *img, *cal_img, *sum_img, *mask; CvSize size = { IMAGE_WIDTH, IMAGE_HEIGHT }; img = cvCreateImage(size, IPL_DEPTH_8U, 1); if (!img) return 0; cal_img = cvCreateImage(size, IPL_DEPTH_8U, 1); if (!cal_img) { cvReleaseImage(&img); return 0; } mask = cvCreateImage(size, IPL_DEPTH_8U, 1); if (!mask) { cvReleaseImage(&img); cvReleaseImage(&cal_img); return 0; } sum_img = cvCreateImage(size, IPL_DEPTH_32F, 1); if (!sum_img) { cvReleaseImage(&img); cvReleaseImage(&cal_img); cvReleaseImage(&mask); return 0; } bkgd_color.val[0] = BACKGROUND_COLOR; cvSet(img, bkgd_color, NULL); cvSet(cal_img, bkgd_color, NULL); one.val[0] = 1.0; cvSet(mask, one, NULL); cvZero(sum_img); for (i = 0; i < num_cal_images; i++) { draw_shapes(img); save_image(dir, img, i); cvAcc(img, sum_img, mask); cvZero(cal_img); cvConvertScale(sum_img, cal_img, 1.0 / (i + 1), 0); cvShowImage("shapegen", cal_img); if (dir) key = 0xff & cvWaitKey(500); else key = 0xff & cvWaitKey(0); if (key == ESCAPE_KEY) break; } if (key != ESCAPE_KEY) save_image(dir, cal_img, -1); cvReleaseImage(&img); cvReleaseImage(&cal_img); cvReleaseImage(&sum_img); cvReleaseImage(&mask); return (key != ESCAPE_KEY); }
static void on_paint (ClutterActor *actor, CallbackData *data) { int i; ClutterGeometry stage_size; gint hand_width, hand_height; GSList *node; clutter_actor_get_allocation_geometry (data->stage, &stage_size); hand_width = cogl_texture_get_width (data->hand); hand_height = cogl_texture_get_height (data->hand); /* Setup the clipping */ for (node = data->clips; node; node = node->next) { Clip *clip = (Clip *) node->data; if (clip->type == CLIP_RECTANGLE) cogl_clip_push_rectangle (clip->x1, clip->y1, clip->x2, clip->y2); else if (clip->type == CLIP_ROTATED_RECTANGLE) { float size = MIN (ABS (clip->x2 - clip->x1), ABS (clip->y2 - clip->y1)); int cx = (clip->x1 + clip->x2) / 2; int cy = (clip->y1 + clip->y2) / 2; size = sqrtf ((size / 2) * (size / 2) * 2); cogl_push_matrix (); /* Rotate 45° about the centre point */ cogl_translate (cx, cy, 0.0f); cogl_rotate (45.0f, 0.0f, 0.0f, 1.0f); cogl_clip_push_rectangle (-size / 2, -size / 2, size / 2, size / 2); cogl_pop_matrix (); } else { make_clip_path (clip); cogl_clip_push_from_path (); } } /* Draw a rectangle filling the entire stage */ cogl_set_source_color4ub (0x80, 0x80, 0xff, 0xff); cogl_rectangle (0, 0, stage_size.width, stage_size.height); draw_shapes (10, 10); /* Draw the hand at different rotations */ for (i = -2; i <= 2; i++) { cogl_push_matrix (); cogl_translate (stage_size.width / 2 + stage_size.width / 6 * i, stage_size.height / 2, 0); cogl_rotate (i * 40, 0, 1, 0); cogl_set_source_color4ub (0xff, 0xff, 0xff, 0xff); cogl_set_source_texture (data->hand); cogl_rectangle_with_texture_coords ((-hand_width / 2), (-hand_height / 2), (hand_width / 2), (hand_height / 2), 0, 0, 1, 1); cogl_pop_matrix (); } draw_shapes (stage_size.width - 310, stage_size.height - 110); /* Remove all of the clipping */ g_slist_foreach (data->clips, (GFunc) cogl_clip_pop, NULL); /* Draw the bounding box for each of the clips */ for (node = data->clips; node; node = node->next) { Clip *clip = (Clip *) node->data; make_clip_path (clip); cogl_set_source_color4ub (0x00, 0x00, 0xff, 0xff); cogl_path_stroke (); } /* Draw the bounding box for the pending new clip */ if (data->current_clip.type != CLIP_NONE) { make_clip_path (&data->current_clip); cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff); cogl_path_stroke (); } }