Пример #1
0
void bg_image_input(Fl_Input *w, void *d)
{
    changed=true;

    Fl_String val(w->value());
    filename = fl_file_expand(val);

    if(mini_wpaper) { delete mini_wpaper; mini_wpaper=0; }
    if(mini_image)  { delete mini_image; mini_image=0; }

    Fl_Image *im = Fl_Image::read(filename);
    if(im) {
        im->system_convert();
        float scalew = (float)mini_image_box->w()/(float)desktop->w();
        float scaleh = (float)mini_image_box->h()/(float)desktop->h();
        mini_image = im->scale(int(im->width()*scalew), int(im->height()*scaleh));
        delete im;
    }

    if(mini_image) {
        mini_wpaper = make_image(color, mini_image,
                                 mini_image_box->w(), mini_image_box->h(),
                                 mode, opacity);
        mini_image_box->image(mini_wpaper);
    } else {
        mini_image_box->image(0);
    }

    image_input->value(filename);
    image_input->redraw();
    mini_image_box->redraw();
}
Пример #2
0
void Icon::update_icon()
{
    if(icon_im) delete icon_im;

    Fl_String path(PREFIX"/share/ede/icons/48x48/");
    path += icon_file;

    if(!fl_file_exists(path)) path = icon_file;

    if(fl_file_exists(path))
    {
        icon_im = Fl_Image::read(path, 0);
    } else {
        icon_im = 0;
    }

    if(!icon_im) {
        icon_im = Fl_Image::read(PREFIX"/share/ede/icons/48x48/folder.png", 0);
    }

    if(icon_im) {
        if(icon_im->width()!=48 || icon_im->height()!=48) {
            Fl_Image *old = icon_im;
            icon_im = old->scale(48,48);
            delete old;
        }
        icon_im->mask_type(MASK_ALPHA);
        icon_im->threshold(128);
    }
}
Пример #3
0
void Flcc_ValueBox::generate()
{
    int X = 0, Y = 0, W = w(), H = h();
    box()->inset(X,Y,W,H);

    Fl_Image *im = new Fl_Image(W, H, 32);

    uint32 *dst = (uint32*)im->data();
    uint32 rgb;
    int skip = (im->pitch() - W * im->bytespp()) >> 2;

    for(int y = 0; y < H; y++) {

        float Yf = 255*(1.0-float(y)/H);
        fl_rgb888_from_rgb(rgb, uchar(tr*Yf+.5f), uchar(tg*Yf+.5f), uchar(tb*Yf+.5f));

        for(int x = 0; x < W; x++) {
            *dst++ = rgb;
        }

        dst += skip;
    }
    if(bg) delete bg;
    bg = im;
}
Пример #4
0
void DerivedShared_Image::reload ()
{
    int i;
    FILE * fp;
    uchar header[64];
    Fl_Image * img;

    if (!name_)
        return;

    if ((fp = fl_fopen (name_, "rb")) != NULL)
    {
        if (fread (header, 1, sizeof (header), fp) == 0)
        { /* ignore */
        }
        fclose (fp);
    }
    else
    {
        return;
    }

    if (memcmp (header, "#define", 7) == 0) // XBM file
        img = new Fl_XBM_Image (name_);
    else if (memcmp (header, "/* XPM */", 9) == 0) // XPM file
        img = new Fl_XPM_Image (name_);
    else
    {
        for (i = 0, img = 0; i < num_handlers_; i++)
        {
            // The only difference is the cast
            img = (static_cast<Fl_Image *> (
                (fl_handlers_[i]) (name_, header, sizeof (header))));

            if (img)
                break;
        }
    }

    if (img)
    {
        if (alloc_image_)
            delete image_;

        alloc_image_ = 1;

        if ((img->w () != w () && w ()) || (img->h () != h () && h ()))
        {
            Fl_Image * temp = img->copy (w (), h ());
            delete img;
            image_ = temp;
        }
        else
        {
            image_ = img;
        }

        update ();
    }
};
Пример #5
0
void Flcc_HueBox::generate()
{
    int X = 0, Y = 0, W = w(), H = h();
    box()->inset(X,Y,W,H);

#ifdef UPDATE_HUE_BOX
    const float V = ((Fl_Color_Chooser*)(parent()))->v();
#else
    const float V = 1.0f;
#endif

    Fl_Image *im = new Fl_Image(W, H, 32);

    uint32 *dst = (uint32 *)im->data();
    int skip = (im->pitch() - W * im->bytespp()) >> 2;
    register float r,g,b;

    for(int y = 0; y < H; y++) {

        float Yf = (float)y / H;

        for (int x = 0; x < W; x++)
        {
            float Xf = (float)x / W;
            float H,S; tohs(Xf, Yf, H, S);
            Fl_Color_Chooser::hsv2rgb(H,S,V,r,g,b);
            fl_rgb888_from_rgb(*dst++, uchar(255*r+.5f), uchar(255*g+.5f), uchar(255*b+.5f));
        }
        dst += skip;
    }

    if(bg) delete bg;
    bg = im;
}
Пример #6
0
void desktop_properties(Fl_Widget *, void *arg)
{
    if(!shown) {
        make_desktop_properties();
        shown = true;
    }

    mode = desktop->bg_mode;
    color = desktop->bg_color;
    opacity = desktop->bg_opacity;
    use = desktop->bg_use;
    filename = desktop->bg_filename;

    if(bg_prop_window->visible()) {
        bg_prop_window->show();
        return;
    }

    if(mini_image) { delete mini_image; mini_image=0;  }
    if(mini_wpaper){ delete mini_wpaper; mini_wpaper=0;}

    color_button->selection_color(color);
    mini_image_box->color(color);
    opacity_slider->value(opacity);
    mode_choice->value(mode);
    use_button->value(use);
    image_input->value(filename);

    if(!desktop->bg_filename.empty())
    {
        Fl_Image *im = Fl_Image::read(desktop->bg_filename);
        if(im) {
	    im->system_convert();
            float scalew = (float)mini_image_box->w()/(float)desktop->w();
            float scaleh = (float)mini_image_box->h()/(float)desktop->h();
            mini_image = im->scale(int(im->width()*scalew), int(im->height()*scaleh));
            delete im;
        }
    }

    if(mini_image) {
        mini_wpaper = make_image(color, mini_image,
                                 mini_image_box->w(), mini_image_box->h(),
                                 mode, opacity);
        mini_image_box->image(mini_wpaper);
    } else
        mini_image_box->image(0);

    if(use)
        bg_image_group->activate();
    else {
        bg_image_group->deactivate();
        mini_image_box->image(0);
    }

    bg_prop_window->show();
}
Пример #7
0
Файл: Panner.C Проект: 0mk/non
void
Panner::draw_the_box ( int tx, int ty, int tw, int th )
{
    draw_box();

    Fl_Image *i = 0;

    if ( _bg_image && ( _bg_image->h() != th || projection() != _bg_image_projection ) )
    {
        if ( _bg_image_scaled )
            delete _bg_image;
        else
            ((Fl_Shared_Image*)_bg_image)->release();

        _bg_image = 0;
    }

    if ( ! _bg_image )
    {
        if ( projection() == POLAR )
        {
            if ( th <= 92 )
                i = Fl_Shared_Image::get( PIXMAP_PATH "/non-mixer/panner-sphere-92x92.png" );
            else if ( th <= 502 )
                i = Fl_Shared_Image::get( PIXMAP_PATH "/non-mixer/panner-sphere-502x502.png" );
            else if ( th <= 802 )
                i = Fl_Shared_Image::get( PIXMAP_PATH "/non-mixer/panner-sphere-802x802.png" );
        }
        else
        {
            if ( th <= 92 )
                i = Fl_Shared_Image::get( PIXMAP_PATH "/non-mixer/panner-plane-92x92.png" );
            else if ( th <= 502 )
                i = Fl_Shared_Image::get( PIXMAP_PATH "/non-mixer/panner-plane-502x502.png" );
            else if ( th <= 802 )
                i = Fl_Shared_Image::get( PIXMAP_PATH "/non-mixer/panner-plane-802x802.png" );
        }

        if ( i && i->h() != th )
        {
            Fl_Image *scaled = i->copy( th, th );

            _bg_image = scaled;
            _bg_image_scaled = true;
        }
        else
        {
            _bg_image = i;
            _bg_image_scaled = false;
        }
    }
    
    _bg_image_projection = projection();

    if ( _bg_image )
        _bg_image->draw( tx, ty );
}
// Tests Open SLImage
TEST(ImageControllerTest, loadSLImageWithImageController) {
    ImageController imageController;
    imageController.open(filename);
    Fl_Image * image = imageController.getCurrentImage();
    ASSERT_NE((void *)NULL, image ) << "File did not open " << filename;
    EXPECT_EQ(30, image->w());
    EXPECT_EQ(30, image->h());
    EXPECT_EQ(3, image->d());
    EXPECT_EQ(92, image->ld()); //4 byte aligned under OpenCV not under FLTK
}
// Tests load OpenCVImage
TEST(ImageControllerTest, loadOpenCVImage) {
	OpenCVImage * openCVImage = OpenCVImage::NULL_OBJECT->load(filename);
    ASSERT_NE((void *)NULL, openCVImage ) << "File did not open " << filename;
    Fl_Image * image = openCVImage->getFlImage();
    ASSERT_NE((void *)NULL, image ) << "File did not open " << filename;
    EXPECT_EQ(30, image->w());
    EXPECT_EQ(30, image->h());
    EXPECT_EQ(3, image->d());
    EXPECT_EQ(92, image->ld()); //4 byte aligned under OpenCV not under FLTK
    EXPECT_EQ(8, openCVImage->getDepth());
    EXPECT_EQ(92, openCVImage->getWidthStep());
}
Пример #10
0
Fl_Image *Fl_Image_Filter::apply_to_new(Fl_Image *image, Fl_Rect *rect, Fl_Image_Filter *filter, float val1, float val2, float val3)
{
    Fl_Rect r(0,0,image->width(),image->height());
    if(!rect) { rect = &r; }
    Fl_Image *ret = new Fl_Image(*image);

    uint8 *data = ret->data();
    if(!filter->execute(&data, *rect, ret->pitch(), ret->format(), val1, val2, val3)) {
        delete ret;
        return 0;
    }
    return ret;
}
Пример #11
0
    void draw() {
        if(!(damage()&FL_DAMAGE_ALL)) return;

        int X=0,Y=0,W=w(),H=h();
        box()->inset(X,Y,W,H);

        if(image()) {
            draw_frame();
            fl_push_clip(X,Y,W,H);

            Fl_Image *im = image();

            W=im->width();
            H=im->height();
            int pbw = w() - 10;
            int pbh = h() - 10;
            if(W > pbw || H > pbh) {
                W = pbw;
                H = W * im->height() / im->width();
                if(H > pbh) {
                    H = pbh;
                    W = H * im->width() / im->height();
                }
            }
            X=(w()/2)-W/2;
            Y=(h()/2)-H/2;
            if(X<5) X=5;
            if(Y<5) Y=5;

            im->mask_type(MASK_NONE);
            im->draw(X,Y,W,H,FL_ALIGN_SCALE);

            fl_clip_out(X,Y,W,H);

            X=0,Y=0,W=w(),H=h();
            box()->inset(X,Y,W,H);

            fl_color(color());
            fl_rectf(X,Y,W,H);

            fl_pop_clip();

        } else {

            draw_box();

            if(w()<=120) label_size(8);
            if(w()>120) label_size(10);
            if(w()>180) label_size(12);
            if(w()>250) label_size(14);

            if(label()[0]=='?'&&label()[1]=='\0') label_size(100);

            draw_label(X, Y, W, H, align());
        }
    }
