s_johnson@csc32.enet.dec.com (Scott Johnson) (03/27/91)
Hi, I have a problem. I am in graphics mode and write a number to the display device using outtextxy(). I overwrite the number with a string of spaces to clear it. When this statement gets executed, the number is still there. After that I write a new number to the same location. The problem is that the space does not get cleared away before writing the new number. If this is done enough, then the number becomes a square and is no longer a number. The following code demonstrates the problem. A message is sent to Display to initialize and then a series of messages is sent to update the display with a new value being passed in for fish each time. I am using dos 3.3 with c++ 1.0. My monitor is vga and it uses a paradise card. Is this a bug or am I doing something wrong? Thanks for any and all help. scott --------------------------------------------- #include <iostream.h> #include <graphics.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define fishx 20 int maxy; void Display::initialize(void) { int i; int delta; int gdriver=DETECT,gmode,errorcode; initgraph(&gdriver, &gmode,"\\tc\\bgi"); errorcode = graphresult(); if (errorcode != grOk){ cout<<"Graphics Error\n"; getch(); } // Get the maximum coordinates for the display in both the x and y dir. maxy = getmaxy()-20; outtextxy(fishx,maxy+10,"Fish:"); }; void Display::update(int fish) { char temp[5]; strcpy(temp," "); outtextxy(fishx+43,maxy+10,temp); getch(); itoa(fish,temp,10); outtextxy(fishx+43,maxy+10,temp); }; ------------------------------------------------------------------- Scott Johnson Digital Equipment Corporation Colorado Springs, Co
boba@hpwarau.hp.com (Bob Alexander) (03/27/91)
>I have a problem. I am in graphics mode and write a number to the display >device using outtextxy(). I overwrite the number with a string of spaces to >clear it. When this statement gets executed, the number is still there. Finally, I can contribute something knowledgable to this group! Outtextxy is a function unique to Borland's C products, so this is not really a C++ question. Outtextxy draws lines on the screen to represent letters, but never erases. To "draw" a space, it simply doesn't draw anything. When it draws a letter like "O" it draws the necessary lines, but doesn't erase the inside of the letter. To erase an area before writing text, I use the bar function (which fills a rectangular area.) Be sure to set the fill style to SOLID_FILL and the color to whatever background you want. Use textwidth and textheight to figure out the dimensions of the bar. If you wanted to clear the area to black (or whatever color #0 is set to) you could also use setviewport and clearviewport. But you'd have to be careful to restore the old viewport (the default is the entire screen) or the rest of your graphics commands would be executed within and relative to the small viewport you just created. I recommend the bar function over the viewport functions. Bob Alexander boba@hpwala.hp.com ------------------------------------------------------------------------ Organizations don't have opinions: individuals do. The opinions expressed above do not necessarily reflect those of the stockholders, employees, or directors of Hewlett-Packard.