void Console::ToggleVisible() { if (CON_isVisible(mSdlConsole)){ CON_Hide(mSdlConsole); } else { CON_Show(mSdlConsole); } }
/* Updates the console, draws the background and the history lines. Does not draw the Commandline */ void CON_UpdateConsole(ConsoleInformation *console) { int loop; int loop2; int Screenlines; SDL_Rect DestRect; BitFont *CurrentFont = DT_FontPointer(console->FontNumber); if(!console) return; /* Due to the Blits, the update is not very fast: So only update if it's worth it */ if(!CON_isVisible(console)) return; Screenlines = console->ConsoleSurface->h / console->FontHeight; SDL_FillRect(console->ConsoleSurface, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, console->ConsoleAlpha)); // TR2 // if(console->OutputScreen->flags & SDL_OPENGLBLIT) // SDL_SetSurfaceAlphaMod(console->ConsoleSurface, SDL_ALPHA_OPAQUE); /* draw the background image if there is one */ if(console->BackgroundImage) { DestRect.x = console->BackX; DestRect.y = console->BackY; DestRect.w = console->BackgroundImage->w; DestRect.h = console->BackgroundImage->h; SDL_BlitSurface(console->BackgroundImage, NULL, console->ConsoleSurface, &DestRect); } /* Draw the text from the back buffers, calculate in the scrollback from the user * this is a normal SDL software-mode blit, so we need to temporarily set the ColorKey * for the font, and then clear it when we're done. */ /*TR2 if((console->OutputScreen->flags & SDL_OPENGLBLIT) && (console->OutputScreen->format->BytesPerPixel > 2)) { Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels); SDL_SetColorKey(CurrentFont->FontSurface, SDL_TRUE, *pix); }*/ /* now draw text from last but second line to top loop: for every line in the history loop2: draws the scroll indicators to the line above the Commandline */ for(loop = 0; loop < Screenlines-1 && loop < console->LineBuffer - console->ConsoleScrollBack; loop++) { if(console->ConsoleScrollBack != 0 && loop == 0) for(loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++) DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER + (loop2*5*console->FontWidth), (Screenlines - loop - 2) * console->FontHeight); else DT_DrawText(console->ConsoleLines[console->ConsoleScrollBack + loop], console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER, (Screenlines - loop - 2) * console->FontHeight); } // TR2 //if(console->OutputScreen->flags & SDL_OPENGLBLIT) // SDL_SetColorKey(CurrentFont->FontSurface, 0, 0); }
/* Updates the console, draws the background and the history lines. Does not draw the Commandline */ void CON_UpdateConsole(ConsoleInformation * console) { int loop; int loop2; int Screenlines; SDL_Rect DestRect; /*BitFont *CurrentFont = DT_FontPointer(console->FontNumber);*/ if (!console) return; /* Due to the Blits, the update is not very fast: So only update if it's worth it */ if (!CON_isVisible(console)) return; Screenlines = console->ConsoleSurface->h / console->FontHeight; SDL_FillRect(console->ConsoleSurface, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 20, 0, SDL_ALPHA_OPAQUE)); /* draw the background image if there is one */ if (console->BackgroundImage) { DestRect.x = console->BackX; DestRect.y = console->BackY; DestRect.w = console->BackgroundImage->w; DestRect.h = console->BackgroundImage->h; SDL_BlitSurface(console->BackgroundImage, NULL, console->ConsoleSurface, &DestRect); } /* now draw text from last but second line to top loop: for every line in the history loop2: draws the scroll indicators to the line above the Commandline */ for (loop = 0; loop < Screenlines - 1 && loop < console->LineBuffer - console->ConsoleScrollBack; loop++) { if (console->ConsoleScrollBack != 0 && loop == 0) for (loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++) DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER + (loop2 * 5 * console->FontWidth), (Screenlines - loop - 2) * console->FontHeight); else DT_DrawText(console-> ConsoleLines[console->ConsoleScrollBack + loop], console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER, (Screenlines - loop - 2) * console->FontHeight); } }
/* Takes keys from the keyboard and inputs them to the console If the event was not handled (i.e. WM events or unknown ctrl-shift sequences) the function returns the event for further processing. */ SDL_Event* CON_Events(SDL_Event *event) { if(Topmost == NULL) return event; if(!CON_isVisible(Topmost)) return event; if(event->type == SDL_KEYDOWN) { if(event->key.keysym.mod & KMOD_CTRL) { /* CTRL pressed */ switch(event->key.keysym.sym) { case SDLK_a: Cursor_Home(Topmost); break; case SDLK_e: Cursor_End(Topmost); break; case SDLK_c: Clear_Command(Topmost); break; case SDLK_l: Clear_History(Topmost); CON_UpdateConsole(Topmost); break; default: return event; } } else if(event->key.keysym.mod & KMOD_ALT) { /* the console does not handle ALT combinations! */ return event; } else { /* first of all, check if the console hide key was pressed */ if(event->key.keysym.sym == Topmost->HideKey) { CON_Hide(Topmost); return NULL; } switch (event->key.keysym.sym) { case SDLK_HOME: if(event->key.keysym.mod & KMOD_SHIFT) { Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; CON_UpdateConsole(Topmost); } else { Cursor_Home(Topmost); } break; case SDLK_END: if(event->key.keysym.mod & KMOD_SHIFT) { Topmost->ConsoleScrollBack = 0; CON_UpdateConsole(Topmost); } else { Cursor_End(Topmost); } break; case SDLK_PAGEUP: Topmost->ConsoleScrollBack += CON_LINE_SCROLL; if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1) Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; CON_UpdateConsole(Topmost); break; case SDLK_PAGEDOWN: Topmost->ConsoleScrollBack -= CON_LINE_SCROLL; if(Topmost->ConsoleScrollBack < 0) Topmost->ConsoleScrollBack = 0; CON_UpdateConsole(Topmost); break; case SDLK_UP: Command_Up(Topmost); break; case SDLK_DOWN: Command_Down(Topmost); break; case SDLK_LEFT: Cursor_Left(Topmost); break; case SDLK_RIGHT: Cursor_Right(Topmost); break; case SDLK_BACKSPACE: Cursor_BSpace(Topmost); break; case SDLK_DELETE: Cursor_Del(Topmost); break; case SDLK_INSERT: Topmost->InsMode = 1-Topmost->InsMode; break; case SDLK_TAB: CON_TabCompletion(Topmost); break; case SDLK_RETURN: if(strlen(Topmost->Command) > 0) { CON_NewLineCommand(Topmost); /* copy the input into the past commands strings */ strcpy(Topmost->CommandLines[0], Topmost->Command); /* display the command including the prompt */ CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command); CON_Execute(Topmost, Topmost->Command); /* printf("Command: %s\n", Topmost->Command); */ Clear_Command(Topmost); Topmost->CommandScrollBack = -1; } break; case SDLK_ESCAPE: /* deactivate Console */ CON_Hide(Topmost); return NULL; default: if(Topmost->InsMode) Cursor_Add(Topmost, event); else { Cursor_Add(Topmost, event); Cursor_Del(Topmost); } } } return NULL; } return event; }
/* Takes keys from the keyboard and inputs them to the console If the event was not handled (i.e. WM events or unknown ctrl-shift sequences) the function returns the event for further processing. */ SDL_Event *CON_Events(SDL_Event * event) { if (Topmost == NULL) return event; if (!CON_isVisible(Topmost)) return event; if (event->type == SDL_KEYDOWN) { if (event->key.keysym.mod & KMOD_CTRL) { /* CTRL pressed */ /* kps - please modify this to work like in talk.c */ switch (event->key.keysym.sym) { case SDLK_a: Cursor_Home(Topmost); break; case SDLK_b: Cursor_Left(Topmost); break; case SDLK_f: Cursor_Right(Topmost); break; case SDLK_e: Cursor_End(Topmost); break; /* * kps - Ctrl-k should really just clear from current * cursor position to end of line. */ case SDLK_k: case SDLK_u: Clear_Command(Topmost); break; case SDLK_l: Clear_History(Topmost); CON_UpdateConsole(Topmost); break; default: return event; } #if 0 } else if (event->key.keysym.mod & KMOD_ALT) { /* the console does not handle ALT combinations! */ return event; #endif } else { switch (event->key.keysym.sym) { case SDLK_HOME: if (event->key.keysym.mod & KMOD_SHIFT) { Topmost->ConsoleScrollBack = Topmost->LineBuffer - 1; CON_UpdateConsole(Topmost); } else { Cursor_Home(Topmost); } break; case SDLK_END: if (event->key.keysym.mod & KMOD_SHIFT) { Topmost->ConsoleScrollBack = 0; CON_UpdateConsole(Topmost); } else { Cursor_End(Topmost); } break; case SDLK_PAGEUP: Topmost->ConsoleScrollBack += CON_LINE_SCROLL; if (Topmost->ConsoleScrollBack > Topmost->LineBuffer - 1) Topmost->ConsoleScrollBack = Topmost->LineBuffer - 1; CON_UpdateConsole(Topmost); break; case SDLK_PAGEDOWN: Topmost->ConsoleScrollBack -= CON_LINE_SCROLL; if (Topmost->ConsoleScrollBack < 0) Topmost->ConsoleScrollBack = 0; CON_UpdateConsole(Topmost); break; case SDLK_UP: Command_Up(Topmost); break; case SDLK_DOWN: Command_Down(Topmost); break; case SDLK_LEFT: Cursor_Left(Topmost); break; case SDLK_RIGHT: Cursor_Right(Topmost); break; case SDLK_BACKSPACE: Cursor_BSpace(Topmost); break; case SDLK_DELETE: Cursor_Del(Topmost); break; case SDLK_INSERT: Topmost->InsMode = 1 - Topmost->InsMode; break; case SDLK_TAB: CON_TabCompletion(Topmost); break; case SDLK_RETURN: if (strlen(Topmost->Command) > 0) { CON_NewLineCommand(Topmost); /* copy the input into the past commands strings */ strcpy(Topmost->CommandLines[0], Topmost->Command); /* display the command including the prompt */ CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command); CON_Execute(Topmost, Topmost->Command); /* printf("Command: %s\n", Topmost->Command); */ Clear_Command(Topmost); Topmost->CommandScrollBack = -1; } else /* deactivate Console if return is pressed on empty line */ /* was: CON_Hide(Topmost); */ Talk_set_state(false); break; case SDLK_ESCAPE: if (strlen(Topmost->Command) > 0) { CON_NewLineCommand(Topmost); /* copy the input into the past commands strings */ strcpy(Topmost->CommandLines[0], Topmost->Command); Clear_Command(Topmost); Topmost->CommandScrollBack = -1; } /* deactivate Console */ /*was: CON_Hide(Topmost);*/ Talk_set_state(false); return NULL; default: if (Topmost->InsMode) Cursor_Add(Topmost, event); else { Cursor_Add(Topmost, event); Cursor_Del(Topmost); } } } return NULL; } return event; }
/* Takes keys from the keyboard and inputs them to the console If the event was not handled (i.e. WM events or unknown ctrl-shift sequences) the function returns the event for further processing. */ int CON_Events(int event) { if(Topmost == NULL) return event; if(!CON_isVisible(Topmost)) return event; if(event & KEY_CTRLED) { //CTRL pressed switch(event & ~KEY_CTRLED) { case KEY_A: Cursor_Home(Topmost); break; case KEY_E: Cursor_End(Topmost); break; case KEY_C: Clear_Command(Topmost); break; case KEY_L: Clear_History(Topmost); CON_UpdateConsole(Topmost); break; default: return event; } } else if(event & KEY_ALTED) { //the console does not handle ALT combinations! return event; } else { //first of all, check if the console hide key was pressed if(event == Topmost->HideKey) { CON_Hide(Topmost); return 0; } switch (event & 0xff) { case KEY_LSHIFT: case KEY_RSHIFT: return event; case KEY_HOME: if(event & KEY_SHIFTED) { Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; CON_UpdateConsole(Topmost); } else { Cursor_Home(Topmost); } break; case KEY_END: if(event & KEY_SHIFTED) { Topmost->ConsoleScrollBack = 0; CON_UpdateConsole(Topmost); } else { Cursor_End(Topmost); } break; case KEY_PAGEUP: Topmost->ConsoleScrollBack += CON_LINE_SCROLL; if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1) Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; CON_UpdateConsole(Topmost); break; case KEY_PAGEDOWN: Topmost->ConsoleScrollBack -= CON_LINE_SCROLL; if(Topmost->ConsoleScrollBack < 0) Topmost->ConsoleScrollBack = 0; CON_UpdateConsole(Topmost); break; case KEY_UP: Command_Up(Topmost); break; case KEY_DOWN: Command_Down(Topmost); break; case KEY_LEFT: Cursor_Left(Topmost); break; case KEY_RIGHT: Cursor_Right(Topmost); break; case KEY_BACKSP: Cursor_BSpace(Topmost); break; case KEY_DELETE: Cursor_Del(Topmost); break; case KEY_INSERT: Topmost->InsMode = 1-Topmost->InsMode; break; case KEY_TAB: CON_TabCompletion(Topmost); break; case KEY_ENTER: if(strlen(Topmost->Command) > 0) { CON_NewLineCommand(Topmost); // copy the input into the past commands strings strcpy(Topmost->CommandLines[0], Topmost->Command); // display the command including the prompt CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command); CON_UpdateConsole(Topmost); CON_Execute(Topmost, Topmost->Command); //printf("Command: %s\n", Topmost->Command); Clear_Command(Topmost); Topmost->CommandScrollBack = -1; } break; case KEY_ESC: //deactivate Console if (event & KEY_SHIFTED) { CON_Hide(Topmost); return 0; } break; default: if(Topmost->InsMode) Cursor_Add(Topmost, event); else { Cursor_Add(Topmost, event); Cursor_Del(Topmost); } } } return 0; }