Original Post
This is rather weird. I have a closed-loop input function (the rest of the app freezes until input is done) that updates the input area only via a call to SDL_UpdateRects(). The only problem is that in a fullscreen app this doesn't seem to work at all. The function takes a surface to draw to and update, and I pass in the primary surface. I have a feeling the windowed mode handle page flipping differently than the fullscreen mode or something because when I try flipping the page in fullscreen I get two different surfaces flickering in and out, but that doesn't happen in windowed mode. I'm pretty confused right now and I'm still sifting through the possibilities. Just wondering if anyone else has run up against the same problem.
Here's the code for the input function, dunno if it'll do any good tho. It wasn't written by me so don't whine to me about how it looks
_________________________________________________________________
Drew Sikora
A.K.A. Gaiiden
ICQ #: 70449988
AOLIM: DarkPylat
Blade Edge Software
Staff Member, GDNet
Public Relations, Game Institute
3-time Contributing author, Game Design Methods , Charles River Media
Online column - Design Corner at Pixelate
Unnoficial IGDA chat! [polaris.starchat.net -> #igda]
NJ IGDA Chapter - NJ developers unite!! [Chapter Home | Chapter Forum]
"Real programmers don't work from 9 to 5. If any real programmers are around at 9am it's because they were up all night."
-Anon.
"It's not the size of the source that matters, it's how you use it"
- Self
string SoFont::InputText(SDL_Surface *Dest, int x, int y, const char *input, int clip_w, int clip_h)
{
string str_input;
SDL_Event event;
int ch=-1,blink=0;
long blinktimer=0;
SDL_Surface *Back;
SDL_Rect rect;
int previous;
//int ofs=(text[0]-33)*2+1;
//int leftshift=(this->CharPos[ofs]-this->CharPos[ofs-1])/2;
Back = SDL_AllocSurface(Dest->flags, Dest->w,
FontHeight(),
Dest->format->BitsPerPixel,
Dest->format->Rmask,
Dest->format->Gmask,
Dest->format->Bmask, 0);
rect.x=0;
rect.y=y;
rect.w=Dest->w;
rect.h=picture->h;
SDL_BlitSurface(Dest, ▭, Back, NULL);
PutString(Dest,x,y,input);
SDL_UpdateRects(Dest, 1, ▭);
// start input
str_input.assign(input);
previous=SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
blinktimer=SDL_GetTicks();
while (ch!=SDLK_RETURN) {
if (event.type==SDL_KEYDOWN) {
ch=event.key.keysym.unicode;
if (event.key.keysym.sym==SDLK_DELETE)
str_input = "";
if (((ch>31)||(ch=='\b')) && (ch<128)) {
if ((ch=='\b')&&(str_input.size()>0))
str_input.replace(str_input.size()-1, 1, "");
else if (ch!='\b')
str_input += ch;
SDL_BlitSurface( Back, NULL, Dest, ▭);
PutString(Dest, x, y, str_input.c_str());
SDL_UpdateRects(Dest, 1, ▭);
// printf("%s ## %d\n",text,strlen(text));
SDL_WaitEvent(&event);
}
}
if (SDL_GetTicks()>blinktimer) {
blink=1-blink;
blinktimer=SDL_GetTicks()+500;
if (blink) {
PutString(Dest, x+TextWidth(str_input.c_str()), y, "|");
SDL_UpdateRects(Dest, 1, ▭);
// SDL_UpdateRect(Dest, x+TextWidth2(Font,text), y, TextWidth2(Font,"|"), Font->Surface->h);
} else {
SDL_BlitSurface( Back, NULL, Dest, ▭);
if (!PutString(Dest, x, y, str_input.c_str()), clip_w, clip_h, false)
str_input.replace(str_input.size()-1, 1, "");
SDL_UpdateRects(Dest, 1, ▭);
// SDL_UpdateRect(Dest, x-(Font->CharPos[ofs]-Font->CharPos[ofs-1])/2, y, PixelWidth, Font->Surface->h);
}
}
SDL_Delay(1);
SDL_PollEvent(&event);
}
str_input += '\0';
SDL_FreeSurface(Back);
SDL_EnableUNICODE(previous); //restore the previous state
SDL_EnableKeyRepeat(0, 0);
return str_input;
}