void ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data) { GnomeCanvasGroup *group; static GnomeCanvasRE *cursor = NULL; double x1, y1, x2, y2; float hp; guint r, g, b; x1 = x * ghack_glyph_width() - 1; y1 = y * ghack_glyph_height() - 1; x2 = x1 + ghack_glyph_width() + 2; y2 = y1 + ghack_glyph_height() + 2; hp = u.mtimedone ? (u.mhmax ? (float) u.mh / u.mhmax : 1) : (u.uhpmax ? (float) u.uhp / u.uhpmax : 1); r = 255; g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255 * 2 * (hp - 0.25) : 0); b = (hp >= 0.75) ? 255 * 4 * (hp - 0.75) : (hp >= 0.25 ? 0 : 255 * 4 * (0.25 - hp)); group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); if (!cursor) { cursor = GNOME_CANVAS_RE(gnome_canvas_item_new( group, gnome_canvas_rect_get_type(), "width_units", 1.0, NULL)); } gnome_canvas_item_set(GNOME_CANVAS_ITEM(cursor), "outline_color_rgba", GNOME_CANVAS_COLOR(r, g, b), "x1", x1, "y1", y1, "x2", x2, "y2", y2, NULL); gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(cursor)); gnome_canvas_item_show(GNOME_CANVAS_ITEM(cursor)); }
static void create_rect_and_text (ETableClickToAdd *etcta) { GtkWidget *widget; GdkColor fg, bg; widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etcta)->canvas); e_utils_get_theme_color_color (widget, "theme_selected_fg_color", E_UTILS_DEFAULT_THEME_SELECTED_FG_COLOR, &fg); e_utils_get_theme_color_color (widget, "theme_selected_bg_color", E_UTILS_DEFAULT_THEME_SELECTED_BG_COLOR, &bg); if (!etcta->rect) etcta->rect = gnome_canvas_item_new ( GNOME_CANVAS_GROUP (etcta), gnome_canvas_rect_get_type (), "x1", (gdouble) 0, "y1", (gdouble) 1, "x2", (gdouble) etcta->width, "y2", (gdouble) etcta->height, "fill_color_gdk", &bg, NULL); if (!etcta->text) etcta->text = gnome_canvas_item_new ( GNOME_CANVAS_GROUP (etcta), e_text_get_type (), "text", etcta->message ? etcta->message : "", "width", etcta->width - 4, "fill_color_gdk", &fg, NULL); }
// paste external text void clipboard_paste_text(gchar *text) { struct Item *item; double pt[2]; reset_selection(); get_current_pointer_coords(pt); set_current_page(pt); ui.selection = g_new(struct Selection, 1); ui.selection->type = ITEM_SELECTRECT; ui.selection->layer = ui.cur_layer; ui.selection->items = NULL; item = g_new(struct Item, 1); ui.selection->items = g_list_append(ui.selection->items, item); ui.cur_layer->items = g_list_append(ui.cur_layer->items, item); ui.cur_layer->nitems++; item->type = ITEM_TEXT; g_memmove(&(item->brush), &(ui.brushes[ui.cur_mapping][TOOL_PEN]), sizeof(struct Brush)); item->text = text; // text was newly allocated, we keep it item->font_name = g_strdup(ui.font_name); item->font_size = ui.font_size; item->bbox.left = pt[0]; item->bbox.top = pt[1]; make_canvas_item_one(ui.cur_layer->group, item); update_item_bbox(item); // move the text to fit on the page if needed if (item->bbox.right > ui.cur_page->width) item->bbox.left += ui.cur_page->width-item->bbox.right; if (item->bbox.left < 0) item->bbox.left = 0; if (item->bbox.bottom > ui.cur_page->height) item->bbox.top += ui.cur_page->height-item->bbox.bottom; if (item->bbox.top < 0) item->bbox.top = 0; gnome_canvas_item_set(item->canvas_item, "x", item->bbox.left, "y", item->bbox.top, NULL); update_item_bbox(item); ui.selection->bbox = item->bbox; ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right, "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL); make_dashed(ui.selection->canvas_item); prepare_new_undo(); undo->type = ITEM_PASTE; undo->layer = ui.cur_layer; undo->itemlist = g_list_copy(ui.selection->items); update_copy_paste_enabled(); update_color_menu(); update_thickness_buttons(); update_color_buttons(); update_font_button(); update_cursor(); // FIXME: can't know if pointer is within selection! }
static ETableGroupContainerChildNode * create_child_node (ETableGroupContainer *etgc, void *val) { ETableGroup *child; ETableGroupContainerChildNode *child_node; ETableGroup *etg = E_TABLE_GROUP(etgc); child_node = g_new (ETableGroupContainerChildNode, 1); child_node->rect = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), gnome_canvas_rect_get_type (), "fill_color", "grey70", "outline_color", "grey50", NULL); child_node->text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), e_text_get_type (), "anchor", GTK_ANCHOR_SW, "fill_color", "black", "draw_background", FALSE, NULL); child = e_table_group_new (GNOME_CANVAS_GROUP (etgc), etg->full_header, etg->header, etg->model, etgc->sort_info, etgc->n + 1); gnome_canvas_item_set(GNOME_CANVAS_ITEM(child), "alternating_row_colors", etgc->alternating_row_colors, "horizontal_draw_grid", etgc->horizontal_draw_grid, "vertical_draw_grid", etgc->vertical_draw_grid, "drawfocus", etgc->draw_focus, "cursor_mode", etgc->cursor_mode, "selection_model", etgc->selection_model, "length_threshold", etgc->length_threshold, "uniform_row_height", etgc->uniform_row_height, "minimum_width", etgc->minimum_width - GROUP_INDENT, NULL); g_signal_connect (child, "cursor_change", G_CALLBACK (child_cursor_change), etgc); g_signal_connect (child, "cursor_activated", G_CALLBACK (child_cursor_activated), etgc); g_signal_connect (child, "double_click", G_CALLBACK (child_double_click), etgc); g_signal_connect (child, "right_click", G_CALLBACK (child_right_click), etgc); g_signal_connect (child, "click", G_CALLBACK (child_click), etgc); g_signal_connect (child, "key_press", G_CALLBACK (child_key_press), etgc); g_signal_connect (child, "start_drag", G_CALLBACK (child_start_drag), etgc); child_node->child = child; child_node->key = e_table_model_duplicate_value (etg->model, etgc->ecol->col_idx, val); child_node->string = e_table_model_value_to_string (etg->model, etgc->ecol->col_idx, val); child_node->count = 0; return child_node; }
void create_image_from_pixbuf(GdkPixbuf *pixbuf, double *pt) { double scale; struct Item *item; item = g_new(struct Item, 1); item->type = ITEM_IMAGE; item->canvas_item = NULL; item->bbox.left = pt[0]; item->bbox.top = pt[1]; item->image = pixbuf; item->image_png = NULL; item->image_png_len = 0; // Scale at native size, unless that won't fit, in which case we shrink it down. scale = 1 / ui.zoom; if ((scale * gdk_pixbuf_get_width(item->image)) > ui.cur_page->width - item->bbox.left) scale = (ui.cur_page->width - item->bbox.left) / gdk_pixbuf_get_width(item->image); if ((scale * gdk_pixbuf_get_height(item->image)) > ui.cur_page->height - item->bbox.top) scale = (ui.cur_page->height - item->bbox.top) / gdk_pixbuf_get_height(item->image); item->bbox.right = item->bbox.left + scale * gdk_pixbuf_get_width(item->image); item->bbox.bottom = item->bbox.top + scale * gdk_pixbuf_get_height(item->image); ui.cur_layer->items = g_list_append(ui.cur_layer->items, item); ui.cur_layer->nitems++; make_canvas_item_one(ui.cur_layer->group, item); // add undo information prepare_new_undo(); undo->type = ITEM_IMAGE; undo->item = item; undo->layer = ui.cur_layer; ui.cur_item = NULL; ui.cur_item_type = ITEM_NONE; // select image reset_selection(); ui.selection = g_new0(struct Selection, 1); ui.selection->type = ITEM_SELECTRECT; ui.selection->layer = ui.cur_layer; ui.selection->bbox = item->bbox; ui.selection->items = g_list_append(ui.selection->items, item); ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right, "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL); make_dashed(ui.selection->canvas_item); update_copy_paste_enabled(); }
static void e_minicard_label_realize (GnomeCanvasItem *item) { EMinicardLabel *e_minicard_label; GnomeCanvasGroup *group; e_minicard_label = E_MINICARD_LABEL (item); group = GNOME_CANVAS_GROUP ( item ); if (GNOME_CANVAS_ITEM_CLASS ( parent_class )->realize) (* GNOME_CANVAS_ITEM_CLASS ( parent_class )->realize) (item); e_canvas_item_request_reflow (item); e_minicard_label->rect = gnome_canvas_item_new ( group, gnome_canvas_rect_get_type (), "x1", (double) 0, "y1", (double) 0, "x2", (double) e_minicard_label->width - 1, "y2", (double) e_minicard_label->height - 1, "outline_color", NULL, NULL ); e_minicard_label->fieldname = gnome_canvas_item_new ( group, e_text_get_type (), "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), "clip", TRUE, "use_ellipsis", TRUE, "fill_color", "black", "draw_background", FALSE, "im_context", E_CANVAS (item->canvas)->im_context, NULL ); e_canvas_item_move_absolute (e_minicard_label->fieldname, 2, 1); e_minicard_label->field = gnome_canvas_item_new ( group, e_text_get_type (), "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), "clip", TRUE, "use_ellipsis", TRUE, "fill_color", "black", "editable", FALSE, /* e_minicard_label->editable, */ "draw_background", FALSE, "im_context", E_CANVAS (item->canvas)->im_context, NULL ); e_canvas_item_move_absolute (e_minicard_label->field, ( e_minicard_label->width / 2 + 2), 1); set_colors (e_minicard_label); e_canvas_item_request_reflow (item); }
void start_selectrect(GdkEvent *event) { double pt[2]; reset_selection(); ui.cur_item_type = ITEM_SELECTRECT; ui.selection = g_new(struct Selection, 1); ui.selection->type = ITEM_SELECTRECT; ui.selection->items = NULL; ui.selection->layer = ui.cur_layer; get_pointer_coords(event, pt); ui.selection->bbox.left = ui.selection->bbox.right = pt[0]; ui.selection->bbox.top = ui.selection->bbox.bottom = pt[1]; ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", pt[0], "x2", pt[0], "y1", pt[1], "y2", pt[1], NULL); update_cursor(); }
void start_vertspace(GdkEvent *event) { double pt[2]; GList *itemlist; struct Item *item; reset_selection(); ui.cur_item_type = ITEM_MOVESEL_VERT; ui.selection = g_new(struct Selection, 1); ui.selection->type = ITEM_MOVESEL_VERT; ui.selection->items = NULL; ui.selection->layer = ui.cur_layer; get_pointer_coords(event, pt); ui.selection->bbox.top = ui.selection->bbox.bottom = pt[1]; for (itemlist = ui.cur_layer->items; itemlist!=NULL; itemlist = itemlist->next) { item = (struct Item *)itemlist->data; if (item->bbox.top >= pt[1]) { ui.selection->items = g_list_append(ui.selection->items, item); if (item->bbox.bottom > ui.selection->bbox.bottom) ui.selection->bbox.bottom = item->bbox.bottom; } } ui.selection->anchor_x = ui.selection->last_x = 0; ui.selection->anchor_y = ui.selection->last_y = pt[1]; ui.selection->orig_pageno = ui.pageno; ui.selection->move_pageno = ui.pageno; ui.selection->move_layer = ui.selection->layer; ui.selection->move_pagedelta = 0.; ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", -100.0, "x2", ui.cur_page->width+100, "y1", pt[1], "y2", pt[1], NULL); update_cursor(); }
static void midi_section_init(MidiSection* self) { MidiSectionPrivate* p = MIDI_SECTION_GET_PRIVATE(self); GtkBox* box = GTK_BOX(self); GtkWidget* pad; GtkWidget* view; GtkWidget* scroll; GnomeCanvas* canvas; GnomeCanvasPoints* points; int x1, x2, y1, y2; p->patch = -1; p->ignore = FALSE; x1 = 0; y1 = 0; x2 = (PHIN_KEYBOARD_KEY_WIDTH * MIDI_NOTES); y2 = HEIGHT; /* adjustment */ p->adj = (GtkAdjustment*) gtk_adjustment_new(0, 0, 0, 0, 0, 0); /* viewport */ view = gtk_viewport_new(p->adj, NULL); gtk_box_pack_start(box, view, FALSE, FALSE, 0); gtk_viewport_set_shadow_type(GTK_VIEWPORT(view), GTK_SHADOW_NONE); gtk_widget_set_size_request(view, 0, y2); gtk_widget_show(view); /* canvas */ canvas = (GnomeCanvas*) gnome_canvas_new(); gtk_widget_set_size_request(GTK_WIDGET(canvas), x2, y2); gnome_canvas_set_scroll_region(canvas, 0, 0, x2 - 1, y2 -1); gtk_container_add(GTK_CONTAINER(view), GTK_WIDGET(canvas)); g_signal_connect(G_OBJECT(canvas), "event", G_CALLBACK(range_cb), (gpointer)p); gtk_widget_show(GTK_WIDGET(canvas)); /* range display backdrop */ gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_rect_get_type(), "x1", (gdouble)0, "y1", (gdouble)0, "x2", (gdouble)x2, "y2", (gdouble)y2, "fill-color-rgba", BG_COLOR, NULL); /* range */ p->range = gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_rect_get_type(), "x1", (gdouble)x1, "y1", (gdouble)y1, "x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH, "y2", (gdouble)y2, "fill-color-rgba", RANGE_COLOR, "outline-color", "black", NULL); gnome_canvas_item_hide(p->range); /* range root note */ p->note = gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_rect_get_type(), "x1", (gdouble)x1, "y1", (gdouble)y1, "x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH, "y2", (gdouble)y2, "fill-color-rgba", NOTE_COLOR, "outline-color", "black", NULL); gnome_canvas_item_hide(p->note); p->canvas = canvas; /* range display border */ points = gnome_canvas_points_new(4); points->coords[0] = x1; points->coords[1] = y2; points->coords[2] = x1; points->coords[3] = y1; points->coords[4] = x2-1; points->coords[5] = y1; points->coords[6] = x2-1; points->coords[7] = y2; gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_line_get_type(), "points", points, "width-units", (gdouble)1, "fill-color-rgba", 0, NULL); gnome_canvas_points_unref(points); /* keyboard */ p->keyboard = phin_hkeyboard_new(p->adj, MIDI_NOTES, TRUE); gtk_box_pack_start(box, p->keyboard, FALSE, FALSE, 0); gtk_widget_show(p->keyboard); /* vpad */ pad = gui_vpad_new(GUI_SCROLLSPACE); gtk_box_pack_start(box, pad, FALSE, FALSE, 0); gtk_widget_show(pad); /* scrollbar */ scroll = gtk_hscrollbar_new(p->adj); gtk_box_pack_start(box, scroll, FALSE, FALSE, 0); gtk_widget_show(scroll); /* done */ connect(p); }
// paste xournal native data void clipboard_paste_from_xournal(GtkSelectionData *sel_data) { unsigned char *p; int nitems, npts, i, len; struct Item *item; double hoffset, voffset, cx, cy; double *pf; int sx, sy, wx, wy; reset_selection(); ui.selection = g_new(struct Selection, 1); p = sel_data->data + sizeof(int); g_memmove(&nitems, p, sizeof(int)); p+= sizeof(int); ui.selection->type = ITEM_SELECTRECT; ui.selection->layer = ui.cur_layer; g_memmove(&ui.selection->bbox, p, sizeof(struct BBox)); p+= sizeof(struct BBox); ui.selection->items = NULL; // find by how much we translate the pasted selection gnome_canvas_get_scroll_offsets(canvas, &sx, &sy); gdk_window_get_geometry(GTK_WIDGET(canvas)->window, NULL, NULL, &wx, &wy, NULL); gnome_canvas_window_to_world(canvas, sx + wx/2, sy + wy/2, &cx, &cy); cx -= ui.cur_page->hoffset; cy -= ui.cur_page->voffset; if (cx + (ui.selection->bbox.right-ui.selection->bbox.left)/2 > ui.cur_page->width) cx = ui.cur_page->width - (ui.selection->bbox.right-ui.selection->bbox.left)/2; if (cx - (ui.selection->bbox.right-ui.selection->bbox.left)/2 < 0) cx = (ui.selection->bbox.right-ui.selection->bbox.left)/2; if (cy + (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 > ui.cur_page->height) cy = ui.cur_page->height - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2; if (cy - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 < 0) cy = (ui.selection->bbox.bottom-ui.selection->bbox.top)/2; hoffset = cx - (ui.selection->bbox.right+ui.selection->bbox.left)/2; voffset = cy - (ui.selection->bbox.top+ui.selection->bbox.bottom)/2; ui.selection->bbox.left += hoffset; ui.selection->bbox.right += hoffset; ui.selection->bbox.top += voffset; ui.selection->bbox.bottom += voffset; ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right, "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL); make_dashed(ui.selection->canvas_item); while (nitems-- > 0) { item = g_new(struct Item, 1); ui.selection->items = g_list_append(ui.selection->items, item); ui.cur_layer->items = g_list_append(ui.cur_layer->items, item); ui.cur_layer->nitems++; g_memmove(&item->type, p, sizeof(int)); p+= sizeof(int); if (item->type == ITEM_STROKE) { g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush); g_memmove(&npts, p, sizeof(int)); p+= sizeof(int); item->path = gnome_canvas_points_new(npts); pf = (double *)p; for (i=0; i<npts; i++) { item->path->coords[2*i] = pf[2*i] + hoffset; item->path->coords[2*i+1] = pf[2*i+1] + voffset; } p+= 2*item->path->num_points*sizeof(double); if (item->brush.variable_width) { item->widths = g_memdup(p, (item->path->num_points-1)*sizeof(double)); p+= (item->path->num_points-1)*sizeof(double); } else item->widths = NULL; update_item_bbox(item); make_canvas_item_one(ui.cur_layer->group, item); } if (item->type == ITEM_TEXT) { g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush); g_memmove(&item->bbox.left, p, sizeof(double)); p+= sizeof(double); g_memmove(&item->bbox.top, p, sizeof(double)); p+= sizeof(double); item->bbox.left += hoffset; item->bbox.top += voffset; g_memmove(&len, p, sizeof(int)); p+= sizeof(int); item->text = g_malloc(len+1); g_memmove(item->text, p, len+1); p+= len+1; g_memmove(&len, p, sizeof(int)); p+= sizeof(int); item->font_name = g_malloc(len+1); g_memmove(item->font_name, p, len+1); p+= len+1; g_memmove(&item->font_size, p, sizeof(double)); p+= sizeof(double); make_canvas_item_one(ui.cur_layer->group, item); } if (item->type == ITEM_IMAGE) { item->canvas_item = NULL; item->image_png = NULL; item->image_png_len = 0; g_memmove(&item->bbox, p, sizeof(struct BBox)); p+= sizeof(struct BBox); item->bbox.left += hoffset; item->bbox.right += hoffset; item->bbox.top += voffset; item->bbox.bottom += voffset; g_memmove(&item->image_png_len, p, sizeof(gsize)); p+= sizeof(gsize); if (item->image_png_len > 0) { item->image_png = g_memdup(p, item->image_png_len); item->image = pixbuf_from_buffer(item->image_png, item->image_png_len); p+= item->image_png_len; } else { item->image = NULL; } make_canvas_item_one(ui.cur_layer->group, item); } } prepare_new_undo(); undo->type = ITEM_PASTE; undo->layer = ui.cur_layer; undo->itemlist = g_list_copy(ui.selection->items); gtk_selection_data_free(sel_data); update_copy_paste_enabled(); update_color_menu(); update_thickness_buttons(); update_color_buttons(); update_font_button(); update_cursor(); // FIXME: can't know if pointer is within selection! }
void finalize_selectregion(void) { GList *itemlist; struct Item *item; ArtVpath *vpath; ArtSVP *lassosvp; int i, n; double *pt; ui.cur_item_type = ITEM_NONE; // build SVP for the lasso path n = ui.cur_path.num_points; vpath = g_malloc((n+2)*sizeof(ArtVpath)); for (i=0; i<n; i++) { vpath[i].x = ui.cur_path.coords[2*i]; vpath[i].y = ui.cur_path.coords[2*i+1]; } vpath[n].x = vpath[0].x; vpath[n].y = vpath[0].y; vpath[0].code = ART_MOVETO; for (i=1; i<=n; i++) vpath[i].code = ART_LINETO; vpath[n+1].code = ART_END; lassosvp = art_svp_from_vpath(vpath); g_free(vpath); // see which items we selected for (itemlist = ui.selection->layer->items; itemlist!=NULL; itemlist = itemlist->next) { item = (struct Item *)itemlist->data; if (hittest_item(lassosvp, item)) { // update the selection bbox if (ui.selection->items==NULL || ui.selection->bbox.left>item->bbox.left) ui.selection->bbox.left = item->bbox.left; if (ui.selection->items==NULL || ui.selection->bbox.right<item->bbox.right) ui.selection->bbox.right = item->bbox.right; if (ui.selection->items==NULL || ui.selection->bbox.top>item->bbox.top) ui.selection->bbox.top = item->bbox.top; if (ui.selection->items==NULL || ui.selection->bbox.bottom<item->bbox.bottom) ui.selection->bbox.bottom = item->bbox.bottom; // add the item ui.selection->items = g_list_append(ui.selection->items, item); } } art_svp_free(lassosvp); if (ui.selection->items == NULL) { // if we clicked inside a text zone or image? pt = ui.cur_path.coords; item = click_is_in_text_or_image(ui.selection->layer, pt[0], pt[1]); if (item!=NULL) { for (i=0; i<n; i++, pt+=2) { if (pt[0]<item->bbox.left || pt[0]>item->bbox.right || pt[1]<item->bbox.top || pt[1]>item->bbox.bottom) { item = NULL; break; } } } if (item!=NULL) { ui.selection->items = g_list_append(ui.selection->items, item); g_memmove(&(ui.selection->bbox), &(item->bbox), sizeof(struct BBox)); } } if (ui.selection->items == NULL) reset_selection(); else { // make a selection rectangle instead of the lasso shape gtk_object_destroy(GTK_OBJECT(ui.selection->canvas_item)); ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right, "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL); make_dashed(ui.selection->canvas_item); ui.selection->type = ITEM_SELECTRECT; } update_cursor(); update_copy_paste_enabled(); update_font_button(); }
WireItem * wire_item_new (Sheet *sheet, Wire *wire) { WireItem *item; GnomeCanvasPoints *points; WireItemPriv *priv; SheetPos start_pos, length; g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (IS_SHEET (sheet), NULL); //g_object_ref (G_OBJECT(wire)); /* XXX Ver si hay equivalente gtk_object_sink (GTK_OBJECT (wire)); */ wire_get_pos_and_length (wire, &start_pos, &length); /* * Because of the GnomeCanvasGroup inheritance, a small hack is needed * here. The group starts at the startpoint of the wire, and the line * goes from (0,0) to (length.x, length.y). */ item = WIRE_ITEM (gnome_canvas_item_new ( sheet->object_group, wire_item_get_type (), "data", wire, "x", (double) start_pos.x, "y", (double) start_pos.y, NULL)); priv = item->priv; priv->resize1 = GNOME_CANVAS_RECT (gnome_canvas_item_new ( GNOME_CANVAS_GROUP (item), gnome_canvas_rect_get_type (), "x1", -RESIZER_SIZE, "y1", -RESIZER_SIZE, "x2", RESIZER_SIZE, "y2", RESIZER_SIZE, "fill_color", "red", "fill_color_rgba", 0x3cb37180, "outline_color", "blue", "width_pixels", 1, NULL)); priv->resize2 = GNOME_CANVAS_RECT (gnome_canvas_item_new ( GNOME_CANVAS_GROUP (item), gnome_canvas_rect_get_type (), "x1", length.x-RESIZER_SIZE, "y1", length.y-RESIZER_SIZE, "x2", length.x+RESIZER_SIZE, "y2", length.y+RESIZER_SIZE, "fill_color", "red", "fill_color_rgba", 0x3cb37180, "outline_color", "blue", "width_pixels", 1, NULL)); gnome_canvas_item_hide (GNOME_CANVAS_ITEM (priv->resize1)); gnome_canvas_item_hide (GNOME_CANVAS_ITEM (priv->resize2)); points = gnome_canvas_points_new (2); points->coords[0] = 0; points->coords[1] = 0; points->coords[2] = length.x; points->coords[3] = length.y; priv->line = GNOME_CANVAS_LINE (gnome_canvas_item_new ( GNOME_CANVAS_GROUP (item), gnome_canvas_line_get_type (), "points", points, "fill_color", "blue", "width_pixels", 1, NULL)); gnome_canvas_points_free (points); g_signal_connect_object(G_OBJECT(wire), "rotated", G_CALLBACK(wire_rotated_callback), G_OBJECT(item), 0); g_signal_connect_object(G_OBJECT(wire), "flipped", G_CALLBACK(wire_flipped_callback), G_OBJECT(item), 0); g_signal_connect_object(G_OBJECT(wire), "moved", G_CALLBACK(wire_moved_callback), G_OBJECT(item), 0); g_signal_connect (G_OBJECT (wire), "changed", G_CALLBACK (wire_changed_callback), item); g_signal_connect (G_OBJECT (wire), "delete", G_CALLBACK (wire_delete_callback), item); wire_update_bbox (wire); return item; }
/* so much gayness in here, either I suck or gnome-canvas does; most * likely, we both do */ static void draw_key(PhatKeyboard* self, gint index, gint pos, guint bg, guint hi, guint low, guint pre, guint on, guint shad) { _Key* key = &self->keys[index]; GnomeCanvasPoints* points; gint x1; gint y1; gint x2; gint y2; if (self->orientation == GTK_ORIENTATION_VERTICAL) { x1 = 0; y1 = pos + 1; /* teh gayz0r */ x2 = PHAT_KEYBOARD_KEY_LENGTH - 1; y2 = pos - PHAT_KEYBOARD_KEY_WIDTH + 1; } else { x1 = pos + PHAT_KEYBOARD_KEY_WIDTH - 1; y1 = 0; x2 = pos; y2 = PHAT_KEYBOARD_KEY_LENGTH - 1; } /* key group */ key->group = (GnomeCanvasGroup*) gnome_canvas_item_new(gnome_canvas_root(self->canvas), gnome_canvas_group_get_type(), NULL); g_signal_connect(G_OBJECT(key->group), "event", G_CALLBACK(key_press_cb), (gpointer)key); key->index = index; key->hold = 0; key->keyboard = self; /* draw main key rect */ gnome_canvas_item_new(key->group, gnome_canvas_rect_get_type(), "x1", (gdouble)x1, "y1", (gdouble)y1, "x2", (gdouble)x2, "y2", (gdouble)y2, "fill-color-rgba", bg, NULL); /* draw prelight rect */ key->pre = gnome_canvas_item_new(key->group, gnome_canvas_rect_get_type(), "x1", (gdouble)x1, "y1", (gdouble)y1, "x2", (gdouble)x2, "y2", (gdouble)y2, "fill-color-rgba", pre, NULL); gnome_canvas_item_hide(key->pre); /* draw key highlight */ points = gnome_canvas_points_new(3); if (self->orientation == GTK_ORIENTATION_VERTICAL) { points->coords[0] = x1+1; points->coords[1] = y1; points->coords[2] = x1+1; points->coords[3] = y2+1; points->coords[4] = x2; points->coords[5] = y2+1; } else { points->coords[0] = x1; points->coords[1] = y1+1; points->coords[2] = x2; points->coords[3] = y1+1; points->coords[4] = x2; points->coords[5] = y2; } gnome_canvas_item_new(key->group, gnome_canvas_line_get_type(), "points", points, "width-units", (gdouble)1, "fill-color-rgba", hi, NULL); gnome_canvas_points_unref(points); /* draw key border */ points = gnome_canvas_points_new(4); if (self->orientation == GTK_ORIENTATION_VERTICAL) { points->coords[0] = x1; points->coords[1] = y1; points->coords[2] = x1; points->coords[3] = y2; points->coords[4] = x2; points->coords[5] = y2; points->coords[6] = x2; points->coords[7] = y1; } else { points->coords[0] = x2; points->coords[1] = y1; points->coords[2] = x1; points->coords[3] = y1; points->coords[4] = x1; points->coords[5] = y2; points->coords[6] = x2; points->coords[7] = y2; } gnome_canvas_item_new(key->group, gnome_canvas_line_get_type(), "points", points, "width-units", (gdouble)1, "fill-color-rgba", low, NULL); gnome_canvas_points_unref(points); if (self->orientation == GTK_ORIENTATION_VERTICAL) { /* draw active rect */ key->on = gnome_canvas_item_new(key->group, gnome_canvas_rect_get_type(), "x1", (gdouble)x1+1, "y1", (gdouble)y1, "x2", (gdouble)x2, "y2", (gdouble)y2+1, "fill-color-rgba", on, NULL); } else { /* draw active rect */ key->on = gnome_canvas_item_new(key->group, gnome_canvas_rect_get_type(), "x1", (gdouble)x1, "y1", (gdouble)y1+1, "x2", (gdouble)x2, "y2", (gdouble)y2, "fill-color-rgba", on, NULL); } gnome_canvas_item_hide(key->on); /* draw active shadow */ points = gnome_canvas_points_new(6); if (self->orientation == GTK_ORIENTATION_VERTICAL) { points->coords[0] = x1+1; points->coords[1] = y1; points->coords[2] = x1+1; points->coords[3] = y2+1; points->coords[4] = x2; points->coords[5] = y2+1; points->coords[6] = x2; points->coords[7] = y2 + 3; points->coords[8] = x1 + 3; points->coords[9] = y2 + 3; points->coords[10] = x1 + 3; points->coords[11] = y1; } else { points->coords[0] = x1; points->coords[1] = y1 + 1; points->coords[2] = x2; points->coords[3] = y1 + 1; points->coords[4] = x2; points->coords[5] = y2; points->coords[6] = x2 + 2; points->coords[7] = y2; points->coords[8] = x2 + 2; points->coords[9] = y1 + 3; points->coords[10] = x1; points->coords[11] = y1 + 3; } key->shad = gnome_canvas_item_new(key->group, gnome_canvas_polygon_get_type(), "points", points, "fill-color-rgba", shad, NULL); gnome_canvas_item_hide(key->shad); gnome_canvas_points_unref(points); /* draw label if applicable */ if (self->label && (index % 12) == 0) { gchar* s = g_strdup_printf("%d", index / 12 + 1); if (self->orientation == GTK_ORIENTATION_VERTICAL) { gnome_canvas_item_new(key->group, gnome_canvas_text_get_type(), "text", s, "x", (gdouble)(x2 - 2), "y", (gdouble)(y1 - (PHAT_KEYBOARD_KEY_WIDTH / 2)), "anchor", GTK_ANCHOR_EAST, "fill-color-rgba", (gint)KEY_TEXT_BG, "font", "sans", "size-points", (gdouble)TEXT_POINTS, NULL); } else { gnome_canvas_item_new(key->group, gnome_canvas_text_get_type(), "text", s, "x", (gdouble)(x1 - (PHAT_KEYBOARD_KEY_WIDTH / 2)), "y", (gdouble)(y2 - 2), "anchor", GTK_ANCHOR_SOUTH, "fill-color-rgba", (gint)KEY_TEXT_BG, "font", "sans", "size-points", (gdouble)TEXT_POINTS, "justification", GTK_JUSTIFY_CENTER, NULL); } g_free(s); } }