Thursday, 15 July 2010

c++ - SDL - Printing text like a console? -


I have some code (below) which uses SDL_TTF and would like to:

  1. Be able to render the text in alignment (with TTF) (with a buffer or array) such as a console (each character will be printed in separate cells).
  2. A blinking cursor (possibly render and render underscores, may be?)
  3. Go to the user input text from the keyboard and whenever every character is typed on the screen , Then be able to fix it (returning to SDLK_charhere # 1: I'm thinking of using the width of the last character printed on the screen (by TTF) and its width is pixel) the next character is the last Character To print just after, plus 2 pixels. & lt; - The difference between the charkha in the regular Vern 32 console is a different size, so let me know. Here is the code that needs to be modified: #include "included / sdl / sdl h" # "included / sdl / sdl_tate h" Int currentx = 0; Int currentY = 0; Int NW; Int newH; SDL_Surface * screen; SDL_Surface * fontSurface; SDL_Color fColor; SDL_Fixed Reset Font; SDL_Event Event; TTF_font * font; // start the font, set it in white zero font () {ttf_init (); Font = TTF_OpenFont ("dos.ttf", 12); FColor.r = 0; // 255 fColor.g = 204; // 255 fColor.b = 0; // 255} // Print the specified coordinate to the specified coordinate Zero PrintStr (char * c, int x, int y) {fontSurface = TTF_RenderText_Solid (font, c, fColor); FontRect.x = x; FontRect.y = y; SDL_ BlitSurface (fontSurfus, Faucet, Screen, & Font); SDL_Flip (screen); } Int main (int argc, char ** argv) {// start the SDL library with the video subsystem SDL_init (SDLINITVDADADLLININNOPTRAT); // Create a screen screen SDL_SetVideoMode (320, 480, 0, SDL_SWSURFACE); // Start Fonts fontInit (); PrintStr ("", 0, 0); {// When taking action on events (SDL_PollEvent (and event)) {Switch (event.type) {Case SDL_KEYDOWN: switch (event.key.keysym.sym) {// Destiny app case forced us to leave SDLK_ESCAPE Does: Event.type = SDL_QUIT; break; Default: Break; } break; Default: Break; }} SDL Della (10); } While (event.type! = SDL_QUIT); // CleanUp SDL_Quit (); Return 0; }

    This is not a trivial thing to do, but it sounds good Learning project! You may need some thousand lines, instead you have a few tens of numbers. Perhaps start by thinking about these questions and their answers.

    • Do you want a fixed width font, or a variable width font?
    • How can you buff the text rendered in a wise way?
    • How can you translate key press into text?
    • What is its translation and driving?

      All of these will need to be considered with the most important question:

      • Do I want to do this?

        If you do this, it will teach you a lot about programming, but it can not give you the best full screen console.

No comments:

Post a Comment