static gboolean lmplayer_lyric_widget_da_add_file(LmplayerLyricWidget *lyric, const gchar *file) { g_return_val_if_fail(LMPLAYER_IS_LYRIC_WIDGET_DA(lyric), FALSE); g_return_val_if_fail(file != NULL, FALSE); LmplayerLyricWidgetDaPrivate *priv = LMPLAYER_LYRIC_WIDGET_DA(lyric)->priv; if(g_access(file, R_OK) != 0) return FALSE; if(priv->lines != NULL) { g_list_free(priv->lines); priv->lines = NULL; priv->da_height = 0; } priv->loaded = parse_lyric_file_without_check(LMPLAYER_LYRIC_WIDGET_DA(lyric), file); if(priv->loaded) { gtk_layout_move(GTK_LAYOUT(lyric), priv->alignment, 0, 0); gdk_window_invalidate_rect(priv->da->window, NULL, FALSE); } priv->changed = TRUE; priv->current_second = -1; update_pixmap(LMPLAYER_LYRIC_WIDGET_DA(lyric)); return priv->loaded; }
extern int NLDT_gtk_set_position(struct lua_State *L) { /* LUA Use: gtk_set_position(widget, x, y) */ if(lua_gettop(L)!=3) { lua_pushstring(L,"ERROR gtk_set_position usage widget, x, y\n"); lua_error(L); } GtkWidget *widget; widget = (GtkWidget*)luaL_checkint(L,1); if(widget==NULL) { lua_pushstring(L,"ERROR widget is Nil"); lua_error(L); } int x, y; x = luaL_checkint(L,2); y = luaL_checkint(L,3); nldt_gizmo_node *owner = nldt_gizmo_lookup(L); if(owner==NULL) { fprintf(stderr,"ERROR: Attempted to draw before initialisation (Offender: gtk.set_position)\n"); return 0; } gtk_layout_move(GTK_LAYOUT(owner->gizmo_space),widget,x,y); return 0; }
static gboolean scroll_label_artist(track_t *t) { gint len = 0; len = t->track.artistLen-SCROLL_SIZE_W+23; if (t->track.x.artist > -len) { gtk_layout_move(GTK_LAYOUT(t->trackw.layout.artist), t->trackw.label.artist, --t->track.x.artist, 0); if (t->track.x.artist > -len+1) t->track.x.artist2 = -len; } else { gtk_layout_move(GTK_LAYOUT(t->trackw.layout.artist), t->trackw.label.artist, ++t->track.x.artist2, 0); if (t->track.x.artist2 == 1) t->track.x.artist = 0; } return TRUE; }
static gboolean scroll_label_album(track_t *t) { gint len = 0; len = t->track.albumLen-SCROLL_SIZE_W+40; if (t->track.x.album > -len) { gtk_layout_move(GTK_LAYOUT(t->trackw.layout.album), t->trackw.label.album, --t->track.x.album, 0); if (t->track.x.album > -len+1) t->track.x.album2 = -len; } else { gtk_layout_move(GTK_LAYOUT(t->trackw.layout.album), t->trackw.label.album, ++t->track.x.album2, 0); if (t->track.x.album2 == 1) t->track.x.album = 0; } return TRUE; }
static gboolean scroll_label_name(track_t *t) { gint len = 0; len = t->track.nameLen-SCROLL_SIZE_W; if (t->track.x.name > -len) { gtk_layout_move(GTK_LAYOUT(t->trackw.layout.name), t->trackw.label.name, --t->track.x.name, 0); if (t->track.x.name > -len+1) t->track.x.name2 = -len; } else { gtk_layout_move(GTK_LAYOUT(t->trackw.layout.name), t->trackw.label.name, ++t->track.x.name2, 0); if (t->track.x.name2 == 1) t->track.x.name = 0; } return TRUE; }
static void but_click (GtkWidget *widget, gpointer data) { gint x = widget->allocation.x; gint y = widget->allocation.y; gint e_x = empty_but->allocation.x; gint e_y = empty_but->allocation.y; GtkWidget *layout = gtk_widget_get_parent (widget); int i,n, e_i, e_n; if ( ((x == e_x) && ((y == (e_y-25)) || (y == (e_y+25)))) || ((y == e_y) && ((x == (e_x-25)) || (x == (e_x+25))))) { gtk_layout_move (GTK_LAYOUT (layout), widget, e_x, e_y); gtk_layout_move (GTK_LAYOUT (layout), empty_but, x, y); n = 4*((y-10) / 25) + ((x-10) / 25) + 1; i = 0; while (pos[i++] != n); e_n = 4*((e_y-10) / 25) + ((e_x-10) / 25) + 1; e_i = 0; while (pos[e_i++] != e_n); pos[--e_i] = n; pos[--i] = e_n; if (test ()) { if (!dialog) { dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_parent (layout)), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Yeeees!!!!"); } gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); gtk_widget_destroy (gtk_widget_get_parent (layout)); } } }
static gboolean motion_notify_event (GtkWidget * widget, GdkEventMotion * event, App * app) { gint x, y; gboolean ret; GtkAdjustment *hadjustment, *vadjustment; gfloat hval, vval; GET_UI_ELEMENT (GtkWidget, scrolledwindow2); GET_UI_ELEMENT (GtkWidget, layout1); gtk_widget_translate_coordinates (widget, layout1, event->x, event->y, &x, &y); x -= offsetx; y -= offsety; // make sure the potential coordinates x,y: // 1) will not push any part of the widget outside of its parent container // 2) is a multiple of Sensitivity x = RoundToNearestMultiple (Max (Min (x, maxx), 0), Sensitivity); y = RoundToNearestMultiple (Max (Min (y, maxy), 0), Sensitivity); if (x != px || y != py) { g_object_get (scrolledwindow2, "hadjustment", &hadjustment, "vadjustment", &vadjustment, NULL); hval = gtk_adjustment_get_value (hadjustment); vval = gtk_adjustment_get_value (vadjustment); x += hval; y += vval; px = x; py = y; gtk_layout_move (GTK_LAYOUT (layout1), widget, x, y); } gtk_widget_queue_draw (layout1); return TRUE; }
static gboolean gnc_item_edit_update (GncItemEdit *item_edit) { gint x, y, w, h; gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &w, &h); gtk_layout_move (GTK_LAYOUT(item_edit->sheet), GTK_WIDGET(item_edit), x, y); if (item_edit->is_popup) { gtk_widget_show (item_edit->popup_toggle.ebox); if (item_edit->show_popup) gnc_item_edit_show_popup (item_edit); } return FALSE; }
static void draw (HTMLObject *o, HTMLPainter *p, gint x, gint y, gint width, gint height, gint tx, gint ty) { HTMLEmbedded *element = HTML_EMBEDDED (o); gint new_x, new_y; d (printf ("draw embedded %p\n", element)); if (!element->widget) return; if (element->parent) { GtkWidget *parent; new_x = o->x + tx; new_y = o->y + ty - o->ascent; if ((parent = gtk_widget_get_parent (element->widget))) { if (new_x != element->abs_x || new_y != element->abs_y) { d (printf ("element: %p moveto: %d,%d shown: %d\n", element, new_x, new_y, GTK_WIDGET_VISIBLE (element->widget))); gtk_layout_move (GTK_LAYOUT (parent), element->widget, new_x, new_y); } else if (!GTK_HTML (parent)->engine->expose) gtk_widget_queue_draw (element->widget); } element->abs_x = new_x; element->abs_y = new_y; if (!parent) { d (printf ("element: %p put: %d,%d shown: %d\n", element, new_x, new_y, GTK_WIDGET_VISIBLE (element->widget))); gtk_layout_put (GTK_LAYOUT (element->parent), element->widget, new_x, new_y); } } d (printf ("draw embedded %p - call painter tx %d ty %d\n", element, tx, ty)); html_painter_draw_embedded (p, element, tx, ty); }
int clip_GTK_LAYOUTMOVE(ClipMachine * cm) { C_widget *ccon = _fetch_cw_arg(cm); C_widget *cwid = _fetch_cwidget(cm,_clip_spar(cm,2)); gint x = _clip_parni(cm,3); gint y = _clip_parni(cm,4); CHECKARG2(2,MAP_t,NUMERIC_t); CHECKOPT(3,NUMERIC_t); CHECKOPT(4,NUMERIC_t); CHECKCWID(ccon,GTK_IS_LAYOUT); CHECKCWID(cwid,GTK_IS_WIDGET); if (_clip_parinfo(cm,3) == UNDEF_t) x = cwid->widget->allocation.x; if (_clip_parinfo(cm,4) == UNDEF_t) y = cwid->widget->allocation.y; gtk_layout_move(GTK_LAYOUT(ccon->widget), cwid->widget, x,y); return 0; err: return 1; }
static void gui_move(GtkWidget* window, GtkLayout* screen, gint x, gint y) { if(GTK_IS_WINDOW(window)) { gtk_window_move(GTK_WINDOW(window), x, y); } else { if(gtk_widget_get_parent(window) != GTK_WIDGET(screen)) //gtk_layout_put(screen, window, x, y); g_assert(0 && "gui_move not a child"); else { GValue value_x; GValue value_y; memset(&value_x, 0, sizeof(GValue)); memset(&value_y, 0, sizeof(GValue)); g_value_init(&value_x, G_TYPE_INT); g_value_init(&value_y, G_TYPE_INT); gtk_container_child_get_property(GTK_CONTAINER(screen), window, "x", &value_x); gtk_container_child_get_property(GTK_CONTAINER(screen), window, "y", &value_y); if(x != g_value_get_int (&value_x) || y != g_value_get_int(&value_y)) gtk_layout_move(screen, window, x, y); } } }
void cgraphics_update_bounds( object_t *obj ) { widget_t *widget = (widget_t *)obj; if (widget->size_req == NULL) { // these widgets use special OS-determined bounds. return; } if ( widget->native == NULL ) return; if ( widget->size_req->w <= -1 || widget->size_req->h <= -1 ) clog( CL_ERROR, "widget '%s' @ %p about to be sized with negative width or height!", obj->type, obj ); gtk_widget_set_size_request( widget->native, widget->size_req->w, widget->size_req->h ); if ( strcmp( obj->parent->type, "claro.graphics.widgets.splitter" ) ) gtk_layout_move( GTK_LAYOUT(GTK_WIDGET(widget->native)->parent), widget->native, widget->size_req->x, widget->size_req->y ); }
static void icon_scroll_size_allocate_cb(GtkWidget *widget, GtkAllocation *size, MimeView *mimeview) { GtkAllocation *mainbox_size; GtkAllocation *vbox_size; GtkAllocation *layout_size; GtkAdjustment *adj; adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll)); mainbox_size = &mimeview->icon_mainbox->allocation; vbox_size = &mimeview->icon_vbox->allocation; layout_size = &mimeview->icon_scroll->allocation; /* centralise the vbox */ gtk_layout_move(GTK_LAYOUT(mimeview->icon_scroll), mimeview->icon_vbox, (mainbox_size->width - vbox_size->width)/2, 0); gtk_layout_set_size(GTK_LAYOUT(mimeview->icon_scroll), GTK_LAYOUT(mimeview->icon_scroll)->width, MAX(vbox_size->height, layout_size->height)); adj->step_increment = 5; }
gboolean update_track_info(track_t *t) { gchar dummy[10], *markup = NULL, *markupProps = NULL; gint i = 0; GdkPixbuf *starPix = NULL; PangoLayout *layout = NULL; get_track_info(&t->track); if (!validate_track_info(&t->track)) { g_print("Malformed track data\n"); gtk_main_quit(); } if (t->track.changed) { gtk_image_set_from_file(GTK_IMAGE(t->trackw.image), t->track.artworkId); markupProps = g_strdup("<span font='Sans 11' font_weight='bold' color='#FFFFFF'>%s</span>"); t->track.x.name = 0; t->track.x.name2 = 0; markup = g_markup_printf_escaped(markupProps, t->track.name); gtk_label_set_markup(GTK_LABEL(t->trackw.label.name), markup); layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.name)); pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.nameLen, NULL); if (t->track.nameLen > SCROLL_SIZE_W) { if (t->track.nameScroll) g_source_remove(t->track.nameTag); t->track.nameScroll = TRUE; t->track.nameTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_name, t); } else if (t->track.nameScroll) { /* if the previous label was scrolled and this one doesn't need do * it stops the scrolling and puts the label at it's origin. Failure to do * so causes the new label to be displayed at the last position the previous * label was scrolled. */ g_source_remove(t->track.nameTag); gtk_layout_move(GTK_LAYOUT(t->trackw.layout.name), t->trackw.label.name, 0, 0); t->track.nameScroll = FALSE; } g_free(markup); t->track.x.artist = 0; t->track.x.artist2 = 0; markup = g_markup_printf_escaped(markupProps, t->track.artist); gtk_label_set_markup(GTK_LABEL(t->trackw.label.artist), markup); layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.artist)); pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.artistLen, NULL); if (t->track.artistLen > SCROLL_SIZE_W-23) { if (t->track.artistScroll) g_source_remove(t->track.artistTag); t->track.artistScroll = TRUE; t->track.artistTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_artist, t); } else if (t->track.artistScroll) { g_source_remove(t->track.artistTag); gtk_layout_move(GTK_LAYOUT(t->trackw.layout.artist), t->trackw.label.artist, 0, 0); t->track.artistScroll = FALSE; } g_free(markup); t->track.x.album = 0; t->track.x.album2 = 0; markup = g_markup_printf_escaped(markupProps, t->track.album); gtk_label_set_markup(GTK_LABEL(t->trackw.label.album), markup); layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.album)); pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.albumLen, NULL); if (t->track.albumLen > SCROLL_SIZE_W-40) { if (t->track.albumScroll) g_source_remove(t->track.albumTag); t->track.albumScroll = TRUE; t->track.albumTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_album, t); } else if (t->track.albumScroll) { g_source_remove(t->track.albumTag); gtk_layout_move(GTK_LAYOUT(t->trackw.layout.album), t->trackw.label.album, 0, 0); t->track.albumScroll = FALSE; } g_free(markup); g_free(markupProps); markupProps = g_strdup("<span font='Sans 11' color='#FFFFFF'>%s</span>"); markup = g_markup_printf_escaped(markupProps, t->track.genre); gtk_label_set_markup(GTK_LABEL(t->trackw.genre), markup); g_free(markup); g_sprintf(dummy, "%d", t->track.year); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.year), markup); g_free(markup); dummy[0] = '\0'; format_time(dummy, t->track.length); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.length), markup); g_free(markup); g_free(markupProps); dummy[0] = '\0'; gtk_range_set_range(GTK_RANGE(t->trackw.slider), 0, t->track.length); /* set the rating */ starPix = gdk_pixbuf_new_from_xpm_data(starFull_xpm); for (i = 1; i <= t->track.rating; i++) gtk_image_set_from_pixbuf(GTK_IMAGE(t->trackw.stars[i-1]), GDK_PIXBUF(starPix)); g_object_unref(starPix); starPix = gdk_pixbuf_new_from_xpm_data(starHollow_xpm); while (i <= 5) { gtk_image_set_from_pixbuf(GTK_IMAGE(t->trackw.stars[i-1]), GDK_PIXBUF(starPix)); i++; } g_object_unref(starPix); } markupProps = g_strdup("<span font='Sans 11' color='#FFFFFF'>%s</span>"); g_sprintf(dummy, "%d", t->track.playcount); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.playcount), markup); g_free(markup); dummy[0] = '\0'; format_time(dummy, t->track.position); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.position), markup); g_free(markup); g_free(markupProps); dummy[0] = '\0'; gtk_range_set_fill_level(GTK_RANGE(t->trackw.slider), t->track.position); gtk_range_set_value(GTK_RANGE(t->trackw.slider), t->track.position); /* NOTE: reuses the starPix pixbuf */ if (t->playerInfo.counter == 4) { /* 2 seconds on currently UPDATE_SPEED */ if (!get_player_info(&t->playerInfo)) return FALSE; else { if (t->playerInfo.status) { starPix = gdk_pixbuf_new_from_xpm_data(pause_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.playPause), starPix); g_object_unref(starPix); } else { starPix = gdk_pixbuf_new_from_xpm_data(play_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.playPause), starPix); g_object_unref(starPix); } if (t->playerInfo.repeat == 0) { starPix = gdk_pixbuf_new_from_xpm_data(repeatOff_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix); g_object_unref(starPix); } else if (t->playerInfo.repeat == 1) { starPix = gdk_pixbuf_new_from_xpm_data(repeatAll_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix); g_object_unref(starPix); } else { starPix = gdk_pixbuf_new_from_xpm_data(repeatSingle_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix); g_object_unref(starPix); } if (t->playerInfo.shuffle) { starPix = gdk_pixbuf_new_from_xpm_data(shuffleOn_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.shuffle), starPix); g_object_unref(starPix); } else { starPix = gdk_pixbuf_new_from_xpm_data(shuffleOff_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.shuffle), starPix); g_object_unref(starPix); } } t->playerInfo.counter = 0; } free_track_info(&t->track); t->playerInfo.counter++; return TRUE; }
void gnc_item_edit_show_popup (GncItemEdit *item_edit) { GtkToggleButton *toggle; GtkAdjustment *vadj, *hadj; GtkAllocation alloc; GnucashSheet *sheet; gint x, y, w, h; gint y_offset, x_offset; gint popup_x, popup_y; gint popup_w = -1, popup_h = -1; gint popup_max_width, popup_max_height; gint view_width, view_height; gint down_height, up_height; gint sheet_width; g_return_if_fail (item_edit != NULL); g_return_if_fail (GNC_IS_ITEM_EDIT(item_edit)); if (!item_edit->is_popup) return; sheet = item_edit->sheet; sheet_width = sheet->width; gtk_widget_get_allocation (GTK_WIDGET (sheet), &alloc); view_height = alloc.height; view_width = alloc.width; vadj = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(sheet)); hadj = gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(sheet)); y_offset = gtk_adjustment_get_value(vadj); x_offset = gtk_adjustment_get_value(hadj); gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &w, &h); popup_x = x; up_height = y - y_offset; down_height = view_height - (up_height + h); popup_max_height = MAX (up_height, down_height); popup_max_width = sheet_width - popup_x + x_offset; // always pops to the right if (item_edit->popup_get_height) popup_h = item_edit->popup_get_height (item_edit->popup_item, popup_max_height, h, item_edit->popup_user_data); if (item_edit->popup_autosize) popup_w = item_edit->popup_autosize (item_edit->popup_item, popup_max_width, item_edit->popup_user_data); else popup_w = 0; // Adjust the popup_y point based on popping above or below if (up_height > down_height) popup_y = y - popup_h; else popup_y = y + h; if (!gtk_widget_get_parent (item_edit->popup_item)) gtk_layout_put (GTK_LAYOUT(sheet), item_edit->popup_item, popup_x, popup_y); gtk_widget_set_size_request (item_edit->popup_item, popup_w - 1, popup_h); toggle = GTK_TOGGLE_BUTTON(item_edit->popup_toggle.tbutton); if (!gtk_toggle_button_get_active (toggle)) { block_toggle_signals (item_edit); gtk_toggle_button_set_active (toggle, TRUE); unblock_toggle_signals (item_edit); } // set the popup arrow direction up item_edit->popup_toggle.arrow_down = FALSE; if (item_edit->popup_set_focus) item_edit->popup_set_focus (item_edit->popup_item, item_edit->popup_user_data); if (item_edit->popup_post_show) item_edit->popup_post_show (item_edit->popup_item, item_edit->popup_user_data); if (item_edit->popup_get_width) { int popup_width; popup_width = item_edit->popup_get_width (item_edit->popup_item, item_edit->popup_user_data); if (popup_width > popup_w) popup_width = popup_w; if (popup_width > popup_max_width) { popup_x -= popup_width - popup_max_width; popup_x = MAX (0, popup_x); } else popup_x = x; gtk_layout_move (GTK_LAYOUT(sheet), item_edit->popup_item, popup_x, popup_y); } }
void FloatingWindow::rectangle_set (const GdkRectangle& rectangle) { my_gdk_rectangle = rectangle; gtk_layout_move (GTK_LAYOUT (layout), vbox_window, my_gdk_rectangle.x, my_gdk_rectangle.y); gtk_widget_set_size_request (vbox_window, my_gdk_rectangle.width, my_gdk_rectangle.height); }
static void draw_mosaic (GtkLayout *where, GtkWidget **widgets, int rsize, int focus_on, int rwidth, int rheight) { boxes_drawn = 0; int cur_x = options.center_x - rwidth/2; int cur_y = options.center_y - rheight/2; if (rsize) { int i = 0; int offset = 0; int max_offset = (width*2) / rwidth + (height*2) / rheight; int side = 0; while (i < rsize) { int j = 0; do { if (i == rsize) break; if (cur_x >= 0 && cur_x+rwidth <= width && cur_y >= 0 && cur_y+rheight <= height) { offset = 0; if (gtk_widget_get_parent (widgets[i])) gtk_layout_move (GTK_LAYOUT (where), widgets[i], cur_x, cur_y); else gtk_layout_put (GTK_LAYOUT (where), widgets[i], cur_x, cur_y); gtk_widget_set_size_request (widgets[i], rwidth, rheight); gtk_widget_show (widgets[i]); if (!options.screenshot) { box_rects[i].x = cur_x; box_rects[i].y = cur_y; boxes_drawn++; } i++; } else { offset++; } if (side) { if (j % (side * 4) < side || j % (side * 4) >= side * 3) cur_x += rwidth; else cur_x -= rwidth; if (j % (side * 4) < side * 2) cur_y += rheight; else cur_y -= rheight; } j++; } while (j < side * 4); if (offset >= max_offset) break; side++; cur_x = options.center_x - rwidth/2; cur_y -= rheight; } if (focus_on >= rsize) // If some window was killed and focus was on the last element focus_on = rsize-1; gtk_widget_grab_focus (widgets[focus_on]); } if (!options.screenshot) { draw_mask (window_shape_bitmap, rsize); gtk_widget_shape_combine_mask (window, window_shape_bitmap, 0, 0); } }
static void lmplayer_lyric_widget_da_set_current_second(LmplayerLyricWidget *lyric, gint sec) { gint w, h; gint n; gboolean find = FALSE; GList *iter = NULL; LyricLine *line = NULL; g_return_if_fail(LMPLAYER_IS_LYRIC_WIDGET_DA(lyric)); g_return_if_fail(sec >= 0); LmplayerLyricWidgetDaPrivate *priv = LMPLAYER_LYRIC_WIDGET_DA(lyric)->priv; if(priv->current_second == sec) return; priv->current_second = sec; gtk_widget_get_size_request(GTK_WIDGET(lyric), &w, &h); for(iter = priv->lines, n = 0; iter; iter = iter->next, ++n) { line = iter->data; if(line && line->sec == sec) { find = TRUE; break; } else if(line && line->sec > sec) { find = FALSE; break; } find = FALSE; } if(find && line) { if(line->text != NULL) { gdk_gc_set_rgb_fg_color(priv->da_gc, &priv->current); pango_layout_set_text(priv->pango_layout, line->text, -1); pango_layout_set_width(priv->pango_layout, priv->da_width * PANGO_SCALE); pango_layout_set_alignment(priv->pango_layout, PANGO_ALIGN_CENTER); // 注意:这里是在da上直接绘,而不是在pixmap上 gdk_draw_layout(priv->da->window, priv->da_gc, line->x, line->y, priv->pango_layout); //gdk_draw_layout(priv->pixmap, priv->da_gc, line->x, line->y, priv->pango_layout); } gtk_layout_move(GTK_LAYOUT(lyric), priv->alignment, 0, h / 2 - line->y); if(n > 0) { line = (LyricLine*)g_list_nth_data(priv->lines, n - 1); if(line->text != NULL) { gdk_gc_set_rgb_fg_color(priv->da_gc, &priv->fg); pango_layout_set_text(priv->pango_layout, line->text, -1); pango_layout_set_width(priv->pango_layout, priv->da_width * PANGO_SCALE); pango_layout_set_alignment(priv->pango_layout, PANGO_ALIGN_CENTER); // 注意:这里是在da上直接绘,而不是在pixmap上 gdk_draw_layout(priv->da->window, priv->da_gc, line->x, line->y, priv->pango_layout); //gdk_draw_layout(priv->pixmap, priv->da_gc, line->x, line->y, priv->pango_layout); } } } }
static void recalc_bounds (FooCanvasWidget *witem) { FooCanvasItem *item; double wx, wy; item = FOO_CANVAS_ITEM (witem); /* Get world coordinates */ wx = witem->x; wy = witem->y; foo_canvas_item_i2w (item, &wx, &wy); /* Get canvas pixel coordinates */ foo_canvas_w2c (item->canvas, wx, wy, &witem->cx, &witem->cy); /* Anchor widget item */ switch (witem->anchor) { case GTK_ANCHOR_NW: case GTK_ANCHOR_W: case GTK_ANCHOR_SW: break; case GTK_ANCHOR_N: case GTK_ANCHOR_CENTER: case GTK_ANCHOR_S: witem->cx -= witem->cwidth / 2; break; case GTK_ANCHOR_NE: case GTK_ANCHOR_E: case GTK_ANCHOR_SE: witem->cx -= witem->cwidth; break; default: break; } switch (witem->anchor) { case GTK_ANCHOR_NW: case GTK_ANCHOR_N: case GTK_ANCHOR_NE: break; case GTK_ANCHOR_W: case GTK_ANCHOR_CENTER: case GTK_ANCHOR_E: witem->cy -= witem->cheight / 2; break; case GTK_ANCHOR_SW: case GTK_ANCHOR_S: case GTK_ANCHOR_SE: witem->cy -= witem->cheight; break; default: break; } /* Bounds */ item->x1 = witem->cx; item->y1 = witem->cy; item->x2 = witem->cx + witem->cwidth; item->y2 = witem->cy + witem->cheight; if (witem->widget) gtk_layout_move (GTK_LAYOUT (item->canvas), witem->widget, witem->cx, witem->cy); }