// Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // // Copyright(C) 2006 Simon Howard // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. // #include #include #include #include "doomkeys.h" #include "txt_desktop.h" #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" #include "txt_separator.h" #include "txt_window.h" #define MAXWINDOWS 128 static char *desktop_title; static txt_window_t *all_windows[MAXWINDOWS]; static int num_windows = 0; static int main_loop_running = 0; void TXT_AddDesktopWindow(txt_window_t *win) { // Previously-top window loses focus: if (num_windows > 0) { TXT_SetWindowFocus(all_windows[num_windows - 1], 0); } all_windows[num_windows] = win; ++num_windows; // New window gains focus: TXT_SetWindowFocus(win, 1); } void TXT_RemoveDesktopWindow(txt_window_t *win) { int from, to; // Window must lose focus if it's being removed: TXT_SetWindowFocus(win, 0); for (from=0, to=0; from 0) { TXT_SetWindowFocus(all_windows[num_windows - 1], 1); } } txt_window_t *TXT_GetActiveWindow(void) { if (num_windows == 0) { return NULL; } return all_windows[num_windows - 1]; } static void DrawDesktopBackground(const char *title) { int i; unsigned char *screendata; unsigned char *p; screendata = TXT_GetScreenData(); // Fill the screen with gradient characters p = screendata; for (i=0; i 0) { if (num_windows > 0) { // Send the keypress to the top window TXT_WindowKeyPress(all_windows[num_windows - 1], c); } } } void TXT_ExitMainLoop(void) { main_loop_running = 0; } void TXT_DrawASCIITable(void) { unsigned char *screendata; char buf[10]; int x, y; int n; screendata = TXT_GetScreenData(); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); TXT_BGColor(TXT_COLOR_BLACK, 0); for (y=0; y<16; ++y) { for (x=0; x<16; ++x) { n = y * 16 + x; TXT_GotoXY(x * 5, y); sprintf(buf, "%02x ", n); TXT_Puts(buf); // Write the character directly to the screen memory buffer: screendata[(y * TXT_SCREEN_W + x * 5 + 3) * 2] = n; } } TXT_UpdateScreen(); } void TXT_GUIMainLoop(void) { main_loop_running = 1; while (main_loop_running) { TXT_DispatchEvents(); // After the last window is closed, exit the loop if (num_windows <= 0) { TXT_ExitMainLoop(); } TXT_DrawDesktop(); // TXT_DrawASCIITable(); TXT_Sleep(0); } }