FltkImage * FltkImage::load(char const * filename) const {
	if (SLStringUtil::empty(filename))
		return 0;
	Fl_Shared_Image *sharedImage = Fl_Shared_Image::get(filename);
	Fl_Image * image = sharedImage->copy();
	sharedImage->release();
	if ( image->h() == 0 ) {
		delete image;
		return 0;
	}
	FltkImage * result = new FltkImage(image);
	result->setFilename(filename);
	return result;
}
Пример #13
0
Fl_Image *make_bg(int w, int h)
{
#ifdef GENERATE_16BIT
    Fl_Image *ret = new Fl_Image(w, h, 16, 0, true, 0x0000F000, 0x00000F00, 0x000000F0, 0x0000000F);
#else
    Fl_Image *ret = new Fl_Image(w, h, 32, 0, true, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
#endif

    printf("BG Format:\n Rmask: 0x%08x\n Gmask: 0x%08x\n Bmask: 0x%08x\n", ret->format()->Rmask, ret->format()->Gmask, ret->format()->Bmask);

    // pitch = WORD alignment bits per line
    int pitch=Fl_Renderer::calc_pitch(ret->format()->bytespp, w);
    int skip = pitch - w * ret->format()->bytespp;

    uint8 *p = ret->data();
    uint8 r,g,b;

    for (int y = 0; y < h; y++) {
        double Y = double(y)/(h-1);
        for (int x = 0; x < w; x++) {
            double X = double(x)/(w-1);
            r = uchar(255*((1-X)*(1-Y))); // red in upper-left
            g = uchar(255*((1-X)*Y));	// green in lower-left
            b = uchar(255*(X*Y));	// blue in lower-right
            fl_assemble_rgb(p,
                            ret->format()->bytespp, ret->format(),
                            r, g, b);
            p+=ret->format()->bytespp;
        }
        p+=skip;
    }
    return ret;
}
Пример #14
0
Fl_Image *Fl_Image::scale(int W, int H)
{
    Fl_Image *ret = new Fl_Image(W, H, bitspp());
    ret->format()->copy(format());

    Fl_Rect olds(0,0,width(),height()); Fl_Rect news(0,0,W,H);
    bool success = Fl_Renderer::stretch(m_data, bytespp(), pitch(), &olds,
                                        ret->data(), bytespp(), ret->pitch(), &news);
    if(!success) {
        delete ret;
        ret = 0;
    }
    return ret;
}
Пример #15
0
MovableIcon::MovableIcon(Icon *i)
: Fl_Window(desktop->x()+i->x(), desktop->y()+i->y(), i->w(), i->h())
{
    icon = i;
    set_override();
    create();

    Fl_Image *im = i->icon_im;
    if(im)
    {
        Pixmap mask = im->create_mask(im->width(), im->height());
        XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet);

        align(FL_ALIGN_INSIDE);
        image(im);
    }
}
Пример #16
0
MovableIcon::MovableIcon(Icon* i) : Fl_Window(i->x(), i->y(), i->w(), i->h()), icon(i)
{
	assert(icon != NULL);
	set_override();
	create();

	Fl_Image* img = icon->icon_image();
	if(img)
	{
#ifdef SHAPE
		Pixmap mask = img->create_mask(img->width(), img->height());
		XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet);
#endif
		align(FL_ALIGN_INSIDE);
		image(img);
	}
}
Пример #17
0
void Icon::draw()
{
    Fl_Flags f=0;
    Fl_Image *im = icon_im;
    if(focused()) {
        f=FL_SELECTED;
    }

    if(im)
        im->draw(0, 0, w(), h(),f);
    else {
        fl_color(FL_RED);
        fl_rect(0,0,w(),h());
        fl_color(FL_BLACK);
        fl_rectf(1,1,w()-2,h()-2);
        fl_color(FL_WHITE);
        fl_font(label_font()->bold(), 10);
        fl_draw("NO ICON FOUND!", 1, 1, w()-2, h()-2, FL_ALIGN_TOP|FL_ALIGN_LEFT|FL_ALIGN_WRAP);
    }

    int X = w()-(w()/2)-(lwidth/2);
    int Y = h()+2;

    if(!label_trans) {
        fl_color(label_background);
        fl_rectf(X,Y,lwidth,lheight);
    }

    if(focused()) {
        focus_box()->draw(X, Y, lwidth, lheight, color(), 0);
    }

    fl_font(label_font(), label_size());

    // A little shadow, from Dejan's request :)
    // SUCKS!
    /*fl_color(fl_darker(label_color()));
    fl_draw(label(), X-1, Y+1, lwidth, lheight, flags());
    fl_draw(label(), X, Y+1, lwidth, lheight, flags());
    */

    fl_color(label_color());
    fl_draw(label(), X, Y, lwidth, lheight, flags());
}
Пример #18
0
/* =============================================================================
 =============================================================================== */
