void Gui_ControlPanel::on_about_button(){ Gtk::Window* parent = (Gtk::Window*) get_toplevel(); MyAboutDialog about; about.set_transient_for(*parent); DEV_INFOS(parent); about.run(); }
static void set_foreground(GdkColor *color, int status) { int i, num; GdkPoint *p; int num_app_shells = get_num_shells(); GdkGC *app_gc = get_toplevel(); num = numpoints[status]; p = polyptr[status]; if (num) { gdk_gc_set_rgb_fg_color(app_gc, color); for (i = 0; i < num_app_shells; i++) { tape_status_widget *ts = &app_shells[i].tape_status; if (ts) { gdk_draw_polygon(ts->control_pixmap, app_gc, TRUE, p, num); gtk_widget_queue_draw(ts->control); } } } else { gdk_gc_set_rgb_fg_color(app_gc, &drive_led_on_red_pixel); for (i = 0; i < num_app_shells; i++) { tape_status_widget *ts = &app_shells[i].tape_status; if (ts) { gdk_draw_arc(ts->control_pixmap, app_gc, TRUE, 3, 1, CTRL_WIDTH - 6, CTRL_HEIGHT - 2, 0, 360 * 64); gtk_widget_queue_draw(ts->control); } } } }
static GObject * get_toplevel_from_string (GladePreviewer *app, gchar *name, gchar *string, gsize size) { gchar *wd = NULL; GObject *retval; /* We need to change the working directory so builder get a chance to load resources */ if (app->file_name) { gchar *dirname = g_path_get_dirname (app->file_name); wd = g_get_current_dir (); g_chdir (dirname); g_free (dirname); } /* We use template flag as a hint since the user can turn on and off template * while the preview is live. */ retval = (app->is_template) ? glade_preview_template_object_new (string, size) : NULL; if (!retval) { GtkBuilder *builder = gtk_builder_new (); GError *error = NULL; /* We do not know if its a template yet */ app->is_template = FALSE; if (gtk_builder_add_from_string (builder, string, size, &error)) retval = get_toplevel (builder, name); else { if (error->code == GTK_BUILDER_ERROR_UNHANDLED_TAG && (retval = glade_preview_template_object_new (string, size))) { /* At this point we know it is a template, so keep a hint for next time */ app->is_template = TRUE; } else { gchar *message = g_strdup_printf (_("Couldn't load builder definition: %s"), error->message); glade_preview_window_set_message (app->window, GTK_MESSAGE_ERROR, message); g_free (message); } g_error_free (error); } g_object_unref (builder); } /* restore directory */ if (wd) { g_chdir (wd); g_free (wd); } return retval; }
/** Open a dot graph and display it. */ void SkillGuiGraphDrawingArea::open() { Gtk::Window *w = dynamic_cast<Gtk::Window *>(get_toplevel()); __fcd_open->set_transient_for(*w); int result = __fcd_open->run(); if (result == Gtk::RESPONSE_OK) { __update_graph = false; __graph_dot = ""; char *basec = strdup(__fcd_open->get_filename().c_str()); char *basen = basename(basec); __graph_fsm = basen; free(basec); FILE *f = fopen(__fcd_open->get_filename().c_str(), "r"); while (! feof(f)) { char tmp[4096]; size_t s; if ((s = fread(tmp, 1, 4096, f)) > 0) { __graph_dot.append(tmp, s); } } fclose(f); __signal_update_disabled.emit(); queue_draw(); } __fcd_open->hide(); }
static void set_led(GdkColor *color1, int i, int drive_number) { GdkGC *app_gc = get_toplevel(); drive_status_widget *ds = &app_shells[i].drive_status[drive_number]; gdk_gc_set_rgb_fg_color(app_gc, color1); gdk_draw_rectangle(ds->led_pixmap, app_gc, TRUE, 0, 0, LED_WIDTH, LED_HEIGHT); gtk_widget_queue_draw(ds->led); }
static void popup_marshal_func (GtkObject *object, gpointer data, guint n_args, GtkArg *args) { ActivateFunc func; gpointer user_data; GObject *tl; GtkWidget *for_widget; tl = G_OBJECT (get_toplevel(GTK_WIDGET (object))); user_data = g_object_get_data (tl, "gnome_popup_menu_do_popup_user_data"); for_widget = g_object_get_data (tl, "gnome_popup_menu_do_popup_for_widget"); g_object_set_data (G_OBJECT (get_toplevel(GTK_WIDGET (object))), "gnome_popup_menu_active_item", object); func = (ActivateFunc) data; if (func) (* func) (object, user_data, for_widget); }
static void set_background(GdkColor *color) { int i; int num_app_shells = get_num_shells(); GdkGC *app_gc = get_toplevel(); gdk_gc_set_rgb_fg_color(app_gc, color); for (i = 0; i < num_app_shells; i++) { tape_status_widget *ts = &app_shells[i].tape_status; if (ts) { gdk_draw_rectangle(ts->control_pixmap, app_gc, TRUE, 0, 0, CTRL_WIDTH, CTRL_HEIGHT); } } }
static void set_led2(GdkColor *color1, GdkColor *color2, int i, int drive_number) { GdkGC *app_gc = get_toplevel(); drive_status_widget *ds = &app_shells[i].drive_status[drive_number]; /* LED 1 (left) */ gdk_gc_set_rgb_fg_color(app_gc, color1); gdk_draw_rectangle(ds->led1_pixmap, app_gc, TRUE, 0, 0, LED_WIDTH / 2, LED_HEIGHT); gtk_widget_queue_draw(ds->led1); /* LED 2 (right) */ gdk_gc_set_rgb_fg_color(app_gc, color2); gdk_draw_rectangle(ds->led2_pixmap, app_gc, TRUE, 0, 0, LED_WIDTH / 2, LED_HEIGHT); gtk_widget_queue_draw(ds->led2); }
Ref<World2D> CanvasItem::get_world_2d() const { ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>()); CanvasItem *tl = get_toplevel(); if (tl->canvas_layer) { return tl->canvas_layer->get_world_2d(); } else if (tl->get_viewport()) { return tl->get_viewport()->find_world_2d(); } else { return Ref<World2D>(); } }
// Activate parent if necessary void PersistentTransientWindow::activateParent() { // Only activate if this window is active already if (gobj()->is_active) { Gtk::Container* toplevel = get_toplevel(); if (toplevel != NULL && toplevel->is_toplevel() && toplevel->is_visible() && dynamic_cast<Gtk::Window*>(toplevel) != NULL) { static_cast<Gtk::Window*>(toplevel)->present(); } } }
/** Enable/disable recording. * @param recording true to enable recording, false otherwise * @return true if recording is enabled now, false if it is disabled. * Enabling the recording may fail for example if the user chose to abort * the directory creation process. */ bool SkillGuiGraphDrawingArea::set_recording(bool recording) { if (recording) { Gtk::Window *w = dynamic_cast<Gtk::Window *>(get_toplevel()); __fcd_recording->set_transient_for(*w); int result = __fcd_recording->run(); if (result == Gtk::RESPONSE_OK) { __record_directory = __fcd_recording->get_filename(); __recording = true; } __fcd_recording->hide(); } else { __recording = false; } return __recording; }
void ui_display_tape_control_status(int control) { GdkColor *color; int status = 0; #if !defined(HAVE_CAIRO) GdkGC *app_gc = get_toplevel(); #endif DBG(("ui_display_tape_control_status (%d) motor:%d image:%d\n", control, tape_motor_status, tape_image_status)); if (control < 0) { control = tape_control_status; } else { tape_control_status = control; } #if !defined(HAVE_CAIRO) if (app_gc == NULL) { DBG(("ui_display_tape_control_status skipped\n")); return; } #endif /* Set background color */ color = (tape_image_status == 1) ? &drive_led_on_green_pixel : &drive_led_on_red_pixel; set_background(color); /* set foreground color for tape-button */ color = (tape_motor_status == 1) ? &motor_running_pixel : &tape_control_pixel; switch (control) { case DATASETTE_CONTROL_START: status = 1; break; case DATASETTE_CONTROL_FORWARD: status = 2; break; case DATASETTE_CONTROL_REWIND: status = 3; break; case DATASETTE_CONTROL_RECORD: status = 4; break; } set_foreground(color, status); gdk_flush(); }
void Gobby::PreferencesDialog::Security::on_create_key_clicked() { m_file_dialog.reset(new FileChooser::Dialog( m_file_chooser, get_toplevel(*m_btn_key_file_create), _("Select a location for the generated key"), Gtk::FILE_CHOOSER_ACTION_SAVE)); const std::string& key_file = m_preferences.security.key_file; if(!key_file.empty()) m_file_dialog->set_filename(key_file); m_file_dialog->signal_response().connect( sigc::mem_fun( *this, &Security::on_file_dialog_response_key)); m_file_dialog->present(); }
static void set_joy(GdkColor *colors[5], int i, int joystick_number) { GdkGC *app_gc = get_toplevel(); joystick_status_widget *ds = &app_shells[i].joystick_status[joystick_number]; if ((ds) && (ds->led)) { GdkColor colbg; gdk_color_parse ("#c0c0c0", &colbg); gdk_gc_set_rgb_fg_color(app_gc, &colbg); gdk_draw_rectangle(ds->led_pixmap, app_gc, TRUE, 0, 0, JOY_AREA_WIDTH + 2, JOY_AREA_HEIGHT + 2); gtk_widget_queue_draw(ds->led); for (i = 0; i < 5; i++) { int tx = joyledx[i] + 1; int ty = joyledy[i] + 1; gdk_gc_set_rgb_fg_color(app_gc, colors[i]); gdk_draw_rectangle(ds->led_pixmap, app_gc, TRUE, tx, ty, JOY_LED_WIDTH, JOY_LED_HEIGHT); gtk_widget_queue_draw(ds->led); } } }
// called when OpenGL context is ready and GTK widget is ready bool Graph_disp::initiaize(const Cairo::RefPtr<Cairo::Context> & unused) { // clear the screen glClearColor(bkg_color.r, bkg_color.g, bkg_color.b, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); display(); // init glew if(glewInit() != GLEW_OK) { Gtk::MessageDialog error_dialog("Error loading Glew", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text("Aborting..."); error_dialog.run(); std::cerr<<"Error loading glew. Aborting"<<std::endl; dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } // check for required OpenGL version if(!GLEW_VERSION_3_3) { Gtk::MessageDialog error_dialog("OpenGL version too low", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text("Version 3.3 required\nInstalled version is: " + std::string((const char *)glGetString(GL_VERSION)) + "\nAborting..."); error_dialog.run(); std::cerr<<"OpenGL version too low. Version 3.3 required"<<std::endl; std::cerr<<"Installed version is: "<<glGetString(GL_VERSION)<<std::endl; dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } std::cerr<<"OpenGL version is: "<<glGetString(GL_VERSION)<<std::endl; // init GL state vars glEnable(GL_DEPTH_TEST); glDepthRangef(0.0f, 1.0f); glLineWidth(5.0f); glEnable(GL_POLYGON_SMOOTH); glHint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendColor(1.0f, 1.0f, 1.0f, 0.1f); glEnable(GL_BLEND); // build shader programs GLuint graph_vert = compile_shader(check_in_pwd("shaders/graph.vert"), GL_VERTEX_SHADER); GLuint line_vert = compile_shader(check_in_pwd("shaders/line.vert"), GL_VERTEX_SHADER); GLuint common_frag = compile_shader(check_in_pwd("shaders/common.frag"), GL_FRAGMENT_SHADER); GLuint tex_frag = compile_shader(check_in_pwd("shaders/tex.frag"), GL_FRAGMENT_SHADER); GLuint color_frag = compile_shader(check_in_pwd("shaders/color.frag"), GL_FRAGMENT_SHADER); GLuint flat_color_frag = compile_shader(check_in_pwd("shaders/flat_color.frag"), GL_FRAGMENT_SHADER); if(graph_vert == 0 || line_vert == 0 || tex_frag == 0 || color_frag == 0 || flat_color_frag == 0) { // error messages are displayed by the compile_shader function Gtk::MessageDialog error_dialog("Error compiling shaders", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text("See console output for details.\nAborting..."); error_dialog.run(); dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } // link shaders _prog_tex.prog = link_shader_prog(std::vector<GLuint> {graph_vert, tex_frag, common_frag}); _prog_color.prog = link_shader_prog(std::vector<GLuint> {graph_vert, color_frag, common_frag}); _prog_line.prog = link_shader_prog(std::vector<GLuint> {line_vert, flat_color_frag}); if(_prog_tex.prog == 0 || _prog_color.prog == 0 || _prog_line.prog == 0) { // error messages are displayed by the link_shader_prog function Gtk::MessageDialog error_dialog("Error linking shaders", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text("See console output for details.\nAborting..."); error_dialog.run(); dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } check_error("build shaders"); // free shader objects glDeleteShader(graph_vert); glDeleteShader(line_vert); glDeleteShader(common_frag); glDeleteShader(tex_frag); glDeleteShader(color_frag); glDeleteShader(flat_color_frag); // get uniform locations for each shader bool uniform_success = true; uniform_success &= _prog_tex.add_uniform("view_model_perspective"); uniform_success &= _prog_tex.add_uniform("view_model"); uniform_success &= _prog_tex.add_uniform("normal_transform"); uniform_success &= _prog_tex.add_uniform("material.shininess"); uniform_success &= _prog_tex.add_uniform("material.specular"); uniform_success &= _prog_tex.add_uniform("ambient_color"); uniform_success &= _prog_tex.add_uniform("cam_light.base.color"); uniform_success &= _prog_tex.add_uniform("cam_light.base.strength"); uniform_success &= _prog_tex.add_uniform("cam_light.pos_eye"); uniform_success &= _prog_tex.add_uniform("cam_light.const_atten"); uniform_success &= _prog_tex.add_uniform("cam_light.linear_atten"); uniform_success &= _prog_tex.add_uniform("cam_light.quad_atten"); uniform_success &= _prog_tex.add_uniform("dir_light.base.color"); uniform_success &= _prog_tex.add_uniform("dir_light.base.strength"); uniform_success &= _prog_tex.add_uniform("dir_light.dir"); uniform_success &= _prog_tex.add_uniform("dir_light.half_vec"); uniform_success &= _prog_tex.add_uniform("light_forward"); check_error("_prog_tex GetUniformLocation"); if(!uniform_success) { std::string missing_uniforms; for(auto const & uniform: _prog_tex.uniforms) { if(uniform.second == -1) { missing_uniforms += uniform.first + "\n"; } } std::cerr<<"Error finding texture shader uniforms:\n"<<missing_uniforms<<std::endl; Gtk::MessageDialog error_dialog("Error finding texture shader uniforms", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text(missing_uniforms + "Aborting..."); error_dialog.run(); dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } uniform_success = true; uniform_success &= _prog_color.add_uniform("view_model_perspective"); uniform_success &= _prog_color.add_uniform("view_model"); uniform_success &= _prog_color.add_uniform("normal_transform"); uniform_success &= _prog_color.add_uniform("material.shininess"); uniform_success &= _prog_color.add_uniform("material.specular"); uniform_success &= _prog_color.add_uniform("color"); uniform_success &= _prog_color.add_uniform("ambient_color"); uniform_success &= _prog_color.add_uniform("cam_light.base.color"); uniform_success &= _prog_color.add_uniform("cam_light.base.strength"); uniform_success &= _prog_color.add_uniform("cam_light.pos_eye"); uniform_success &= _prog_color.add_uniform("cam_light.const_atten"); uniform_success &= _prog_color.add_uniform("cam_light.linear_atten"); uniform_success &= _prog_color.add_uniform("cam_light.quad_atten"); uniform_success &= _prog_color.add_uniform("dir_light.base.color"); uniform_success &= _prog_color.add_uniform("dir_light.base.strength"); uniform_success &= _prog_color.add_uniform("dir_light.dir"); uniform_success &= _prog_color.add_uniform("dir_light.half_vec"); uniform_success &= _prog_color.add_uniform("light_forward"); check_error("_prog_color GetUniformLocation"); if(!uniform_success) { std::string missing_uniforms; for(auto const & uniform: _prog_color.uniforms) { if(uniform.second == -1) { missing_uniforms += uniform.first + "\n"; } } std::cerr<<"Error finding color shader uniforms:\n"<<missing_uniforms<<std::endl; Gtk::MessageDialog error_dialog("Error finding color shader uniforms", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text(missing_uniforms + "Aborting..."); error_dialog.run(); dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } uniform_success = true; uniform_success &= _prog_line.add_uniform("perspective"); uniform_success &= _prog_line.add_uniform("view_model"); uniform_success &= _prog_line.add_uniform("color"); check_error("_prog_line GetUniformLocation"); if(!uniform_success) { std::string missing_uniforms; for(auto const & uniform: _prog_line.uniforms) { if(uniform.second == -1) { missing_uniforms += uniform.first + "\n"; } } std::cerr<<"Error finding line shader uniforms:\n"<<missing_uniforms<<std::endl; Gtk::MessageDialog error_dialog("Error finding line shader uniforms", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text(missing_uniforms + "Aborting..."); error_dialog.run(); dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } // set up un-changing lighting values (in eye space) glm::vec3 cam_light_pos_eye(0.0f); glm::vec3 light_forward(0.0f, 0.0f, 1.0f); glUseProgram(_prog_tex.prog); glUniform3fv(_prog_tex.uniforms["cam_light.pos_eye"], 1, &cam_light_pos_eye[0]); glUniform3fv(_prog_tex.uniforms["light_forward"], 1, &light_forward[0]); check_error("_prog_tex uniforms static"); glUseProgram(_prog_color.prog); glUniform3fv(_prog_color.uniforms["cam_light.pos_eye"], 1, &cam_light_pos_eye[0]); glUniform3fv(_prog_color.uniforms["light_forward"], 1, &light_forward[0]); check_error("_prog_color uniforms static"); // create static geometry objects - cursor, axes try { _cursor.build(check_in_pwd("img/cursor.png")); } catch(Glib::Exception &e) { std::cerr<<"Error reading cursor image file:"<<std::endl<<e.what()<<std::endl; Gtk::MessageDialog error_dialog("Error reading cursor image_file", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); error_dialog.set_transient_for(*dynamic_cast<Gtk::Window *>(get_toplevel())); error_dialog.set_title("Fatal Error"); error_dialog.set_secondary_text(e.what() + std::string("\nAborting...")); error_dialog.run(); dynamic_cast<Gtk::Window *>(get_toplevel())->hide(); return_code = EXIT_FAILURE; return true; } _axes.build(); _draw_connection.disconnect(); _draw_connection = signal_draw().connect(sigc::mem_fun(*this, &Graph_disp::draw)); // explicitly setup the window size (since resize is automatically called before initialization Gtk::Allocation allocation(0, 0, get_allocated_width(), get_allocated_height()); resize(allocation); _signal_initialized.emit(); return draw(unused); }
void Terminal::focus_vte() { gtk_window_set_focus(GTK_WINDOW(get_toplevel()->gobj()), vte); }
// main input processing bool Graph_disp::input() { // state vars static std::unordered_map<sf::Keyboard::Key, bool, std::hash<int>> key_lock; static sf::Vector2i old_mouse_pos = sf::Mouse::getPosition(glWindow); static sf::Clock cursor_delay; static sf::Clock zoom_delay; // the neat thing about having this in a timeout func is that we // don't need to calculate dt for movement controls. // it is always (almost) exactly 10ms // only process when the window is active and display is focused if(dynamic_cast<Gtk::Window *>(get_toplevel())->is_active()) { sf::Vector2i new_mouse_pos = sf::Mouse::getPosition(glWindow); if(!has_focus() && new_mouse_pos.x >= 0 && new_mouse_pos.y >= 0 && new_mouse_pos.x < get_allocated_width() && new_mouse_pos.y < get_allocated_height()) { grab_focus(); } if(has_focus()) { // Camera controls float mov_scale = 0.1f; if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) { mov_scale *= 2.0f; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) { mov_scale *= 0.1f; } // orbiting rotational cam if(use_orbit_cam) { // reset if(sf::Keyboard::isKeyPressed(sf::Keyboard::R) && !key_lock[sf::Keyboard::R]) { key_lock[sf::Keyboard::R] = true; reset_cam(); } else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::R)) key_lock[sf::Keyboard::R] = false; // tilt up if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { _orbit_cam.phi += (float)M_PI / 90.0f * mov_scale; invalidate(); } // tilt down if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { _orbit_cam.phi -= (float)M_PI / 90.0f * mov_scale; invalidate(); } // rotate clockwise if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { _orbit_cam.theta += (float)M_PI / 90.0f * mov_scale; invalidate(); } // rotate counter-clockwise if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { _orbit_cam.theta -= (float)M_PI / 90.0f * mov_scale; invalidate(); } // move camera in if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) { _orbit_cam.r -= mov_scale; invalidate(); } // move camera out if(sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { _orbit_cam.r += mov_scale; invalidate(); } // rotate w/ mouse click & drag if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { int d_x = new_mouse_pos.x - old_mouse_pos.x; int d_y = new_mouse_pos.y - old_mouse_pos.y; _orbit_cam.theta -= 0.005f * d_x; _orbit_cam.phi -= 0.005f * d_y; invalidate(); } // wrap theta if(_orbit_cam.theta > (float)M_PI * 2.0f) _orbit_cam.theta -= (float)M_PI * 2.0f; if(_orbit_cam.theta < 0.0f) _orbit_cam.theta += (float)M_PI * 2.0f; // clamp phi if(_orbit_cam.phi > (float)M_PI) _orbit_cam.phi = (float)M_PI; if(_orbit_cam.phi < 0.0f) _orbit_cam.phi = 0.0f; } else // free camera { // reset if(sf::Keyboard::isKeyPressed(sf::Keyboard::R) && !key_lock[sf::Keyboard::R]) { key_lock[sf::Keyboard::R] = true; reset_cam(); } else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::R)) key_lock[sf::Keyboard::R] = false; // move forward if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { _cam.translate(mov_scale * _cam.forward()); invalidate(); } // move backwards if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { _cam.translate(-mov_scale * _cam.forward()); invalidate(); } // move left if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { _cam.translate(-mov_scale * _cam.right()); invalidate(); } // move right if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { _cam.translate(mov_scale * _cam.right()); invalidate(); } // move up if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) { _cam.translate(mov_scale * glm::vec3(0.0f, 0.0f, 1.0f)); invalidate(); } // move down if(sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { _cam.translate(-mov_scale * glm::vec3(0.0f, 0.0f, 1.0f)); invalidate(); } // rotate view with mouse click & drag if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { int d_x = new_mouse_pos.x - old_mouse_pos.x; int d_y = new_mouse_pos.y - old_mouse_pos.y; _cam.rotate(0.001f * d_y, _cam.right()); _cam.rotate(0.001f * d_x, glm::vec3(0.0f, 0.0f, 1.0f)); invalidate(); } } const int zoom_timeout = 200; // zoom in if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z) && zoom_delay.getElapsedTime().asMilliseconds() >= zoom_timeout) { _scale *= 2.0f; zoom_delay.restart(); invalidate(); } // zoom out if(sf::Keyboard::isKeyPressed(sf::Keyboard::X) && zoom_delay.getElapsedTime().asMilliseconds() >= zoom_timeout) { _scale *= 0.5f; zoom_delay.restart(); invalidate(); } // move cursor with arrow keys if(draw_cursor_flag && _active_graph) { const int cursor_timeout = 200; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && cursor_delay.getElapsedTime().asMilliseconds() >= cursor_timeout) { _active_graph->move_cursor(Graph::UP); cursor_delay.restart(); invalidate(); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && cursor_delay.getElapsedTime().asMilliseconds() >= cursor_timeout) { _active_graph->move_cursor(Graph::DOWN); cursor_delay.restart(); invalidate(); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && cursor_delay.getElapsedTime().asMilliseconds() >= cursor_timeout) { _active_graph->move_cursor(Graph::LEFT); cursor_delay.restart(); invalidate(); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && cursor_delay.getElapsedTime().asMilliseconds() >= cursor_timeout) { _active_graph->move_cursor(Graph::RIGHT); cursor_delay.restart(); invalidate(); } } } old_mouse_pos = new_mouse_pos; } return true; }
/** save current graph. */ void SkillGuiGraphDrawingArea::save() { Gtk::Window *w = dynamic_cast<Gtk::Window *>(get_toplevel()); __fcd_save->set_transient_for(*w); int result = __fcd_save->run(); if (result == Gtk::RESPONSE_OK) { Gtk::FileFilter *f = __fcd_save->get_filter(); std::string filename = __fcd_save->get_filename(); if (filename != "") { if (f == __filter_dot) { save_dotfile(filename.c_str()); } else { Cairo::RefPtr<Cairo::Surface> surface; bool write_to_png = false; if (f == __filter_pdf) { surface = Cairo::PdfSurface::create(filename, __bbw, __bbh); } else if (f == __filter_svg) { surface = Cairo::SvgSurface::create(filename, __bbw, __bbh); } else if (f == __filter_png) { surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, (int)ceilf(__bbw), (int)ceilf(__bbh)); write_to_png = true; } if (surface) { __cairo = Cairo::Context::create(surface); bool old_scale_override = __scale_override; double old_tx = __translation_x; double old_ty = __translation_y; double old_scale = __scale; __translation_x = __pad_x; __translation_y = __bbh - __pad_y; __scale = 1.0; __scale_override = true; if (__graph) { gvRender(__gvc, __graph, (char *)"skillguicairo", NULL); } if (write_to_png) { surface->write_to_png(filename); } __cairo.clear(); __translation_x = old_tx; __translation_y = old_ty; __scale = old_scale; __scale_override = old_scale_override; } } } else { Gtk::MessageDialog md(*w, "Invalid filename", /* markup */ false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, /* modal */ true); md.set_title("Invalid File Name"); md.run(); } } __fcd_save->hide(); }