![]() |
determing whitespace to center text
hello, im trying to center my title in a console application, no matter what size the window is, and i dont quite know how to calculate how many whitespaces are on each line, is there a c++ function that counts the white spaces for a given console size/width?
|
Re: determing whitespace to center text
If you use MFC there is a CDC c++ class that will help you with that centering. There is also the win32 api function TextOut() But you have to know where you want the text to start (x and y coordinates). That will depend on the font and font size being used. If you navigate through some of the links in MSDN you will probably find some example(s) you can use.
|
Re: determing whitespace to center text
Quote:
|
Re: determing whitespace to center text
Quote:
Quote:
When using GUI terminals you have to calculate with width or the screen and string in pixels. I don't know how to do that in *nix, but it will depend on what GUI libraries you are using. |
Re: determing whitespace to center text
I think you want to use something like ncurses. Don't try to reinvent the console GUI, they did that like 20 years ago ;).
|
Re: determing whitespace to center text
ncurses is useless on GUI screens and not necessary for this question on text screens.
|
Re: determing whitespace to center text
He is a linux user talking about "consoles". Which means he writing a terminal program. If you are writing a terminal program and wish to make a decent text bested interface, using something like ncurses is the way to go. This is the same thing I would say to someone on windows trying to slog it out with the Win32 API. I would tell them to go use something like QT or wxWidgets. Somebodies already done the work take advantage of it.
|
Re: determing whitespace to center text
Quote:
Quote:
|
Re: determing whitespace to center text
Well the problem can't really be pixel width because my gnome terminal open right beside the firefox I am currently using, has fixed widths fonts. The issue is that I can decide for it to be 80 characters wide (the standard) or 180 characters wide. Now its obvious terminal programs can determine the width, at least in characters, because when I open nano in that terminal its completely aware of how many characters wide the terminal is.
A quick download of the nano source code shows that it indeed uses ncurses. Although it also uses terminfo, termcap, and termlib. From what I have found they might be real source of terminal information needed. Of course ncurses might just use them underneath. The point I was trying to make above was not to use QT, but that this is a very solved problem for which you want to use a text based user interface library like ncurses. |
Re: determing whitespace to center text
If gnome terminal has fixed width font then possibly your suggestion will work. I don't have such a terminal so I can't really say.
|
| All times are GMT -5. The time now is 4:11 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC