Ejemplo n.º 1
0
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
{
    wxCHECK_MSG( IsOk(), false, wxT("invalid bitmap") );

    wxBitmapHandler *handler = FindHandler(type);

    if ( handler == NULL )
    {
        wxImage image = ConvertToImage();
#if wxUSE_PALETTE
        if ( palette )
            image.SetPalette(*palette);
#endif // wxUSE_PALETTE

        if ( image.IsOk() )
            return image.SaveFile(filename, type);
        else
        {
            wxLogError(_("No bitmap handler for type %d defined."), type);
            return false;
        }
    }

    return handler->SaveFile(this, filename, type, palette);
}
Ejemplo n.º 2
0
void
JXImage::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	if (sender == itsColormap && message.Is(JXColormap::kNewColormap) &&
		itsDepth > 1 && (itsPixmap != None || itsImage != NULL))
		{
		const JXColormap::NewColormap* info =
			dynamic_cast(const JXColormap::NewColormap*, &message);
		assert( info != NULL );

		ConvertToImage();

		const JCoordinate width  = GetWidth();
		const JCoordinate height = GetHeight();
		for (JCoordinate y=0; y<height; y++)
			{
			for (JCoordinate x=0; x<width; x++)
				{
				const unsigned long xPixel = XGetPixel(itsImage, x,y);
				XPutPixel(itsImage, x,y, info->ConvertPixel(xPixel));
				}
			}

		ConvertToDefaultState();
		}

	else
		{
Ejemplo n.º 3
0
bool wxBitmap::SaveFile(const wxString &name, wxBitmapType type,
              const wxPalette *WXUNUSED(palette) ) const
{   
    #if wxUSE_IMAGE
    //Try to save using wx
    wxImage image = ConvertToImage();
    if (image.IsOk() && image.SaveFile(name, type))
        return true;
    #endif
    
    //Try to save using Qt
    const char* type_name = NULL;
    switch (type)
    {
        case wxBITMAP_TYPE_BMP:  type_name = "bmp";  break;
        case wxBITMAP_TYPE_ICO:  type_name = "ico";  break;
        case wxBITMAP_TYPE_JPEG: type_name = "jpeg"; break;
        case wxBITMAP_TYPE_PNG:  type_name = "png";  break;
        case wxBITMAP_TYPE_GIF:  type_name = "gif";  break;
        case wxBITMAP_TYPE_CUR:  type_name = "cur";  break;
        case wxBITMAP_TYPE_TIFF: type_name = "tif";  break;
        case wxBITMAP_TYPE_XBM:  type_name = "xbm";  break;
        case wxBITMAP_TYPE_PCX:  type_name = "pcx";  break;
        case wxBITMAP_TYPE_BMP_RESOURCE:
        case wxBITMAP_TYPE_ICO_RESOURCE:
        case wxBITMAP_TYPE_CUR_RESOURCE:
        case wxBITMAP_TYPE_XBM_DATA:
        case wxBITMAP_TYPE_XPM:
        case wxBITMAP_TYPE_XPM_DATA:
        case wxBITMAP_TYPE_TIFF_RESOURCE:
        case wxBITMAP_TYPE_GIF_RESOURCE:
        case wxBITMAP_TYPE_PNG_RESOURCE:
        case wxBITMAP_TYPE_JPEG_RESOURCE:
        case wxBITMAP_TYPE_PNM:
        case wxBITMAP_TYPE_PNM_RESOURCE:
        case wxBITMAP_TYPE_PCX_RESOURCE:
        case wxBITMAP_TYPE_PICT:
        case wxBITMAP_TYPE_PICT_RESOURCE:
        case wxBITMAP_TYPE_ICON:
        case wxBITMAP_TYPE_ICON_RESOURCE:
        case wxBITMAP_TYPE_ANI:
        case wxBITMAP_TYPE_IFF:
        case wxBITMAP_TYPE_TGA:
        case wxBITMAP_TYPE_MACCURSOR:
        case wxBITMAP_TYPE_MACCURSOR_RESOURCE:
        case wxBITMAP_TYPE_MAX:
        case wxBITMAP_TYPE_ANY:
        default:
            break;
    }
    return type_name &&
        M_PIXDATA.save(wxQtConvertString(name), type_name);
}
Ejemplo n.º 4
0
unsigned long
JXImage::GetSystemColor
	(
	const JCoordinate x,
	const JCoordinate y
	)
	const
{
	if (itsImage == NULL)
		{
		ConvertToImage();
		}

	return XGetPixel(itsImage, x,y);
}
Ejemplo n.º 5
0
// -----------------------------------------------------------------------------
// SIconButton class constructor
// -----------------------------------------------------------------------------
SIconButton::SIconButton(wxWindow* parent, Icons::Type icon_type, const wxString& icon, const wxString& tooltip) :
	wxBitmapButton{ parent, -1, wxNullBitmap }
{
	// Create icon
	auto bmp = Icons::getIcon(icon_type, icon.ToStdString(), UI::scaleFactor() > 1.);

	// Scale icon if required
	auto size = UI::scalePx(16);
	if (bmp.GetWidth() != size)
	{
		auto img = bmp.ConvertToImage();
		img.Rescale(size, size, wxIMAGE_QUALITY_BICUBIC);
		bmp = wxBitmap(img);
	}

	// Set button image and tooltip
	SetBitmap(bmp);
	if (!tooltip.empty())
		SetToolTip(tooltip);
}
Ejemplo n.º 6
0
void
JXImage::SetColor
	(
	const JCoordinate x,
	const JCoordinate y,
	const JColorIndex color
	)
{
	ConvertToImage();

	unsigned long xPixel;
	if (itsDepth == 1)
		{
		xPixel = JXImageMask::ColorToBit(color);
		}
	else
		{
		xPixel = color;
		}

	XPutPixel(itsImage, x,y, xPixel);
}
Ejemplo n.º 7
0
void
JXImage::JXImageFromDrawable
	(
	JXDisplay*		display,
	JXColormap*		colormap,
	Drawable		source,
	const JRect&	origRect
	)
{
	JXImageX(display, colormap);

	JRect rect = origRect;
	{
	Window rootWindow;
	int x,y;
	unsigned int w,h, bw, depth;
	XGetGeometry(*itsDisplay, source, &rootWindow, &x, &y, &w, &h, &bw, &depth);

	itsDepth = depth;
	if (rect.IsEmpty())
		{
		SetDimensions(w,h);
		rect = GetBounds();
		}
	}

	itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(),
							  GetWidth(), GetHeight(), itsDepth);
	assert( itsPixmap != None );

	if (itsDepth != itsDisplay->GetDepth())
		{
		itsGC = new JXGC(itsDisplay, itsColormap, itsPixmap);
		assert( itsGC != NULL );
		}

	(GetGC())->CopyPixels(source, rect.left, rect.top,
						  rect.width(), rect.height(), itsPixmap, 0,0);

	// register the colors that are used in the drawable

	const JBoolean needRegister =
		JConvertToBoolean( itsDepth > 1 && !itsColormap->AllColorsPreallocated() );

	if (needRegister && itsColormap->GetVisualClass() == DirectColor)
		{
		// With DirectColor, there could be just as many colors as pixels,
		// so we actually waste time (and memory!) by building a list of
		// X pixel values before converting them to JColorIndices.

		ConvertToImage();

		const JCoordinate w = GetWidth();
		const JCoordinate h = GetHeight();
		for (JCoordinate y=0; y<=h; y++)
			{
			for (JCoordinate x=0; x<=w; x++)
				{
				JColorIndex color;
				const unsigned long xPixel = XGetPixel(itsImage, x,y);
				itsColormap->AllocateStaticColor(xPixel, &color);
				RegisterColor(color, kJFalse);
				}
			}
		}
	else if (needRegister)	// using PseudoColor => small # of X pixels
		{
		// By building a list of unique X pixel values and then converting
		// each once, we reduce O(W H (alloc)) to O(W H) + O(P (alloc)),
		// where W=width, H=height, P=# of distinct pixels in Drawable.
		// Typically, W*H is much larger than P.  Alloc usually requires
		// a server call.

		JIndex i;

		// build boolean array telling which X pixel values are used

		ConvertToImage();

		const JSize maxColorCount = itsColormap->GetMaxColorCount();
		char* pixelUsed = new char [ maxColorCount ];
		assert( pixelUsed != NULL );
		for (i=0; i<maxColorCount; i++)
			{
			pixelUsed[i] = 0;
			}

		const JCoordinate w = GetWidth();
		const JCoordinate h = GetHeight();
		for (JCoordinate y=0; y<=h; y++)
			{
			for (JCoordinate x=0; x<=w; x++)
				{
				const unsigned long xPixel = XGetPixel(itsImage, x,y);
				assert( xPixel < maxColorCount );
				pixelUsed [ xPixel ] = 1;
				}
			}

		// register each X pixel value that is used

		JColorIndex color;
		for (i=0; i<maxColorCount; i++)
			{
			if (pixelUsed[i])
				{
				itsColormap->AllocateStaticColor(i, &color);
				RegisterColor(color, kJFalse);
				}
			}

		delete [] pixelUsed;
		}
}
Ejemplo n.º 8
0
bool CToolBar::Realize()
{
	wxASSERT(HasFlag(wxTB_NOICONS));

	bool ret = wxToolBar::Realize();
	if (!ret) {
		return false;
	}

	wxSize const size = GetToolBitmapSize();
	wxASSERT(size.x > 0 && size.y > 0);
	auto toolImages = std::make_unique<wxImageList>(size.x, size.y, false, 0);
	auto disabledToolImages = std::make_unique<wxImageList>(size.x, size.y, false, 0);

	HWND hwnd = GetHandle();

	auto hImgList = reinterpret_cast<HIMAGELIST>(toolImages->GetHIMAGELIST());
	auto hDisabledImgList = reinterpret_cast<HIMAGELIST>(disabledToolImages->GetHIMAGELIST());
	::SendMessage(hwnd, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(hImgList));
	::SendMessage(hwnd, TB_SETDISABLEDIMAGELIST, 0, reinterpret_cast<LPARAM>(hDisabledImgList));

	toolImages_ = std::move(toolImages);
	disabledToolImages_ = std::move(disabledToolImages);

	for (size_t i = 0; i < GetToolsCount(); ++i) {
		auto tool = GetToolByPos(static_cast<int>(i));
		if (!tool || tool->GetStyle() != wxTOOL_STYLE_BUTTON) {
			continue;
		}

		auto bmp = tool->GetBitmap();
		if (!bmp.IsOk()) {
			continue;
		}
			
		int image = toolImages_->Add(bmp);
		auto disabled = tool->GetDisabledBitmap();
		if (!disabled.IsOk()) {
			disabled = wxBitmap(bmp.ConvertToImage().ConvertToGreyscale());
		}
		disabledToolImages_->Add(disabled);

		TBBUTTONINFO btn{};
		btn.cbSize = sizeof(TBBUTTONINFO);
		btn.dwMask = TBIF_BYINDEX;
		int index = ::SendMessage(hwnd, TB_GETBUTTONINFO, i, reinterpret_cast<LPARAM>(&btn));
		if (index != static_cast<int>(i)) {
			return false;
		}

		btn.dwMask = TBIF_BYINDEX | TBIF_IMAGE;
		btn.iImage = image;
		if (::SendMessage(hwnd, TB_SETBUTTONINFO, i, reinterpret_cast<LPARAM>(&btn)) == 0) {
			return false;
		}
	}

	::SendMessage(hwnd, TB_SETINDENT, ConvertDialogToPixels(wxPoint(1, 0)).x, 0);

	return true;
}