Drawing lines and shapes in a console window

J

john

Hi I am a C++ newbie, I am looking to draw single lines and simple
boxes in a C++ console window. Is there a draw command with x and y
coordinates that can be used with my Dev C++ compiler. For simplicity
sake, I would be prepared to draw using characters such as _ or * if
proper line drawing is really complicated.

Thanks in advance.

Walt
 
G

gabriel

john said:
Hi I am a C++ newbie, I am looking to draw single lines and simple
boxes in a C++ console window. Is there a draw command with x and y
coordinates that can be used with my Dev C++ compiler. For simplicity
sake, I would be prepared to draw using characters such as _ or * if
proper line drawing is really complicated.

Am I missing smoething, or is a console, by definition, incapable of
graphics handling?

I'd suggest posting this question in a group that deals with your operating
system, as in standard C++ there are no sophisticated facilities to do
fancy stuff. Not even clearing the screen (Someone please correct me if
I'm wrong).
 
H

Heath McKay

from my time in C++ class in High school, i remember that we did use a
drawing library that allowed us to both create pictures and output
precreated pictures to the screen, but i cannot remember what it was called.
We were using Borland and Windows, but i don't think it was just for
Borland.

PS. i found the library, it was called GFXLIB8 (.h or .cpp, i cannot
remember) but i don't think it is easy to find on the internet. my teacher
gave it to us, but i don't know where you could obtain it now, or even if
there is a newer version.
 
A

Andras Tantos

Hi I am a C++ newbie, I am looking to draw single lines and simple
boxes in a C++ console window. Is there a draw command with x and y
coordinates that can be used with my Dev C++ compiler. For simplicity
sake, I would be prepared to draw using characters such as _ or * if
proper line drawing is really complicated.

Thanks in advance.

This is probably OT here since standard C++ has no notion of 'lines and
boxes on a C++ console window'. Without OS info (though DevC++ suggests a
MinGW GCC compiler under Windows) it's hard to answer. In the Unix world
NCurses and it's variants (PCurses) is one library capable of this and much
more. There's a windows port of that library too.
 
C

Christopher Benson-Manica

gabriel said:
Am I missing smoething, or is a console, by definition, incapable of
graphics handling?

<ot>
Not if you count things like the curses library as graphics
handling. Of course, the curses library isn't standard...
</ot>
 
J

john

OK, what is the simplest way of drawing lines, vertical and horizontal
in Microsoft visual C++ or Dev C++
 
V

Victor Bazarov

john said:
OK, what is the simplest way of drawing lines, vertical and horizontal
in Microsoft visual C++ or Dev C++

The only way I know to draw single horizontal lines in C++ is to output
either character '-' (minus) or '_' (underscore). For double lines use
'=' (equal sign). For vertical lines use '|' (bar) if it's among the
available characters. For oblique lines use a slash or a backslash,
depending on the angle. For intersections use a plus or a pound. Also,
for intersections of oblique lines you could use the capital x...

What it has to do with the language I have no idea.

Victor
 
J

John Carson

john said:
OK, what is the simplest way of drawing lines, vertical and horizontal
in Microsoft visual C++ or Dev C++

I don't know why anyone would want to bother drawing lines in console mode,
but you need to look at the character set of the font that your console
uses. It probably incorporates some special characters for the purpose. For
example, under Windows the default font is 8514oem. Characters 0xB3 to 0xDF
are line drawing charactes. For example, 0xB3 is a vertical line, 0xC4 is a
horizontal line and 0xBF, 0xC0, 0xD9, 0xDA are corners. Thus you can draw a
square with:


cout << '\n';
// top line and corners
cout << (char)0xDa;
for(int i=0; i<10; ++i)
cout << (char)0xC4;
cout << (char)0xBF;
cout << '\n';
// vertical edges
for(int i=0; i<10; ++i)
{
cout << (char)0xB3;
for(int j=0; j<10; ++j)
cout << ' ';
cout << (char)0xB3;
cout << '\n';
}
// bottom line and corners
cout << (char)0xC0;
for(int i=0; i<10; ++i)
cout << (char)0xC4;
cout << (char)0xD9;
cout << '\n';
 
R

Roger Leigh

Christopher Benson-Manica said:
<ot>
Not if you count things like the curses library as graphics
handling. Of course, the curses library isn't standard...
</ot>

curses is standardised by POSIX (now Single UNIX Specification version
3). It's not a C++ standard, but is standardised nonetheless.
 
Joined
Oct 31, 2008
Messages
1
Reaction score
0
When in College I actually compiled a windows for consoles library, basically it can define window shapes with different background colors and borders for a console. Its capable of keeping text within its boundarys and holding it in memory to be re-drawn. If you want a sample of its use, you can go to jbtatro dot com go to the code link section and select the ConnectFour.zip (not the ConnectFour2.zip) and you can see how to manipulate your console in all the ways you ever wished and more. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top