本文整理汇总了C++中wxBitmap::GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ wxBitmap::GetWidth方法的具体用法?C++ wxBitmap::GetWidth怎么用?C++ wxBitmap::GetWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxBitmap
的用法示例。
在下文中一共展示了wxBitmap::GetWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawMinimisedPanel
void wxRibbonAUIArtProvider::DrawMinimisedPanel(
wxDC& dc,
wxRibbonPanel* wnd,
const wxRect& rect,
wxBitmap& bitmap)
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(m_background_brush);
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
wxRect true_rect(rect);
RemovePanelPadding(&true_rect);
dc.SetPen(m_panel_border_pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(true_rect.x, true_rect.y, true_rect.width, true_rect.height);
true_rect.Deflate(1);
if(wnd->IsHovered() || wnd->GetExpandedPanel())
{
wxColour colour = m_page_hover_background_colour;
wxColour gradient = m_page_hover_background_gradient_colour;
#ifdef __WXMAC__
if(!wnd->GetExpandedPanel())
#else
if(wnd->GetExpandedPanel())
#endif
{
wxColour temp = colour;
colour = gradient;
gradient = temp;
}
dc.GradientFillLinear(true_rect, colour, gradient, wxSOUTH);
}
wxRect preview;
DrawMinimisedPanelCommon(dc, wnd, true_rect, &preview);
dc.SetPen(m_panel_border_pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(preview.x, preview.y, preview.width, preview.height);
preview.Deflate(1);
wxRect preview_caption_rect(preview);
preview_caption_rect.height = 7;
preview.y += preview_caption_rect.height;
preview.height -= preview_caption_rect.height;
#ifdef __WXMAC__
dc.GradientFillLinear(preview_caption_rect,
m_panel_hover_label_background_gradient_colour,
m_panel_hover_label_background_colour, wxSOUTH);
dc.GradientFillLinear(preview,
m_page_hover_background_gradient_colour,
m_page_hover_background_colour, wxSOUTH);
#else
dc.GradientFillLinear(preview_caption_rect,
m_panel_hover_label_background_colour,
m_panel_hover_label_background_gradient_colour, wxSOUTH);
dc.GradientFillLinear(preview,
m_page_hover_background_colour,
m_page_hover_background_gradient_colour, wxSOUTH);
#endif
if(bitmap.IsOk())
{
dc.DrawBitmap(bitmap, preview.x + (preview.width - bitmap.GetWidth()) / 2,
preview.y + (preview.height - bitmap.GetHeight()) / 2, true);
}
}
示例2: SplitGlyphs
void wxSpeedButton::SplitGlyphs(const wxBitmap &inBitmap, int inCount) {
int n;
int bw,bh;
int sw,sh;
wxRect rr;
wxImage img;
wxBitmap *bmp;
// no images yet
mGlyphUp = wxNullBitmap;
mGlyphDown = wxNullBitmap;
mGlyphDisabled = wxNullBitmap;
// if no bitmap, then we are done
if (! inBitmap.Ok()) return;
// size of the bitmap
bw = inBitmap.GetWidth();
bh = inBitmap.GetHeight();
if ((bw <= 0) || (bh <= 0)) return;
// determine the number of images in the source bitmap
// if inCount > 0, then that is the count specified by the user
// else, count number of square sub-images
if (inCount > 0) n = inCount;
else if (bw >= bh) n = (int) bw / bh;
else n = (int) bh / bw;
// extract sub-images, either vertically or horizontally
if (n == 1) {
mGlyphUp = inBitmap;
mGlyphDown = inBitmap;
img = inBitmap.ConvertToImage();
img = img.ConvertToGreyscale();
bmp = new wxBitmap(img);
mGlyphDisabled = *bmp;
}
else if ((n == 2) && (bw >= bh)) {
sw = (int) bw / n;
sh = bh;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetX(sw);
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
}
else if ((n == 2) && (bh > bw)) {
sw = bw;
sh = (int) bh / n;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetY(sh);
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
}
else if ((n >= 3) && (bw >= bh)) {
sw = (int) bw / n;
sh = bh;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
rr.SetX(sw);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetX(sw+sw);
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
}
else { // (n >= 3) && (bh > bw)
sw = bw;
sh = (int) bh / n;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
rr.SetY(sh);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetY(sh+sh);;
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
};
// make them all transparent
//.........这里部分代码省略.........
示例3: DoInsertItem
void wxHeaderCtrl::DoInsertItem(const wxHeaderColumn& col, unsigned int idx)
{
wxASSERT_MSG( !col.IsHidden(), "should only be called for shown columns" );
wxHDITEM hdi;
// notice that we need to store the string we use the pointer to until we
// pass it to the control
hdi.mask |= HDI_TEXT;
wxWxCharBuffer buf = col.GetTitle().t_str();
hdi.pszText = buf.data();
hdi.cchTextMax = wxStrlen(buf);
const wxBitmap bmp = col.GetBitmap();
if ( bmp.IsOk() )
{
hdi.mask |= HDI_IMAGE;
if ( bmp.IsOk() )
{
const int bmpWidth = bmp.GetWidth(),
bmpHeight = bmp.GetHeight();
if ( !m_imageList )
{
m_imageList = new wxImageList(bmpWidth, bmpHeight);
(void) // suppress mingw32 warning about unused computed value
Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList));
}
else // already have an image list
{
// check that all bitmaps we use have the same size
int imageWidth,
imageHeight;
m_imageList->GetSize(0, imageWidth, imageHeight);
wxASSERT_MSG( imageWidth == bmpWidth && imageHeight == bmpHeight,
"all column bitmaps must have the same size" );
}
m_imageList->Add(bmp);
hdi.iImage = m_imageList->GetImageCount() - 1;
}
else // no bitmap but we still need to update the item
{
hdi.iImage = I_IMAGENONE;
}
}
if ( col.GetAlignment() != wxALIGN_NOT )
{
hdi.mask |= HDI_FORMAT | HDF_LEFT;
switch ( col.GetAlignment() )
{
case wxALIGN_LEFT:
hdi.fmt |= HDF_LEFT;
break;
case wxALIGN_CENTER:
case wxALIGN_CENTER_HORIZONTAL:
hdi.fmt |= HDF_CENTER;
break;
case wxALIGN_RIGHT:
hdi.fmt |= HDF_RIGHT;
break;
default:
wxFAIL_MSG( "invalid column header alignment" );
}
}
if ( col.IsSortKey() )
{
hdi.mask |= HDI_FORMAT;
hdi.fmt |= col.IsSortOrderAscending() ? HDF_SORTUP : HDF_SORTDOWN;
}
if ( col.GetWidth() != wxCOL_WIDTH_DEFAULT )
{
hdi.mask |= HDI_WIDTH;
hdi.cxy = col.GetWidth();
}
hdi.mask |= HDI_ORDER;
hdi.iOrder = MSWToNativeOrder(m_colIndices.Index(idx));
if ( ::SendMessage(GetHwnd(), HDM_INSERTITEM,
MSWToNativeIdx(idx), (LPARAM)&hdi) == -1 )
{
wxLogLastError(wxT("Header_InsertItem()"));
}
}
示例4: DrawTool
void wxRibbonAUIArtProvider::DrawTool(
wxDC& dc,
wxWindow* WXUNUSED(wnd),
const wxRect& rect,
const wxBitmap& bitmap,
wxRibbonButtonKind kind,
long state)
{
if(kind == wxRIBBON_BUTTON_TOGGLE)
{
if(state & wxRIBBON_TOOLBAR_TOOL_TOGGLED)
state ^= wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK;
}
wxRect bg_rect(rect);
bg_rect.Deflate(1);
if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0)
bg_rect.width++;
bool is_custom_bg = (state & (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK |
wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)) != 0;
bool is_split_hybrid = kind == wxRIBBON_BUTTON_HYBRID && is_custom_bg;
// Background
if(is_custom_bg)
{
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(m_tool_hover_background_brush);
dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)
{
wxRect active_rect(bg_rect);
if(kind == wxRIBBON_BUTTON_HYBRID)
{
active_rect.width -= 8;
if(state & wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE)
{
active_rect.x += active_rect.width;
active_rect.width = 8;
}
}
dc.SetBrush(m_tool_active_background_brush);
dc.DrawRectangle(active_rect.x, active_rect.y, active_rect.width,
active_rect.height);
}
}
// Border
if(is_custom_bg)
dc.SetPen(m_toolbar_hover_borden_pen);
else
dc.SetPen(m_toolbar_border_pen);
if((state & wxRIBBON_TOOLBAR_TOOL_FIRST) == 0)
{
wxColour existing;
if(!dc.GetPixel(rect.x, rect.y + 1, &existing) ||
existing != m_toolbar_hover_borden_pen.GetColour())
{
dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
}
}
if(is_custom_bg)
{
wxRect border_rect(bg_rect);
border_rect.Inflate(1);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(border_rect.x, border_rect.y, border_rect.width,
border_rect.height);
}
// Foreground
int avail_width = bg_rect.GetWidth();
if(kind & wxRIBBON_BUTTON_DROPDOWN)
{
avail_width -= 8;
if(is_split_hybrid)
{
dc.DrawLine(rect.x + avail_width + 1, rect.y,
rect.x + avail_width + 1, rect.y + rect.height);
}
dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2,
bg_rect.y + (bg_rect.height / 2) - 2, true);
}
dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
}
示例5: DrawBitmap
void ocpnDC::DrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask )
{
#ifdef ocpnUSE_GLES // Do not attempt to do anything with glDrawPixels if using opengles
return;
#endif
wxBitmap bmp;
if( x < 0 || y < 0 ) {
int dx = ( x < 0 ? -x : 0 );
int dy = ( y < 0 ? -y : 0 );
int w = bitmap.GetWidth() - dx;
int h = bitmap.GetHeight() - dy;
/* picture is out of viewport */
if( w <= 0 || h <= 0 ) return;
wxBitmap newBitmap = bitmap.GetSubBitmap( wxRect( dx, dy, w, h ) );
x += dx;
y += dy;
bmp = newBitmap;
} else {
bmp = bitmap;
}
if( dc )
dc->DrawBitmap( bmp, x, y, usemask );
#ifdef ocpnUSE_GL
else {
wxImage image = bmp.ConvertToImage();
int w = image.GetWidth(), h = image.GetHeight();
if( usemask ) {
unsigned char *d = image.GetData();
unsigned char *a = image.GetAlpha();
unsigned char mr, mg, mb;
if( !image.GetOrFindMaskColour( &mr, &mg, &mb ) && !a ){
printf("trying to use mask to draw a bitmap without alpha or mask\n" );
}
unsigned char *e = new unsigned char[4 * w * h];
if(e && d){
for( int y = 0; y < h; y++ )
for( int x = 0; x < w; x++ ) {
unsigned char r, g, b;
int off = ( y * image.GetWidth() + x );
r = d[off * 3 + 0];
g = d[off * 3 + 1];
b = d[off * 3 + 2];
e[off * 4 + 0] = r;
e[off * 4 + 1] = g;
e[off * 4 + 2] = b;
e[off * 4 + 3] =
a ? a[off] : ( ( r == mr ) && ( g == mg ) && ( b == mb ) ? 0 : 255 );
}
}
glColor4f( 1, 1, 1, 1 );
GLDrawBlendData( x, y, w, h, GL_RGBA, e );
delete[] ( e );
} else {
glRasterPos2i( x, y );
glPixelZoom( 1, -1 ); /* draw data from top to bottom */
if(image.GetData())
glDrawPixels( w, h, GL_RGB, GL_UNSIGNED_BYTE, image.GetData() );
glPixelZoom( 1, 1 );
}
}
#endif
}
示例6: wxFrame
SplashScreen::SplashScreen( wxBitmap &label, long timeout, wxWindow *parent, wxWindowID id, long style )
: wxFrame( parent, id, wxEmptyString, wxPoint( 0, 0 ), wxSize( 100, 100 ), style ),
r( 0, 0, 181, 181 ), m_timer( this, cbSplashScreen_timer_id ),
timeUp(false)
{
r.Union( label );
int w = label.GetWidth();
int h = label.GetHeight();
SetClientSize( w, h );
CentreOnScreen();
wxScreenDC screen_dc;
wxMemoryDC label_dc;
int x;
int y;
x = GetPosition().x;
y = GetPosition().y;
m_label.Create( w, h );
label_dc.SelectObject( m_label );
label_dc.Blit( 0, 0, w, h, &screen_dc, x, y );
label_dc.DrawBitmap( label, 0, 0, true );
label_dc.SelectObject( wxNullBitmap );
SetShape( r );
Show( true );
SetThemeEnabled( false ); // seems to be useful by description
SetBackgroundStyle( wxBG_STYLE_CUSTOM ); // the trick for GTK+ (notice it's after Show())
SetTitle("GDevelop");
wxIconBundle icons;
icons.AddIcon("res/icon16.png");
icons.AddIcon("res/icon24.png");
#if defined(LINUX) || defined(MACOS)
icons.AddIcon("res/icon32linux.png");
icons.AddIcon("res/icon48linux.png");
icons.AddIcon("res/icon64linux.png");
icons.AddIcon("res/icon128linux.png");
#else
icons.AddIcon("res/icon32.png");
icons.AddIcon("res/icon48.png");
icons.AddIcon("res/icon128.png");
#endif
SetIcons(icons);
Centre( wxBOTH | wxCENTRE_ON_SCREEN ); // centre only works when the window is showing
Update();
wxYieldIfNeeded();
if ( timeout != -1 )
{
m_timer.Start( timeout, true );
}
}
示例7: DoPreviewBitmap
void wxGenericColourDialog::DoPreviewBitmap(wxBitmap& bmp, const wxColour& colour)
{
if ( bmp.HasAlpha() && colour.Alpha() != wxALPHA_OPAQUE )
{
// For real ARGB draw a chessboard grid
// with actual ARGB fields and reference RGB fields.
const int w = bmp.GetWidth();
const int h = bmp.GetHeight();
// Calculate field size: 4 fields per row/column,
// with size in range [2..10]
int dx = wxMax(wxMin(w / 4, 10), 2);
int dy = wxMax(wxMin(h / 4, 10), 2);
// We want a square field
dx = wxMax(dx, dy);
dy = dx;
// Prepare opaque colour
wxColour colourRGB(colour.Red(), colour.Green(), colour.Blue(), wxALPHA_OPAQUE);
{
wxBrush brushARGB(colour);
wxBrush brushRGB(colourRGB);
wxMemoryDC mdc(bmp);
{
wxGCDC gdc(mdc);
gdc.SetPen(*wxTRANSPARENT_PEN);
for (int x = 0, ix = 0; x < w; x += dx, ix++)
{
for (int y = 0, iy = 0; y < h; y += dy, iy++)
{
if ( (ix+iy) % 2 == 0 )
{
gdc.SetBrush(brushARGB);
}
else
{
gdc.SetBrush(brushRGB);
}
gdc.DrawRectangle(x, y, dx, dy);
}
}
// Draw a frame
gdc.SetPen(*wxBLACK_PEN);
gdc.SetBrush(*wxTRANSPARENT_BRUSH);
gdc.DrawRectangle(0, 0, w, h);
}
}
}
else
{
wxMemoryDC mdc(bmp);
// Fill with custom colour
wxBrush brush(colour);
mdc.SetPen(*wxBLACK_PEN);
mdc.SetBrush(brush);
mdc.DrawRectangle(wxPoint(0, 0), bmp.GetSize());
}
}
示例8: DrawLabel
void wxDCBase::DrawLabel(const wxString& text,
const wxBitmap& bitmap,
const wxRect& rect,
int alignment,
int indexAccel,
wxRect *rectBounding)
{
// find the text position
wxCoord widthText, heightText, heightLine;
GetMultiLineTextExtent(text, &widthText, &heightText, &heightLine);
wxCoord width, height;
if ( bitmap.Ok() )
{
width = widthText + bitmap.GetWidth();
height = bitmap.GetHeight();
}
else // no bitmap
{
width = widthText;
height = heightText;
}
wxCoord x, y;
if ( alignment & wxALIGN_RIGHT )
{
x = rect.GetRight() - width;
}
else if ( alignment & wxALIGN_CENTRE_HORIZONTAL )
{
x = (rect.GetLeft() + rect.GetRight() + 1 - width) / 2;
}
else // alignment & wxALIGN_LEFT
{
x = rect.GetLeft();
}
if ( alignment & wxALIGN_BOTTOM )
{
y = rect.GetBottom() - height;
}
else if ( alignment & wxALIGN_CENTRE_VERTICAL )
{
y = (rect.GetTop() + rect.GetBottom() + 1 - height) / 2;
}
else // alignment & wxALIGN_TOP
{
y = rect.GetTop();
}
// draw the bitmap first
wxCoord x0 = x,
y0 = y,
width0 = width;
if ( bitmap.Ok() )
{
DrawBitmap(bitmap, x, y, true /* use mask */);
wxCoord offset = bitmap.GetWidth() + 4;
x += offset;
width -= offset;
y += (height - heightText) / 2;
}
// we will draw the underscore under the accel char later
wxCoord startUnderscore = 0,
endUnderscore = 0,
yUnderscore = 0;
// split the string into lines and draw each of them separately
wxString curLine;
for ( const wxChar *pc = text; ; pc++ )
{
if ( *pc == _T('\n') || *pc == _T('\0') )
{
int xRealStart = x; // init it here to avoid compielr warnings
if ( !curLine.empty() )
{
// NB: can't test for !(alignment & wxALIGN_LEFT) because
// wxALIGN_LEFT is 0
if ( alignment & (wxALIGN_RIGHT | wxALIGN_CENTRE_HORIZONTAL) )
{
wxCoord widthLine;
GetTextExtent(curLine, &widthLine, NULL);
if ( alignment & wxALIGN_RIGHT )
{
xRealStart += width - widthLine;
}
else // if ( alignment & wxALIGN_CENTRE_HORIZONTAL )
{
xRealStart += (width - widthLine) / 2;
}
}
//else: left aligned, nothing to do
DrawText(curLine, xRealStart, y);
}
//.........这里部分代码省略.........
示例9: CreateBmp
void ocpnCompass::CreateBmp( bool newColorScheme )
{
if(!m_shown)
return;
wxString gpsIconName;
ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
// In order to draw a horizontal compass window when the toolbar is vertical, we
// need to save away the sizes and backgrounds for the two icons.
static wxBitmap compassBg, gpsBg;
static wxSize toolsize;
static int topmargin, leftmargin, radius;
if( ! compassBg.IsOk() || newColorScheme ) {
int orient = style->GetOrientation();
style->SetOrientation( wxTB_HORIZONTAL );
if( style->HasBackground() ) {
compassBg = style->GetNormalBG();
style->DrawToolbarLineStart( compassBg );
compassBg = style->SetBitmapBrightness( compassBg );
gpsBg = style->GetNormalBG();
style->DrawToolbarLineEnd( gpsBg );
gpsBg = style->SetBitmapBrightness( gpsBg );
}
if(fabs(m_scale-1.0) > 0.1){
wxImage bg_img = compassBg.ConvertToImage();
bg_img.Rescale(compassBg.GetWidth() * m_scale, compassBg.GetHeight() *m_scale, wxIMAGE_QUALITY_NORMAL);
compassBg = wxBitmap( bg_img );
bg_img = gpsBg.ConvertToImage();
bg_img.Rescale(gpsBg.GetWidth() * m_scale, gpsBg.GetHeight() *m_scale, wxIMAGE_QUALITY_NORMAL);
gpsBg = wxBitmap( bg_img );
}
leftmargin = style->GetCompassLeftMargin();
topmargin = style->GetCompassTopMargin();
toolsize = style->GetToolSize();
toolsize.x *= 2;
radius = style->GetCompassCornerRadius();
if( orient ) style->SetOrientation( wxTB_VERTICAL );
}
bool b_need_refresh = false;
if( bGPSValid ) {
if( g_bSatValid ) {
gpsIconName = _T("gps3Bar");
if( g_SatsInView <= 8 ) gpsIconName = _T("gps2Bar");
if( g_SatsInView <= 4 ) gpsIconName = _T("gps1Bar");
if( g_SatsInView < 0 ) gpsIconName = _T("gpsGry");
} else
gpsIconName = _T("gpsGrn");
} else
gpsIconName = _T("gpsRed");
if( m_lastgpsIconName != gpsIconName ) b_need_refresh = true;
double rose_angle = -999.;
if( ( fabs( cc1->GetVPRotation() ) > .01 ) || ( fabs( cc1->GetVPSkew() ) > .01 ) ) {
rose_angle = -cc1->GetVPRotation();
if( !g_bCourseUp && !g_bskew_comp )
rose_angle -= cc1->GetVPSkew();
} else
rose_angle = 0.;
if( fabs( m_rose_angle - rose_angle ) > .1 ) b_need_refresh = true;
if( !b_need_refresh )
return;
m_StatBmp.Create(
m_scale * ( ( _img_compass.GetWidth() + _img_gpsRed.GetWidth() ) + style->GetCompassLeftMargin() * 2
+ style->GetToolSeparation()),
m_scale * (_img_compass.GetHeight() + style->GetCompassTopMargin() + style->GetCompassBottomMargin()) );
if( !m_StatBmp.IsOk() )
return;
m_MaskBmp = wxBitmap( m_StatBmp.GetWidth(), m_StatBmp.GetHeight() );
if( style->marginsInvisible ) {
wxMemoryDC sdc( m_MaskBmp );
sdc.SetBackground( *wxWHITE_BRUSH );
sdc.Clear();
sdc.SetBrush( *wxBLACK_BRUSH );
sdc.SetPen( *wxBLACK_PEN );
sdc.DrawRoundedRectangle( wxPoint( leftmargin, topmargin ), toolsize, radius );
sdc.SelectObject( wxNullBitmap );
} else if(radius) {
wxMemoryDC sdc( m_MaskBmp );
sdc.SetBackground( *wxWHITE_BRUSH );
sdc.Clear();
sdc.SetBrush( *wxBLACK_BRUSH );
//.........这里部分代码省略.........
示例10: CompareToGraphicsContext
void AffineTransformTestCase::CompareToGraphicsContext()
{
wxPoint2DDouble pointA1(1.0, 3.0), pointA2(60.0, 50.0),
pointG1(1.0, 3.0), pointG2(60.0, 50.0);
// Create affine matrix and transform it
wxAffineMatrix2D matrixA1, matrixA2;
matrixA2.Rotate(M_PI / 3);
matrixA1.Translate(-m_bmpOrig.GetWidth()/2, -m_bmpOrig.GetHeight()/2);
matrixA1.Rotate(-M_PI *2/ 6);
matrixA1.Translate(m_bmpOrig.GetWidth()/2, m_bmpOrig.GetHeight()/2);
matrixA1.Mirror(wxHORIZONTAL);
matrixA1.Concat(matrixA2);
matrixA1.Mirror(wxVERTICAL);
matrixA1.Translate(m_bmpOrig.GetWidth()/2, -m_bmpOrig.GetHeight()/2);
matrixA1.Scale(0.9, 0.9);
matrixA1.Invert();
// Create image using first matrix
wxBitmap bmpUsingMatrixA1(m_bmpOrig.GetHeight(), m_bmpOrig.GetWidth());
// Build the transformed image using the transformation matrix
{
wxMemoryDC dc(bmpUsingMatrixA1);
if ( !dc.CanUseTransformMatrix() )
return;
// Draw the bitmap
dc.SetTransformMatrix(matrixA1);
dc.DrawBitmap(m_bmpOrig, 0, 0);
// Draw a line
matrixA1.TransformPoint(&pointA1.m_x, &pointA1.m_y);
matrixA1.TransformDistance(&pointA2.m_x, &pointA2.m_y);
dc.DrawLine(wxRound(pointA1.m_x), wxRound(pointA1.m_y),
wxRound(pointA1.m_x + pointA2.m_x), wxRound(pointA1.m_x + pointA2.m_y));
}
// Create graphics matrix and transform it
wxMemoryDC mDc;
wxGraphicsContext* gDc = wxGraphicsContext::Create(mDc);
wxGraphicsMatrix matrixG1 = gDc->CreateMatrix();
wxGraphicsMatrix matrixG2 = gDc->CreateMatrix();
matrixG2.Rotate(M_PI / 3);
matrixG1.Translate(-m_bmpOrig.GetWidth()/2, -m_bmpOrig.GetHeight()/2);
matrixG1.Rotate(-M_PI*2 / 6);
matrixG1.Translate(m_bmpOrig.GetWidth()/2, m_bmpOrig.GetHeight()/2);
matrixG1.Scale(-1, 1);
matrixG1.Concat(matrixG2);
matrixG1.Scale(1, -1);
matrixG1.Translate(m_bmpOrig.GetWidth()/2, -m_bmpOrig.GetHeight()/2);
matrixG1.Scale(0.9, 0.9);
matrixG1.Invert();
// Create affine matrix from the graphics matrix
wxMatrix2D mat2D;
wxPoint2DDouble tr;
matrixG1.Get(&mat2D.m_11, &mat2D.m_12, &mat2D.m_21, &mat2D.m_22, &tr.m_x, &tr.m_y);
wxAffineMatrix2D matrixAG;
matrixAG.Set(mat2D, tr);
delete gDc;
// Create image using last matrix
wxBitmap bmpUsingMatrixAG(m_bmpOrig.GetHeight(), m_bmpOrig.GetWidth());
// Build the transformed image using the transformation matrix
{
wxMemoryDC dc(bmpUsingMatrixAG);
if ( !dc.CanUseTransformMatrix() )
return;
// Draw the bitmap
dc.SetTransformMatrix(matrixAG);
dc.DrawBitmap(m_bmpOrig, 0, 0);
// Draw a line
matrixG1.TransformPoint(&pointG1.m_x, &pointG1.m_y);
matrixG1.TransformDistance(&pointG2.m_x, &pointG2.m_y);
dc.DrawLine(wxRound(pointG1.m_x), wxRound(pointG1.m_y),
wxRound(pointG1.m_x + pointG2.m_x), wxRound(pointG1.m_x + pointG2.m_y));
}
CPPUNIT_ASSERT_EQUAL( bmpUsingMatrixA1.ConvertToImage(),
bmpUsingMatrixAG.ConvertToImage() );
// Save the images to check that something _is_ inside the visible area.
//bmpUsingMatrixA1.SaveFile("matrixA1.jpg", wxBITMAP_TYPE_JPEG);
//bmpUsingMatrixAG.SaveFile("matrixAG.jpg", wxBITMAP_TYPE_JPEG);
}
示例11: DoDraw
void wxSheetCellStringRendererRefData::DoDraw(wxSheet& sheet,
const wxSheetCellAttr& attr,
wxDC& dc,
const wxRect& rectCell,
const wxSheetCoords& coords,
bool isSelected)
{
wxRect rect = rectCell;
rect.Inflate(-1);
int align = attr.GetAlignment();
int orient = attr.GetOrientation();
wxString value( sheet.GetCellValue(coords) );
int best_width = DoGetBestSize(sheet, attr, dc, value).GetWidth();
wxSheetCoords cellSpan(sheet.GetCellSpan(coords)); // shouldn't get here if <=0
int cell_rows = cellSpan.m_row;
int cell_cols = cellSpan.m_col;
bool is_grid_cell = coords.IsGridCell();
// no overflow for row/col/corner labels
bool overflow = is_grid_cell && (orient == wxSHEET_AttrOrientHoriz) ? attr.GetOverflow() : false;
int overflowCols = 0;
int num_cols = sheet.GetNumberCols();
// this is the right col which includes overflow
int rightCol = coords.m_col + cell_cols - 1;
// Check if this cell should overflow to right and for how many cells
if (overflow)
{
bool is_editing = sheet.IsCellEditControlShown();
wxSheetCoords editorCell = is_editing ? sheet.GetEditControlCoords() : wxNullSheetCoords;
int row = coords.GetRow(), col = coords.GetCol();
wxSheetCoords ownerCell;
if ((best_width > rectCell.width) && (col < num_cols-1) && sheet.GetTable())
{
wxSheetCoords cell;
for (cell.m_col = col+cell_cols; cell.m_col < num_cols; cell.m_col++)
{
bool is_empty = true;
for (cell.m_row = row; cell.m_row < row+cell_rows; cell.m_row++)
{
// check w/ anchor cell for spanned cell block
ownerCell = sheet.GetCellOwner(cell);
if ( sheet.GetTable()->HasValue(ownerCell) ||
(ownerCell == editorCell) )
{
is_empty = false;
break;
}
}
if (is_empty)
rect.width += sheet.GetColWidth(cell.m_col);
else
{
cell.m_col--;
break;
}
if (rect.width >= best_width)
break;
}
// this may extend out of sheet
overflowCols = cell.m_col - col - cell_cols + 1;
rightCol = wxMin(coords.m_col+cell_cols-1+overflowCols, num_cols - 1);
}
// redraw overflow cells individually for proper selection hilight
if (overflowCols > 0)
{
// if overflowed then it's left aligned (yes I know ALIGN_LEFT=0)
align &= ~wxSHEET_AttrAlignHoriz_Mask;
align |= wxSHEET_AttrAlignLeft;
wxRect clip(rect);
clip.x += rectCell.width;
int col_width;
wxSheetCoords cell(coords);
// draw each cell individually since it may be selected or not
for (cell.m_col = col+cell_cols; cell.m_col <= rightCol; cell.m_col++)
{
col_width = sheet.GetColWidth(cell.m_col);
clip.width = col_width - 1;
dc.DestroyClippingRegion();
dc.SetClippingRegion(clip);
SetTextColoursAndFont(sheet, attr, dc, sheet.IsCellSelected(cell));
sheet.DrawTextRectangle(dc, value, rect, align, orient);
clip.x += col_width - 1;
}
rect = rectCell;
rect.Inflate(-1);
rect.width++;
dc.DestroyClippingRegion();
}
}
// Draw the text
//.........这里部分代码省略.........
示例12: MergeBitmaps
wxBitmap MergeBitmaps( wxBitmap back, wxBitmap front, wxSize offset )
{
wxBitmap merged( back.GetWidth(), back.GetHeight(), back.GetDepth() );
#if (defined(__WXGTK__) || defined(__WXMAC__))
// Manual alpha blending for broken wxWidgets platforms.
merged.UseAlpha();
back.UseAlpha();
front.UseAlpha();
wxImage im_front = front.ConvertToImage();
wxImage im_back = back.ConvertToImage();
wxImage im_result = back.ConvertToImage();// Only way to make result have alpha channel in wxW 2.8.
unsigned char *presult = im_result.GetData();
unsigned char *pback = im_back.GetData();
unsigned char *pfront = im_front.GetData();
unsigned char *afront = NULL;
if( im_front.HasAlpha() )
afront = im_front.GetAlpha();
unsigned char *aback = NULL;
if( im_back.HasAlpha() )
aback = im_back.GetAlpha();
unsigned char *aresult = NULL;
if( im_result.HasAlpha() )
aresult = im_result.GetAlpha();
// Do alpha blending, associative version of "over" operator.
for( int i = 0; i < back.GetHeight(); i++ ) {
for( int j = 0; j < back.GetWidth(); j++ ) {
int fX = j - offset.x;
int fY = i - offset.y;
bool inFront = true;
if( fX < 0 || fY < 0 ) inFront = false;
if( fX >= front.GetWidth() ) inFront = false;
if( fY >= front.GetHeight() ) inFront = false;
if( inFront ) {
double alphaF = (double) ( *afront++ ) / 256.0;
double alphaB = (double) ( *aback++ ) / 256.0;
double alphaRes = alphaF + alphaB * ( 1.0 - alphaF );
unsigned char a = alphaRes * 256;
*aresult++ = a;
unsigned char r = (*pfront++ * alphaF + *pback++ * alphaB * ( 1.0 - alphaF )) / alphaRes;
*presult++ = r;
unsigned char g = (*pfront++ * alphaF + *pback++ * alphaB * ( 1.0 - alphaF )) / alphaRes;
*presult++ = g;
unsigned char b = (*pfront++ * alphaF + *pback++ * alphaB * ( 1.0 - alphaF )) / alphaRes;
*presult++ = b;
} else {
*aresult++ = *aback++;
*presult++ = *pback++;
*presult++ = *pback++;
*presult++ = *pback++;
}
}
}
merged = wxBitmap( im_result );
#else
wxMemoryDC mdc( merged );
mdc.DrawBitmap( back, 0, 0, true );
mdc.DrawBitmap( front, offset.x, offset.y, true );
mdc.SelectObject( wxNullBitmap );
#endif
return merged;
}
示例13: MergeBitmaps
wxBitmap MergeBitmaps( wxBitmap back, wxBitmap front, wxSize offset )
{
// If the front bitmap has no alpha channel, then merging will accomplish nothing
// So, simply return the bitmap intact
// However, if the bitmaps are different sizes, do the render anyway.
wxImage im_front = front.ConvertToImage();
if(!im_front.HasAlpha() && (front.GetWidth() == back.GetWidth()) )
return front;
wxBitmap merged( back.GetWidth(), back.GetHeight(), back.GetDepth() );
#if !wxCHECK_VERSION(2,9,4)
// Manual alpha blending for broken wxWidgets alpha bitmap support, pervasive in wx2.8.
merged.UseAlpha();
back.UseAlpha();
front.UseAlpha();
// wxImage im_front = front.ConvertToImage();
wxImage im_back = back.ConvertToImage();
wxImage im_result = back.ConvertToImage();// Only way to make result have alpha channel in wxW 2.8.
unsigned char *presult = im_result.GetData();
unsigned char *pback = im_back.GetData();
unsigned char *pfront = im_front.GetData();
unsigned char *afront = NULL;
if( im_front.HasAlpha() )
afront = im_front.GetAlpha();
unsigned char *aback = NULL;
if( im_back.HasAlpha() )
aback = im_back.GetAlpha();
unsigned char *aresult = NULL;
if( im_result.HasAlpha() )
aresult = im_result.GetAlpha();
// Do alpha blending, associative version of "over" operator.
if(presult && pback && pfront && afront && aback && aresult){
for( int i = 0; i < back.GetHeight(); i++ ) {
for( int j = 0; j < back.GetWidth(); j++ ) {
int fX = j - offset.x;
int fY = i - offset.y;
bool inFront = true;
if( fX < 0 || fY < 0 ) inFront = false;
if( fX >= front.GetWidth() ) inFront = false;
if( fY >= front.GetHeight() ) inFront = false;
if( inFront ) {
double alphaF = (double) ( *afront++ ) / 256.0;
double alphaB = (double) ( *aback++ ) / 256.0;
double alphaRes = alphaF + alphaB * ( 1.0 - alphaF );
unsigned char a = alphaRes * 256;
*aresult++ = a;
unsigned char r = (*pfront++ * alphaF + *pback++ * alphaB * ( 1.0 - alphaF )) / alphaRes;
*presult++ = r;
unsigned char g = (*pfront++ * alphaF + *pback++ * alphaB * ( 1.0 - alphaF )) / alphaRes;
*presult++ = g;
unsigned char b = (*pfront++ * alphaF + *pback++ * alphaB * ( 1.0 - alphaF )) / alphaRes;
*presult++ = b;
} else {
*aresult++ = *aback++;
*presult++ = *pback++;
*presult++ = *pback++;
*presult++ = *pback++;
}
}
}
}
merged = wxBitmap( im_result );
#else
wxMemoryDC mdc( merged );
mdc.Clear();
mdc.DrawBitmap( back, 0, 0, true );
mdc.DrawBitmap( front, offset.x, offset.y, true );
mdc.SelectObject( wxNullBitmap );
#endif
return merged;
}
示例14: DrawTool
void wxRibbonMetroArtProvider::DrawTool(
wxDC& dc,
wxWindow* WXUNUSED(wnd),
const wxRect& rect,
const wxBitmap& bitmap,
wxRibbonButtonKind kind,
long state)
{
if(kind == wxRIBBON_BUTTON_TOGGLE)
{
if(state & wxRIBBON_TOOLBAR_TOOL_TOGGLED)
state ^= wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK;
}
wxRect bg_rect(rect);
bg_rect.Deflate(1);
if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0)
bg_rect.width++;
bool is_split_hybrid = (kind == wxRIBBON_BUTTON_HYBRID && (state &
(wxRIBBON_TOOLBAR_TOOL_HOVER_MASK | wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)));
dc.SetPen(m_toolbar_border_pen);
if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)
{
dc.SetBrush(m_tool_background_colour);
dc.DrawRectangle(rect);
}
else if(state & wxRIBBON_TOOLBAR_TOOL_HOVER_MASK)
{
dc.SetBrush(m_tool_hover_background_colour);
dc.DrawRectangle(rect);
}
// remove the highlight from the non-active split part of the hybrid
if(is_split_hybrid)
{
wxRect nonrect(bg_rect);
if(state & (wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED |
wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE))
{
nonrect.width -= 8;
}
else
{
nonrect.x += nonrect.width - 8;
nonrect.width = 7;
}
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(m_page_background_top_gradient_colour);
dc.DrawRectangle(nonrect.x, nonrect.y, nonrect.width, nonrect.height);
}
// Foreground
int avail_width = bg_rect.GetWidth();
if(kind & wxRIBBON_BUTTON_DROPDOWN)
{
avail_width -= 8;
if(is_split_hybrid)
{
dc.SetPen(m_toolbar_border_pen);
dc.DrawLine(rect.x + avail_width + 1, rect.y,
rect.x + avail_width + 1, rect.y + rect.height);
}
dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2,
bg_rect.y + (bg_rect.height / 2) - 2, true);
}
dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
}
示例15: Create
bool wxBitmapButton::Create( wxWindow* pParent,
wxWindowID vId,
const wxBitmap& rBitmap,
const wxPoint& rPos,
const wxSize& rSize,
long lStyle,
const wxValidator& rValidator,
const wxString& rsName )
{
m_bitmaps[State_Normal] = rBitmap;
SetName(rsName);
#if wxUSE_VALIDATORS
SetValidator(rValidator);
#endif
pParent->AddChild(this);
m_backgroundColour = pParent->GetBackgroundColour() ;
m_foregroundColour = pParent->GetForegroundColour() ;
m_windowStyle = lStyle;
if (lStyle & wxBU_AUTODRAW)
{
m_marginX = wxDEFAULT_BUTTON_MARGIN;
m_marginY = wxDEFAULT_BUTTON_MARGIN;
}
int nX = rPos.x;
int nY = rPos.y;
int nWidth = rSize.x;
int nHeight = rSize.y;
if (vId == wxID_ANY)
m_windowId = NewControlId();
else
m_windowId = vId;
if (nWidth == wxDefaultCoord && rBitmap.IsOk())
nWidth = rBitmap.GetWidth() + 4 * m_marginX;
if (nHeight == wxDefaultCoord && rBitmap.IsOk())
nHeight = rBitmap.GetHeight() + 4 * m_marginY;
ULONG ulOS2Style = WS_VISIBLE | WS_TABSTOP | BS_USERBUTTON;
if (m_windowStyle & wxCLIP_SIBLINGS)
ulOS2Style |= WS_CLIPSIBLINGS;
m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(pParent)
,WC_BUTTON
,(PSZ)wxEmptyString
,ulOS2Style
,0, 0, 0, 0
,GetHwndOf(pParent)
,HWND_TOP
,m_windowId
,NULL
,NULL
);
//
//Subclass again for purposes of dialog editing mode
//
SubclassWin(m_hWnd);
SetFont(*wxSMALL_FONT);
SetSize( nX
,nY
,nWidth
,nHeight
);
return true;
} // end of wxBitmapButton::Create