int C3DSceneMgr::createTexture(string strFileName, int &width, int &height, int iTxMode)
{
	if (strFileName == "") //  Return from the function if no file name was passed in
		return -1;
	if (!fileexists(strFileName))
		return -1;

	//  Load the image and store the data
	int textureID = -1;
	if (getExt(strFileName) == ".dds")
	{
		DDS_IMAGE_DATA	*pDDSImageData = NULL;
		if ((pDDSImageData = loadDDSTextureFile(strFileName)) != NULL)
		{
			textureID = createTextureDDS(pDDSImageData);
			height = pDDSImageData->sizeY;
			width = pDDSImageData->sizeX;
		}
		else	//  case where worldwind wraps jpegs in dds files
		{
			Fl_RGB_Image *img = new Fl_JPEG_Image(strFileName.c_str());
			if (img->d() == 0)
				return -1;
			width = img->w();
			height = img->h();
			const unsigned char *pData = (const unsigned char *) img->data()[0];
			textureID = createTexture(pData, width, height, GL_RGB, GL_RGB, iTxMode);
			delete img;
		}
	}
	else
	{
		Fl_Image * img = openTextureFile(strFileName);
		if (img == NULL)
			return -1;
		width = img->w();
		height = img->h();
		const unsigned char *pData = (const unsigned char *) img->data()[0];
		textureID = createTexture(pData, width, height, img->d() == 4 ? GL_RGBA : GL_RGB, GL_RGBA, iTxMode);
		delete img;
	}

	return textureID;
}
Пример #19
0
void bg_image_browse(Fl_Button *w, void *d)
{
    changed=true;
    fc_initial_preview = true;
    const char *f=fl_select_file(image_input->value(),
                                 _("All Files, *,"
                                   "Png Images, *.png,"
                                   "Xpm Images, *.xpm,"
                                   "Jpeg Images, *.{jpg|jpeg},"
                                   "Gif Images, *.gif,"
                                   "Bmp Images, *.bmp"),
                                 _("Choose wallpaper:")
                                );

    if(f) {
        if(mini_wpaper) { delete mini_wpaper; mini_wpaper=0; }
        if(mini_image)  { delete mini_image; mini_image=0; }

        filename = f;

        Fl_Image *im = Fl_Image::read(f);
        if(im) {
            im->system_convert();
            float scalew = (float)mini_image_box->w()/(float)desktop->w();
            float scaleh = (float)mini_image_box->h()/(float)desktop->h();
            mini_image = im->scale(int(im->width()*scalew), int(im->height()*scaleh));
            delete im;
        }

        if(mini_image) {
            mini_wpaper = make_image(color, mini_image,
                                     mini_image_box->w(), mini_image_box->h(),
                                     mode, opacity);
            mini_image_box->image(mini_wpaper);
        } else
            mini_image_box->image(0);

        image_input->value(filename);
        image_input->redraw();
        mini_image_box->redraw();
        delete []f;
    }
}
Пример #20
0
void DesktopIcon::load_icon(int face) {
	const char* ic = NULL;

	if(face != ICON_FACE_TWO) {
		if(!settings->icon.empty())
			ic = settings->icon.c_str();
	} else {
		if(!settings->icon2.empty())
			ic = settings->icon2.c_str();
	}

	if(!ic)
		return;

	if(!IconLoader::set(this, ic, ICON_SIZE_HUGE)) {
		E_DEBUG(E_STRLOC ": Unable to load %s icon\n", ic);
		return;
	}	

	/* fetch image object for sizes */
	Fl_Image* img = image();

	int img_w = img->w();
	int img_h = img->h();

	/* resize box if icon is larger */
	if(img_w > ICON_SIZE_MIN_W || img_h > ICON_SIZE_MIN_H)
		size(img_w + OFFSET_W, img_h + OFFSET_H);

	/* darker icon version for selection */
	delete darker_img;

	darker_img = img->copy(img->w(), img->h());
	darker_img->color_average(FL_BLUE, 0.6);
}
Пример #21
0
MovableIcon::MovableIcon(DesktopIcon* ic) : Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0) {
	E_ASSERT(icon != NULL);

	set_override();
	color(ic->color());

	begin();
		/*
		 * Force box be same width/height as icon so it
		 * can fit inside masked window.
		 */
#ifdef HAVE_SHAPE 
		Fl_Image* img = ic->icon_image();
		if(img)
			icon_box = new Fl_Box(0, 0, img->w(), img->h());
		else
			icon_box = new Fl_Box(0, 0, w(), h());
#else
		icon_box = new Fl_Box(0, 0, w(), h());
#endif
		icon_box->image(ic->icon_image());
	end();
}
Пример #22
0
void C3DSceneMgr::createNewTileTexture(string strFileName)
{
	Fl_Image * img = openTextureFile(strFileName);
	if (img == NULL)
		return;
	int width = img->w();
	int height = img->h();
	const unsigned char *pOld = (const unsigned char *) img->data()[0];

	//image processing on water
	unsigned char	*pData = NULL;
	if (!mem_alloc(pData, width * height * 3))
		return;

	unsigned char	*p = pData;
	for (int i = 0; i < width * height; i++, p+=3, pOld+=3)
	{
		p[0] = pOld[0];		//red
		p[1] = pOld[1];		//green
		if (pOld[2] < 220 && pOld[2] > pOld[1]*5/4 && pOld[2] > pOld[0]*5/4)
			p[2] = pOld[2] + (220-pOld[2])/4;
		else
			p[2] = pOld[2];		//blue
	}

	string strnew = strFileName;
	setExt(strnew, ".png");
	saveImage(strnew, pData, width, height);
	int txID = createTexture(pData, width, height, GL_RGB, GL_RGB, TX_CLAMP_EDGE);

	delete pData;
	delete img;

	setExt(strFileName, ".dds");
	saveDDSTextureFile(strFileName, txID);
	deleteTexture(txID);
}
Пример #23
0
MovableIcon::MovableIcon(DesktopIcon* ic) :
Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0), opacity_atom(0) 
{
	E_ASSERT(icon != NULL);

	set_override();
	color(ic->color());

	begin();
		/* force box be same width/height as icon so it can fit inside masked window */
#ifdef HAVE_SHAPE 
		Fl_Image* img = ic->image();
		if(img)
			icon_box = new Fl_Box(0, 0, img->w(), img->h());
		else
			icon_box = new Fl_Box(0, 0, w(), h());
#else
		icon_box = new Fl_Box(0, 0, w(), h());
#endif
		icon_box->image(ic->image());
	end();

	opacity_atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False);
}
Пример #24
0
void Fl_Image::copy(Fl_Image &src, Fl_Image &dst)
{
    dst.clear();

    dst.m_width     = src.m_width;
    dst.m_height    = src.m_height;
    dst.m_pitch     = src.m_pitch;
    dst.m_threshold = src.m_threshold;
    dst.m_quality   = src.m_quality;
    dst.m_state_effect = src.m_state_effect;
    dst.m_data_alloc = true;

    dst.m_id_alloc = dst.m_mask_alloc = false;
    dst.id = dst.mask = 0;

    dst.m_fmt.copy(&src.m_fmt);

    dst.m_data = (uint8*)malloc(sizeof(uint8) * (src.m_height*src.m_pitch));
    memcpy(dst.m_data, src.m_data, src.m_height*src.m_pitch);
}
Пример #25
0
/* =============================================================================
 =============================================================================== */
