Thread: [C++] Drawing a window border with asterisks

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    93

    [C++] Drawing a window border with asterisks

    Hello, I am just wondering if there is an easy way to do the following in my constructor

    IOScreen(int row, int col, int width, int height); sets the row, col, width, height attributes of the IOScreen to the corresponding incoming values in the argument list. If an IOScreen is made using this constructor, it means that the IOScreen window is not a full-screen size window. (i.e it will only cover the screen partially and when it is displayed, it will show a frame using the asterisk character on the border line characters of the window
    I assume Ill want to use my row, col, width and height in some kind of for loop to make the border line characters of the window but am unsure of the conditions to do so. Appreciate any help whatsoever.

    Thanks in advance.

    Edit: Think I forgot to mention that I can use a function I wrote called cio_cursor

    /* Places cursor at specified row/column number */
    void cio_cursor(int row, int column){
    So far I have got

    Code:
    IOScreen::IOScreen(int row, int col, int width, int height){
    	this->row = row;
    	this->col = col;
    	this->width = width;
    	this->height = height;
    	cio_start();
    	cio_cursor(row,col);
    	// Adjust window settings for this constructor using height and width
    }
    Last edited by INFERNO2K; 11-16-2005 at 07:05 PM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Taking what you have already coded:
    Code:
    #include <string>
    
    IOScreen::IOScreen(int row, int col, int width, int height){
    	this->row = row;
    	this->col = col;
    	this->width = width;
    	this->height = height;
    	cio_start();
    	cio_cursor(row,col);
    	// Adjust window settings for this constructor using height and width
    
    	std::cout << std::string(width,'*');
    	for (int i=1; i<height-1; ++i)
    	{
    		cio_cursor(row+i,col);
    		std::cout << '*';
    		cio_cursor(row+i,col+width-1);
    		std::cout << '*';
    	}
    	//Draw the bottom of the border
    }
    Replace cout with the appropriate output command, if you are using something different to output characters. Instead of std::string, you could also use a for-loop to draw the top of the border.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    Will this draw the bottom row?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Will this draw the bottom row?
    No, just the top and sides.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    Unsure of how to draw the bottom

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    	cio_cursor(row,col);
    	std::cout << std::string(width,'*');
    The above two lines draw the top. So what I would recommend is changing this line:
    Code:
    	std::cout << std::string(width,'*');
    into a for-loop to draw the top. If you can do that then you can easily draw the bottom.

    The key to getting code to work is to play with it. Write a couple of lines of code, compile it, run it, and see what it does. Then make changes until it works. Then add more code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM