static void set_surface_from_name(HippoCanvasImage *image) { if (image->image_name == NULL) { set_surface(image, NULL); } else { cairo_surface_t *surface; HippoCanvasContext *context; context = hippo_canvas_box_get_context(HIPPO_CANVAS_BOX(image)); /* If context is NULL, we'll call set_surface_from_name again * when a new context is set */ if (context != NULL) { /* may return NULL */ surface = hippo_canvas_context_load_image(context, image->image_name); set_surface(image, surface); if (surface != NULL) cairo_surface_destroy(surface); } else { set_surface(image, NULL); } } }
static scene *make_scene() { /* Place the checkerboard */ checkerboards.normal.x = 0.0; checkerboards.normal.y = 1.0; checkerboards.normal.z = 0.0; checkerboards.distance = -2.0; set_surface(&checkerboards.p1, 0.9, 0.9, 0.9, 0.0); set_surface(&checkerboards.p2, 0.1, 0.1, 0.1, 0.0); int num_checkerboards = 1; /* Place a set of spheres. */ int num_spheres = 5; sphere *spheres = (sphere *)malloc(num_spheres * sizeof(sphere)); int i; vector pos = { -2.5, -0.5, 3.0 }; double radius = pos.y - checkerboards.distance; for (i = 0; i < num_spheres; i++) { spheres[i].center = pos; spheres[i].radius = radius; colour c = colour_phase((double)i / num_spheres); set_surface(&spheres[i].props, c.r, c.g, c.b, 0.5); spheres[i].fuzz_size = 0.0; spheres[i].fuzz_style = none; pos.x += 2.5; pos.z += 2.0; } scene *result = (scene *)malloc(sizeof(scene)); result->spheres = spheres; result->num_spheres = num_spheres; result->checkerboards = &checkerboards; result->num_checkerboards = num_checkerboards; result->lights = lights; result->num_lights = num_lights; result->num_samples = 1000; result->blur_size = 6.0; result->antialias_size = 0.5; result->focal_depth = 5.0; result->callback = NULL; return result; }
void cairo_box::draw(void) { // using fltk functions, set up white background with thin black frame //fl_color(FL_WHITE); //fl_rectf(x(), y(), w(), h()); draw_box(); // Rahmen außenrum? #if 0 fl_color(FL_BLACK); fl_rect(x(), y(), w(), h()); #endif //fl_push_clip(100,100,100,100); //fl_color(FL_BLACK); //fl_line(1,1,parent()->w(),parent()->h()); // set up cairo structures Fl_Widget *p = this; while (p->parent ()) p = p->parent (); //printf ("p=%p\n", p); surface = set_surface(p->w(), p->h()); cr = cairo_create(surface); cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); // set drawing color to black cairo_new_path(cr); //printf ("x()=%i, y()=%i, w()=%i, h()=%i\n", x(), y(), w(), h()); cairo_draw (); // release the cairo context cairo_destroy(cr); cairo_surface_destroy(surface); }
void CairoBox::draw(void) { // using fltk functions, set up white background with thin black frame fl_push_no_clip(); /* remove any clipping region set by the expose events... */ fl_push_clip(x(), y(), w(), h()); fl_color(FL_WHITE); fl_rectf(x(), y(), w(), h()); fl_color(FL_BLACK); fl_rect(x(), y(), w(), h()); // set up cairo structures surface = set_surface(w(), h()); cr = cairo_create(surface); /* All Cairo co-ordinates are shifted by 0.5 pixels to correct anti-aliasing */ cairo_translate(cr, 0.5, 0.5); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); // set drawing color to black cairo_new_path(cr); // virtual function defined in driver program graphic(cr, x(), y(), w(), h()); // release the cairo context cairo_destroy(cr); cairo_surface_destroy(surface); // cr = NULL; // remove clip regions fl_pop_clip(); // local clip region fl_pop_clip(); // "no_clip" region }
static void champlain_point_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { ChamplainPoint *point = CHAMPLAIN_POINT (object); switch (prop_id) { case PROP_COLOR: champlain_point_set_color (point, clutter_value_get_color (value)); break; case PROP_SIZE: champlain_point_set_size (point, g_value_get_double (value)); break; case PROP_SURFACE: set_surface (CHAMPLAIN_EXPORTABLE (object), g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
/* Make a spherical shell filled with spheres. */ static scene *make_scene() { /* Place the checkerboard */ checkerboards.normal.x = 0.0; checkerboards.normal.y = 1.0; checkerboards.normal.z = 0.0; checkerboards.distance = -2.0; set_surface(&checkerboards.p1, 0.9, 0.9, 0.9, 0.0); set_surface(&checkerboards.p2, 0.1, 0.1, 0.1, 0.0); int num_checkerboards = 1; /* Place a set of spheres. */ int num_spheres = 1; sphere *spheres = (sphere *)malloc(num_spheres * sizeof(sphere)); vector pos = { 0.0, 0.0, 5.0 }; spheres->center = pos; spheres->radius = pos.y - checkerboards.distance; set_surface(&(spheres->props), 0.7, 0.7, 0.7, 0.5); spheres->fuzz_size = 0.0; spheres->fuzz_style = none; scene *result = (scene *)malloc(sizeof(scene)); result->spheres = spheres; result->num_spheres = num_spheres; result->checkerboards = &checkerboards; result->num_checkerboards = num_checkerboards; result->lights = lights; result->num_lights = num_lights; result->num_samples = 1000; result->blur_size = 0.0; result->antialias_size = 0.5; result->focal_depth = 0.0; result->callback = NULL; return result; }
static void champlain_path_layer_set_property (GObject *object, guint property_id, G_GNUC_UNUSED const GValue *value, GParamSpec *pspec) { switch (property_id) { case PROP_CLOSED_PATH: champlain_path_layer_set_closed (CHAMPLAIN_PATH_LAYER (object), g_value_get_boolean (value)); break; case PROP_FILL: champlain_path_layer_set_fill (CHAMPLAIN_PATH_LAYER (object), g_value_get_boolean (value)); break; case PROP_STROKE: champlain_path_layer_set_stroke (CHAMPLAIN_PATH_LAYER (object), g_value_get_boolean (value)); break; case PROP_FILL_COLOR: champlain_path_layer_set_fill_color (CHAMPLAIN_PATH_LAYER (object), clutter_value_get_color (value)); break; case PROP_STROKE_COLOR: champlain_path_layer_set_stroke_color (CHAMPLAIN_PATH_LAYER (object), clutter_value_get_color (value)); break; case PROP_STROKE_WIDTH: champlain_path_layer_set_stroke_width (CHAMPLAIN_PATH_LAYER (object), g_value_get_double (value)); break; case PROP_VISIBLE: champlain_path_layer_set_visible (CHAMPLAIN_PATH_LAYER (object), g_value_get_boolean (value)); break; case PROP_SURFACE: set_surface (CHAMPLAIN_EXPORTABLE (object), g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } }
static void draw (ClutterCanvas *canvas, cairo_t *cr, gint width, gint height, ChamplainPoint *point) { ChamplainPointPrivate *priv = point->priv; gdouble size = priv->size; gdouble radius = size / 2.0; const ClutterColor *color; set_surface (CHAMPLAIN_EXPORTABLE (point), cairo_get_target (cr)); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); if (champlain_marker_get_selected (CHAMPLAIN_MARKER (point))) color = champlain_marker_get_selection_color (); else color = priv->color; cairo_set_source_rgba (cr, color->red / 255.0, color->green / 255.0, color->blue / 255.0, color->alpha / 255.0); cairo_arc (cr, radius, radius, radius, 0, 2 * M_PI); cairo_fill (cr); cairo_fill_preserve (cr); cairo_set_line_width (cr, 1.0); cairo_stroke (cr); }
static gboolean redraw_path (ClutterCanvas *canvas, cairo_t *cr, int width, int height, ChamplainPathLayer *layer) { ChamplainPathLayerPrivate *priv = layer->priv; GList *elem; ChamplainView *view = priv->view; gint viewport_x, viewport_y; gint anchor_x, anchor_y; /* layer not yet added to the view */ if (view == NULL) return FALSE; if (!priv->visible || width == 0.0 || height == 0.0) return FALSE; champlain_view_get_viewport_origin (priv->view, &viewport_x, &viewport_y); champlain_view_get_viewport_anchor (priv->view, &anchor_x, &anchor_y); if (canvas == CLUTTER_CANVAS (priv->right_canvas)) clutter_actor_set_position (priv->right_actor, viewport_x, viewport_y); else clutter_actor_set_position (priv->left_actor, -anchor_x, viewport_y); /* Clear the drawing area */ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); for (elem = priv->nodes; elem != NULL; elem = elem->next) { ChamplainLocation *location = CHAMPLAIN_LOCATION (elem->data); gfloat x, y; x = champlain_view_longitude_to_x (view, champlain_location_get_longitude (location)); y = champlain_view_latitude_to_y (view, champlain_location_get_latitude (location)); if (canvas == CLUTTER_CANVAS (priv->right_canvas)) cairo_line_to (cr, x, y); else cairo_line_to (cr, x + (viewport_x + anchor_x), y); } if (priv->closed_path) cairo_close_path (cr); cairo_set_source_rgba (cr, priv->fill_color->red / 255.0, priv->fill_color->green / 255.0, priv->fill_color->blue / 255.0, priv->fill_color->alpha / 255.0); if (priv->fill) cairo_fill_preserve (cr); cairo_set_source_rgba (cr, priv->stroke_color->red / 255.0, priv->stroke_color->green / 255.0, priv->stroke_color->blue / 255.0, priv->stroke_color->alpha / 255.0); cairo_set_line_width (cr, priv->stroke_width); cairo_set_dash(cr, priv->dash, priv->num_dashes, 0); if (priv->stroke) cairo_stroke (cr); set_surface (CHAMPLAIN_EXPORTABLE (layer), cairo_get_target (cr)); return FALSE; }
/* * LeftEll is the piece that looks like this * * ## * ## * #### * * It's also known as "L", "gun", or "right gun". */ SDLLeftEll::SDLLeftEll(SDL_Surface *surface_in) : SDLShape() { set_shape(new LeftEll()); set_surface(surface_in); set_color(SDL_MapRGB(surface_in->format, 0xFF, 0x8C, 0x31)); }
/* * RightSlant is the piece that looks like this * * #### * #### * * This piece is also known as "inverted N", or "S". */ SDLRightSlant::SDLRightSlant(SDL_Surface *surface_in) : SDLShape() { set_shape(new RightSlant()); set_surface(surface_in); set_color(SDL_MapRGB(surface_in->format, 0x73, 0xFF, 0x31)); }
static void hippo_canvas_image_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { HippoCanvasImage *image; image = HIPPO_CANVAS_IMAGE(object); switch (prop_id) { case PROP_IMAGE: { cairo_surface_t *surface = g_value_get_boxed(value); if (image->image_name) { g_free(image->image_name); image->image_name = NULL; g_object_notify(G_OBJECT(image), "image-name"); } set_surface(image, surface); } break; case PROP_IMAGE_NAME: { const char *name = g_value_get_string(value); if (!(image->image_name == name || (image->image_name && name && strcmp(image->image_name, name) == 0))) { g_free(image->image_name); image->image_name = g_strdup(name); set_surface_from_name(image); /* will recursively call set_property("image") which * will result in a request_changed if required */ } } break; case PROP_SCALE_WIDTH: { int w = g_value_get_int(value); if (w != image->scale_width) { image->scale_width = w; hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(image)); } } break; case PROP_SCALE_HEIGHT: { int h = g_value_get_int(value); if (h != image->scale_height) { image->scale_height = h; hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(image)); } } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }