// Initialise the card bitmap to the background colour
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_bmapCard);
+ memoryDC.SetPen( *wxTRANSPARENT_PEN );
memoryDC.SetBrush(FortyApp::BackgroundBrush());
memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
memoryDC.SelectObject(*m_bmap);
}
for (i = 0; i <= m_topCard; i++)
{
- int pos = rand() % (m_topCard + 1);
- while (temp[pos])
- {
- pos--;
- if (pos < 0) pos = m_topCard;
- }
- m_cards[i]->TurnCard(facedown);
- temp[pos] = m_cards[i];
+ int pos = rand() % (m_topCard + 1);
+ while (temp[pos])
+ {
+ pos--;
+ if (pos < 0) pos = m_topCard;
+ }
+ m_cards[i]->TurnCard(facedown);
+ temp[pos] = m_cards[i];
m_cards[i] = 0;
}
// unoccupied position after the random position.
for (i = 0; i <= m_topCard; i++)
{
- int pos = rand() % (m_topCard + 1);
- while (m_cards[pos])
- {
- pos++;
+ int pos = rand() % (m_topCard + 1);
+ while (m_cards[pos])
+ {
+ pos++;
if (pos > m_topCard) pos = 0;
- }
+ }
m_cards[pos] = temp[i];
}
}
char str[10];
sprintf(str, "%d ", m_topCard + 1);
+ dc.SetBackgroundMode( wxSOLID );
dc.SetTextBackground(FortyApp::BackgroundColour());
dc.SetTextForeground(FortyApp::TextColour());
dc.DrawText(str, m_x + CardWidth + 5, m_y + CardHeight / 2);
{
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
- delete m_cards[m_topCard];
+ delete m_cards[m_topCard];
}
};
if (m_topCard >= 0)
{
- if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
- m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
- {
+ if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
+ m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
+ {
retval = TRUE;
}
}
if (m_topCard >= 0)
{
- if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
- m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
- {
+ if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
+ m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
+ {
retval = TRUE;
}
}
else if (card->GetPipValue() == 1)
{
- // It's an ace and the pile is empty - ACCEPT
+ // It's an ace and the pile is empty - ACCEPT
retval = TRUE;
}
return retval;
{
if (m_topCard >= 0)
{
- if (m_dx == 0 && m_dy == 0)
- {
+ if (m_dx == 0 && m_dy == 0)
+ {
m_cards[m_topCard]->Draw(dc, m_x, m_y);
- }
- else
- {
- int x = m_x;
- int y = m_y;
- for (int i = 0; i <= m_topCard; i++)
+ }
+ else
{
- m_cards[i]->Draw(dc, x, y);
- x += m_dx;
- y += m_dy;
- if (i == 31)
- {
- x = m_x;
+ int x = m_x;
+ int y = m_y;
+ for (int i = 0; i <= m_topCard; i++)
+ {
+ m_cards[i]->Draw(dc, x, y);
+ x += m_dx;
+ y += m_dy;
+ if (i == 31)
+ {
+ x = m_x;
y = m_y + CardHeight / 3;
}
}
{
if (m_topCard < 0)
{
- x = m_x;
- y = m_y;
+ x = m_x;
+ y = m_y;
}
else if (m_topCard > 31)
{
- x = m_x + m_dx * (m_topCard - 32);
- y = m_y + CardHeight / 3;
+ x = m_x + m_dx * (m_topCard - 32);
+ y = m_y + CardHeight / 3;
}
else
{
- x = m_x + m_dx * m_topCard;
- y = m_y;
+ x = m_x + m_dx * m_topCard;
+ y = m_y;
}
}
}
Layout();
+
+ CentreOnParent();
}
PlayerSelectionDialog::~PlayerSelectionDialog()
void SetWidth( int width );
void SetDepth( int depth );
void SetPixmap( GdkPixmap *pixmap );
+ void SetBitmap( GdkBitmap *bitmap );
GdkPixmap *GetPixmap() const;
GdkBitmap *GetBitmap() const;
void SetWidth( int width );
void SetDepth( int depth );
void SetPixmap( GdkPixmap *pixmap );
+ void SetBitmap( GdkBitmap *bitmap );
GdkPixmap *GetPixmap() const;
GdkBitmap *GetBitmap() const;
wxImage( const wxBitmap &bitmap );
operator wxBitmap() const { return ConvertToBitmap(); }
wxBitmap ConvertToBitmap() const;
+#ifdef __WXGTK__
+ wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue );
+#endif
void Create( int width, int height );
void Destroy();
if (my_smile_xbm && my_smile_xbm->Ok())
{
dc.DrawText( "XBM bitmap", 30, 1745 );
- dc.SetPen( *wxRED_PEN );
+ dc.SetTextForeground( "RED" );
+ dc.SetTextBackground( "GREEN" );
dc.DrawBitmap( *my_smile_xbm, 30, 1760 );
dc.DrawText( "After wxImage conversion", 150, 1745 );
wxImage i( *my_smile_xbm );
- i.SetMaskColour( 0,0,0 );
- i.Replace( 255,255,255,
+ i.SetMaskColour( 0,0,0 );
+ i.Replace( 255,255,255,
wxRED_PEN->GetColour().Red(),
wxRED_PEN->GetColour().Green(),
wxRED_PEN->GetColour().Blue() );
dc.DrawBitmap( i.ConvertToBitmap(), 150, 1760, TRUE );
}
+ dc.SetTextForeground( "BLACK" );
+
+ wxBitmap mono( 30,30,1 );
+ wxMemoryDC memdc;
+ memdc.SelectObject( mono );
+ memdc.SetPen( *wxTRANSPARENT_PEN );
+ memdc.SetBrush( *wxBLACK_BRUSH );
+ memdc.DrawRectangle( 0,0,30,30 );
+ memdc.SetBrush( *wxWHITE_BRUSH );
+ memdc.DrawRectangle( 5,5,20,20 );
+ memdc.SelectObject( wxNullBitmap );
+ if (mono.Ok())
+ {
+ dc.DrawText( "Mono bitmap", 30, 1845 );
+ dc.SetTextForeground( "RED" );
+ dc.SetTextBackground( "GREEN" );
+ dc.DrawBitmap( mono, 30, 1860 );
+
+ dc.DrawText( "After wxImage conversion", 150, 1845 );
+ wxImage i( mono );
+ i.SetMaskColour( 0,0,0 );
+ i.Replace( 255,255,255,
+ wxRED_PEN->GetColour().Red(),
+ wxRED_PEN->GetColour().Green(),
+ wxRED_PEN->GetColour().Blue() );
+ dc.DrawBitmap( i.ConvertToBitmap(), 150, 1860, TRUE );
+ }
}
void MyCanvas::CreateAntiAliasedBitmap()
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
// 500 width * 1900 height
- m_canvas->SetScrollbars( 10, 10, 50, 190 );
+ m_canvas->SetScrollbars( 10, 10, 50, 200 );
}
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
#include <gdk/gdkrgb.h>
#endif
+wxBitmap wxImage::ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue )
+{
+ wxBitmap bitmap;
+
+ wxCHECK_MSG( Ok(), bitmap, wxT("invalid image") );
+
+ int width = GetWidth();
+ int height = GetHeight();
+
+ bitmap.SetHeight( height );
+ bitmap.SetWidth( width );
+
+ bitmap.SetBitmap( gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, 1 ) );
+
+ bitmap.SetDepth( 1 );
+
+ // Create picture image
+
+ unsigned char *data_data = (unsigned char*)malloc( ((width >> 3)+8) * height );
+
+ GdkImage *data_image =
+ gdk_image_new_bitmap( gdk_visual_get_system(), data_data, width, height );
+
+ // Create mask image
+
+ GdkImage *mask_image = (GdkImage*) NULL;
+
+ if (HasMask())
+ {
+ unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height );
+
+ mask_image = gdk_image_new_bitmap( gdk_visual_get_system(), mask_data, width, height );
+
+ wxMask *mask = new wxMask();
+ mask->m_bitmap = gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, 1 );
+
+ bitmap.SetMask( mask );
+ }
+
+ int r_mask = GetMaskRed();
+ int g_mask = GetMaskGreen();
+ int b_mask = GetMaskBlue();
+
+ unsigned char* data = GetData();
+
+ int index = 0;
+ for (int y = 0; y < height; y++)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ int r = data[index];
+ index++;
+ int g = data[index];
+ index++;
+ int b = data[index];
+ index++;
+
+ if (HasMask())
+ {
+ if ((r == r_mask) && (b == b_mask) && (g == g_mask))
+ gdk_image_put_pixel( mask_image, x, y, 1 );
+ else
+ gdk_image_put_pixel( mask_image, x, y, 0 );
+ }
+
+ if ((r == red) && (b == blue) && (g == green))
+ gdk_image_put_pixel( data_image, x, y, 1 );
+ else
+ gdk_image_put_pixel( data_image, x, y, 0 );
+
+ } // for
+ } // for
+
+ // Blit picture
+
+ GdkGC *data_gc = gdk_gc_new( bitmap.GetBitmap() );
+
+ gdk_draw_image( bitmap.GetBitmap(), data_gc, data_image, 0, 0, 0, 0, width, height );
+
+ gdk_image_destroy( data_image );
+ gdk_gc_unref( data_gc );
+
+ // Blit mask
+
+ if (HasMask())
+ {
+ GdkGC *mask_gc = gdk_gc_new( bitmap.GetMask()->GetBitmap() );
+
+ gdk_draw_image( bitmap.GetMask()->GetBitmap(), mask_gc, mask_image, 0, 0, 0, 0, width, height );
+
+ gdk_image_destroy( mask_image );
+ gdk_gc_unref( mask_gc );
+ }
+
+ return bitmap;
+}
+
+
wxBitmap wxImage::ConvertToBitmap() const
{
wxBitmap bitmap;
gdk_image_put_pixel( mask_image, x, y, 0 );
}
- if (HasMask())
- {
- if ((r == r_mask) && (b == b_mask) && (g == g_mask))
- gdk_image_put_pixel( mask_image, x, y, 1 );
- else
- gdk_image_put_pixel( mask_image, x, y, 0 );
- }
-
switch (bpp)
{
case 8:
M_BMPDATA->m_pixmap = pixmap;
}
+void wxBitmap::SetBitmap( GdkPixmap *bitmap )
+{
+ if (!m_refData) m_refData = new wxBitmapRefData();
+
+ M_BMPDATA->m_bitmap = bitmap;
+}
+
GdkPixmap *wxBitmap::GetPixmap() const
{
wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") );
wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") );
+ bool is_mono = (bitmap.GetBitmap());
+
/* scale/translate size and position */
int xx = XLOG2DEV(x);
if ((w != ww) || (h != hh))
{
wxImage image( bitmap );
- image = image.Scale( ww, hh );
-
- use_bitmap = image.ConvertToBitmap();
+ image.Rescale( ww, hh );
+ if (is_mono)
+ use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ else
+ use_bitmap = image.ConvertToBitmap();
}
else
{
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, mask );
- gdk_gc_set_clip_origin( m_penGC, xx, yy );
- }
-
- /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */
-
- GdkPixmap *pm = use_bitmap.GetPixmap();
- if (pm)
- {
- gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 );
- }
- else
- {
- GdkBitmap *bm = use_bitmap.GetBitmap();
- if (bm)
+ if (is_mono)
{
- gdk_draw_bitmap( m_window, m_penGC, bm, 0, 0, xx, yy, -1, -1 );
+ gdk_gc_set_clip_mask( m_textGC, mask );
+ gdk_gc_set_clip_origin( m_textGC, xx, yy );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, mask );
+ gdk_gc_set_clip_origin( m_penGC, xx, yy );
}
}
+ /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
+ drawing a mono-bitmap (XBitmap) we use the current text GC */
+ if (is_mono)
+ gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), 0, 0, xx, yy, -1, -1 );
+ else
+ gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
+
/* remove mask again if any */
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
- gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_textGC, 0, 0 );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ }
}
}
wxMemoryDC *memDC = (wxMemoryDC*)source;
bool use_bitmap_method = FALSE;
+ bool is_mono = FALSE;
if (srcDC->m_isMemDC)
{
/* we HAVE TO use the direct way for memory dcs
that are bitmaps because XCopyArea doesn't cope
with different bit depths */
+ is_mono = TRUE;
use_bitmap_method = TRUE;
}
else if ((xsrc == 0) && (ysrc == 0) &&
wxImage image( memDC->m_selected );
image = image.Scale( bm_ww, bm_hh );
- use_bitmap = image.ConvertToBitmap();
+ if (is_mono)
+ use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ else
+ use_bitmap = image.ConvertToBitmap();
}
else
{
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, mask );
- gdk_gc_set_clip_origin( m_penGC, xx, yy );
- }
-
- /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */
-
- GdkPixmap *pm = use_bitmap.GetPixmap();
- if (pm)
- {
- gdk_draw_pixmap( m_window, m_penGC, pm, xsrc, ysrc, xx, yy, ww, hh );
- }
- else
- {
- GdkBitmap *bm = use_bitmap.GetBitmap();
- if (bm)
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, mask );
+ gdk_gc_set_clip_origin( m_textGC, xx, yy );
+ }
+ else
{
- /* we use the textGC here because blitting a bitmap is done
- using the current text colour */
- gdk_draw_bitmap( m_window, m_textGC, bm, xsrc, ysrc, xx, yy, ww, hh );
+ gdk_gc_set_clip_mask( m_penGC, mask );
+ gdk_gc_set_clip_origin( m_penGC, xx, yy );
}
}
+ /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
+ drawing a mono-bitmap (XBitmap) we use the current text GC */
+ if (is_mono)
+ gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
+ else
+ gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
+
/* remove mask again if any */
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
- gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_textGC, 0, 0 );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ }
}
}
else /* use_bitmap_method */
M_BMPDATA->m_pixmap = pixmap;
}
+void wxBitmap::SetBitmap( GdkPixmap *bitmap )
+{
+ if (!m_refData) m_refData = new wxBitmapRefData();
+
+ M_BMPDATA->m_bitmap = bitmap;
+}
+
GdkPixmap *wxBitmap::GetPixmap() const
{
wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") );
wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") );
+ bool is_mono = (bitmap.GetBitmap());
+
/* scale/translate size and position */
int xx = XLOG2DEV(x);
if ((w != ww) || (h != hh))
{
wxImage image( bitmap );
- image = image.Scale( ww, hh );
-
- use_bitmap = image.ConvertToBitmap();
+ image.Rescale( ww, hh );
+ if (is_mono)
+ use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ else
+ use_bitmap = image.ConvertToBitmap();
}
else
{
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, mask );
- gdk_gc_set_clip_origin( m_penGC, xx, yy );
- }
-
- /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */
-
- GdkPixmap *pm = use_bitmap.GetPixmap();
- if (pm)
- {
- gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 );
- }
- else
- {
- GdkBitmap *bm = use_bitmap.GetBitmap();
- if (bm)
+ if (is_mono)
{
- gdk_draw_bitmap( m_window, m_penGC, bm, 0, 0, xx, yy, -1, -1 );
+ gdk_gc_set_clip_mask( m_textGC, mask );
+ gdk_gc_set_clip_origin( m_textGC, xx, yy );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, mask );
+ gdk_gc_set_clip_origin( m_penGC, xx, yy );
}
}
+ /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
+ drawing a mono-bitmap (XBitmap) we use the current text GC */
+ if (is_mono)
+ gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), 0, 0, xx, yy, -1, -1 );
+ else
+ gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
+
/* remove mask again if any */
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
- gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_textGC, 0, 0 );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ }
}
}
wxMemoryDC *memDC = (wxMemoryDC*)source;
bool use_bitmap_method = FALSE;
+ bool is_mono = FALSE;
if (srcDC->m_isMemDC)
{
/* we HAVE TO use the direct way for memory dcs
that are bitmaps because XCopyArea doesn't cope
with different bit depths */
+ is_mono = TRUE;
use_bitmap_method = TRUE;
}
else if ((xsrc == 0) && (ysrc == 0) &&
wxImage image( memDC->m_selected );
image = image.Scale( bm_ww, bm_hh );
- use_bitmap = image.ConvertToBitmap();
+ if (is_mono)
+ use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ else
+ use_bitmap = image.ConvertToBitmap();
}
else
{
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, mask );
- gdk_gc_set_clip_origin( m_penGC, xx, yy );
- }
-
- /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */
-
- GdkPixmap *pm = use_bitmap.GetPixmap();
- if (pm)
- {
- gdk_draw_pixmap( m_window, m_penGC, pm, xsrc, ysrc, xx, yy, ww, hh );
- }
- else
- {
- GdkBitmap *bm = use_bitmap.GetBitmap();
- if (bm)
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, mask );
+ gdk_gc_set_clip_origin( m_textGC, xx, yy );
+ }
+ else
{
- /* we use the textGC here because blitting a bitmap is done
- using the current text colour */
- gdk_draw_bitmap( m_window, m_textGC, bm, xsrc, ysrc, xx, yy, ww, hh );
+ gdk_gc_set_clip_mask( m_penGC, mask );
+ gdk_gc_set_clip_origin( m_penGC, xx, yy );
}
}
+ /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
+ drawing a mono-bitmap (XBitmap) we use the current text GC */
+ if (is_mono)
+ gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh );
+ else
+ gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
+
/* remove mask again if any */
if (useMask && mask)
{
- gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
- gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ if (is_mono)
+ {
+ gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_textGC, 0, 0 );
+ }
+ else
+ {
+ gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL );
+ gdk_gc_set_clip_origin( m_penGC, 0, 0 );
+ }
}
}
else /* use_bitmap_method */