📄 mplayer_ui.c
字号:
#include "mplayer_ui.h"#include "mymarquee.h"#include <unistd.h>GdkPixmap *gdk_pixmap1 = NULL;GdkBitmap *mask1;GtkWidget *pixmap1 = NULL;GdkPixmap *gdk_pixmap;GdkBitmap *mask;GtkPixmap *gtk_pixmap;GdkColor c;GtkStyle *style;GdkGC *gc;GdkPixbuf *pixbuf_main_png;GdkPixbuf *pixbuf_main_alpha;GdkPixmap *pixmap_main;GdkBitmap *bitmap_main;GdkColormap *cmap_main;cursor_pos cp1;GdkPixbuf *myexit_1;GdkPixbuf *myexit_2;GdkPixbuf *myexit_3;/////////////////////////////add for polygon ui////////////////////////void rings3d_mask_init (void);void myexit_png_3subpixbuf_init(void);gbooleanwindow_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data);gbooleanimage1_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data);static void shape_pressed (GtkWidget * widget, GdkEventButton * event);static void shape_released (GtkWidget * widget);static void image1_pressed (GtkWidget * widget, GdkEvent * event);static void menuitem_response (char *data);static gboolean click_on_m2 (GtkWidget * widget, GdkEvent * event);static voidmyexit_pressed (GtkWidget * widget, GtkWidget * marquee);static voidmyexit_released (GtkWidget * widget);gbooleanmyexit_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data);/* This is called every time a button-press-event occurs on the GtkEventBox. */static gbooleanbutton_pressed (GtkWidget * eventbox, GdkEventButton * event, GtkWidget * win){ gint w, h; GtkRequisition wh; GtkStyle *style; if (event->type == GDK_2BUTTON_PRESS) { g_print ("-----before w,h\n"); if (eventbox != NULL) { gtk_widget_size_request (eventbox, &wh); w = wh.width; h = wh.height; g_print ("----window size is:%d,%d\n", (int) w, (int) h); } style = gtk_widget_get_default_style (); gc = style->black_gc; gdk_pixmap = gdk_pixmap_create_from_xpm (win->window, &mask, &win->style->white_gc, "3DRings.xpm"); gtk_pixmap = gtk_image_new_from_pixmap (gdk_pixmap, mask); gtk_widget_shape_combine_mask (win, mask, 0, 0); } return FALSE;}/***************** lib func *****************/GdkPixmap *load_pixmap (GtkWidget * widget, gchar * filename){ GdkPixbuf *pixbuf = NULL; GdkPixmap *pixmap = NULL; pixbuf = gdk_pixbuf_new_from_file (filename, NULL); if (!widget) { printf ("-------Widget--NULL\n"); return NULL; } if (pixbuf != NULL) { pixmap = gdk_pixmap_new (widget->window, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), -1); g_print ("--------null pixmap ok\n"); gdk_pixbuf_render_to_drawable (pixbuf, pixmap, widget->style->fg_gc[GTK_STATE_NORMAL], 0, 0, 0, 0, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GDK_RGB_DITHER_NORMAL, 0, 0); g_print ("------------------pixmap ok\n"); //g_object_unref(pixbuf); } if (pixmap != NULL) { return pixmap; } else return NULL;}gbooleanset_widget_bg_picture (GtkWidget * widget, gchar * filename){ GdkPixmap *bg_pict; bg_pict = load_pixmap (widget, filename); if (bg_pict != NULL) { gdk_window_set_back_pixmap (widget->window, bg_pict, FALSE); //////////////? //gdk_window_clear(widget->window); g_print ("--------------bg_pict ok\n"); return TRUE; } else return FALSE;}/************************** callback **************/static voidon_b1_clicked (GtkWidget * button, GtkWidget * win){ if (set_widget_bg_picture (win, "fruits.jpg")) g_print ("--------main ok\n");}static voidwin_expose_cb (GtkWidget * window, gpointer data){ g_print ("win_expose_cb happen\n"); /* gdk_draw_pixbuf(window->window, pixbuf_main_png, style->white_gc, 0,0,0,0, 440,120, GDK_RGB_DITHER_NORMAL, 0,0); */}static voiddestroy (GtkWidget * window, gpointer data){ gtk_main_quit ();}/****************** main *****************/intmain (int argc, char *argv[]){ GtkWidget *window; gtk_init (&argc, &argv); //gtk_rc_parse("gtkrc_mui"); rings3d_mask_init (); myexit_png_3subpixbuf_init(); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "polygon ui"); gtk_window_set_decorated (GTK_WINDOW (window),FALSE); gtk_container_set_border_width (GTK_CONTAINER (window), 0); gtk_widget_set_size_request (GTK_WIDGET (window), 440, 120); //fixed GtkWidget *fixed = gtk_fixed_new (); gtk_widget_set_size_request (fixed, 440, 120); gtk_fixed_set_has_window (GTK_FIXED (fixed), TRUE); gtk_container_add (GTK_CONTAINER (window), fixed);//main.png GtkWidget *main_png = gtk_image_new_from_file ("blue/main.png"); gtk_fixed_put (GTK_FIXED (fixed), main_png, 0, 0); //image1 and eventbox1 GtkWidget *eventbox1 = gtk_event_box_new (); //gtk_box_pack_start_defaults(GTK_BOX(vbox),eventbox); gtk_fixed_put(GTK_FIXED(fixed),eventbox1,35,30); gtk_event_box_set_above_child (GTK_EVENT_BOX (eventbox1), FALSE); gtk_widget_set_events (eventbox1, GDK_BUTTON_PRESS_MASK); gdk_window_set_cursor (eventbox1->window , gdk_cursor_new (GDK_CROSS)); gtk_event_box_set_visible_window(eventbox1,FALSE); //image1 GtkWidget *image1 = gtk_image_new_from_file("../picture/3DRings.xpm"); gtk_container_add (GTK_CONTAINER (eventbox1), image1); g_signal_connect (eventbox1, "button_press_event", G_CALLBACK (image1_pressed), NULL); g_signal_connect (eventbox1, "motion_notify_event", G_CALLBACK (image1_motion_notify_event), NULL); //myexit_png and eventbox2 GtkWidget *eventbox2 = gtk_event_box_new (); //gtk_box_pack_start_defaults(GTK_BOX(vbox),eventbox); gtk_fixed_put(GTK_FIXED(fixed),eventbox2,412,48); gtk_event_box_set_above_child (GTK_EVENT_BOX (eventbox2), TRUE); gtk_widget_set_events (eventbox2, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); gdk_window_set_cursor (eventbox2->window , gdk_cursor_new (GDK_GUMBY)); gtk_event_box_set_visible_window(eventbox2,FALSE); //exit_1,2 GtkWidget *image_exit_1 = gtk_image_new_from_pixbuf(myexit_1); gtk_container_add (GTK_CONTAINER (eventbox2), image_exit_1); //to transparent gtk_widget_shape_combine_mask (window, bitmap_main, 0, 0); /////////////////////////////////////////////////////////////////// // new for polygonal ui gtk_widget_set_events (window, gtk_widget_get_events (window) | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); /////////popmenu GtkWidget *menu = gtk_menu_new (); char buf[1024]; GtkWidget *menu_items; int i = 0; for (i = 0; i < 3; i++) { sprintf (buf, "Test-undermenu - %d", i); // Create a new menu-item with a name... menu_items = gtk_menu_item_new_with_label (buf); // ...and add it to the menu. gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); // Do something interesting when the menuitem is selected g_signal_connect_swapped (G_OBJECT (menu_items), "activate", G_CALLBACK (menuitem_response), (gpointer) g_strdup (buf)); // Show the widget gtk_widget_show (menu_items); } //marquee GtkWidget *marquee; PangoFontDescription *fd; fd = pango_font_description_from_string ("Monospace,Regular,12"); marquee = my_marquee_new (); gtk_widget_modify_font (marquee, fd); my_marquee_set_message (MY_MARQUEE (marquee), "Wheee!"); my_marquee_set_speed (MY_MARQUEE (marquee), 10); pango_font_description_free (fd); gtk_widget_set_size_request (marquee, 160, 20); gtk_fixed_put (GTK_FIXED (fixed), marquee, 240, 30); g_timeout_add (100, (GSourceFunc) my_marquee_slide, (gpointer) marquee); g_signal_connect_swapped (G_OBJECT (marquee), "event", G_CALLBACK (click_on_m2), G_OBJECT (menu)); //myexit png signal g_signal_connect (eventbox2, "button_press_event", G_CALLBACK (myexit_pressed), marquee); g_signal_connect (eventbox2, "button_release_event", G_CALLBACK (myexit_released), NULL); g_signal_connect (eventbox2, "motion_notify_event", G_CALLBACK (myexit_motion_notify_event), NULL); //main window signal g_signal_connect (window, "button_press_event", G_CALLBACK (shape_pressed), NULL); g_signal_connect (window, "button_release_event", G_CALLBACK (shape_released), NULL); g_signal_connect (window, "motion_notify_event", G_CALLBACK (window_motion_notify_event), NULL); g_signal_connect (G_OBJECT (window), "delete_event" , G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (G_OBJECT (window), "destroy" , G_CALLBACK (destroy), NULL); g_signal_connect (G_OBJECT (window), "expose_event", G_CALLBACK (win_expose_cb), NULL); gtk_widget_show_all (window); /* GdkEventExpose *main_expose_1; main_expose_1->type = GDK_EXPOSE; gtk_propagate_event(window,(main_expose_1)); */ gtk_main (); return 0;}/******************poly ui func def ***********/gbooleanwindow_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data){ int x, y; GdkModifierType state; gdk_window_set_cursor (event->window , gdk_cursor_new (GDK_HAND1)); //get absolute (x,y) gdk_window_get_pointer (NULL, &x, &y, &state); //g_print(" x %d,r y %d\n", x, y); if (state & GDK_BUTTON1_MASK) { gtk_window_move (GTK_WINDOW (widget) , x - cp1.event_x , y - cp1.event_y ); } /* also not just the state ,use root_x = NULL(absolute) - event_x); gdk_window_get_pointer (NULL, &xp, &yp, &mask); gtk_widget_set_uposition (widget, xp - p->x, yp - p->y); */ return TRUE;}static voidimage1_pressed (GtkWidget * widget, GdkEvent * event){ if ((event->type == GDK_BUTTON_PRESS)) { GdkEventButton *bevent = (GdkEventButton *) event; if (bevent->button == 3) { g_print ("image right clicked\n"); } }}gbooleanimage1_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data){ gdk_window_set_cursor (event->window, gdk_cursor_new (GDK_CROSS)); return TRUE;} voidrings3d_mask_init (void){ GError *err1 = NULL; cmap_main = gdk_colormap_get_system (); if ((pixbuf_main_png = gdk_pixbuf_new_from_file ("blue/main.png", &err1)) != NULL) { pixbuf_main_alpha = gdk_pixbuf_add_alpha (pixbuf_main_png, TRUE, 255, 0, 255); g_print ("pixbuf_main_png ok\n"); gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf_main_alpha, cmap_main, &pixmap_main, &bitmap_main, 127); } g_object_unref(err1);}void myexit_png_3subpixbuf_init(void){ GError *err1 = NULL; int width,height; GdkPixbuf *src; if (( src = gdk_pixbuf_new_from_file ("blue/myexit.png", &err1)) != NULL) { width = gdk_pixbuf_get_width (src); height = gdk_pixbuf_get_height (src); myexit_1 = gdk_pixbuf_new_subpixbuf( src,0,0,width,height/3); myexit_2 = gdk_pixbuf_new_subpixbuf( src,0,height/3,width,height/3); myexit_3 = gdk_pixbuf_new_subpixbuf( src,0,height*2/3,width,height/3); }}static voidshape_pressed (GtkWidget * widget, GdkEventButton * event){ gint x,y; GdkModifierType state; /* ignore double and triple click */ if (event->type != GDK_BUTTON_PRESS) return; gdk_window_get_pointer (event->window , &x, &y, &state); cp1.event_x = x; cp1.event_y = y; gtk_grab_add (widget); gdk_pointer_grab (widget->window, TRUE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, NULL, 0);}static voidshape_released (GtkWidget * widget){ gtk_grab_remove (widget); gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);}static voidmenuitem_response (char *data){ g_print ("*** %s\n", data);}static gbooleanclick_on_m2 (GtkWidget * widget, GdkEvent * event){ if ((event->type == GDK_BUTTON_PRESS)) { GdkEventButton *bevent = (GdkEventButton *) event; if (bevent->button == 3) { gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, bevent->button, bevent->time); /* Tell calling code that we have handled this event; the buck * stops here. */ return TRUE; } } /* Tell calling code that we have not handled this event; pass it on. */ return FALSE;}static voidmyexit_pressed (GtkWidget * widget,GtkWidget *marquee){ GtkWidget *image_exit_2 = gtk_image_new_from_pixbuf(myexit_2); gtk_container_remove(GTK_CONTAINER(widget), GTK_WIDGET(gtk_container_children(GTK_CONTAINER(widget))->data)); gtk_container_add (GTK_CONTAINER (widget), image_exit_2); gtk_widget_show_all(image_exit_2); g_print("myexit_pressed \n"); /////////////////////////////////////////////////////////// //set mymarquee bg_pixmap GError *err_bg = NULL; GdkPixbuf *my_marquee_bg_pixbuf_src = gdk_pixbuf_new_from_file( "blue/mymain.png",&err_bg); /* GdkPixbuf *my_marquee_sub_pixbuf = gdk_pixbuf_new_subpixbuf( my_marquee_bg_pixbuf_src, 240,30,160,20); */ GdkColor pa; pa.pixel = 0xff00ff; pa.red = 65535; pa.green = 32768; pa.blue = 0; //gdk_window_set_background(fixed->window,&pa); g_print("111 \n"); //GtkStyle *new_style = gtk_style_new(); //gtk_style_detach(marquee->style); //new_style = gtk_style_attach(marquee->style,marquee->window); g_print("144 \n"); int w,h,depth; gdk_drawable_get_size(widget->window,&w,&h); depth = gdk_drawable_get_depth(widget->window); g_print("%d,%d,%d\n",w,h,depth); GdkPixmap *my_marquee_bg_pixmap = gdk_pixmap_new(widget->window, 160,20,depth ); g_print("145 \n"); gdk_draw_pixbuf (my_marquee_bg_pixmap, widget->style->white_gc, my_marquee_bg_pixbuf_src, 240,30, 0,0, 160,20, GDK_RGB_DITHER_NORMAL, 0,0); g_print("155 \n"); gdk_window_set_back_pixmap(widget->window, my_marquee_bg_pixmap, FALSE); //marquee->style->bg_pixmap[GTK_STATE_NORMAL] = my_marquee_bg_pixmap; //new_style->bg[GTK_STATE_NORMAL] = pa; //gtk_style_set_background(new_style,marquee->window,GTK_STATE_NORMAL); //gdk_window_show(marquee->window); g_print("199 \n"); // gtk_widget_show_all(marquee); }static voidmyexit_released (GtkWidget * widget){ g_print("myexit_released \n"); GtkWidget *image_exit_1 = gtk_image_new_from_pixbuf(myexit_1); gtk_container_remove(GTK_CONTAINER(widget), GTK_WIDGET(gtk_container_children(GTK_CONTAINER(widget))->data) ); gtk_container_add (GTK_CONTAINER (widget), image_exit_1); gtk_widget_show_all(image_exit_1); }gbooleanmyexit_motion_notify_event (GtkWidget * widget, GdkEventMotion * event, gpointer data){ gdk_window_set_cursor (event->window, gdk_cursor_new (GDK_GUMBY)); return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -