📄 gtk_factory.cpp
字号:
// the callback function is actually called (e.g. the user selects a different file) GtkWidget* this_widget = m_ambulant_widget->get_gtk_widget(); dirty_area_widget* dirty = new dirty_area_widget(); dirty->widget = gtk_widget_get_parent(this_widget); dirty->area = r; if ( ! gtk_widget_translate_coordinates (this_widget, dirty->widget, r.left(), r.top(), &dirty->area.x, &dirty->area.y)) { AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::need_redraw(0x%x): gtk_widget_translate_coordinates failed.", (void *)this); } g_idle_add((GSourceFunc) gtk_C_callback_helper_queue_draw_area, (void *)dirty);// gtk_widget_queue_draw_area(m_ambulant_widget->get_gtk_widget(), r.left(), r.top(), r.width(), r.height());// gdk_threads_leave ();// g_main_context_dispatch(g_main_loop_get_context(m_main_loop)); }voidambulant_gtk_window::redraw(const lib::rect &r){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::redraw(0x%x): ltrb=(%d,%d,%d,%d)",(void *)this, r.left(), r.top(), r.width(), r.height()); _screenTransitionPreRedraw(); m_handler->redraw(r, this);//XXXX if ( ! isEqualToPrevious(m_pixmap)) _screenTransitionPostRedraw(r); gdk_pixmap_bitblt(m_ambulant_widget->get_gtk_widget()->window, r.left(), r.top(), m_pixmap, r.left(), r.top(), r.width(), r.height()); GError *error = NULL; gint width; gint height; gdk_drawable_get_size(m_ambulant_widget->get_gtk_widget()->window, &width, &height); GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(NULL, m_ambulant_widget->get_gtk_widget()->window, 0, 0, 0, 0, 0, width, height);// if (!gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &buffer_size, "jpeg", &error, "quality", "100", NULL)) { if (m_ambulant_widget->m_screenshot_data) { g_free(m_ambulant_widget->m_screenshot_data); m_ambulant_widget->m_screenshot_data = NULL; m_ambulant_widget->m_screenshot_size = 0; } if (!gdk_pixbuf_save_to_buffer (pixbuf, &m_ambulant_widget->m_screenshot_data, &m_ambulant_widget->m_screenshot_size, "jpeg", &error, "quality", "100", NULL)) { printf (" Tenemos un error%s", error->message); g_error_free (error); } g_object_unref (G_OBJECT (pixbuf));#ifdef DUMPPIXMAP gdk_pixmap_dump(m_pixmap, "top");#endif/*DUMPPIXMAP*/}voidambulant_gtk_window::redraw_now(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::redraw_now()");}voidambulant_gtk_window::mouse_region_changed(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::mouse_region_changed needs to be implemented");}voidambulant_gtk_window::user_event(const lib::point &where, int what) { AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::user_event(0x%x): point=(%d,%d)", this, where.x, where.y); m_handler->user_event(where, what);}voidambulant_gtk_window::need_events(bool want) { AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::need_events(0x%x): want=%d", this, want);}voidambulant_gtk_window::set_ambulant_widget(gtk_ambulant_widget* gtkaw){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::set_ambulant_widget(0x%x)",(void *)gtkaw); // Don't destroy! //if (m_ambulant_widget != NULL) // delete m_ambulant_widget; m_ambulant_widget = gtkaw; GdkColor color; GdkColormap *cmap = gdk_colormap_get_system(); if (gtkaw != NULL) { // color is white gdk_color_parse("white", &color); // in debugging mode, initialize with purple background AM_DBG gdk_color_parse("Purple", &color); gdk_colormap_alloc_color(cmap, &color, FALSE, TRUE); // set the color in the widget gtk_widget_modify_bg (GTK_WIDGET (gtkaw->get_gtk_widget()), GTK_STATE_NORMAL, &color ); // Initialize m_pixmap gint width; gint height; gtk_widget_get_size_request(GTK_WIDGET (gtkaw->get_gtk_widget()), &width, &height); m_pixmap = gdk_pixmap_new(gtkaw->get_gtk_widget()->window, width, height, -1); AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::set_ambulant_widget(0x%x); size (%i,%i)",(void *)gtkaw, width, height); // User Interaction } // }else{// gtk_widget_hide(GTK_WIDGET (gtkaw->get_gtk_widget()));// gtk_box_pack_start (GTK_BOX (parent_widget), GTK_WIDGET (m_widget), TRUE, TRUE, 0);// gtk_container_remove(GTK_CONTAINER (gtkaw->get_gtk_widget()->parent), GTK_WIDGET (gtkaw->get_gtk_widget()));// free(gtkaw->get_gtk_widget());// }}gtk_ambulant_widget*ambulant_gtk_window::get_ambulant_widget(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::get_ambulant_widget(0x%x)",(void *)m_ambulant_widget); return m_ambulant_widget;}GdkPixmap* ambulant_gtk_window::get_ambulant_pixmap(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::ambulant_pixmap(0x%x) = 0x%x",(void *)this,(void *)m_pixmap); return m_pixmap;}voidambulant_gtk_window::set_gui_player(gui_player* gpl){ m_gui_player = gpl;} gui_player*ambulant_gtk_window::get_gui_player(){ return m_gui_player;}GdkPixmap*ambulant_gtk_window::new_ambulant_surface(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::new_ambulant_surface(0x%x)",(void *)m_surface); if (m_surface != NULL) delete m_surface; gint width; gint height; gdk_drawable_get_size(GDK_DRAWABLE (m_pixmap), &width, &height); m_surface = gdk_pixmap_new(m_pixmap, width, height, -1); AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::new_ambulant_surface(0x%x)",(void *)m_surface); return m_surface;}GdkPixmap*ambulant_gtk_window::get_ambulant_oldpixmap(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::get_ambulant_oldpixmap(0x%x) = 0x%x",(void *)this,(void *)m_oldpixmap); if (m_fullscreen_count && m_fullscreen_old_pixmap) return m_fullscreen_old_pixmap; return m_oldpixmap;}GdkPixmap*ambulant_gtk_window::get_ambulant_surface(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::get_ambulant_surface(0x%x) = 0x%x",(void *)this,(void *)m_surface); return m_surface;}GdkPixmap*ambulant_gtk_window::get_pixmap_from_screen(const lib::rect &r){ GdkPixmap *rv = gdk_pixmap_new(m_ambulant_widget->get_gtk_widget()->window, r.width(), r.height(), -1); gdk_pixmap_bitblt(rv, r.left(), r.top(), m_pixmap, r.left(), r.top(), r.width(), r.height()); AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::get_pixmap_from_screen(0x%x) = 0x%x",(void *)this,(void *)m_pixmap); return rv;}voidambulant_gtk_window::reset_ambulant_surface(void){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::reset_ambulant_surface(0x%x) m_oldpixmap = 0x%x",(void *)this,(void *)m_oldpixmap); if (m_oldpixmap != NULL) m_pixmap = m_oldpixmap;}voidambulant_gtk_window::set_ambulant_surface(GdkPixmap* surf){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::set_ambulant_surface(0x%x) surf = 0x%x",(void *)this,(void *)surf); m_oldpixmap = m_pixmap; if (surf != NULL) m_pixmap = surf;}voidambulant_gtk_window::delete_ambulant_surface(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::delete_ambulant_surface(0x%x) m_surface = 0x%x",(void *)this, (void *)m_surface); delete m_surface; m_surface = NULL;}// Transitions void ambulant_gtk_window::startScreenTransition(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::startScreenTransition()"); if (m_fullscreen_count) logger::get_logger()->warn("ambulant_gtk_window::startScreenTransition():multiple Screen transitions in progress (m_fullscreen_count=%d)",m_fullscreen_count); m_fullscreen_count++; if (m_fullscreen_old_pixmap) g_object_unref(G_OBJECT(m_fullscreen_old_pixmap)); m_fullscreen_old_pixmap = m_fullscreen_prev_pixmap; m_fullscreen_prev_pixmap = NULL;}void ambulant_gtk_window::endScreenTransition(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::endScreenTransition()"); assert(m_fullscreen_count > 0); m_fullscreen_count--;}void ambulant_gtk_window::screenTransitionStep(smil2::transition_engine* engine, lib::transition_info::time_type now){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::screenTransitionStep()"); assert(m_fullscreen_count > 0); m_fullscreen_engine = engine; m_fullscreen_now = now;} void ambulant_gtk_window::_screenTransitionPreRedraw(){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::_screenTransitionPreRedraw()"); if (m_fullscreen_count == 0) return; // XXX setup drawing to transition surface}void ambulant_gtk_window::_screenTransitionPostRedraw(const lib::rect &r){ AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::_screenTransitionPostRedraw()"); if (m_fullscreen_count == 0 && m_fullscreen_old_pixmap == NULL) { // Neither in fullscreen transition nor wrapping one up. // Take a snapshot of the screen and return. AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::_screenTransitionPostRedraw: screen snapshot"); if (m_fullscreen_prev_pixmap) g_object_unref(G_OBJECT(m_fullscreen_prev_pixmap)); m_fullscreen_prev_pixmap = get_pixmap_from_screen(r); // XXX wrong#ifdef DUMPPIXMAP gdk_pixmap_dump(m_fullscreen_prev_pixmap, "snap");#endif/*DUMPPIXMAP*/ return; } if (m_fullscreen_old_pixmap == NULL) { // Just starting a new fullscreen transition. Get the // bits from the snapshot saved during the previous // redraw. m_fullscreen_old_pixmap = m_fullscreen_prev_pixmap; m_fullscreen_prev_pixmap = NULL; } AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::_screenTransitionPostRedraw: bitblit"); if (m_fullscreen_engine) { // Do the transition step GdkPixmap* new_src = get_ambulant_surface(); if ( ! new_src) new_src = new_ambulant_surface(); gdk_pixmap_bitblt(m_surface, 0, 0, m_pixmap, r.left(), r.top(), r.width(), r.height()); gdk_pixmap_bitblt(m_pixmap, 0, 0, m_fullscreen_old_pixmap, r.left(), r.top(), r.width(), r.height());#ifdef DUMPPIXMAP gdk_pixmap_dump(new_src, "fnew"); gdk_pixmap_dump(m_pixmap, "fold");#endif/*DUMPPIXMAP*/ m_fullscreen_engine->step(m_fullscreen_now);#ifdef DUMPPIXMAP gdk_pixmap_dump(m_pixmap, "fres");#endif/*DUMPPIXMAP*/ } if (m_fullscreen_count == 0) { // Finishing a fullscreen transition. AM_DBG lib::logger::get_logger()->debug("ambulant_gtk_window::_screenTransitionPostRedraw: cleanup after transition done"); if (m_fullscreen_old_pixmap) g_object_unref(G_OBJECT(m_fullscreen_old_pixmap)); m_fullscreen_old_pixmap = NULL; m_fullscreen_engine = NULL; }}//// gtk_ambulant_widget//gtk_ambulant_widget::gtk_ambulant_widget(GtkWidget* parent_widget): m_gtk_window(NULL), m_screenshot_data(NULL), m_screenshot_size(0){ m_widget = parent_widget; GObject* toplevel_widget = G_OBJECT (GTK_WIDGET (gtk_widget_get_toplevel(m_widget))); AM_DBG lib::logger::get_logger()->debug("gtk_ambulant_widget::gtk_ambulant_widget(0x%x-0x%x)", (void *)this, (void*) parent_widget); m_expose_event_handler_id = g_signal_connect_swapped (G_OBJECT (m_widget), "expose_event", G_CALLBACK (gtk_C_callback_do_paint_event), (void*) this); m_motion_notify_handler_id = g_signal_connect_swapped (toplevel_widget, "motion_notify_event", G_CALLBACK (gtk_C_callback_do_motion_notify_event), (void*) this); m_button_release_handler_id = g_signal_connect_swapped (toplevel_widget, "button_release_event", G_CALLBACK (gtk_C_callback_do_button_release_event), (void*) this); gtk_widget_add_events( (GTK_WIDGET (gtk_widget_get_toplevel(m_widget))), GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK);}gtk_ambulant_widget::~gtk_ambulant_widget(){ AM_DBG lib::logger::get_logger()->debug("gtk_ambulant_widget::~gtk_ambulant_widget(0x%x): m_gtk_window=0x%x", (void*)this, m_gtk_window); GObject* toplevel_widget = G_OBJECT (GTK_WIDGET (gtk_widget_get_toplevel(m_widget))); if (g_signal_handler_is_connected (G_OBJECT (m_widget), m_expose_event_handler_id)) g_signal_handler_disconnect(G_OBJECT (m_widget), m_expose_event_handler_id); if (g_signal_handler_is_connected (toplevel_widget, m_motion_notify_handler_id)) g_signal_handler_disconnect(toplevel_widget, m_motion_notify_handler_id); if (g_signal_handler_is_connected (toplevel_widget, m_button_release_handler_id)) g_signal_handler_disconnect(toplevel_widget, m_button_release_handler_id); if (m_gtk_window) { m_gtk_window->set_ambulant_widget(NULL); m_gtk_window = NULL; } if (m_screenshot_data) { g_free(m_screenshot_data); m_screenshot_data = NULL; m_screenshot_size = 0; }}void gtk_ambulant_widget::set_gtk_window( ambulant_gtk_window* agtkw){ // Note: the window and widget are destucted independently. // if (m_gtk_window != NULL) // delete m_gtk_window; m_gtk_window = agtkw; AM_DBG lib::logger::get_logger()->debug("gtk_ambulant_widget::set_gtk_window(0x%x): m_gtk_window==0x%x)", (void*) this, (void*) m_gtk_window);}ambulant_gtk_window* gtk_ambulant_widget::gtk_window() { return m_gtk_window;}GtkWidget*gtk_ambulant_widget::get_gtk_widget(){ return m_widget;}void gtk_ambulant_widget::do_paint_event (GdkEventExpose *e) { AM_DBG lib::logger::get_logger()->debug("gtk_ambulant_widget::paintEvent(0x%x): e=0x%x)", (void*) this, (void*) e); lib::rect r = lib::rect( lib::point(e->area.x, e->area.y), lib::size(e->area.width, e->area.height)); if (m_gtk_window == NULL) { lib::logger::get_logger()->debug("gtk_ambulant_widget::paintEvent(0x%x): e=0x%x m_gtk_window==NULL", (void*) this, (void*) e); return; } m_gtk_window->redraw(r);}void gtk_ambulant_widget::do_motion_notify_event(GdkEventMotion *e) { int m_o_x = 0, m_o_y = 0; //27; // XXXX Origin of MainWidget AM_DBG lib::logger::get_logger()->debug("gtk_ambulant_widget::mouseMoveEvent(0x%x) e=(%d,%d) m_gtk_window=0x%x\n", this, e->x,e->y, m_gtk_window); if (! m_gtk_window) return; //XXXX This is not right!!! ambulant::lib::point ap = ambulant::lib::point((int)e->x, (int)e->y-25); gui_player* gui_player = m_gtk_window->get_gui_player(); if (gui_player) { gui_player->before_mousemove(0); m_gtk_window->user_event(ap, 1); } int cursid = 0; if (gui_player) cursid = gui_player->after_mousemove(); // Set hand cursor if cursid==1, arrow if cursid==0. GdkCursor* cursor; // gdk cursors need to be cached by the window factory cursor = cursid == 0 ? m_gtk_window->get_gdk_cursor(GDK_ARROW) : m_gtk_window->get_gdk_cursor(GDK_HAND1); if (cursor) gdk_window_set_cursor (m_widget->window, cursor);}voidgtk_ambulant_widget::do_button_release_event(GdkEventButton *e) { AM_DBG lib::logger::get_logger()->debug("gtk_ambulant_widget::do_button_release_event(0x%x): e=0x%x, position=(%d, %d))", (void*) this, (void*) e, e->x, e->y); if (m_gtk_window == NULL) { lib::logger::get_logger()->debug("gtk_ambulant_widget::do_button_release_event(0x%x): e=0x%x position=(%d, %d) m_gtk_window==NULL", (void*) this, (void*) e, e->x, e->y); return; } if (e->type == GDK_BUTTON_RELEASE){ lib::point amwhere = lib::point((int)e->x, (int)e->y); m_gtk_window->user_event(amwhere); }}void gtk_ambulant_widget::get_size(int *width, int *height){ gdk_drawable_get_size(m_widget->window, width, height);}bool gtk_ambulant_widget::get_screenshot(const char *type, char **out_data, size_t *out_size){ *out_data = NULL; *out_size = 0; *out_data= m_screenshot_data; *out_size = m_screenshot_size; return TRUE;}// Not implementedbool gtk_ambulant_widget::set_overlay(const char *type, const char *data, size_t size){ return FALSE;}// Not implementedbool gtk_ambulant_widget::clear_overlay(){ return FALSE;}bool gtk_ambulant_widget::set_screenshot(gchar **screenshot_data, gsize *screenshot_size){ return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -