示例#1
0
QImage imageForIconString(const QString& name, int size, GtkIconTheme* theme)
{
    if (!theme) {
        theme = gtk_icon_theme_get_default();
    }
    QByteArray utf8Name = name.toUtf8();

    /* Load the icon by creating a GIcon from the string icon_name.
       icon_name can contain more than a simple icon name but possibly
       a string as returned by g_icon_to_string().
    */
    GObjectScopedPointer<GIcon> icon(g_icon_new_for_string(utf8Name.data(), NULL));
    GScopedPointer<GtkIconInfo, gtk_icon_info_free> iconInfo;
    iconInfo.reset(gtk_icon_theme_lookup_by_gicon(
        theme,
        icon.data(),
        size,
        (GtkIconLookupFlags)0)
        );

    if (!iconInfo) {
        UQ_WARNING << "Failed to find icon:" << name;
        return QImage();
    }

    GObjectScopedPointer<GdkPixbuf> pixbuf(gtk_icon_info_load_icon(iconInfo.data(), NULL));
    if (!pixbuf) {
        UQ_WARNING << "Failed to load icon:" << name;
        return QImage();
    }

    return imageForPixbuf(pixbuf.data(), name);
}
	void blend(drawable_type dw, const rectangle& area, pixel_color_t color, double fade_rate)
	{
		if (fade_rate <= 0) return;
		if (fade_rate > 1) fade_rate = 1;

		rectangle r;
		if (false == ::nana::overlap(rectangle{ drawable_size(dw) }, area, r))
			return;

		unsigned red = static_cast<unsigned>((color.value & 0xFF0000) * fade_rate);
		unsigned green = static_cast<unsigned>((color.value & 0xFF00) * fade_rate);
		unsigned blue = static_cast<unsigned>((color.value & 0xFF) * fade_rate);

		double lrate = 1 - fade_rate;
		pixel_buffer pixbuf(dw, r.y, r.height);

		for (std::size_t row = 0; row < r.height; ++row)
		{
			auto i = pixbuf.raw_ptr(row) + r.x;
			const auto end = i + r.width;
			for (; i < end; ++i)
			{
				unsigned px_r = ((static_cast<unsigned>((i->value & 0xFF0000) * lrate) + red) & 0xFF0000);
				unsigned px_g = ((static_cast<unsigned>((i->value & 0xFF00) * lrate) + green) & 0xFF00);
				unsigned px_b = ((static_cast<unsigned>((i->value & 0xFF) * lrate) + blue) & 0xFF);
				i->value = (px_r | px_g | px_b);
			}
		}
		pixbuf.paste(nana::rectangle(r.x, 0, r.width, r.height), dw, point{r.x, r.y});
	}
示例#3
0
			void _m_render_edge_nimbus(core_window_t* wd, const nana::rectangle & visual)
			{
				nana::rectangle r(visual);
				r.pare_off(-static_cast<int>(weight()));
				nana::rectangle good_r;
				if(nana::gui::overlap(r, nana::rectangle(wd->root_graph->size()), good_r))
				{
					if(	(good_r.x < wd->pos_root.x) || (good_r.y < wd->pos_root.y) ||
						(good_r.x + good_r.width > visual.x + visual.width) || (good_r.y + good_r.height > visual.y + visual.height))
					{
						nana::paint::graphics * graph = wd->root_graph;
						nana::paint::pixel_buffer pixbuf(graph->handle(), r);

						pixel_rgb_t px0, px1, px2, px3;
						
						px0 = pixbuf.pixel(0, 0);
						px1 = pixbuf.pixel(r.width - 1, 0);
						px2 = pixbuf.pixel(0, r.height - 1);
						px3 = pixbuf.pixel(r.width - 1, r.height - 1);

						good_r.x = good_r.y = 1;
						good_r.width = r.width - 2;
						good_r.height = r.height - 2;
						pixbuf.rectangle(good_r, wd->color.active, 0.95, false);

						good_r.x = good_r.y = 0;
						good_r.width = r.width;
						good_r.height = r.height;
						pixbuf.rectangle(good_r, wd->color.active, 0.4, false);

						pixbuf.pixel(0, 0, px0);
						pixbuf.pixel(r.width - 1, 0, px1);
						pixbuf.pixel(0, r.height - 1, px2);
						pixbuf.pixel(r.width - 1, r.height - 1, px3);

						pixbuf.paste(wd->root, r.x, r.y);

						std::vector<typename window_layer::wd_rectangle> overlaps;
						if(window_layer::read_overlaps(wd, visual, overlaps))
						{
							typename std::vector<typename window_layer::wd_rectangle>::iterator i = overlaps.begin(), end = overlaps.end();
							for(; i != end; ++i)
							{
								const nana::rectangle& r = i->r;
								graph->paste(wd->root, r, r.x, r.y);
							}
						}
					}
					else
						wd->root_graph->paste(wd->root, visual, visual.x, visual.y);
				}
			}
示例#4
0
			void _m_render_edge_nimbus(core_window_t* wd, const nana::rectangle & visual)
			{
				auto r = visual;
				r.pare_off(-static_cast<int>(weight()));
				rectangle good_r;
				if (overlap(r, rectangle{ wd->root_graph->size() }, good_r))
				{
					if ((good_r.x < wd->pos_root.x) || (good_r.y < wd->pos_root.y) || 
						(good_r.right() > visual.right()) || (good_r.bottom() > visual.bottom()))
					{
						auto graph = wd->root_graph;
						nana::paint::pixel_buffer pixbuf(graph->handle(), r);

						pixel_argb_t px0, px1, px2, px3;
						
						px0 = pixbuf.pixel(0, 0);
						px1 = pixbuf.pixel(r.width - 1, 0);
						px2 = pixbuf.pixel(0, r.height - 1);
						px3 = pixbuf.pixel(r.width - 1, r.height - 1);

						good_r.x = good_r.y = 1;
						good_r.width = r.width - 2;
						good_r.height = r.height - 2;
						pixbuf.rectangle(good_r, wd->scheme->activated.get_color(), 0.95, false);

						good_r.x = good_r.y = 0;
						good_r.width = r.width;
						good_r.height = r.height;
						pixbuf.rectangle(good_r, wd->scheme->activated.get_color(), 0.4, false);

						pixbuf.pixel(0, 0, px0);
						pixbuf.pixel(r.width - 1, 0, px1);
						pixbuf.pixel(0, r.height - 1, px2);
						pixbuf.pixel(r.width - 1, r.height - 1, px3);

						pixbuf.paste(wd->root, { r.x, r.y });

						std::vector<typename window_layer::wd_rectangle> overlaps;
						if(window_layer::read_overlaps(wd, visual, overlaps))
						{
							for(auto & wdr : overlaps)
								graph->paste(wd->root, wdr.r, wdr.r.x, wdr.r.y);
						}
					}
					else
						wd->root_graph->paste(wd->root, visual, visual.x, visual.y);
				}
			}
 virtual void do_refresh_form_data()
 {    
   Gtk::Entry *entry;
   int w, h;
   _be.get_size(w, h);
   _xml->get_widget("width_entry", entry);
   entry->set_text(strfmt("%i", w));
   _xml->get_widget("height_entry", entry);
   entry->set_text(strfmt("%i", h));
   
   Gtk::CheckButton *check;
   _xml->get_widget("aspect_check", check);
   check->set_active(_be.get_keep_aspect_ratio());
 
   Glib::RefPtr<Gdk::Pixbuf> pixbuf(Gdk::Pixbuf::create_from_file(_be.get_attached_image_path()));
   if (pixbuf)
     _image->set(pixbuf);  
   else
     g_message("ImageEditorFE: can not set image from %s[%s]", _be.get_filename().c_str(), _be.get_attached_image_path().c_str());    
 }
/** Returns a pointer to a new image, based on 'surface'
    but with changed hue. Changing the hue means to "rotate"
    the color spectrum. You can read more about the HSV color
    model on the Internet.
    This method is used to change the color of a sprite
    (e.g. a car or another object). I suggest to make the
    basic images in a red color-spectrum and create all
    other colors from it.
    For examples, please visit the Trophy homepage developer
    corner (http://trophy.sourceforge.net)
    \param hue Changing of hue: 0-360
    \param saturation Changing of saturation: -100...100
    \param value Changing of value (Color intensity): -100...100
*/
CL_PixelBuffer
CAImageManipulation::changeHSV( CL_PixelBuffer pixBufOriginal,
                                int hue, int saturation, int value )
{
    CL_PixelBuffer pixbuf(pixBufOriginal.get_width(), pixBufOriginal.get_height(), pixBufOriginal.get_format());
    pixBufOriginal.convert(pixbuf);

    CL_TextureFormat pf = pixbuf.get_format();
    // Check that we handle this pixel format
    if(pf != CL_TextureFormat::cl_rgba8 && pf != CL_TextureFormat::cl_rgb8 &&
            pf != CL_TextureFormat::cl_rgba4 )
    {
        std::cout << "Unknow pixel format !" << pf << std::endl;
        return pixBufOriginal.copy();
    }

    // Calc size in bytes:
    //
    int bpp = pixBufOriginal.get_bytes_per_pixel();
    int size = pixbuf.get_width() * pixbuf.get_height() * bpp;

    pixbuf.lock(CL_BufferAccess::cl_access_read_write);

    unsigned char *data = (unsigned char*)pixbuf.get_data();

    // Change hue:
    //
    int r, g, b, a(0);
    int h, s, v;

    for(int i=0; i<size; i+=bpp )
    {
        if(pf == CL_TextureFormat::cl_rgba8)
        {
            a = data[i];
            b = data[i+1];
            g = data[i+2];
            r = data[i+3];
        } else if (pf == CL_TextureFormat::cl_rgb8)
        {
            std::cout << "TextureFormat : rgb888\n";
            b = data[i];
            g = data[i+1];
            r = data[i+2];
        } else if (pf == CL_TextureFormat::cl_rgba4)
        {
            std::cout << "TextureFormat : rgba4444\n";
            r = data[i] && 0x0F;
            g = (data[i] && 0xF0) >> 4;
            b = data[i+1] && 0x0F;
            a = (data[i+1] && 0xF0) >> 4;
        }

        if( a!=0 && (r!=g || r!=b || g!=b) ) 
        {
            rgbToHsv( r, g, b, &h, &s, &v );

            h += hue;
            s += saturation;
            v += value;
            if( h > 360 ) h -= 360;
            if( s > 255 ) s = 255;
            if( v > 255 ) v = 255;
            if( h < 0 ) h += 360;
            if( s < 0 ) s = 0;
            if( v < 0 ) v = 0;

            hsvToRgb( h, s, v, &r, &g, &b );

            if(pf == CL_TextureFormat::cl_rgba8)
            {
                data[i] = a;
                data[i+1] = b;
                data[i+2] = g;
                data[i+3] = r;
            } else if (pf == CL_TextureFormat::cl_rgb8)
            {
                data[i] = b;
                data[i+1] = g;
                data[i+2] = r;
            } else if (pf == CL_TextureFormat::cl_rgba4)
            {
                data[i] = r + (g << 4);
                data[i+1] = b + (a << 4);
            }
        }
    }