int C3DSceneMgr::createUITexture(string strFileName, int &width, int &height, int &txWidth)
{
	Fl_Image * img = openTextureFile(strFileName);
	if (img == NULL) {
		return -1;
	}

	width = img->w();
	height = img->h();

	//  need to add an alpha channel to properly overlay on existing textures
	const unsigned char *pData = NULL;
	if (img->d() == 3)
		pData = makeRGBA((const unsigned char *) img->data()[0], width, height);
	else
		pData = (const unsigned char *) img->data()[0];

	GLuint	textureID;
	glGenTextures(1, &textureID);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glBindTexture(GL_TEXTURE_2D, textureID);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

	int txHeight = height;
	txWidth = (width <= 64) ? 64 : (width <= 128) ? 128 : width;

	const unsigned char *pDataNew = NULL;
	if (width != txWidth)
	{
		pDataNew = padOut(pData, width, height, txWidth);
		txHeight = txWidth;
	}

	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, txWidth, txHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pDataNew ? pDataNew : pData);

	if (pDataNew) delete[] pDataNew;
	if (img->d() == 3) delete[] pData;
	delete img;

	return textureID;
}
Пример #26
0
WPaper *make_image(Fl_Color bg_color,
                     Fl_Image *im,
                     int w, int h,
                     int mode,
                     uchar opacity=255)
{
    // secret box render function from Fl_Image :)
    extern uint8 *render_box(int w, int h, int bitspp, uint color, Fl_Colormap *pal, uint8 *buffer);

    Fl_PixelFormat *fmt = Fl_Renderer::system_format();
    WPaper *bg_image = new WPaper(w, h, Fl_Renderer::system_format());

    int iw=im->width(), ih=im->height();
    int ix=0, iy=0;
    int xoff=0, yoff=0;
    Fl_Image *newim = im;

    switch(mode) {
    //CENTER
    case 0: {
        ix=(w/2)-(iw/2);
        iy=(h/2)-(ih/2);
        if(ix<0) xoff=-ix; if(iy<0) yoff=-iy;
        if(ix<0) ix=0; if(iy<0) iy=0;
    }
    break;

    //STRECH
    case 1: {
        ix=0, iy=0, iw=w, ih=h;
        if(w!=im->width()||h!=im->height()) {
            newim = im->scale(w,h);
        }
    }
    break;

    //STRETCH ASPECT
    case 2: {
        int pbw = w, pbh = h;
        iw = pbw;
        ih = iw * im->height() / im->width();
        if(ih > pbh) {
            ih = pbh;
            iw = ih * im->width() / im->height();
        }
        ix=(w/2)-(iw/2), iy=(h/2)-(ih/2);
        if(ix<0) ix=0; if(iy<0) iy=0;
        if(iw>w) iw=w; if(ih>h) ih=h;
        if(iw!=im->width()||ih!=im->height()) {
            newim = im->scale(iw,ih);
        }
    }
    break;
    }

    // This could be an option, opacity
    newim->format()->alpha = opacity;

    if( (iw<w || ih<h) || newim->format()->alpha!=255) {
        // If image doesnt fill the whole screen, or opacity < 255
        // fill image first with bg color.
        render_box(w, h, fmt->bitspp, bg_color, fmt->palette, bg_image->data());
    }

    if(iw>w) iw=w; if(ih>h) ih=h;
    Fl_Rect r(xoff, yoff, iw, ih);
    Fl_Rect r2(ix,iy, iw, ih);

    if(newim->format()->alpha>0) {
        // Blit image data to our bg_image
        bg_image->check_map(newim->format());
        Fl_Renderer::alpha_blit(newim->data(), &r, newim->format(), newim->pitch(),
                                bg_image->data(), &r2, bg_image->format(), bg_image->pitch(),
                                0);
    }

    if(newim!=im)
        delete newim;

    return bg_image;
}
Пример #27
0
void tabbar::draw() {
    const u32 startx = x();
    const u32 endx = x() + w() - 1;

    const u32 gradarea = h() - 2;
    u32 i, j;

    // bg
    u32 r1 = 63, g1 = 72, b1 = 81;
    u32 r2 = 38, g2 = 48, b2 = 59;
    for (i = 0; i <= gradarea; i++) {
        const float pos = i / (float) gradarea;

        fl_color(mix(r1, r2, pos),
                 mix(g1, g2, pos),
                 mix(b1, b2, pos));

        const u32 posy = y() + 1 + i;
        fl_line(startx, posy, endx, posy);
    }

    // Borders
    fl_color(37, 46, 52);
    fl_line(startx, y(), endx, y());
    fl_line(startx, y() + h() - 1, endx, y() + h() - 1);

    // Tabs
    u32 max;
    u32 tabw = calctabw(&max, w());

    bool highborder = false;
    if ((mousex - x()) % tabw > tabw / 2)
        highborder = true;

    u32 posx = x();
    const u32 lowy = y();
    const u32 highy = y() + h() - 1;
    for (i = 0; i < max; i++) {
        bool hover = false;
        // Borders
        fl_color(FL_BLACK);
        if (!i)
            fl_line(posx, lowy, posx, highy);
        fl_line(posx + tabw, lowy, posx + tabw, highy);

        // Bg
        r1 = 83, g1 = 92, b1 = 101;
        r2 = 58, g2 = 68, b2 = 79;

        if (i == g->curtab) {
            r1 = 100, g1 = 160, b1 = 191;
            r2 = 42, g2 = 100, b2 = 125;
        } else if ((mousein && mousex >= posx && mousex <= (posx + tabw - 1)) ||
                   (!firstpress && longorder.size() && longorder[longpress] == i)) {
            r1 = 150, g1 = 150, b1 = 191;
            r2 = 100, g2 = 100, b2 = 155;
            hover = true;
        }

        if (dragging && mousein && mousex >= posx && mousex <= (posx + tabw - 1)) {
            fl_color(FL_WHITE);
            if (!highborder)
                fl_line(posx, lowy, posx, highy);
            else
                fl_line(posx + tabw, lowy, posx + tabw, highy);
        }

        for (j = 0; j <= gradarea; j++) {
            const float pos = j / (float) gradarea;

            fl_color(mix(r1, r2, pos),
                     mix(g1, g2, pos),
                     mix(b1, b2, pos));

            const u32 posy = y() + 1 + j;
            fl_line(posx + 1, posy, posx + tabw - 1, posy);
        }

        // Icon
        Fl_Image *img = g->tabs[i].icon;
        if (!img)
            img = Fl_Shared_Image::get("newtab.png");

        const u32 imgy = y() + (h() - 16) / 2;
        img->draw(posx + 4, imgy, 16, 16);

        // Text
        fl_color(200, 200, 200);
        if (i == g->curtab)
            fl_color(FL_WHITE);
        else if (hover)
            fl_color(230, 230, 230);
        fl_font(labelfont(), labelsize());

        char tmp[80];
        memset(tmp, 0, 80);
        strncpy(tmp, g->tabs[i].title(), 79);

        int textw = 0, texth = 0;
        fl_measure(tmp, textw, texth, 0);

        const u32 textarea = tabw - 2 - 8 - 16 - 4;
        while ((u32) textw >= textarea) {
            // Shorten it until it fits
            const u32 len = strlen(tmp) - 1;
            tmp[len] = '\0';
            tmp[len - 1] = '.';
            tmp[len - 2] = '.';
            tmp[len - 3] = '.';

            textw = texth = 0;
            fl_measure(tmp, textw, texth, 0);
        }

        const u32 texty = y() - fl_descent() + fl_height() + (h() - fl_height())/2;
        fl_draw(tmp, posx + 2 + 8 + 16, texty);

        posx += tabw;
    }
}
Пример #28
0
    virtual Bitmap *Load(IStream *stream) {
        SPADES_MARK_FUNCTION();

        // read all
        std::string data = stream->ReadAllBytes();

        // copy to buffer
        Fl_Image *img = LoadFltkImage(data);

        SPAssert(img);
        SPAssert(img->count() >= 1);

        const unsigned char* inPixels =
            (const unsigned char *)img->data()[0];
        int depth = img->d();
        int width = img->w();
        int height = img->h();
        int pitch = width * depth + img->ld();

        Handle<Bitmap> bmp;
        try {
            bmp = new Bitmap(width, height);
        } catch(...) {
            delete img;
            throw;
        }
        try {
            unsigned char *outPixels = (unsigned char *)bmp->GetPixels();

            if(pitch == width * 4 && depth == 4) {
                // if the format matches the requirement of Bitmap,
                // just use it
                memcpy(outPixels, inPixels, pitch * height);
            } else {
                // convert
                const unsigned char* line;
                for(int y = 0; y < height; y++) {
                    line = inPixels;
                    for(int x = 0; x < width; x++) {
                        uint8_t r, g, b, a;
                        switch(depth) {
                        case 1:
                            r = g = b = *(line++);
                            a = 255;
                            break;
                        case 2:
                            r = g = b = *(line++);
                            a = *(line++);
                            break;
                        case 3:
                            r = *(line++);
                            g = *(line++);
                            b = *(line++);
                            a = 255;
                            break;
                        case 4:
                            r = *(line++);
                            g = *(line++);
                            b = *(line++);
                            a = *(line++);
                            break;
                        default:
                            SPAssert(false);
                        }
                        *(outPixels++) = r;
                        *(outPixels++) = g;
                        *(outPixels++) = b;
                        *(outPixels++) = a;
                    }
                    inPixels += pitch;
                }
            }
            delete img;
            return bmp.Unmanage();
        } catch(...) {
            delete img;
            throw;
        }
    }
Пример #29
0
//=============================================================================
Fl_Image * openTextureFile(string strFileName)
{
	Fl_Image *img = NULL;
	try
	{
		if (getExt(strFileName) == ".jpg" || getExt(strFileName) == ".jpeg")
			img = new Fl_JPEG_Image(strFileName.c_str());
		else if (getExt(strFileName) == ".png")
			img = new Fl_PNG_Image(strFileName.c_str());
		else
			img = new Fl_BMP_Image(strFileName.c_str());
	}
	catch(std::bad_alloc x)
	{
		mem_alloc_failure(__FILE__, __LINE__);
		return NULL;
	}

	//  return if no image
	if (img->d() == 0 || img->h() == 0 || img->w() == 0)
	{
		delete img;
		return NULL;
	}

	//  downsize if image is too big
	if (img->h() > 4096 || img->w() > 4096)
	{
		cout << ("Downsizing image to maximum of 4096 a side");
		int h = img->h() >= img->w() ? 4096 : 4096 * img->h() / img->w();
		int w = img->w() >= img->h() ? 4096 : 4096 * img->w() / img->h();
		Fl_Image *img2 = img->copy(w, h);
		delete img;
		img = img2;
	}
	
	return img;
}
Пример #30
0
void DesktopIcon::draw(void) { 
	// draw_box(FL_UP_BOX, FL_BLACK);

	if(image() && (damage() & FL_DAMAGE_ALL)) {
		Fl_Image* im = image();

		/* center image in the box */
		int ix = (w()/2) - (im->w()/2);
		int iy = (h()/2) - (im->h()/2);
		ix += x();
		iy += y();

		/* darker_img is always present if image() is present */
		if(is_focused())
			darker_img->draw(ix, iy);
		else
			im->draw(ix, iy);

		E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
	}

	if(gsettings->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
		int X = x() + w()-(w()/2)-(lwidth/2);
		int Y = y() + h() + LABEL_OFFSET;

		Fl_Color old = fl_color();

		if(!gsettings->label_transparent) {
			fl_color(gsettings->label_background);
			fl_rectf(X, Y, lwidth, lheight);
		}

		int old_font = fl_font();
		int old_font_sz = fl_size();

		/* draw with icon's font */
		fl_font(labelfont(), labelsize());

		/* pseudo-shadow */
		fl_color(FL_BLACK);
		fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);

		fl_color(gsettings->label_foreground);
		fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);

		/* restore old font */
		fl_font(old_font, old_font_sz);

		if(is_focused()) {
			/* draw focused box on our way so later this can be used to draw customised boxes */
			fl_color(gsettings->label_foreground);
			fl_line_style(FL_DOT);

			fl_push_matrix();
			fl_begin_loop();
				fl_vertex(X, Y);
				fl_vertex(X + lwidth, Y);
				fl_vertex(X + lwidth, Y + lheight);
				fl_vertex(X, Y + lheight);
				fl_vertex(X, Y);
			fl_end_loop();
			fl_pop_matrix();

			/* revert to default line style */
			fl_line_style(0);
		}

		/* revert to old color whatever that be */
		fl_color(old);
		E_DEBUG(E_STRLOC ": DesktopIcon label redraw\n");
	}
}