Still not clear on what the OP actually wants, but here's my hack at
it...

This is actually pretty nasty code, so needs a lot of tidying.
Seems to work OK though... For what it is.

May be completely the wrong thing though, of course.

--------------
//
// resizeable group test
// fltk-config --compile demo.cxx
//
#include <stdio.h>

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/fl_draw.H>

/* XPM */
static char *grip_tile_xpm[] = {
"6 6 4 1",
"       c None",
".      c #FCFEFC",
"+      c #D4D6D4",
"@      c #9C9294",
".+++++",
"+...@+.++",
"+...@+",
".+++++",
"+...@+.++",
"+...@+"};

Fl_Double_Window *main_win = NULL;
Fl_Group *outer = NULL;
Fl_Group *inner = NULL;

#define TL -1
#define BR  1

class drag_btn : public Fl_Box {
private:
  int x1, y1; // click posn., used for dragging checks
  int corner; // which corner...

protected:
  // override box draw method to do our textured dragger look
  void draw();
  // override handle method to catch drag operations
  int handle(int event);

public:
  // basic constructor
  drag_btn(int x, int y, int cr);
};

drag_btn::drag_btn(int x, int y, int cr)
 : Fl_Box(x, y, 10, 10) {
  box(FL_THIN_DOWN_BOX);
  corner = cr;
}

void drag_btn::draw() {
  int xo = x();
  int yo = y();
  // Draw the button box
  draw_box(box(), color());
  // set the clip region so we only "tile" the box
  fl_push_clip(xo+1, yo+1, w()-3, h()-3);
  // tile the pixmap onto the button face... there must be a better way
  for(int i = 2; i <= w(); i += 6)
    for(int j = 2; j <= h(); j += 6)
      fl_draw_pixmap(grip_tile_xpm, (xo + i), (yo + j));
  fl_pop_clip();
} // draw

int drag_btn::handle(int event) {
  int ret = Fl_Box::handle(event);
  int dx, dy, xr, yr;
  int xg, yg, wg, hg;

  xr = Fl::event_x_root();
  yr = Fl::event_y_root();
  switch (event) {
  case FL_PUSH: // downclick in button stores cursor offsets
    x1 = xr;
    y1 = yr;
    ret = 1;
    break;

  case FL_DRAG: // drag the button (and its parent group) around the
screen
    dx = xr - x1; dy = yr - y1;
    x1 = xr; y1 = yr;
    // now move the enclosing group
    xg = outer->x();
    yg = outer->y();
    wg = outer->w();
    hg = outer->h();
    if(corner == TL)
      outer->resize(xg+dx, yg+dy, wg-dx, hg-dy);
    else if (corner == BR)
      outer->resize(xg, yg, wg+dx, hg+dy);
    main_win->redraw();
    ret = 1;
    break;

  case FL_RELEASE:
    ret = 1;
    break;

  default:
    break;
  }

  return ret;
} // handle

int main(int argc, char **argv) {
  main_win = new Fl_Double_Window(500, 500, "main");
  main_win->begin();
    outer = new Fl_Group(20, 20, 110, 110);
    outer->begin();
      drag_btn *b1 = new drag_btn(20, 20, TL);
      drag_btn *b2 = new drag_btn(120, 120, BR);
      inner = new Fl_Group(30, 30, 90, 90);
      inner->begin();
        Fl_Text_Buffer *buff = new Fl_Text_Buffer();
        Fl_Text_Editor *disp = new Fl_Text_Editor(30, 30, 90, 90);
        disp->buffer(buff);
      inner->end();
      inner->box(FL_THIN_DOWN_BOX);
      inner->resizable(disp);
    outer->end();
    outer->box(FL_ENGRAVED_FRAME);
    outer->resizable(inner);
  main_win->end();
  main_win->show(argc, argv);

  // fill the editor with some dummy text
  buff->text("line 0\nline 1\nline 2\n"
             "line 3\nline 4\nline 5\n"
             "line 6\nline 7\nline 8\n"
             "line 9\nline 10\nline 11\n"
             "line 12\nline 13\nline 14\n"
             "line 15\nline 16\nline 17\n"
             "line 18\nline 19\nline 20\n"
             "line 21\nline 22\nline 23\n");

  return Fl::run();
} // main
/* End of File */
--------------






SELEX Sensors and Airborne Systems Limited
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

Reply via email to