Hi,
ok, and how i do to extract the position of mouse? x and y coords?
And if I want to change the dimension of rectangle?
thanks!
Giuseppe
>
> >=20
> > i've to drwa a rectangle (with variable dimensione) upon an image.
>
>
> Someone was asking about this quite recently - there should be answers
> in the archives if you have a look.
>
> Something like this might be a starting place:
>
> file: image_draw.cxx
> /***********************************************************************
> */
> // Compile as:
> // fltk-config --use-images --compile image_draw.cxx
> //
> // invoke as:
> // image_draw {something.jpg | something.png | etc...}
> //
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
>
> #include <FL/Fl.H>
> #include <FL/Fl_Box.H>
> #include <FL/Fl_Button.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Shared_Image.H>
> #include <Fl/fl_draw.H>=20
>
> Fl_Double_Window *outer_win;
> Fl_Shared_Image *img;
> Fl_RGB_Image *rgbimg =3D NULL;
>
> /***********************************************************************
> */=20
> class vw_box : public Fl_Box {=20
> protected:
> void draw(void);
> int iw, ih, id;
> char *data;=20
>
> public:
> vw_box(int X, int Y, int W, int H, const char *L=3D0) :
> Fl_Box(X,Y,W,H,L)=20
> {data =3D NULL;}
> =09
> void set_data(char *newdat, int W, int H, int D);=20
> };=20
>
> /***********************************************************************
> */=20
> void vw_box::set_data(char *newdat, int W, int H, int D) {
> iw =3D W; ih =3D H; id =3D D;
> if (data) delete [] data;
> data =3D newdat;=20
> }=20
>
> /***********************************************************************
> */=20
> void vw_box::draw(void) {
> if (!data) return;
> =09
> short wd =3D w(); short ht =3D h();
> short xoff =3D 0; short yoff =3D 0;=20
> static short xp =3D 50, yp =3D 50, dx =3D 10, dy =3D 10;
> =09
> xp +=3D dx; yp +=3D dy;
> if (xp < x()) {xp =3D x(); dx =3D -dx;}
> if ((xp+100) > (x()+wd)) {xp =3D (x()+wd-100); dx =3D -dx;}
> =09
> if (yp < y()) {yp =3D y(); dy =3D -dy;}
> if ((yp+100) > (y()+ht)) {yp =3D (y()+ht-100); dy =3D -dy;}
> =09
> if (ih < ht) yoff =3D (ht - ih) / 2;=20
> if (iw < wd) xoff =3D (wd - iw) / 2;=20
> short xpos =3D x() + xoff;
> short ypos =3D y() + yoff;=20
>
> /* Ensure that the full window is redrawn */
> Fl_Box::draw();
> fl_push_no_clip();=20
>
> /* Redraw the whole image */
> fl_draw_image((const uchar *)data, xpos, ypos, iw, ih, id);=20
>
> // draw a box on top of the image
> fl_rect(xp, yp, 100, 100, FL_RED);
>
> fl_pop_clip();=20
> }=20
> /***********************************************************************
> */=20
> vw_box *box_1;
> /***********************************************************************
> */=20
> void load_file(const char *n) {
> if (img) img->release();
> =09
> img =3D Fl_Shared_Image::get(n);
> if (!img) {
> puts("Image file format not recognized!");
> fflush(stdout);
> return;
> }
> Fl_Image *temp;
> if (img->w() > img->h()) temp =3D img->copy(box_1->w(), box_1->h()
> * img->h() / img->w());
> else temp =3D img->copy(box_1->w() * img->w() / img->h(),
> box_1->h());
> =09
> img->release();
> img =3D (Fl_Shared_Image *)temp;
> box_1->image(img);
> box_1->set_data((char *)img->data()[0], img->w(), img->h(),
> img->d());
> box_1->redraw();
> }
> /***********************************************************************
> */
> void quit_cb(Fl_Button*, void*) {
> outer_win->hide();
> }
> /***********************************************************************
> */
> void animate_box(void*) {
> box_1->redraw();
> Fl::repeat_timeout(0.1, animate_box);
> }
> /***********************************************************************
> */
> int main(int argc, char **argv) {
> fl_register_images();
> Fl::get_system_colors();
> =09
> outer_win =3D new Fl_Double_Window(600, 650, "Picture Window");
> =09
> box_1 =3D new vw_box(5, 5, 590, 500);
> box_1->box(FL_FLAT_BOX);
>
> Fl_Button *quit =3D new Fl_Button(535, 615, 60, 30);
> quit->label("Quit");
> quit->callback((Fl_Callback*)quit_cb);
> outer_win->end();
>
> if (argv[1]) load_file(argv[1]);
> =09
> outer_win->show();
> Fl::add_timeout(0.1, animate_box);
> return Fl::run();
> }
> /* 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