Nano-X: bitmap now showing in wxMessageBox, but it'll be a while
before masked drawing is possible. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14417 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -312,10 +312,10 @@ bool wxBitmap::Create( int width, int height, int depth )
|
|||||||
M_BMPDATA->m_height = height;
|
M_BMPDATA->m_height = height;
|
||||||
|
|
||||||
#if wxUSE_NANOX
|
#if wxUSE_NANOX
|
||||||
M_BMPDATA->m_bitmap = (WXPixmap) GrNewPixmap(width, height, NULL);
|
M_BMPDATA->m_pixmap = (WXPixmap) GrNewPixmap(width, height, NULL);
|
||||||
M_BMPDATA->m_bpp = bpp;
|
M_BMPDATA->m_bpp = bpp;
|
||||||
|
|
||||||
wxASSERT_MSG( M_BMPDATA->m_bitmap, wxT("Bitmap creation failed") );
|
wxASSERT_MSG( M_BMPDATA->m_pixmap, wxT("Bitmap creation failed") );
|
||||||
#else
|
#else
|
||||||
if (depth == 1)
|
if (depth == 1)
|
||||||
{
|
{
|
||||||
@@ -426,13 +426,45 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
if (!Create(w, h, depth))
|
if (!Create(w, h, depth))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
wxMemoryDC memDC;
|
// Unfortunately the mask has to be screen-depth since
|
||||||
memDC.SelectObject(*this);
|
// 1-bpp bitmaps don't seem to be supported
|
||||||
|
// TODO: implement transparent drawing, presumably
|
||||||
|
// by doing several blits as per the Windows
|
||||||
|
// implementation because Nano-X doesn't support
|
||||||
|
// XSetClipMask.
|
||||||
|
|
||||||
// Warning: this is very inefficient.
|
bool hasMask = image.HasMask();
|
||||||
wxPen pen;
|
|
||||||
pen.SetStyle(wxSOLID);
|
GC pixmapGC = GrNewGC();
|
||||||
pen.SetWidth(1);
|
Pixmap pixmap = (Pixmap) GetPixmap();
|
||||||
|
|
||||||
|
GC maskGC = 0;
|
||||||
|
Pixmap maskPixmap = 0;
|
||||||
|
|
||||||
|
unsigned char maskR = 0;
|
||||||
|
unsigned char maskG = 0;
|
||||||
|
unsigned char maskB = 0;
|
||||||
|
|
||||||
|
if (hasMask)
|
||||||
|
{
|
||||||
|
maskR = image.GetMaskRed();
|
||||||
|
maskG = image.GetMaskGreen();
|
||||||
|
maskB = image.GetMaskBlue();
|
||||||
|
|
||||||
|
maskGC = GrNewGC();
|
||||||
|
maskPixmap = GrNewPixmap(w, h, 0);
|
||||||
|
if (!maskPixmap)
|
||||||
|
hasMask = FALSE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxMask* mask = new wxMask;
|
||||||
|
mask->SetBitmap((WXPixmap) maskPixmap);
|
||||||
|
SetMask(mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GR_COLOR lastPixmapColour = 0;
|
||||||
|
GR_COLOR lastMaskColour = 0;
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < w; i++)
|
for (i = 0; i < w; i++)
|
||||||
@@ -442,26 +474,43 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
unsigned char red = image.GetRed(i, j);
|
unsigned char red = image.GetRed(i, j);
|
||||||
unsigned char green = image.GetGreen(i, j);
|
unsigned char green = image.GetGreen(i, j);
|
||||||
unsigned char blue = image.GetBlue(i, j);
|
unsigned char blue = image.GetBlue(i, j);
|
||||||
wxColour colour(red, green, blue);
|
|
||||||
|
|
||||||
pen.SetColour(colour);
|
GR_COLOR colour = GR_RGB(red, green, blue);
|
||||||
memDC.SetPen(pen);
|
|
||||||
memDC.DrawPoint(i, j);
|
// Efficiency measure
|
||||||
|
if (colour != lastPixmapColour || (i == 0 && j == 0))
|
||||||
|
{
|
||||||
|
GrSetGCForeground(pixmapGC, colour);
|
||||||
|
lastPixmapColour = colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
GrPoint(pixmap, pixmapGC, i, j);
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (hasMask)
|
if (hasMask)
|
||||||
{
|
{
|
||||||
// scan the bitmap for the transparent colour and set the corresponding
|
// scan the bitmap for the transparent colour and set the corresponding
|
||||||
// pixels in the mask to BLACK and the rest to WHITE
|
// pixels in the mask to BLACK and the rest to WHITE
|
||||||
if (maskR == red && maskG == green && maskB == blue)
|
if (maskR == red && maskG == green && maskB == blue)
|
||||||
::SetPixel(hMaskDC, i, j, PALETTERGB(0, 0, 0));
|
{
|
||||||
|
colour = GR_RGB(0, 0, 0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
::SetPixel(hMaskDC, i, j, PALETTERGB(255, 255, 255));
|
{
|
||||||
|
colour = GR_RGB(255, 255, 255);
|
||||||
|
}
|
||||||
|
if (colour != lastMaskColour || (i == 0 && j == 0))
|
||||||
|
{
|
||||||
|
GrSetGCForeground(maskGC, colour);
|
||||||
|
lastMaskColour = colour;
|
||||||
|
}
|
||||||
|
GrPoint(maskPixmap, maskGC, i, j);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memDC.SelectObject(wxNullBitmap);
|
|
||||||
|
GrDestroyGC(pixmapGC);
|
||||||
|
if (hasMask)
|
||||||
|
GrDestroyGC(maskGC);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
@@ -760,6 +809,7 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
wxColour pixelCol;
|
wxColour pixelCol;
|
||||||
|
|
||||||
// Warning: this is very inefficient.
|
// Warning: this is very inefficient.
|
||||||
|
// TODO: use GrReadArea to get an array of pixels
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < w; i++)
|
for (i = 0; i < w; i++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user