//---------------------------------------------------------
void CVIEW_ScatterPlot::_Draw_Frame(wxDC &dc, wxRect r)
{
	//-----------------------------------------------------
	Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);

	//-------------------------------------------------
	Draw_Scale(dc, wxRect(r.GetLeft(), r.GetBottom(), r.GetWidth(), 20),
		m_Trend.Get_Data_XMin(), m_Trend.Get_Data_XMax(),
		true , true , true
	);

	Draw_Scale(dc, wxRect(r.GetLeft() - 20, r.GetTop(), 20, r.GetHeight()),
		m_Trend.Get_Data_YMin(), m_Trend.Get_Data_YMax(),
		false, false, false
	);

	Draw_Text(dc, TEXTALIGN_BOTTOMCENTER,
		r.GetLeft() - 25, r.GetTop() + r.GetHeight() / 2, 90.0,
		m_sY.c_str()
	);

	Draw_Text(dc, TEXTALIGN_TOPCENTER,
		r.GetLeft() + r.GetWidth() / 2, r.GetBottom() + 20,
		m_sX.c_str()
	);

	//-------------------------------------------------
	if( m_Options("REG_SHOW")->asBool() )
	{
		_Draw_Regression(dc, r);
	}
}
/// Gets a rectangle from within another image, INCLUDING the alpha channel
/// \bug in wxWidgets, wxImage::GetSubImage should do this itself.
wxImage GetSubImageWithAlpha( const wxImage & Src,  const wxRect &rect )
{
   //First part of this code is lifted from wxImage::GetSubImage() source code.
   wxImage image;

   wxCHECK_MSG( Src.Ok(), image, wxT("invalid image") );

   wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (
      rect.GetRight()<=Src.GetWidth()) && (rect.GetBottom()<=Src.GetHeight()),
      image, wxT("invalid subimage size") );

   int subwidth=rect.GetWidth();
   const int subheight=rect.GetHeight();

   image.Create( subwidth, subheight, false );

   unsigned char *subdata = image.GetData(), *data=Src.GetData();

   wxCHECK_MSG( subdata, image, wxT("unable to create image") );

   // JKC: Quick hack - don't deal with masks - need to understand macro M_IMGDATA first.
//   if (Src.M_IMGDATA->m_hasMask)
//      image.SetMaskColour( Src.M_IMGDATA->m_maskRed, Src.M_IMGDATA->m_maskGreen, Src.M_IMGDATA->m_maskBlue );

   int subleft=3*rect.GetLeft();
   int width=3*Src.GetWidth();
   subwidth*=3;

   data+=rect.GetTop()*width+subleft;

   for (long j = 0; j < subheight; ++j)
   {
      memcpy( subdata, data, subwidth);
      subdata+=subwidth;
      data+=width;
   }

   // OK, so we've copied the RGB data.
   // Now do the Alpha channel.
   wxASSERT( Src.HasAlpha() );
   image.InitAlpha();

   subleft/=3;
   width/=3;
   subwidth/=3;

   data =Src.GetAlpha();
   subdata =image.GetAlpha();

   data+=rect.GetTop()*width+subleft;

   for (long j = 0; j < subheight; ++j)
   {
      memcpy( subdata, data, subwidth);
      subdata+=subwidth;
      data+=width;
   }
   return image;
}
예제 #3
0
static void GetStats(double *mean, double *stdev, const FloatImg& img, const wxRect& win)
{
    // Determine the mean and standard deviation
    double sum = 0.0;
    double a = 0.0;
    double q = 0.0;
    double k = 1.0;
    double km1 = 0.0;

    const int width = img.Size.GetWidth();
    const float *p0 = &img.px[win.GetTop() * width + win.GetLeft()];
    for (int y = 0; y < win.GetHeight(); y++)
    {
        const float *end = p0 + win.GetWidth();
        for (const float *p = p0; p < end; p++)
        {
            double const x = (double) *p;
            sum += x;
            double const a0 = a;
            a += (x - a) / k;
            q += (x - a0) * (x - a);
            km1 = k;
            k += 1.0;
        }
        p0 += width;
    }

    *mean = sum / km1;
    *stdev = sqrt(q / km1);
}
예제 #4
0
//
// Draws a focus rectangle (Taken directly from wxWidgets source)
//
void AColor::DrawFocus(wxDC & dc, wxRect & rect)
{
   // draw the pixels manually: note that to behave in the same manner as
   // DrawRect(), we must exclude the bottom and right borders from the
   // rectangle
   wxCoord x1 = rect.GetLeft(),
         y1 = rect.GetTop(),
         x2 = rect.GetRight(),
         y2 = rect.GetBottom();

   dc.SetPen(wxPen(wxT("MEDIUM GREY"), 0, wxSOLID));

   // this seems to be closer than what Windows does than wxINVERT although
   // I'm still not sure if it's correct
   dc.SetLogicalFunction(wxAND_REVERSE);

   wxCoord z;
   for ( z = x1 + 1; z < x2; z += 2 )
      dc.DrawPoint(z, y1);

   wxCoord shift = z == x2 ? 0 : 1;
   for ( z = y1 + shift; z < y2; z += 2 )
      dc.DrawPoint(x2, z);

   shift = z == y2 ? 0 : 1;
   for ( z = x2 - shift; z > x1; z -= 2 )
      dc.DrawPoint(z, y2);

   shift = z == x1 ? 0 : 1;
   for ( z = y2 - shift; z > y1; z -= 2 )
      dc.DrawPoint(x1, z);

   dc.SetLogicalFunction(wxCOPY);
}
//---------------------------------------------------------
void CVIEW_ScatterPlot::_Draw(wxDC &dc, wxRect r)
{
	r	= _Draw_Get_rDiagram(r);

	if( m_Trend.Get_Data_Count() > 1 )
	{
		//-------------------------------------------------
		if( m_Options("DISPLAY")->asInt() == 1 )
		{
			if( m_Options("DENSITY_LEG")->asBool() )
			{
				r.SetRight(r.GetRight() - 40);

				_Draw_Legend(dc, wxRect(r.GetRight() + 10, r.GetTop(), 40 - 20, r.GetHeight()));
			}

			_Draw_Image (dc, r);
		}
		else
		{
			_Draw_Points(dc, r);
		}

		//-------------------------------------------------
		_Draw_Frame(dc, r);
	}
	else
	{
		Draw_Text(dc, TEXTALIGN_CENTER, r.GetLeft() + r.GetWidth() / 2, r.GetTop() + r.GetHeight() / 2, _TL("Invalid data!"));
	}
}
//---------------------------------------------------------
wxRect CVIEW_ScatterPlot::_Draw_Get_rDiagram(wxRect r)
{
	return(	wxRect(
		wxPoint(r.GetLeft () + 45, r.GetTop   () + 20),
		wxPoint(r.GetRight() - 20, r.GetBottom() - 40)
	));
}
예제 #7
0
void wxGridCellIconRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
	const wxRect& rectCell, int row, int col, bool isSelected)
{
	wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
	const char** psz=NULL;
// 	if (grid.GetCellValue(row, col) == wxT("IDI_PC"))
// 		psz = szIconPC;
// 	else psz = szIconNomad;
	wxIcon icon(psz);
	icon.SetHeight(16);
	icon.SetWidth(16);
//	wxColour colourBackGround = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE);
//	dc.SetBrush(wxBrush(colourBackGround, wxSOLID));
//	dc.SetPen(wxPen(colourBackGround, 1, wxSOLID));
//	dc.DrawRectangle(rectCell);
	int nMargin = (rectCell.GetHeight() - icon.GetHeight()) /2;
	if (nMargin < 0) nMargin = 0;
	dc.DrawIcon(icon, rectCell.x, rectCell.y+nMargin);
	if (m_border == wxLAYOUT_TOP)
	{
		dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
		dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(), 
			rectCell.GetLeft(), rectCell.GetTop());
	}
//	dc.DrawIcon(icon, 16, 0);
}
예제 #8
0
bool MathCell::InUpdateRegion(wxRect rect)
{
  return
    (rect.GetRight()  >= m_updateRegion.GetLeft()  ) &&
    (rect.GetLeft()   <= m_updateRegion.GetRight() ) &&
    (rect.GetBottom() >= m_updateRegion.GetTop()   ) &&
    (rect.GetTop()    <= m_updateRegion.GetBottom());
}
예제 #9
0
void PaddingStyle::FromRect(const wxRect& rect) {
  Left = rect.GetLeft();
  Top = rect.GetTop();
  Bottom = rect.GetHeight();
  Right = rect.GetWidth();
  Width = Left + Right;
  Height = Top + Bottom;
}
예제 #10
0
void wxStdRenderer::DrawFrameWithoutLabel(wxDC& dc,
                                          const wxRect& rectFrame,
                                          const wxRect& rectLabel)
{
    // draw left, bottom and right lines entirely
    DrawVerticalLine(dc, rectFrame.GetLeft(),
                     rectFrame.GetTop(), rectFrame.GetBottom() - 2);
    DrawHorizontalLine(dc, rectFrame.GetBottom() - 1,
                       rectFrame.GetLeft(), rectFrame.GetRight());
    DrawVerticalLine(dc, rectFrame.GetRight() - 1,
                     rectFrame.GetTop(), rectFrame.GetBottom() - 1);

    // and 2 parts of the top line
    DrawHorizontalLine(dc, rectFrame.GetTop(),
                       rectFrame.GetLeft() + 1, rectLabel.GetLeft());
    DrawHorizontalLine(dc, rectFrame.GetTop(),
                       rectLabel.GetRight(), rectFrame.GetRight() - 2);
}
예제 #11
0
 void configuration_visitor::set_bbox(const wxRect& r) {
     boost::shared_ptr<vector_layer_ghost> ghost = m_panel->vectorlayerghost();
     if(!ghost) return;
     ghost->reset<vector_layer_ghost::Rectangle>();
     ghost->add_point(wxRealPoint(r.GetLeft (),r.GetTop   ()));
     ghost->add_point(wxRealPoint(r.GetRight(),r.GetBottom()));
     ghost->m_penRectangle = wxPen(*wxRED, 2, wxDOT);
     ghost->m_brushRectangle = wxBrush(*wxRED, wxTRANSPARENT);
 }
예제 #12
0
wxDCOverlay::wxDCOverlay(wxOverlay &overlay, wxDC *dc) :
    m_overlay(overlay)
{
    const wxRect device(wxPoint(0, 0), dc->GetSize());

    Init(dc,
         dc->DeviceToLogicalX(device.GetLeft()),
         dc->DeviceToLogicalY(device.GetTop()),
         dc->DeviceToLogicalX(device.GetRight()),
         dc->DeviceToLogicalY(device.GetBottom()));
}
//---------------------------------------------------------
void CVIEW_ScatterPlot::_Draw_Regression(wxDC &dc, wxRect r)
{
	wxPen	oldPen	= dc.GetPen();

	dc.SetPen(wxPen(
		m_Options("REG_COLOR")->asColor(),
		m_Options("REG_SIZE" )->asInt()
	));

	//-----------------------------------------------------
	double	dx	= (r.GetWidth () - 1.) / m_Trend.Get_Data_XStats().Get_Range();
	double	dy	= (r.GetHeight() - 1.) / m_Trend.Get_Data_YStats().Get_Range();

	//-----------------------------------------------------
	dc.DrawCircle(
		GET_DC_X(m_Trend.Get_Data_XStats().Get_Mean()),
		GET_DC_Y(m_Trend.Get_Data_YStats().Get_Mean()), 2
	);

	double	ex	= m_Trend.Get_Data_XStats().Get_Range() / (double)r.GetWidth();
	double	x	= m_Trend.Get_Data_XMin();

	for(int ix=0, ay, by=0; ix<r.GetWidth(); ix++, x+=ex)
	{
		double	y	= m_Trend.Get_Value(x);

		ay	= by; by = r.GetBottom() - (int)(dy * (y - m_Trend.Get_Data_YMin()));

		if( ix > 0 && r.GetTop() < ay && ay < r.GetBottom() && r.GetTop() < by && by < r.GetBottom() )
		{
			dc.DrawLine(r.GetLeft() + ix - 1, ay, r.GetLeft() + ix, by);
		}
	}

	dc.SetPen(oldPen);

	//-----------------------------------------------------
	Draw_Text(dc, TEXTALIGN_BOTTOMCENTER, r.GetLeft() + r.GetWidth() / 2, r.GetTop(),
		m_Trend.Get_Formula(SG_TREND_STRING_Compact).c_str()
	);
}
예제 #14
0
//-----------------------------------------------------------------------
CEGUI::Imageset* EditorDocument::generateRealImageset(const wxString& pathName)
{
    const String imagesetName ( CEGUIHelper::ToCEGUIString( m_imagesetName ) );
    const String imageFilename ( CEGUIHelper::ToCEGUIString( pathName + m_imageFilename ) );

    ImagesetManager& isMgr = ImagesetManager::getSingleton();

    if ( isMgr.isImagesetPresent( imagesetName ) )
        // TODO: Maybe ask user whether to continue here?
        isMgr.destroyImageset( imagesetName );

    // create the imageset
    Imageset* imageset = isMgr.createImagesetFromImageFile( imagesetName, imageFilename );

    // auto-scale options
    imageset->setAutoScalingEnabled( m_autoScaled );
    imageset->setNativeResolution( CEGUI::Size( m_nativeResolution.x, m_nativeResolution.y ) );

    // iterate over all the elements in the class
    mapNamedRegion::iterator it;
    for( it = m_mapSetRectangles.begin(); it != m_mapSetRectangles.end(); ++it )
    {
        const String imageName = CEGUIHelper::ToCEGUIString( wxString( it->first ) );

        if ( !imageset->isImageDefined( imageName ) )
        {
            const wxRect r( it->second );
            const CEGUI::Rect newDim( ( ( r.GetLeft() > 0 ) ? r.GetLeft() : 0 ),
                               ( ( r.GetTop() > 0 ) ? r.GetTop() : 0 ),
                               ( ( r.GetRight() + 1 > 0 ) ? r.GetRight() + 1 : 0 ),
                               ( ( r.GetBottom() + 1 > 0 ) ? r.GetBottom() + 1 : 0 ) );
            const CEGUI::Point p ( 0.0f, 0.0f );
            imageset->defineImage( imageName, newDim, p );
        }
    }

    if ( imageset->isImageDefined ( "full_image" ) )
        imageset->undefineImage( "full_image" );

    return imageset;
}
예제 #15
0
wxRect MathCell::CropToUpdateRegion(wxRect rect)
{
  int left  =rect.GetLeft();
  int top   =rect.GetTop ();
  int right =rect.GetRight();
  int bottom=rect.GetBottom();
  if (left   < m_updateRegion.GetLeft())   left   = m_updateRegion.GetLeft();
  if (right  > m_updateRegion.GetRight())  right  = m_updateRegion.GetRight();
  if (top    < m_updateRegion.GetTop())    top    = m_updateRegion.GetTop();
  if (bottom > m_updateRegion.GetBottom()) bottom = m_updateRegion.GetBottom();
  return wxRect(wxPoint(left,top),wxPoint(right,bottom));
}
예제 #16
0
static bool ASCOM_SetROI(IDispatch *cam, const wxRect& roi, EXCEPINFO *excep)
{
    // returns true on error, false if OK

    VARIANTARG rgvarg[1];
    rgvarg[0].vt = VT_I4;

    DISPID dispidNamed = DISPID_PROPERTYPUT;
    DISPPARAMS dispParms;
    dispParms.cArgs = 1;
    dispParms.rgvarg = rgvarg;
    dispParms.cNamedArgs = 1;                   // PropPut kludge
    dispParms.rgdispidNamedArgs = &dispidNamed;

    Variant vRes;
    HRESULT hr;

    rgvarg[0].lVal = roi.GetLeft();
    if (FAILED(hr = cam->Invoke(dispid_startx, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT,
        &dispParms, &vRes, excep, NULL)))
    {
        LogExcep(hr, "set startx", *excep);
        return true;
    }

    rgvarg[0].lVal = roi.GetTop();
    if (FAILED(hr = cam->Invoke(dispid_starty, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT,
        &dispParms, &vRes, excep, NULL)))
    {
        LogExcep(hr, "set starty", *excep);
        return true;
    }

    rgvarg[0].lVal = roi.GetWidth();
    if (FAILED(hr = cam->Invoke(dispid_numx, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT,
        &dispParms, &vRes, excep, NULL)))
    {
        LogExcep(hr, "set numx", *excep);
        return true;
    }

    rgvarg[0].lVal = roi.GetHeight();
    if (FAILED(hr = cam->Invoke(dispid_numy, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT,
        &dispParms, &vRes, excep, NULL)))
    {
        LogExcep(hr, "set numy", *excep);
        return true;
    }

    return false;
}
예제 #17
0
    wxToolInfo(HWND hwndOwner, unsigned int id, const wxRect& rc)
    {
        // initialize all members
        ::ZeroMemory(this, sizeof(TOOLINFO));

        // the structure TOOLINFO has been extended with a 4 byte field in
        // version 4.70 of comctl32.dll and another one in 5.01 but we don't
        // use these extended fields so use the old struct size to ensure that
        // the tooltips work on old (Windows 95) systems too
        cbSize = TTTOOLINFO_V1_SIZE;

        hwnd = hwndOwner;

        if (rc.IsEmpty())
        {
            uFlags = TTF_IDISHWND;
            uId = (UINT_PTR)hwndOwner;
        }
        else
        {
            // this tooltip must be shown only if the mouse hovers a specific rect
            // of the hwnd parameter!
            rect.left = rc.GetLeft();
            rect.right = rc.GetRight();
            rect.top = rc.GetTop();
            rect.bottom = rc.GetBottom();

            // note that not setting TTF_IDISHWND from the uFlags member means that the
            // ti.uId field should not contain the HWND but rather as MSDN says an
            // "Application-defined identifier of the tool"; this is used internally by
            // Windows to distinguish the different tooltips attached to the same window
            uId = id;
        }

        // we use TTF_TRANSPARENT to fix a problem which arises at least with
        // the text controls but may presumably happen with other controls
        // which display the tooltip at mouse position: it can start flashing
        // then as the control gets "focus lost" events and dismisses the
        // tooltip which then reappears because mouse remains hovering over the
        // control, see SF patch 1821229
        if ( wxApp::GetComCtl32Version() >= 470 )
        {
            uFlags |= TTF_TRANSPARENT;
        }
    }
//---------------------------------------------------------
void CVIEW_ScatterPlot::_Draw_Legend(wxDC &dc, wxRect r)
{
	CSG_Colors	Colors(*m_Options("DENSITY_PAL")->asColors());

	Colors.Set_Count(r.GetHeight());

	for(int i=0, y=r.GetBottom(); i<Colors.Get_Count(); i++, y--)
	{
		Draw_FillRect(dc, Get_Color_asWX(Colors.Get_Color(i)), r.GetLeft(), y, r.GetRight(), y + 1);
	}

//	r.Offset(0, -r.GetHeight());

	Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);

	Draw_Text(dc, TEXTALIGN_BOTTOMLEFT, 2 + r.GetRight(), r.GetBottom(), "0");
	Draw_Text(dc, TEXTALIGN_TOPLEFT   , 2 + r.GetRight(), r.GetTop   (), wxString::Format("%d", (int)m_Count.Get_Max()));
}
wxJigsawInputParameter::wxJigsawInputParameterHitTest wxJigsawInputParameter::HitTest(
	const wxPoint & pos, const wxRect & paramRect, bool bDebug)
{
	do
	{
		if(!paramRect.Contains(pos)) break;
		if(pos.x - paramRect.GetLeft() < m_LabelSize.GetWidth())
		{
			return wxJSP_HITETST_LABEL;
		}
		if(m_Shape)
		{
			return wxJSP_HITTEST_SHAPE;
		}
		return wxJSP_HITTEST_SLOT;
	}
	while(false);
	return wxJSP_HITTEST_NONE;
}
예제 #20
0
vector< wxRect > GetCoverage( const wxRect& viewport, const wxRect& canvas, const wxSize& gridSize )
{
    const wxRect clippedViewport( canvas.Intersect( viewport ) );

    vector< wxRect > coverage;
    const int top    = clippedViewport.GetTop()    / gridSize.y;
    const int bottom = clippedViewport.GetBottom() / gridSize.y;
    const int left   = clippedViewport.GetLeft()   / gridSize.x;
    const int right  = clippedViewport.GetRight()  / gridSize.x;
    for( int y = top; y <= bottom; ++y )
    {
        for( int x = left; x <= right; ++x )
        {
            const wxRect candidate( x * gridSize.x, y * gridSize.y, gridSize.x, gridSize.y );
            const wxRect clipped( canvas.Intersect( candidate ) );
            coverage.push_back( clipped );
        }
    }
    return coverage;
}
bool LfnTech::Copy(
	void* destBase,
	const void* srcBase,
	const wxPoint& destPoint,
	const wxRect& srcRect,
	int destStride,
	int srcStride,
	int bytesPerPixel)
{
	bool result = false;

	if (destBase && srcBase && destStride > 0 && srcStride > 0 && bytesPerPixel > 0)
	{
		const int srcLeft = srcRect.GetLeft();
		const int srcBottom = srcRect.GetBottom();
		const int bytesPerRowCopy = bytesPerPixel * srcRect.GetWidth();
		if (bytesPerRowCopy == destStride && bytesPerRowCopy == srcStride)
		{
			wxASSERT(destPoint.x == 0);
			wxASSERT(srcLeft == 0);
			memcpy(
				GetRowMajorPointer(destBase, destStride, bytesPerPixel, destPoint.x, destPoint.y),
				GetRowMajorPointer(srcBase, srcStride, bytesPerPixel, srcLeft, srcRect.GetTop()),
				bytesPerRowCopy * srcRect.GetHeight());
		}
		else
		{
			for (int srcY = srcRect.GetTop(), destY = destPoint.y; srcY <= srcBottom; ++srcY, ++destY)
			{
				memcpy(
					GetRowMajorPointer(destBase, destStride, bytesPerPixel, destPoint.x, destY),
					GetRowMajorPointer(srcBase, srcStride, bytesPerPixel, srcLeft, srcY),
					bytesPerRowCopy);
			}
		}

		result = true;
	}

	return result;
}
예제 #22
0
BOOL FontDropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect, BOOL Disabled, INT32 flags)
{
	ResourceID BitmapID = 0;
	FontClass Type;

	if ((ItemData==&TheTopItem) || !ItemData)
		Type = TheTopItem.Type;
	else
		Type = ((FontDropItem *)ItemData)->Type;

	switch(Type)
	{
		case FC_TRUETYPE:
			BitmapID = _R(IDB_TTF_SYMBOL);
			break;

		case FC_ATM:
			BitmapID = _R(IDB_ATM_SYMBOL);
			break;

		case FC_UNDEFINED:
			BitmapID = _R(IDB_UNKNOWNFONT_SYMBOL);
			break;

		default:
			BitmapID = 0;
			break;
	}

	if(BitmapID == 0)
		return FALSE;

	wxBitmap * pBitmap = CamArtProvider::Get()->FindBitmap(BitmapID, (CamArtFlags)(CAF_DEFAULT|(Disabled?CAF_GREYED:0)));
	if (!pBitmap)
		return FALSE;

	dc.DrawBitmap(*pBitmap, IconRect.GetLeft(), IconRect.GetTop(), TRUE);

	return TRUE;
}
예제 #23
0
void SkinGradient::GenRects(wxGraphicsContext* gc, const wxRect& therect)
{
    if (0 && therect == oldRect) {
        // use already cached rectangles.
        //
        // TODO: this caching falls down with scrolling, since the position of each
        // incoming rectangle is different.
        return;
    }

    float x   = therect.x, y = therect.y;
    float w   = therect.width;
    float h   = therect.height;
    bool vert = direction == wxVERTICAL;

    float p1  = vert? therect.GetTop() : therect.GetLeft();

    size_t lc = colors.size() - 1;
    float dx  = (vert ? h : w) / float(lc);

    rects.clear();
    for (size_t i = 0; i < lc; ++i) {
        wxColour c1(colors[i]);
        wxColour c2(colors[i+1]);

        float delta = i == 0 || i == lc ? 1.0 : 0.0;
        if (vert)
            rects.push_back(BrushRect(
                                gc->CreateLinearGradientBrush(x, p1 - delta, x, p1 + dx + delta*2, c1, c2),
                                wxRect2DDouble(x, p1, w, dx + delta - 1)));
        else
            rects.push_back(BrushRect(
                                gc->CreateLinearGradientBrush(p1 - delta, y, p1 + dx + delta*2, y, c1, c2),
                                wxRect2DDouble(p1, y, dx + delta, h)));
        p1 += dx;
    }

    oldRect = therect;
}
예제 #24
0
void
wxStdRenderer::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags))
{
    // draw the pixels manually because the "dots" in wxPen with wxDOT style
    // may be short traits and not really dots
    //
    // note that to behave in the same manner as DrawRect(), we must exclude
    // the bottom and right borders from the rectangle
    wxCoord x1 = rect.GetLeft(),
            y1 = rect.GetTop(),
            x2 = rect.GetRight(),
            y2 = rect.GetBottom();

    dc.SetPen(m_penBlack);

    // this seems to be closer than what Windows does than wxINVERT although
    // I'm still not sure if it's correct
    dc.SetLogicalFunction(wxAND_REVERSE);

    wxCoord z;
    for ( z = x1 + 1; z < x2; z += 2 )
        dc.DrawPoint(z, rect.GetTop());

    wxCoord shift = z == x2 ? 0 : 1;
    for ( z = y1 + shift; z < y2; z += 2 )
        dc.DrawPoint(x2, z);

    shift = z == y2 ? 0 : 1;
    for ( z = x2 - shift; z > x1; z -= 2 )
        dc.DrawPoint(z, y2);

    shift = z == x1 ? 0 : 1;
    for ( z = y2 - shift; z > y1; z -= 2 )
        dc.DrawPoint(x1, z);

    dc.SetLogicalFunction(wxCOPY);
}
예제 #25
0
PRectangle PRectangleFromwxRect(wxRect rc) {
    return PRectangle(rc.GetLeft(), rc.GetTop(),
                      rc.GetRight()+1, rc.GetBottom()+1);
}
예제 #26
0
void wxSFGridShape::FitShapeToRect(wxSFShapeBase *shape, const wxRect& rct)
{
    wxRect shapeBB = shape->GetBoundingBox();
    wxRealPoint prevPos = shape->GetRelativePosition();

    // do vertical alignment
    switch( shape->GetVAlign() )
    {
        case valignTOP:
            shape->SetRelativePosition( prevPos.x, rct.GetTop() + shape->GetVBorder() );
            break;

        case valignMIDDLE:
            shape->SetRelativePosition( prevPos.x, rct.GetTop() + (rct.GetHeight()/2 - shapeBB.GetHeight()/2) );
            break;

        case valignBOTTOM:
            shape->SetRelativePosition( prevPos.x, rct.GetBottom() - shapeBB.GetHeight() - shape->GetVBorder() );
            break;

        case valignEXPAND:
            if( shape->ContainsStyle( sfsSIZE_CHANGE ) )
            {
                shape->SetRelativePosition( prevPos.x, rct.GetTop() + shape->GetVBorder() );
                shape->Scale( 1.f, double(rct.GetHeight() - 2*shape->GetVBorder())/shapeBB.GetHeight() );
            }
            break;

        default:
            shape->SetRelativePosition( prevPos.x, rct.GetTop() );
            break;
    }

    prevPos = shape->GetRelativePosition();

    // do horizontal alignment
    switch( shape->GetHAlign() )
    {
        case halignLEFT:
            shape->SetRelativePosition( rct.GetLeft() + shape->GetHBorder(), prevPos.y );
            break;

        case halignCENTER:
            shape->SetRelativePosition( rct.GetLeft() + (rct.GetWidth()/2 - shapeBB.GetWidth()/2), prevPos.y );
            break;

        case halignRIGHT:
            shape->SetRelativePosition( rct.GetRight() - shapeBB.GetWidth() - shape->GetHBorder(), prevPos.y );
            break;

        case halignEXPAND:
            if( shape->ContainsStyle( sfsSIZE_CHANGE ) )
            {
                shape->SetRelativePosition( rct.GetLeft() + shape->GetHBorder(), prevPos.y );
                shape->Scale( double(rct.GetWidth() - 2*shape->GetHBorder())/shapeBB.GetWidth(), 1.f );
            }
            break;

        default:
            shape->SetRelativePosition( rct.GetLeft(), prevPos.y );
            break;
    }
}
예제 #27
0
void ImageButton::SetGrid(const wxRect& rect) {
  SetGrid(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
}
예제 #28
0
파일: dropdown.cpp 프로젝트: vata/xarino
wxSize DropDown::HandleDrawItemInternal(wxDC& dc, const wxRect& Rect, INT32 item, INT32 flags, BOOL Draw)
{
	const INT32 border = 2;

	if (CCamApp::IsDisabled())			// Inside an error handler
		return(wxDefaultSize);

	wxOwnerDrawnComboBox * pGadget = GetBox();

//	if ((INT32)pInfo->itemID == -1 || (INT32)pInfo->itemData == -1)	// Draw item -1: just exit
//		return(FALSE);

	void * ItemData = GetItemData(item);
		// Determine if it is a divider item
	if (!ItemData)
	{
		// It's a divider, so draw it specially - it is a simple black line across the center of the rectangle
		wxCoord midpoint = Rect.GetTop()+Rect.GetHeight()/2;
		if (Draw)
		{
			wxPen OldPen=dc.GetPen();
			dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
			dc.DrawLine(Rect.GetLeft(), midpoint, Rect.GetRight()+1, midpoint);
			dc.SetPen(OldPen);
		}
		return(wxSize(-1,5));
	}

	// If we aren't drawing, we should get the size of the text and return that appopriately modified
	if (!Draw)
	{
		// Call the derived class
		wxRect def(-1,-1,-1,-1);
		wxSize TextSize = DrawText(ItemData, dc, def, item, flags, FALSE); // Rect is unused here as Draw is FALSE
		TextSize.x+=2*border;
		TextSize.y+=2*border; // This gives us the bounding rect as we leave some space around it
		if (HasIcon(ItemData))
		{
			// There is an icon. It's width is equal to the text height less 2 (deflated in both
			// directions. There is also a 6 pixel space
			TextSize.x += (TextSize.y-2)+6;
		}
		return TextSize;
	}
	
	wxRect rect=Rect;
	rect.Deflate(border);

	// Calculate where the colour splodge (if any) will go (also used to shift text to the right later)
	wxRect IconRect=rect;
	IconRect.Deflate(1);
	IconRect.SetWidth(IconRect.GetHeight());

	wxRect TextRect=rect;

	wxPalette * OldPal = NULL;

	// If it's a special item with a colour splodge, or a normal colour item, draw the colour splodge
	if (HasIcon(ItemData))
	{
		if (PaletteManager::UsePalette())
			OldPal = PaletteManager::StartPaintPalette(&dc);

		// Call the derived class to draw the icon
		if (Draw)
			DrawIcon(ItemData, dc, IconRect, !pGadget->IsEnabled(), flags);

		// Shift the text to the right of the icon
		INT32 shift=IconRect.GetWidth()+6;
		TextRect.Offset(shift,0);
		INT32 NewWidth=TextRect.GetWidth()-shift;
		TextRect.SetWidth(NewWidth<1?1:NewWidth);
	}
	
	if (TextRect.GetWidth()>1)		// if there's room to draw any text, draw it
	{
		// Call derived class to draw the text
		if (Draw)
			DrawText(ItemData, dc, TextRect, item, flags, TRUE);
	}

	// Restore the DC's previous palette if we selected our one in
	if (OldPal)
		PaletteManager::StopPaintPalette(&dc, OldPal);

	return(wxDefaultSize);
}
예제 #29
0
파일: toplvcmn.cpp 프로젝트: mark711/Cafu
void wxTopLevelWindowBase::DoCentre(int dir)
{
    // on some platforms centering top level windows is impossible
    // because they are always maximized by guidelines or limitations
    //
    // and centering a maximized window doesn't make sense as its position
    // can't change
    if ( IsAlwaysMaximized() || IsMaximized() )
        return;

    // we need the display rect anyhow so store it first: notice that we should
    // be centered on the same display as our parent window, the display of
    // this window itself is not really defined yet
    int nDisplay = wxDisplay::GetFromWindow(GetParent() ? GetParent() : this);
    wxDisplay dpy(nDisplay == wxNOT_FOUND ? 0 : nDisplay);
    const wxRect rectDisplay(dpy.GetClientArea());

    // what should we centre this window on?
    wxRect rectParent;
    if ( !(dir & wxCENTRE_ON_SCREEN) && GetParent() )
    {
        // centre on parent window: notice that we need screen coordinates for
        // positioning this TLW
        rectParent = GetParent()->GetScreenRect();

        // if the parent is entirely off screen (happens at least with MDI
        // parent frame under Mac but could happen elsewhere too if the frame
        // was hidden/moved away for some reason), don't use it as otherwise
        // this window wouldn't be visible at all
        if ( !rectParent.Intersects(rectDisplay) )
        {
            // just centre on screen then
            rectParent = rectDisplay;
        }
    }
    else
    {
        // we were explicitly asked to centre this window on the entire screen
        // or if we have no parent anyhow and so can't centre on it
        rectParent = rectDisplay;
    }

    if ( !(dir & wxBOTH) )
        dir |= wxBOTH; // if neither is specified, center in both directions

    // the new window rect candidate
    wxRect rect = GetRect().CentreIn(rectParent, dir & ~wxCENTRE_ON_SCREEN);

    // we don't want to place the window off screen if Centre() is called as
    // this is (almost?) never wanted and it would be very difficult to prevent
    // it from happening from the user code if we didn't check for it here
    if ( !rectDisplay.Contains(rect.GetTopLeft()) )
    {
        // move the window just enough to make the corner visible
        int dx = rectDisplay.GetLeft() - rect.GetLeft();
        int dy = rectDisplay.GetTop() - rect.GetTop();
        rect.Offset(dx > 0 ? dx : 0, dy > 0 ? dy : 0);
    }

    if ( !rectDisplay.Contains(rect.GetBottomRight()) )
    {
        // do the same for this corner too
        int dx = rectDisplay.GetRight() - rect.GetRight();
        int dy = rectDisplay.GetBottom() - rect.GetBottom();
        rect.Offset(dx < 0 ? dx : 0, dy < 0 ? dy : 0);
    }

    // the window top left and bottom right corner are both visible now and
    // although the window might still be not entirely on screen (with 2
    // staggered displays for example) we wouldn't be able to improve the
    // layout much in such case, so we stop here

    // -1 could be valid coordinate here if there are several displays
    SetSize(rect, wxSIZE_ALLOW_MINUS_ONE);
}
예제 #30
0
/* static */
void wxControlRenderer::DrawBitmap(wxDC &dc,
                                   const wxBitmap& bitmap,
                                   const wxRect& rect,
                                   int alignment,
                                   wxStretch stretch)
{
    // we may change the bitmap if we stretch it
    wxBitmap bmp = bitmap;
    if ( !bmp.IsOk() )
        return;

    int width = bmp.GetWidth(),
        height = bmp.GetHeight();

    wxCoord x = 0,
            y = 0;
    if ( stretch & wxTILE )
    {
        // tile the bitmap
        for ( ; x < rect.width; x += width )
        {
            for ( y = 0; y < rect.height; y += height )
            {
                // no need to use mask here as we cover the entire window area
                dc.DrawBitmap(bmp, x, y);
            }
        }
    }
#if wxUSE_IMAGE
    else if ( stretch & wxEXPAND )
    {
        // stretch bitmap to fill the entire control
        bmp = wxBitmap(wxImage(bmp.ConvertToImage()).Scale(rect.width, rect.height));
    }
#endif // wxUSE_IMAGE
    else // not stretched, not tiled
    {
        if ( alignment & wxALIGN_RIGHT )
        {
            x = rect.GetRight() - width;
        }
        else if ( alignment & wxALIGN_CENTRE )
        {
            x = (rect.GetLeft() + rect.GetRight() - width + 1) / 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() - height + 1) / 2;
        }
        else // alignment & wxALIGN_TOP
        {
            y = rect.GetTop();
        }
    }

    // do draw it
    dc.DrawBitmap(bmp, x, y, true /* use mask */);
}