Computer Graphics

Moderators: Sephiroth
Number of threads: 1241
Number of posts: 2641

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
settextjustify in C++ Posted by Ashu2912 on 21 Oct 2010 at 10:37 AM
Here is a code I have written:
#include <iostream.h>
#include <conio.h>
#include <graphics.h>

void main ()
{
int gd,gm;
clrscr ();
detectgraph (&gd,&gm);
initgraph (&gd,&gm,"c:\\tc\\bgi");
outtext("\n\n\n Welcome to the graphics mode!!!");
getch ();
cleardevice ();
settextstyle (3,0,2);
outtext("Experimenting with fonts......");
getch ();
cleardevice ();
setcolor (5);
outtext("Experimenting with fonts......");
getch ();
cleardevice ();
settextjustify (1,1);
outtext ("Justification of text........");
if (graphresult () == -11)
outtext ("Error.....");
getch ();
}

Now, when I run this code, the settextjustify function does not align the text in the center of the screen. I have also tried the enumetations for the center alignment but still this thing doesn't work. Please help!!!!
Report
Re: settextjustify in C++ Posted by AsmGuru62 on 22 Oct 2010 at 3:53 AM
settextjustify() aligns the text RELATIVE TO CURRENT PEN POSITION. It means two choices:

1. You can use moveto() to set the pen position
2. You can use outtextxy() instead of outtext()

See RED: I set up the center of screen and changed all calls to outtext() to its equivalent, but with X,Y passed.

: #include <iostream.h>
: #include <conio.h>
: #include <graphics.h>
: 
: void main ()
: {
:      int gd,gm,x,y;
:      clrscr ();
:      detectgraph (&gd,&gm);
:      initgraph (&gd,&gm,"c:\\tc\\bgi");
:      outtext("\n\n\n Welcome to the graphics mode!!!");
:      getch ();
:      cleardevice ();
:      settextstyle (3,0,2);
:      outtext("Experimenting with fonts......");
:      getch ();
:      x=getmaxx () / 2;
:      y=getmaxy () / 2;
:      cleardevice ();
:      setcolor (5);
:      outtext("Experimenting with fonts......");
:      getch ();
:      cleardevice ();
:      settextjustify (1,1);
:      outtextxy (x,y,"Justification of text........");
:      settextjustify (0,1);
:      outtextxy (x,y,"-- settextjustify (0,1) --");
:      settextjustify (1,0);
:      outtextxy (x,y,"-- settextjustify (1,0) --");
:      if (graphresult () == -11)
:      outtext ("Error.....");
:      getch ();
: }
Report
Re: settextjustify in C++ Posted by Ashu2912 on 22 Oct 2010 at 6:05 AM
Thanks!!! It has helped me a lot!!!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.