Hi,
I have added the capability to reload the bmp in the upper left corner
try to select a rect in the center of box (where the 2 lines cross)
and press "save".
here is the fluid file:
****************************
# data file for the Fltk User Interface Designer (fluid)
version 1.0106
header_name {.h}
code_name {.cxx}
decl {\#include <stdio.h>} {public
}
decl {\#include <stdlib.h>} {public
}
decl {\#include <FL/Fl_Box.H>} {public
}
decl {\#include <FL/fl_draw.H>} {public
}
decl {\#include <FL/Fl_Shared_Image.H>} {public
}
decl {\#include "bmppix.h"} {public
}
decl {Fl_Shared_Image *img;} {public
}
decl {BMPhf hf_bmp;} {public
}
decl {BMPhi hi_bmp;} {public
}
decl {mRGB myRGB;} {public
}
decl {FILE *outbmp;} {public
}
decl {int ev_p_x;} {public
}
decl {int ev_p_y;} {public
}
decl {int ev_r_x;} {public
}
decl {int ev_r_y;} {public
}
decl {int ev_w;} {public
}
decl {int ev_h;} {public
}
decl {int ev_w3;} {public
}
class Mydrwbox {: {public Fl_Box}
} {
Function {draw()} {private return_type void
} {
code {fl_overlay_clear();
fl_push_clip(this->x(), this->y(), this->w(), this->h());
fl_draw_box(FL_FLAT_BOX, this->x(), this->y(), this->w(), this->h(),
(Fl_Color)53);
//....
fl_line_style(FL_SOLID,5);
fl_color(180,180,180);
fl_line(this->w()/2+this->x(),this->y(),this->w()/2+this->x(),this->h()+this->y());
fl_color(220,80,80);
fl_line(this->x(),this->h()/2+this->y(),this->w()+this->x(),this->h()/2+this->y());
if(img) img->Fl_Image::draw(this->x(),this->y()); /* draws in the upper left
corner of the box */
fl_pop_clip();} {}
}
Function {handle(int e)} {private return_type int
} {
code {int ret = Fl_Box::handle(e);
switch(e)
{
case FL_PUSH:
ev_p_x=Fl::event_x(); ev_p_y=Fl::event_y();
fl_read_image((unsigned char *)&myRGB, ev_p_x, ev_p_y, 1, 1, 0);
printf("RGB: %u %u %u\\n",myRGB.mred,myRGB.mgre,myRGB.mblu);
return(1);
case FL_RELEASE:
ev_r_x=Fl::event_x(); ev_r_y=Fl::event_y();
return(1);
case FL_DRAG:
ev_w=Fl::event_x()-ev_p_x;
ev_h=Fl::event_y()-ev_p_y;
mybox->window()->make_current();
fl_overlay_rect(ev_p_x, ev_p_y, ev_w, ev_h);
return(1);
}
return(ret);} {}
}
Function {redraw()} {return_type void
} {
code {this->draw();} {}
}
decl {public: Mydrwbox(int x,int y,int w,int h):Fl_Box(x,y,w,h) {}} {public
}
}
Function {} {} {
code {fl_register_images();
Fl::visual(FL_RGB);} {}
Fl_Window myw {open
xywh {999 706 520 325} type Double visible
} {
Fl_Box mybox {
xywh {5 5 510 165} labeltype NO_LABEL when 0
class Mydrwbox
}
Fl_Button quitbut {
label Quit
callback {quitbut_cb()}
xywh {365 280 115 25}
}
Fl_Button sv {
label save
callback {sv_cb()}
xywh {40 280 115 25}
}
}
}
Function {quitbut_cb()} {return_type void
} {
code {exit(0);} {}
}
Function {sv_cb()} {return_type void
} {
code {int njunkb=0;
int cnt=0; int cnt1=0;
unsigned char *pnt;
unsigned char *pn2;
unsigned char padd;
div_t result;
myw->damage(1);myw->redraw();
mybox->damage(1); mybox->redraw();fl_overlay_clear();
mybox->window()->make_current();
mybox->damage(1); mybox->redraw(); /* 2 redraw perche' Double_Window (forse
fl_read_image legge il buffer precedente) */
/*printf("ev_p_x: %d ev_p_y: %d ev_w: %d ev_h: %d\\n", ev_p_x, ev_p_y,
ev_w, ev_h);*/
if (ev_w<0) { ev_p_x=ev_r_x; ev_w=ev_w*(-1); }
if (ev_h<0) { ev_p_y=ev_r_y; ev_h=ev_h*(-1); }
ev_w3=ev_w*3; padd=0;
result = div (ev_w3,4);
njunkb = 4 - result.rem;
if(njunkb == 4) njunkb = 0;
/*printf("ev_p_x: %d ev_p_y: %d ev_w: %d ev_h: %d njunkb: %d\\n",
ev_p_x, ev_p_y, ev_w, ev_h, njunkb);*/
pnt = (unsigned char *) malloc ((ev_w3 * ev_h)+1);
if (pnt == 0){printf("no enougth memory\\n"); exit(1);}
fl_read_image(pnt, ev_p_x, ev_p_y, ev_w, ev_h, 0);
hf_bmp.bfType='MB';
hf_bmp.bfRes1=0; hf_bmp.bfRes2=0;
hf_bmp.bfOffBits=54;
hi_bmp.biSize=40;
hi_bmp.biWidth=ev_w;
hi_bmp.biHeight=ev_h;
hi_bmp.biPlanes=1;
hi_bmp.biBitCount=24;
hi_bmp.biCompression=0;
hi_bmp.biSizeImage=((ev_w * ev_h * 3) + (njunkb * ev_h));
hi_bmp.biXPixPerMeter=0;
hi_bmp.biYPixPerMeter=0;
hi_bmp.biClrUsed=0;
hi_bmp.biClrImportant=0;
hf_bmp.bfSize=54 + hi_bmp.biSizeImage;
if((outbmp = fopen("out.bmp","wb")) == NULL){
printf("Errore in apertura file di out\\n\\n"); }
fwrite (&hf_bmp.bfType, 2, 1, outbmp);
fwrite (&hf_bmp.bfSize, 4, 1, outbmp); /* printf("hf_bmp.bfSize:
%u\\n",hf_bmp.bfSize); */
fwrite (&hf_bmp.bfRes1, 2, 1, outbmp);
fwrite (&hf_bmp.bfRes2, 2, 1, outbmp);
fwrite (&hf_bmp.bfOffBits, 4, 1, outbmp);
fwrite (&hi_bmp.biSize, 4, 1, outbmp);
fwrite (&hi_bmp.biWidth, 4, 1, outbmp);
fwrite (&hi_bmp.biHeight, 4, 1, outbmp);
fwrite (&hi_bmp.biPlanes, 2, 1, outbmp);
fwrite (&hi_bmp.biBitCount, 2, 1, outbmp);
fwrite (&hi_bmp.biCompression, 4, 1, outbmp);
fwrite (&hi_bmp.biSizeImage, 4, 1, outbmp);
fwrite (&hi_bmp.biXPixPerMeter, 4, 1, outbmp);
fwrite (&hi_bmp.biYPixPerMeter, 4, 1, outbmp);
fwrite (&hi_bmp.biClrUsed, 4, 1, outbmp);
fwrite (&hi_bmp.biClrImportant, 4, 1, outbmp);
for(cnt=1;cnt<=ev_h;cnt++)
{
pn2=pnt+(ev_w3*(ev_h-cnt));
for(cnt1=0;cnt1<ev_w3;cnt1=cnt1+3)
{
fwrite ((pn2+cnt1+2),1,1,outbmp);
fwrite ((pn2+cnt1+1),1,1,outbmp);
fwrite ((pn2+cnt1),1,1,outbmp);
}
for(cnt1=0;cnt1<njunkb;cnt1++)
fwrite (&padd, 1, 1, outbmp);
}
free(pnt);
fclose(outbmp);
if (img) img->release();
img = Fl_Shared_Image::get("out.bmp");
if (!img) {
printf("Image file format not recognized!\\n");
return;
}
mybox->redraw();} {selected
}
}
***************************
and here is bmppix.h:
***************************
/* bmppix.h */
typedef struct // 14 bytes
{
unsigned short bfType; // 2 BM
unsigned bfSize; // 4 size of the bitmap file
unsigned short bfRes1; // 2 not used
unsigned short bfRes2; // 2 not used
unsigned bfOffBits; // 4 number of bytes from the
// beginning of the file to
// the starting Pix Data byte
} BMPhf;
typedef struct // 40 bytes
{
unsigned biSize; // 4 size of the Head Info in bytes
unsigned biWidth; // 4 width in pixels
unsigned biHeight; // 4 height in pixels
unsigned short biPlanes; // 2 number of planes (must set to 1)
unsigned short biBitCount; // 2 bits per pixel
// 1: (black/white). In 1-bit mode the color table
// has to contain 2 entries (usually white and
black).
// If a bit in the image data is clear, it points
to
// the first palette entry.
// If the bit is set, it points to the second.
// 4: (16 colors). In 4-bit mode the color table
must contain
// 16 colors. Every byte in the image data
represents two pixels.
// The byte is split into the higher 4 bits and
the lower 4 bits
// and each value of them points to a palette
entry.
// 8: (256 colors). In 8-bit mode every byte
represents a pixel.
// The value points to an entry in the color
table which contains
// 256 entries
// 24: (16.7 million colors). Three bytes
represent one pixel.
// The first byte represents the red part,
// the second the green and the third the blue
part.
// There is no need for a palette because every
pixel
// contains a literal RGB-value, so the palette
is omitted.
unsigned biCompression; // 4 0 for uncompressed images
unsigned biSizeImage; // 4 length of the bitmap image data in bytes
unsigned biXPixPerMeter; // 4 pixels per meter (usually set to 0)
unsigned biYPixPerMeter; // 4 pixels per meter (usually set to 0)
unsigned biClrUsed; // 4 number of colors
unsigned biClrImportant;// 4 number of significant colors
} BMPhi;
typedef struct
{
unsigned char mred;
unsigned char mgre;
unsigned char mblu;
} mRGB;
***************************
bye
rogx
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk