« Return to Thread: problem with back-buffered widget
In order to learn the fox toolkit I decided to write a sudoku game. It's not complete yet, but so far does what's expected of it except for some confusing problems.
When first started up it outputs to the console the following errors:
X Error: code 9 major 152 minor 4: BadDrawable (invalid Pixmap or Window parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 23: RenderBadPicture (invalid Picture parameter).
X Error: code 170 major 152 minor 7: RenderBadPicture (invalid Picture parameter).
I suspect these have something to do with the font resizing on the server, but I'm not sure what to do about it. When the app is resized, these errors are repeated and the canvas widget goes blank except for the background and the lines drawn to make the board. Doing things like passing another window over it will restore those parts which shouldn't be blank and doing anything which causes a canvas update restores the whole thing.
Also, the flush left "renderAll= true;" in the method layoutBuffer was necessary in order to have the canvas update restore everything. I would much prefer to have only the dirty bits repainted as oulined in the FAQ about back-buffered widgets.
I have learned much from the docs, FAQs and mailing list archives, but obviously am missing some basic understanding of the repainting process. Whenever I try to include a layout() method as suggested in the FAQ, things go really bad with the canvas always remaining grey and even the menus not getting painted.
The full source is attached, but here are the bits which I would expect to be relevant. I am using fox 1.6.35 and gcc 4.4.0 Any help would be appreciated.
Mike
---
FXMAPFUNC(SEL_PAINT, sudokuWindow::ID_CANVAS, sudokuWindow::onPaint),
---
long sudokuWindow::onPaint(FXObject *, FXSelector, void *ptr)
{
FXEvent *ev = (FXEvent *)ptr;
layoutBuffer();
FXDCWindow dc(canvas,ev);
dc.drawImage(dbuf,0,0);
return 1;
}
---
void sudokuWindow::layoutBuffer()
{
FXDCWindow dc(dbuf);
// builds the game board from the ground up
int w= canvas->getWidth();
int h= canvas->getHeight();
int h9= h/9; int w9= w/9;
if (lastw != w || lasth != h || font==NULL)
{
renderAll= true; // resizing means repaint all
dbuf->resize(w,h);
lastw= w; lasth= h;
// simple guess for proper font size that works well
int fs=h9/2;
if (fs != fontSize)
{
fontSize= fs;
if (font!=NULL)
{
font->destroy();
delete font;
}
font= new FXFont(getApp(),"times",fs);
font->create();
}
// now for the hint font
fs=h9/5;
if (fs != hfontSize)
{
hfontSize= fs;
if (hfont!=NULL) delete hfont;
hfont= new FXFont(getApp(),"times",fs);
hfont->create();
}
}
renderAll=true;
if (renderAll)
{
dc.setForeground(bgColor);
dc.fillRectangle(0,0,w,h);
}
for (int i=0; i<81; ++i)
{
if (renderAll || dirty[i] || board[i].error)
{
int x= i%9; int y=i/9;
int w9= dbuf->getWidth()/9;
int h9= dbuf->getHeight()/9;
// correct for extra space in last row/column
int w= x==8? dbuf->getWidth()-8*w9 : w9;
int h= y==8? dbuf->getHeight()-8*h9 : h9;
// refresh background
if (i==cursor) dc.setForeground(curColor);
else dc.setForeground(bgColor);
dc.fillRectangle(x*w9,y*h9,w,h);
int v= board[i].val;
if (v>0) // square has been solved show number
{
dc.setFont(font);
string text; text.append(1,'0'+v);
int xpos= w9*x+w/2-font->getCharWidth('0'+v)/2;
int ypos= h9*y+h/2+h9/4;
if (board[i].error) dc.setForeground(errorColor);
else dc.setForeground(fgColor);
dc.drawText(xpos,ypos,text.c_str() );
}
else // square not solved show hints
if (allhints || (curshints && i==cursor) )
{
dc.setFont(hfont);
dc.setForeground(hintColor);
set<int>::const_iterator it;
for (it=board[i].possible.begin(); it!=board[i].possible.end(); ++it)
{
int v= *it;
string text; text.append(1,'0'+v);
int fw= hfont->getCharWidth('0'+v)/2;
int xpos= (x*w9)+2*w/10+((v-1)%3)*3*w/10-fw;
int ypos= (y*h9)+3*h/10+((v-1)/3)*3*h/10;
dc.drawText(xpos,ypos,text.c_str() );
}
}
}
if (board[i].error) dirty[i]= true;
else dirty[i]= false;
}
if (renderAll)
{
dc.setForeground(fgColor);
for (int i=1; i<9; ++i)
{
if ( i%3==0 ) dc.setLineWidth(3);
else dc.setLineWidth(1);
dc.drawLine(i*w9,0,i*w9,h);
dc.drawLine(0,i*h9,w,i*h9);
}
}
renderAll= false;
}
« Return to Thread: problem with back-buffered widget
| Free embeddable forum powered by Nabble | Forum Help |