Text based frame in win32 console

This is a discussion on Text based frame in win32 console within the C Programming forums, part of the General Programming Boards category; Hi! I have a huge problem with drawing my frame in win32 console. At the coordinates (79,24) I have to ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Text based frame in win32 console

    Hi!

    I have a huge problem with drawing my frame in win32 console. At the coordinates (79,24) I have to draw a LEFTUP part of the frame (I hope you understand what i mean). My code draws the LEFTUP part but after it draws it program jumps into the new line and everything is moved.

    This is my frame:
    Code:
    RIGHTDOWN part->(|-)-------------------------------------(-|)<- LEFTDOWN part
                     |                                         |
                     |                                         |
                     |                                         |
                     |                                         |
                     |                                         |
                     |                                         |
                     |                                         |
    RIGHTUP part->  (|-)-------------------------------------(-|)<- LEFTUP part
    And here's my code:
    Code:
    // constants for drawing a frame
    # define RIGHTDOWN      218
    # define RIGHTUP     192
    # define LEFTDOWN       191
    # define LEFTUP     217
    # define HORIZONTAL     196
    # define VERTICAL    179
    # define VERTICALRIGHT 195
    # define VERTICALLEFT  180
    
    void Frame ()
    {
    	int i = 0, j = 0, k = 0, l = 0, x, y, length, height;
    
    	x = 0;
    	y = 0;
    	length = 80;
    	height  = 25;
    	// drawing a frame
    	gotoxy (x, y);
    	printf ("%c", RIGHTDOWN); 
    	for (i = 0; i < length-2; i++)
    	{
    		gotoxy (x+1+i, y);
    		printf ("%c", HORIZONTAL);
    		if (i == length-3)
    		{
    			gotoxy (x+length, y);
    			printf ("%c", LEFTDOWN);
    			for (j = 0; j < height-2; j++)
    			{
    				gotoxy (x, y+1+j);
    				if (j == 0)
    				{
    					printf ("%c", VERTICAL);
    					for (l = 0; l < length-2; l++) // drawing spaces
    					{
    						printf (" ");
    					}
    					printf ("%c", VERTICAL);
    				}
    				if (j == 1) // drawing title line
    				{	
    					printf ("%c", VERTICALRIGHT);
    					for (k = 0; k < length-2; k++)
    					{
    						printf ("%c", HORIZONTAL);
    					}
    					printf ("%c", VERTICALLEFT);
    				}
    				else // drawing other parts of the frame
    				{
    					if (j != 0)
    					{
    						printf ("%c", VERTICAL);
    						for (l = 0; l < length-2; l++) // drawing spaces
    						{
    							printf (" ");
    						}
    						printf ("%c", VERTICAL);
    					}
    				}
    			}
    			gotoxy (x, y+height);
    			printf ("%c", RIGHTUP);
    			for (j = 0; j < length-2; j++)
    			{
    				gotoxy (x+1+j, y+height);
    				printf ("%c", HORIZONTAL);
    			}
    		}
    	}
    	gotoxy (length-1, height-1);
    	printf ("%c", LEFTUP);
    }
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    I complied your Frame function and it draws the frame like so:
    Code:
    |                        |
    |------------------------|
    |                        |
    |                        |
    |                        |
    |                        |
    |                        |
    |------------------------|
    The 2 sides stick out at the top is this the problem?
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    No.
    Change this

    Code:
    gotoxy (length-1, height-1);
    printf ("%c", LEFTUP);
    to

    Code:
    gotoxy (length-1, height-2);
    printf ("%c", LEFTUP);
    and you'll se what do i mean.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    >> My code draws the LEFTUP part but after it draws it program jumps into the new line and everything is moved.

    If your screen width is 80 then when you print the 80'th character a newline is automatically performed.
    I changed your width to 79 and used newlines instead of gotoxy and it works, just change it to suit your needs
    Code:
    #include <stdio.h>
    #include <conio.h>
     
    # define RIGHTDOWN     218
    # define RIGHTUP       192
    # define LEFTDOWN      191
    # define LEFTUP        217
    # define HORIZONTAL    196
    # define VERTICAL      179
    # define VERTICALRIGHT 195
    # define VERTICALLEFT  180
    
    #define HEIGHT 25
    #define LENGTH 79
    
    void Frame( void );
    
    int main( void )
    {
    	Frame();
    	getch();
    
    	return 0;
    }
    
    void Frame( void )
    {
    	int loop1, loop2;
    
    	putchar( RIGHTDOWN );
    	for( loop1 = 0; loop1 < ( LENGTH - 2 ); loop1 ++ )
    		putchar( HORIZONTAL );
    	putchar( LEFTDOWN );
    
    	putchar( '\n' );
    	putchar( VERTICAL );
    	for( loop1 = 0; loop1 < ( LENGTH - 2 ); loop1++ )
    		putchar( ' ' );
    	putchar( VERTICAL );
    
    	putchar( '\n' );
    	putchar( VERTICALRIGHT );
    	for( loop1 = 0; loop1 < ( LENGTH - 2 ); loop1++ )
    		putchar( HORIZONTAL );
    	putchar( VERTICALLEFT );
    
    	for( loop1 = 0; loop1 < ( HEIGHT - 4 ); loop1++ )
    	{
    		putchar( '\n' );
    		putchar( VERTICAL );
    		for( loop2 = 0; loop2 < ( LENGTH - 2 ); loop2++ )
    			putchar( ' ' );
    		putchar( VERTICAL );
    	}
    
    	putchar( '\n' );
    	putchar( RIGHTUP );
    	for( loop1 = 0; loop1 < ( LENGTH - 2 ); loop1++ )
    		putchar( HORIZONTAL );
    	putchar( LEFTUP );
    
    }
    using the newlines instead of gotoxy means the table is always left justified and starts from the coords 0,0, try changing HEIGHT & LENGTH. You shuold be able to change it to use gotoxy easy enough.
    Last edited by C_Coder; 04-14-2002 at 06:27 AM.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    That's not good. You draw only to width = 78. I need to draw to width = 79. Is there any way to get rid of that new line?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    >> You draw only to width = 78
    Anymore than that and you get the automatic newlines, I don't know how to stop that. If you must have a 79 width then I suggest you enlarge your console to accomodate it.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    I give up. I can't get rid off of that extra character. Now my frame is only drawed to width = 78. Drawing a frame with my code is very slow. Is there any other way to write the code for drawing a frame?
    Last edited by GaPe; 04-14-2002 at 02:48 PM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #8
    Unregistered
    Guest
    Don't know what frame you exactly need, but try these fillconsoleoutputcharacter and fillconsoleoutputattribute, at least you can make a frame, changing the background.

  9. #9
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Unregistered

    Try my code for the frame and you'll see.
    Last edited by GaPe; 04-16-2002 at 12:33 PM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. Console app: Making pretty text blocks
    By unit335 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2009, 07:22 PM
  3. console text effects
    By algi in forum C++ Programming
    Replies: 4
    Last Post: 12-17-2004, 03:15 PM
  4. Text based frames in win32 console
    By Ragger in forum C Programming
    Replies: 6
    Last Post: 06-19-2004, 08:09 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21