![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
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?
|
|
|
|
|
|
#2 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#3 | |
|
Newbie
|
Re: determing whitespace to center text
Quote:
|
|
|
|
|
|
|
#4 | |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
Re: determing whitespace to center text
Oh well then what I posted isn't relevent to you.
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. |
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
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
.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
|
|
#6 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
Re: determing whitespace to center text
ncurses is useless on GUI screens and not necessary for this question on text screens.
|
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
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.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
|
|
#8 | ||
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
Re: determing whitespace to center text
Quote:
Quote:
|
||
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
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.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
|
|
#10 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Putting spaces between formatted text fields | Fall Back Son | Java | 7 | Feb 12th, 2008 8:40 PM |
| [perl] graphical text editor | glimmy | Existing Project Development | 0 | Aug 6th, 2006 11:47 PM |
| How to detect cursor location and insert text??? | syntax-error | C# | 3 | Jun 30th, 2005 1:42 AM |
| Printing rich text with colored background | jarrod | C# | 1 | Feb 23rd, 2005 11:48 AM |