-void WINAPI Sys_BeginWait (void)
-{
- GdkCursor *cursor = gdk_cursor_new (GDK_WATCH);
- gdk_window_set_cursor (g_pParentWnd->m_pWidget->window, cursor);
- gdk_cursor_unref (cursor);
- g_bWaitCursor = true;
-}
-
-void WINAPI Sys_EndWait (void)
-{
- GdkCursor *cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (g_pParentWnd->m_pWidget->window, cursor);
- gdk_cursor_unref (cursor);
- g_bWaitCursor = false;
-}
-
-void Sys_GetCursorPos (int *x, int *y)
-{
- // FIXME: not multihead safe
- gdk_window_get_pointer (NULL, x, y, NULL);
-}
-
-void Sys_SetCursorPos (int x, int y)
-{
- // NOTE: coordinates are in GDK space, not OS space
-#ifdef _WIN32
- int sys_x = x - g_pParentWnd->GetGDKOffsetX();
- int sys_y = y - g_pParentWnd->GetGDKOffsetY();
-
- SetCursorPos (sys_x, sys_y);
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
- XWarpPointer (GDK_DISPLAY(), None, GDK_ROOT_WINDOW(), 0, 0, 0, 0, x, y);
-#endif
-}
-
-void Sys_Beep (void)
-{
-#if defined (__linux__) || defined (__APPLE__)
- gdk_beep ();
-#else
- MessageBeep (MB_ICONASTERISK);
-#endif
-}
-
-double Sys_DoubleTime (void)
-{
- return clock()/ 1000.0;
-}
-
-/*
-===============================================================
-
- STATUS WINDOW
-
-===============================================================
-*/
-
-void Sys_UpdateStatusBar( void )
-{
- extern int g_numbrushes, g_numentities;
-
- char numbrushbuffer[100]="";
-
- sprintf( numbrushbuffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities );
- g_pParentWnd->SetStatusText(2, numbrushbuffer);
- //Sys_Status( numbrushbuffer, 2 );
-}
-
-void Sys_Status(const char *psz, int part )
-{
- g_pParentWnd->SetStatusText (part, psz);
-}
-
-// =============================================================================
-// MRU
-
-#define MRU_MAX 4
-static GtkWidget *MRU_items[MRU_MAX];
-static int MRU_used;
-typedef char MRU_filename_t[PATH_MAX];
-MRU_filename_t MRU_filenames[MRU_MAX];
-
-static char* MRU_GetText (int index)
-{
- return MRU_filenames[index];
-}
-
-void buffer_write_escaped_mnemonic(char* buffer, const char* string)
-{
- while(*string != '\0')
- {
- if(*string == '_')
- {
- *buffer++ = '_';
- }
-
- *buffer++ = *string++;
- }
- *buffer = '\0';
-}
-
-static void MRU_SetText (int index, const char *filename)
-{
- strcpy(MRU_filenames[index], filename);
-
- char mnemonic[PATH_MAX * 2 + 4];
- mnemonic[0] = '_';
- sprintf(mnemonic+1, "%d", index+1);
- mnemonic[2] = '-';
- mnemonic[3] = ' ';
- buffer_write_escaped_mnemonic(mnemonic+4, filename);
- gtk_label_set_text_with_mnemonic(GTK_LABEL (GTK_BIN (MRU_items[index])->child), mnemonic);
-}
-
-void MRU_Load ()
-{
- int i = g_PrefsDlg.m_nMRUCount;
-
- if(i > 4)
- i = 4; //FIXME: make this a define
-
- for (; i > 0; i--)
- MRU_AddFile (g_PrefsDlg.m_strMRUFiles[i-1].GetBuffer());
-}
-
-void MRU_Save ()
-{
- g_PrefsDlg.m_nMRUCount = MRU_used;
-
- for (int i = 0; i < MRU_used; i++)
- g_PrefsDlg.m_strMRUFiles[i] = MRU_GetText (i);
-}
-
-void MRU_AddWidget (GtkWidget *widget, int pos)
-{
- if (pos < MRU_MAX)
- MRU_items[pos] = widget;
-}
-
-void MRU_AddFile (const char *str)
-{
- int i;
- char* text;
-
- // check if file is already in our list
- for (i = 0; i < MRU_used; i++)
- {
- text = MRU_GetText (i);
-
- if (strcmp (text, str) == 0)
- {
- // reorder menu
- for (; i > 0; i--)
- MRU_SetText (i, MRU_GetText (i-1));
-
- MRU_SetText (0, str);
-
- return;
- }
- }
-
- if (MRU_used < MRU_MAX)
- MRU_used++;
-
- // move items down
- for (i = MRU_used-1; i > 0; i--)
- MRU_SetText (i, MRU_GetText (i-1));
-
- MRU_SetText (0, str);
- gtk_widget_set_sensitive (MRU_items[0], TRUE);
- gtk_widget_show (MRU_items[MRU_used-1]);
-}
-
-void MRU_Activate (int index)
-{
- char *text = MRU_GetText (index);
-
- if (access (text, R_OK) == 0)
- {
- text = strdup (text);
- MRU_AddFile (text);
- Map_LoadFile (text);
- free (text);
- }
- else
- {
- MRU_used--;
-
- for (int i = index; i < MRU_used; i++)
- MRU_SetText (i, MRU_GetText (i+1));
-
- if (MRU_used == 0)
- {
- gtk_label_set_text (GTK_LABEL (GTK_BIN (MRU_items[0])->child), "Recent Files");
- gtk_widget_set_sensitive (MRU_items[0], FALSE);
- }
- else
- {
- gtk_widget_hide (MRU_items[MRU_used]);
- }
- }
-}
-
-/*
-======================================================================
-
-FILE DIALOGS
-
-======================================================================
-*/
-
-qboolean ConfirmModified ()
-{
- if (!modified)
- return true;
-
- if (gtk_MessageBox (g_pParentWnd->m_pWidget, "This will lose changes to the map", "warning", MB_OKCANCEL) == IDCANCEL)
- return false;
- return true;
-}
-
-void ProjectDialog ()
-{
- const char *filename;
- char buffer[NAME_MAX];
-
- /*
- * Obtain the system directory name and
- * store it in buffer.
- */
-
- strcpy(buffer, g_qeglobals.m_strHomeGame.GetBuffer());
- strcat(buffer, g_pGameDescription->mBaseGame.GetBuffer());
- strcat (buffer, "/scripts/");
-
- // Display the Open dialog box
- filename = file_dialog (NULL, TRUE, "Open File", buffer, "project");
-
- if (filename == NULL)
- return; // canceled
-
- // Open the file.
- // NOTE: QE_LoadProject takes care of saving prefs with new path to the project file
- if (!QE_LoadProject(filename))
- Sys_Printf ("Failed to load project from file: %s\n", filename);
- else
- // FIXME TTimo QE_Init is probably broken if you don't call it during startup right now ..
- QE_Init();
-}
-
-/*
-=======================================================
-
-Menu modifications
-
-=======================================================
-*/
-
-/*
-==================
-FillBSPMenu
-
-==================
-*/
-char *bsp_commands[256];
-
-void FillBSPMenu ()
-{
- GtkWidget *item, *menu; // menu points to a GtkMenu (not an item)
- epair_t *ep;
- GList *lst;
- int i;
-
- menu = GTK_WIDGET (g_object_get_data (G_OBJECT (g_qeglobals_gui.d_main_window), "menu_bsp"));
-
- while ((lst = gtk_container_children (GTK_CONTAINER (menu))) != NULL)
- gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (lst->data));
-
- if (g_PrefsDlg.m_bDetachableMenus) {
- item = gtk_tearoff_menu_item_new ();
- gtk_menu_append (GTK_MENU (menu), item);
- gtk_widget_set_sensitive (item, TRUE);
- gtk_widget_show (item);
- }
-
- if (g_qeglobals.bBSPFrontendPlugin)
- {
- CString str = g_BSPFrontendTable.m_pfnGetBSPMenu();
- char cTemp[1024];
- strcpy(cTemp, str);
- char* token = strtok(cTemp, ",;");
- if (token && *token == ' ')
- {
- while (*token == ' ')
- token++;
- }
- i = 0;
-
- // first token is menu name
- item = gtk_menu_get_attach_widget (GTK_MENU (menu));
- gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), token);
-
- token = strtok(NULL, ",;");
- while (token != NULL)
- {
- g_BSPFrontendCommands = g_slist_append (g_BSPFrontendCommands, g_strdup (token));
- item = gtk_menu_item_new_with_label (token);
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (menu), item);
- gtk_signal_connect (GTK_OBJECT (item), "activate",
- GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (CMD_BSPCOMMAND+i));
- token = strtok(NULL, ",;");
- i++;
- }
- }
- else
- {
- i = 0;
- for (ep = g_qeglobals.d_project_entity->epairs; ep; ep = ep->next)
- {
- if (strncmp(ep->key, "bsp_", 4)==0)
- {
- bsp_commands[i] = ep->key;
- item = gtk_menu_item_new_with_label (ep->key+4);
- gtk_widget_show (item);
- gtk_container_add (GTK_CONTAINER (menu), item);
- gtk_signal_connect (GTK_OBJECT (item), "activate",
- GTK_SIGNAL_FUNC (HandleCommand), GINT_TO_POINTER (CMD_BSPCOMMAND+i));
- i++;
- }
- }
- }
-}
-
-//==============================================
-
-void AddSlash(CString& strPath)
-{
- if (strPath.GetLength() > 0)
- {
- if ((strPath.GetAt(strPath.GetLength()-1) != '/') &&
- (strPath.GetAt(strPath.GetLength()-1) != '\\'))
- strPath += '/';
- }
-}
-
-bool ExtractPath_and_Filename(const char* pPath, CString& strPath, CString& strFilename)
-{
- CString strPathName;
- strPathName = pPath;
- int nSlash = strPathName.ReverseFind('\\');
- if (nSlash == -1)
- // TTimo: try forward slash, some are using forward
- nSlash = strPathName.ReverseFind('/');
- if (nSlash >= 0)
- {
- strPath = strPathName.Left(nSlash+1);
- strFilename = strPathName.Right(strPathName.GetLength() - nSlash - 1);
- }
- // TTimo: try forward slash, some are using forward
- else
- strFilename = pPath;
- return true;
-}
-
-//===========================================
-
-//++timo FIXME: no longer used .. remove!
-char *TranslateString (char *buf)
-{
- static char buf2[32768];
- int i, l;
- char *out;
-
- l = strlen(buf);
- out = buf2;
- for (i=0 ; i<l ; i++)
- {
- if (buf[i] == '\n')
- {
- *out++ = '\r';
- *out++ = '\n';
- }
- else
- *out++ = buf[i];
- }
- *out++ = 0;
-
- return buf2;
-}
-
-// called whenever we need to open/close/check the console log file
-void Sys_LogFile (void)
-{
- if (g_PrefsDlg.mGamesDialog.m_bLogConsole && !g_qeglobals.hLogFile)
- {
- // settings say we should be logging and we don't have a log file .. so create it
- // open a file to log the console (if user prefs say so)
- // the file handle is g_qeglobals.hLogFile
- // the log file is erased
- Str name;
- name = g_strTempPath;
- name += "radiant.log";
-#if defined (__linux__) || defined (__APPLE__)
- g_qeglobals.hLogFile = open( name.GetBuffer(), O_TRUNC | O_CREAT | O_WRONLY, S_IREAD | S_IWRITE );
-#endif
-#ifdef _WIN32
- g_qeglobals.hLogFile = _open( name.GetBuffer(), _O_TRUNC | _O_CREAT | _O_WRONLY, _S_IREAD | _S_IWRITE );
-#endif
- if (g_qeglobals.hLogFile)
- {
- Sys_Printf("Started logging to %s\n", name.GetBuffer());
- time_t localtime;
- time(&localtime);
- Sys_Printf( "Today is: %s", ctime(&localtime));
- Sys_Printf( "This is radiant '" RADIANT_VERSION "' compiled " __DATE__ "\n");
- Sys_Printf( RADIANT_ABOUTMSG "\n");
- }
- else
- gtk_MessageBox (NULL, "Failed to create log file, check write permissions in Radiant directory.\n",
- "Console logging", MB_OK );
- }
- else if (!g_PrefsDlg.mGamesDialog.m_bLogConsole && g_qeglobals.hLogFile)
- {
- // settings say we should not be logging but still we have an active logfile .. close it
- time_t localtime;
- time(&localtime);
- Sys_Printf("Closing log file at %s\n", ctime(&localtime));
- #ifdef _WIN32
- _close( g_qeglobals.hLogFile );
- #endif
- #if defined (__linux__) || defined (__APPLE__)
- close( g_qeglobals.hLogFile );
- #endif
- g_qeglobals.hLogFile = 0;
- }
-}
-
-void Sys_ClearPrintf (void)
-{
- GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_qeglobals_gui.d_edit));
- gtk_text_buffer_set_text(buffer, "", -1);
-}
-
-// used to be around 32000, that should be way enough already
-#define BUFFER_SIZE 4096
-
-extern "C" void Sys_FPrintf_VA( int level, const char *text, va_list args ) {
- char buf[BUFFER_SIZE];
-
- buf[0] = 0;
- vsnprintf( buf, BUFFER_SIZE, text, args );
- buf[BUFFER_SIZE-1] = 0;
- const unsigned int length = strlen(buf);
-
- if ( g_qeglobals.hLogFile ) {
-#ifdef _WIN32
- _write( g_qeglobals.hLogFile, buf, length );
- _commit( g_qeglobals.hLogFile );
-#endif
-#if defined (__linux__) || defined (__APPLE__)
- write( g_qeglobals.hLogFile, buf, length );
-#endif
- }
-
- if ( level != SYS_NOCON ) {
- // TTimo: FIXME: killed the console to avoid GDI leak fuckup
- if ( g_qeglobals_gui.d_edit != NULL ) {
- GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_qeglobals_gui.d_edit));
-
- GtkTextIter iter;
- gtk_text_buffer_get_end_iter(buffer, &iter);
-
- static GtkTextMark* end = gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE);
-
- const GdkColor yellow = { 0, 0xb0ff, 0xb0ff, 0x0000 };
- const GdkColor red = { 0, 0xffff, 0x0000, 0x0000 };
- const GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
-
- static GtkTextTag* error_tag = gtk_text_buffer_create_tag (buffer, "red_foreground", "foreground-gdk", &red, NULL);
- static GtkTextTag* warning_tag = gtk_text_buffer_create_tag (buffer, "yellow_foreground", "foreground-gdk", &yellow, NULL);
- static GtkTextTag* standard_tag = gtk_text_buffer_create_tag (buffer, "black_foreground", "foreground-gdk", &black, NULL);
- GtkTextTag* tag;
- switch (level)
- {
- case SYS_WRN:
- tag = warning_tag;
- break;
- case SYS_ERR:
- tag = error_tag;
- break;
- case SYS_STD:
- case SYS_VRB:
- default:
- tag = standard_tag;
- break;
- }
- gtk_text_buffer_insert_with_tags(buffer, &iter, buf, length, tag, NULL);
-
- gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(g_qeglobals_gui.d_edit), end);
-
- // update console widget immediatly if we're doing something time-consuming
- if( !g_bScreenUpdates && GTK_WIDGET_REALIZED( g_qeglobals_gui.d_edit ) )
- {
- gtk_grab_add(g_qeglobals_gui.d_edit);
-
- while(gtk_events_pending())
- gtk_main_iteration();
-
- gtk_grab_remove(g_qeglobals_gui.d_edit);
- }
- }
- }