int sdl_poll_event(SDL_Event* event) { const int result = SDL_PollEvent(event); if(result) { switch(event->type) { case SDL_MOUSEMOTION: { int x = event->motion.x; int y = event->motion.y; get_main_window()->map_mouse_position(&x, &y); event->motion.x = x; event->motion.y = y; break; } case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: { int x = event->button.x; int y = event->button.y; get_main_window()->map_mouse_position(&x, &y); event->button.x = x; event->button.y = y; break; } } } return result; }
void WindowManager::createWindow(WindowPtr wnd) { wnd->createWindow(); // Add a weak_ptr to our window to the list of id versus windows. get_window_list()[wnd->getWindowID()] = wnd; // We consider the first window created the main one. if(get_main_window().lock() == nullptr) { get_main_window() = wnd; } }
void toggle_fullscreen() { preferences::set_fullscreen(preferences::fullscreen() == preferences::FULLSCREEN_NONE ? preferences::FULLSCREEN_WINDOWED : preferences::FULLSCREEN_NONE); get_main_window()->set_window_size(graphics::screen_width(), graphics::screen_height()); }
// ------------------------------------------------------- // text box with automatic, opaque background // ------------------------------------------------------- t_help_balloon::t_help_balloon( t_screen_point point, char const* text ) : t_text_window( ::get_font( 17 ), 0, text, t_pixel_24(0,0,0) ) { m_has_transparency = k_no_transparency; m_drop_shadow = false; m_justification = k_justify_center; m_center_vertical = true; t_screen_rect rect; t_screen_rect frame_rect = get_main_window()->get_client_rect(); m_text_width = get_parent()->get_width() - 8; m_text_width = m_font->wrap_text( m_text_block, text, m_text_width ); rect.top = 0; rect.left = 0; rect.right = m_text_width + 8; rect.bottom = m_text_block.size() * m_font->get_height() + 8; if ( rect.height() > point.y ) rect = rect + point + t_screen_point( 0, 20 ); else rect = rect + point - t_screen_point( 0, rect.bottom ); if (rect.right > frame_rect.right) rect = rect + t_screen_point( frame_rect.right - rect.right, 0 ); init( rect ); }
void choose_address_and_close(GtkWidget *ab){ GtkTreeSelection *select; GtkWidget *addressentry=get_main_window()->addressentry; GtkTreeIter iter; GtkTreeModel *model; gchar *address=NULL; GtkWidget *address_list=lookup_widget(ab,"address_list"); select = gtk_tree_view_get_selection (GTK_TREE_VIEW (address_list)); if (select==NULL) return; if (gtk_tree_selection_get_selected (select, &model, &iter)) { gtk_tree_model_get (model, &iter,SIP_ADDRESS_COLUMN , &address, -1); } if (address!=NULL){ gtk_entry_set_text (GTK_ENTRY(addressentry),address); g_free(address); } gtk_widget_destroy(ab); }
WindowPtr WindowManager::getMainWindow() { return get_main_window().lock(); }
// ------------------------------------------------------------------ // window for a bitmap-based mouse // open for display // ------------------------------------------------------------------ void t_mouse_window::open() { t_window::open( get_screen_rect(), get_main_window() ); }
Uint32 sdl_get_mouse_state(int* x, int* y) { const Uint32 result = SDL_GetMouseState(x, y); get_main_window()->map_mouse_position(x, y); return result; }
void rookie_misc_add_download (const gchar * url) { GtkWidget * dialog = download_dialog_new (url); if (url) download_dialog_set_url (DOWNLOAD_DIALOG(dialog), url); GtkWidget *window = get_main_window (); if (gtk_window_is_active (GTK_WINDOW(window))) gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window)); gchar *turl, *basename; gchar *save_path = NULL; int response; while (GTK_RESPONSE_OK == (response = gtk_dialog_run (GTK_DIALOG(dialog)))){ turl = download_dialog_get_url (DOWNLOAD_DIALOG(dialog)); basename = download_dialog_get_basename (DOWNLOAD_DIALOG(dialog)); save_path = download_dialog_get_save_path (DOWNLOAD_DIALOG(dialog)); if (g_strcmp0 (turl, "") == 0) { rookie_misc_show_error_dialog (_("Empty URL"), _("The URL must not be empty"), GTK_WINDOW(dialog)); continue; } if (!rookie_misc_is_valid_url (turl)) { rookie_misc_show_error_dialog (_("Invalid URL"), _("The URL you have entered is not valid. Please correct it."), GTK_WINDOW(dialog)); continue; } if (g_strcmp0 (basename, "") == 0) { rookie_misc_show_error_dialog (_("Empty Filename"), _("The filename must not be empty"), GTK_WINDOW(dialog)); continue; } /*Check if there is any existing file */ GFile * save_folder = g_file_new_for_path (save_path); GFile * save_file = g_file_get_child (save_folder, basename); if (g_file_query_exists (save_file, NULL)) { gchar * message = g_strdup_printf(_("There is already a file \"%s\". Are you sure you want to overwrite it?"), basename); if (!rookie_misc_run_confirm_dialog (_("File exists"), message, "_Overwrite", GTK_WINDOW(dialog))) { g_object_unref (save_file); g_object_unref (save_folder); continue; } g_file_delete (save_file, NULL, NULL); } g_object_unref (save_file); /* Check Write Permission */ GError * error = NULL; GFileInfo * info = g_file_query_info (save_folder, "access::can-write", G_FILE_QUERY_INFO_NONE, NULL, &error); handle_error (error); if (g_file_info_get_attribute_boolean (info, "access::can-write") == FALSE) { rookie_misc_show_error_dialog (_("Permission Denied"), _("You don't have permission to save file in that folder."), GTK_WINDOW(dialog)); g_object_unref (info); g_object_unref (save_folder); continue; } g_free (save_path); g_free (basename); g_free (turl); break; } if (response == GTK_RESPONSE_OK) { save_path = download_dialog_get_save_path (DOWNLOAD_DIALOG(dialog)); gchar *purl = g_strdup (download_dialog_get_url (DOWNLOAD_DIALOG(dialog))); gchar *path = g_build_filename (save_path, download_dialog_get_basename (DOWNLOAD_DIALOG(dialog)), NULL); GDownloadableBackend *backend = download_dialog_get_backend (DOWNLOAD_DIALOG(dialog)); GDownloadable *download = g_downloadable_create_download (purl, path, backend); Category *category = download_dialog_get_category (DOWNLOAD_DIALOG(dialog)); g_downloadable_set_category (download, category); g_download_list_add (download); if (download_dialog_get_start_downloading (DOWNLOAD_DIALOG (dialog))) { g_downloadable_start (download, FALSE); } } g_free (save_path); gtk_widget_destroy (dialog); }