MacArthur, Ian wrote:
> This example isn't setting the clip though, so how do you expect it to
> work?
> Sorry, but I'm really not sure what you are rying to do - this example
> bears almost no resemblance to your previous one...
Yes I know, but I was just tried to separate each pb.
> Anyway, there's an easy fix to this example to get it to do what I
> *think* you are asking...
> Changing your draw method as follows will get the effect I think you are
> asking for.
>
> =20
> Fl_Box *childWdg;
> =20
> void draw()
> {
> fl_push_clip(x(), y(), w(), h());
> Fl_Group::draw();
> fl_pop_clip();
> }
Thanks a lot for that code. That's what I'm looking for during 2 days.
I finaly fixed the additional pb I had.
All I was trying to do is just a simple vertical splitter with 2 delimited
areas.
Here's my complete and compilable working code:
Thank you guys for helping me.
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
class Container : public Fl_Group
{
void draw()
{
fl_push_clip(x(), y(), w(), h());
Fl_Group::draw();
fl_pop_clip();
}
public:
Container(int x, int y, int w, int h, char *l = 0)
: Fl_Group(x, y, w, h, l)
{
box(FL_DOWN_BOX);
}
};
class VrtSplitter : public Fl_Group
{
Container *container1, *container2;
int wCtn1, border, xPos;
bool bSplit;
void draw()
{
Fl_Group::draw();
fl_color(FL_BLACK);
fl_line_style( FL_DOT, 1);
if(bSplit && Fl::event_button1() != 0)
{
fl_push_clip(x(), y(), w(), h());
xPos = Fl::event_x();
if(Fl::event_x() > w() - (border * 2))
xPos = w() - (border * 2);
if(Fl::event_x() < x() + (border * 2))
xPos = x() + (border * 2);
fl_line(xPos - 1, y() + border, xPos - 1, y() + h() - (border * 2));
fl_line(xPos, y() + border, xPos, y() + h() - (border * 2));
fl_line(xPos + 1, y() + border, xPos + 1, y() + h() - (border * 2));
fl_pop_clip();
}
else
{
fl_push_clip(x(), y(), w(), h());
fl_pop_clip();
}
}
int handle(int e)
{
int ret = Fl_Group::handle(e);
switch(e)
{
case FL_MOVE:
if(Fl::event_x() > wCtn1 - border && Fl::event_x() < wCtn1 + border)
{
fl_cursor(FL_CURSOR_WE);
bSplit = true;
}
else
{
fl_cursor(FL_CURSOR_DEFAULT);
bSplit = false;
}
return 1;
case FL_PUSH:
if(Fl::event_button() == FL_LEFT_MOUSE && bSplit)
{
redraw();
}
return 1;
case FL_RELEASE:
if(Fl::event_button() == FL_LEFT_MOUSE && bSplit)
{
container1->resize(x(), y(), xPos, h());
wCtn1 = xPos;
container2->resize(wCtn1, y(), w() - wCtn1, h());
bSplit = false;
redraw();
}
return 1;
case FL_DRAG:
if(bSplit && Fl::event_state(FL_BUTTON1) != 0)
redraw();
return 1;
}
return(ret);
}
public:
VrtSplitter(int x, int y, int w, int h, const char *l = 0)
: Fl_Group(x, y, w, h, l)
{
begin();
container1 = new Container(x, y, w / 2, h);
container1->color((Fl_Color) FL_RED);
end();
begin();
container2 = new Container(x + (w / 2), y, w / 2, h);
container2->color((Fl_Color) FL_BLUE);
end();
wCtn1 = w / 2;
bSplit = false;
border = Fl::box_dx(FL_DOWN_BOX);
}
void resizeVrtSplitter(int x, int y, int w, int h)
{
resize(x, y, w, h);
container1->resize(x, y, wCtn1, h);
container2->resize(wCtn1, y, w - wCtn1, h);
}
};
class Application : public Fl_Double_Window
{
VrtSplitter *splitter;
void resize(int x, int y, int w, int h)
{
Fl_Double_Window::resize(x, y, w, h);
splitter->resizeVrtSplitter(0, 0, w, h);
}
public:
Application(int w, int h, const char *l, int argc, char *argv[]);
};
Application::Application(int w, int h, const char *l, int argc, char *argv[])
: Fl_Double_Window(w, h, l)
{
begin();
box(FL_DOWN_BOX);
splitter = new VrtSplitter(0, 0, w, h);
end();
resizable(this);
show(argc, argv);
}
int main (int argc, char ** argv)
{
Application myApp(500, 300, "Vertical Splitter", argc, argv);
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk