> With the following code I tried to override the
> Fl_Window::resize () method to set an arbitrary aspect ratio
> (for example a fixed width). The problem is that the window
> frame doesn't get that size, only the canvas seems to do it.
> Can some one figure out what I'm doing wrong?
It is not so much that you are wrong, as that the asynchronous nature of
the window drawing in fltk is sometimes hard to get your head around -
add to this the fact that the O/S and window manager are responsible for
drawing the window borders, not fltk, and things get a bit tricky...
(hand wave explanation) fltk actually does the drawing "later" so at the
point that the WM redraws the border, it really thinks that it has the
"old" size.
Then the fltk managed part of the window is drawn and it does not match
the border...
A possible hack-around is attached below; this over-rides redraw() much
as you had done, but then uses a short timeout to trigger a refresh of
the window border "after the fact".
This actually works OK, but is less than elegant, in my opinion...
Al alternate hack I have used (and pretty much as inelegant...) is to
override the draw() method rather than the resize() method, and forcing
the limits in there... Not much to choose between the two approaches -
I've used both one time or another.
There are probably better ways, though!
-------------------------
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
//#define BASEWIN Fl_Window
#define BASEWIN Fl_Double_Window
class MyWindow : public BASEWIN {
int w1, h1; // maintain initial aspect ratio
int xo, yo, wo, ho;
public:
MyWindow (int W, int H, char* L) : BASEWIN (W, H, L)
{w1 = W; h1 = H;
xo = yo = wo = ho = 0;};
void resize(int X, int Y, int W, int H);
};
void nudge_window(void *v) {
MyWindow *mw = (MyWindow *)v;
// mw->redraw(); -- not enough? force a hide/show
mw->hide();
mw->show();
}
void MyWindow::resize(int X, int Y, int W, int H) {
// force aspect ratio.
// Set height based only on width and initial sizes
int h2 = W * h1 / w1;
if((xo != X) || (yo != Y) || (wo != W) ||
(ho != h2) || (ho != H)) {
xo = X, yo = Y, wo = W, ho = h2;
BASEWIN::resize (xo, yo, wo, ho);
Fl::add_timeout(0.1, nudge_window, (void *)this);
}
}
int main (int argc, char **argv) {
MyWindow *fm = new MyWindow(500, 300, "resize test");
fm->box(FL_FLAT_BOX);
fm->end();
fm->resizable(fm);
fm->show(argc, argv);
return Fl::run();
}
/* end of file */
-------------------------
--
Ian
SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14
3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk