示例#1
0
int LKSurface::GetTextWidth(const TCHAR *text) {
    SIZE tsize;
    GetTextSize(text, &tsize);
    return tsize.cx;
}
//*****************************************************************************
void CBCGPCaptionBar::RecalcLayout ()
{
	CClientDC dc (NULL);

	CFont* pOldFont = dc.SelectObject (
		m_hFont == NULL ? &globalData.fontRegular : CFont::FromHandle (m_hFont));
	ASSERT (pOldFont != NULL);

	TEXTMETRIC tm;
	dc.GetTextMetrics (&tm);

	int nTextHeight = tm.tmHeight + 2;
	CSize sizeImage = GetImageSize ();

	const int nButtonVertMargin = CBCGPVisualManager::GetInstance()->GetMessageBarMargin();
	const int nBorderSize = m_bIsMessageBarMode ? 0 : m_nBorderSize;

	//-------------------------------------------------------------------
	// the height is set to the default (provided by the user in Create)
	// or calculated if it is -1
	//-------------------------------------------------------------------
	if (m_nDefaultHeight != -1)
	{
		m_nCurrentHeight = m_nDefaultHeight;
	}
	else
	{
		if (!m_strBtnText.IsEmpty () && m_bIsMessageBarMode)
		{
			nTextHeight += 2 * nButtonVertMargin;
		}

		m_nCurrentHeight = max (nTextHeight, sizeImage.cy) + 
			m_nMargin * 2 + nBorderSize;
	}

	if (m_bIsMessageBarMode)
	{
		m_nCurrentHeight += CBCGPVisualManager::GetInstance()->GetMessageBarMargin() * 2;
	}

	// for left and center alignment: icon, button, text
	// for right alignment: text, button, icon

	CRect rectClient;
	GetClientRect (rectClient);
	if (rectClient.IsRectEmpty ())
	{
		return;
	}

	if (m_bIsMessageBarMode)
	{
		CSize sizeImage = CBCGPMenuImages::Size ();
		const int nCloseButtonMargin = 4;

		sizeImage.cx += 2 * nCloseButtonMargin;
		sizeImage.cy += 2 * nCloseButtonMargin;

		m_rectClose = CRect (
			CPoint (rectClient.right - sizeImage.cx, rectClient.top + nCloseButtonMargin),
			sizeImage);

		m_rectClose.right--;

		rectClient.DeflateRect (nCloseButtonMargin, nCloseButtonMargin);
		rectClient.right -= m_rectClose.Width ();
	}
	else
	{
		m_rectClose.SetRectEmpty();
	}

	BOOL bButtonLeftOfIcon = FALSE;
	BOOL bTextLeftOfButton = FALSE;
	BOOL bTextLeftOfIcon = FALSE;

	BOOL bIconCenter = FALSE;
	BOOL bButtonCenter = FALSE;
	BOOL bButtonAfterText = FALSE;
	BOOL bTextCenter = FALSE;

	// differs from the current height, because the border size is non-client area
	int nBaseLine = rectClient.CenterPoint ().y;
	int nCenterOffset = rectClient.CenterPoint ().x;

	int nNextXOffsetLeft  = rectClient.left + m_nMargin;
	int nNextXOffsetRight = rectClient.right - m_nMargin;
	int nNextXOffsetCenter = nCenterOffset;

	if (IsImageSet ())
	{
		if (sizeImage.cy < rectClient.Height () || m_bIsMessageBarMode)
		{
			// center the icon if its height lesser than client area height
			m_rectImage.top = nBaseLine - sizeImage.cy / 2;
		}
		else
		{
			// otherwise, clip it from the buttom
			m_rectImage.top = rectClient.top + m_nMargin;
		}

		if (!m_bStretchImage)
		{
			m_rectImage.bottom = m_rectImage.top + sizeImage.cy;
		}
		else
		{
			m_rectImage.bottom = rectClient.bottom - m_nMargin;
		}

		switch (m_iconAlignment)
		{
		case ALIGN_LEFT:
			m_rectImage.left = nNextXOffsetLeft;
			m_rectImage.right = m_rectImage.left + sizeImage.cx;
			nNextXOffsetLeft = m_rectImage.right + m_nHorzElementOffset;
			break;

		case ALIGN_RIGHT:
			m_rectImage.left = nNextXOffsetRight - sizeImage.cx;
			m_rectImage.right = m_rectImage.left + sizeImage.cx;
			nNextXOffsetRight = m_rectImage.left - m_nHorzElementOffset;
			// only in this case button and text is at the left side of the icon
			bButtonLeftOfIcon = TRUE; 
			bTextLeftOfIcon = TRUE;
			break;

		case ALIGN_CENTER:
			bIconCenter = TRUE;
			nNextXOffsetCenter -= sizeImage.cx / 2;

			if (m_btnAlignnment == ALIGN_LEFT)
			{
				bButtonLeftOfIcon = TRUE;
			}

			if (m_textAlignment == ALIGN_LEFT)
			{
				bTextLeftOfIcon = TRUE;
			}
			break;

		default:
			ASSERT (FALSE);
		}
	}
	else
	{
		m_rectImage.SetRectEmpty();
	}

	int nButtonWidth = 0;

	if (!m_strBtnText.IsEmpty ())
	{
		nButtonWidth = dc.GetTextExtent (m_strBtnText).cx + 2 * m_nHorzElementOffset;

		if (m_bIsMessageBarMode)
		{
			nButtonWidth += 2 * nButtonHorzMargin;
		}

		if (m_uiBtnID != 0 && m_bBtnEnabled && m_bBtnHasDropDownArrow)
		{
			nButtonWidth += nMenuArrowWidth;
		}

		// the button always has a height equivalent to the bar's height
		m_rectButton.top = rectClient.top;
		m_rectButton.bottom = rectClient.bottom;

		if (m_bIsMessageBarMode)
		{
			m_rectButton.DeflateRect (0, nButtonVertMargin);
		}

		switch (m_btnAlignnment)
		{
		case ALIGN_LEFT:
			if (!m_bIsMessageBarMode || m_textAlignment != ALIGN_LEFT)
			{
				m_rectButton.left = nNextXOffsetLeft;

				if (nNextXOffsetLeft == rectClient.left + m_nMargin)
				{
					m_rectButton.left = rectClient.left + m_nMargin;
				}

				m_rectButton.right = m_rectButton.left + nButtonWidth;
				nNextXOffsetLeft = m_rectButton.right + m_nHorzElementOffset;
			}
			else
			{
				bButtonAfterText = TRUE;
			}
			break;

		case ALIGN_RIGHT:
			m_rectButton.left = nNextXOffsetRight - nButtonWidth;

			if (nNextXOffsetRight == rectClient.right - m_nMargin)
			{
				m_rectButton.left = rectClient.right - nButtonWidth - m_nMargin;
			}

			m_rectButton.right = m_rectButton.left + nButtonWidth;
			nNextXOffsetRight = m_rectButton.left - m_nHorzElementOffset;
			// only in this case text at the left side of the button
			bTextLeftOfButton = TRUE;
			break;

		case ALIGN_CENTER:
			bButtonCenter = TRUE;
			nNextXOffsetCenter -= nButtonWidth / 2;

			if (m_textAlignment == ALIGN_LEFT)
			{
				bTextLeftOfButton = TRUE;
			}
			break;

		default:
			ASSERT (FALSE);
			return;
		}
	}
	else
	{
		m_rectButton.SetRectEmpty();
	}

	CSize sizeText (0, 0);

	if (!m_strText.IsEmpty ())
	{
		sizeText = GetTextSize (&dc, m_strText);

		m_rectText.top = nBaseLine - sizeText.cy / 2;
		m_rectText.bottom = m_rectText.top + sizeText.cy;

		switch (m_textAlignment)
		{
		case ALIGN_LEFT:
			m_rectText.left = nNextXOffsetLeft;
			nNextXOffsetLeft += sizeText.cx + 2 * m_nMargin;
			break;

		case ALIGN_RIGHT:
			m_rectText.left = nNextXOffsetRight - sizeText.cx;
			break;

		case ALIGN_CENTER:
			bTextCenter = TRUE;
			nNextXOffsetCenter -= sizeText.cx / 2;
			break;

		default:
			ASSERT (FALSE);
			return;
		}

		m_rectText.right = m_rectText.left + sizeText.cx;
		AdjustRectToMargin (m_rectText, rectClient, m_nMargin);
		m_rectDrawText = m_rectText;
	}

	if (bIconCenter)
	{
		m_rectImage.left = nNextXOffsetCenter;
		m_rectImage.right = m_rectImage.left + sizeImage.cx;
		nNextXOffsetCenter = m_rectImage.right + m_nHorzElementOffset;
	}

	if (bButtonAfterText)
	{
		m_rectButton.left = nNextXOffsetLeft;
		m_rectButton.right = m_rectButton.left + nButtonWidth;

		if (m_rectButton.right + m_nMargin > rectClient.right)
		{
			m_rectButton.right = rectClient.right - m_nMargin;
			m_rectButton.left = m_rectButton.right - nButtonWidth;
		}
	}
	else if (bButtonCenter)
	{
		m_rectButton.left = nNextXOffsetCenter;
		m_rectButton.right = m_rectButton.left + nButtonWidth;
		nNextXOffsetCenter = m_rectButton.right + m_nHorzElementOffset;
	}

	if (bTextCenter)
	{
		m_rectText.left = nNextXOffsetCenter;
		m_rectText.right = m_rectText.left + sizeText.cx; 
		AdjustRectToMargin (m_rectText, rectClient, m_nMargin);
		m_rectDrawText = m_rectText;
	}

	if (IsImageSet ())
	{
		// do not retain image size if it should be stretched
		AdjustRectToMargin (m_rectImage, rectClient, m_nMargin, !m_bStretchImage);

		if (m_rectImage.left < rectClient.left || 
			m_rectImage.right > rectClient.right)
		{
			m_rectImage.SetRectEmpty ();
		}
	}

	CRect rectButtonTemp = m_rectButton;
	if (!m_strBtnText.IsEmpty () && IsImageSet ())
	{
		CheckRectangle (rectButtonTemp, m_rectImage, bButtonLeftOfIcon);
	}

	if (!m_strBtnText.IsEmpty ())
	{
		AdjustRectToMargin (rectButtonTemp, rectClient, m_nMargin);

		if (m_rectButton.Width () + m_rectImage.Width () + 2 * m_nMargin > rectClient.Width ())
		{
			m_rectButton.SetRectEmpty ();
		}
	}

	if (!m_strText.IsEmpty ())
	{
		CheckRectangle (m_rectDrawText, m_rectImage, bTextLeftOfIcon); 
		CheckRectangle (m_rectDrawText, rectButtonTemp, bTextLeftOfButton || bButtonAfterText);
	}

	dc.SelectObject (pOldFont);

	m_bTextIsTruncated = m_rectDrawText.Width () < sizeText.cx;

	UpdateTooltips ();
}
void DIALOG_COPPER_ZONE::initDialog()
{
    BOARD* board = m_Parent->GetBoard();

    wxString msg;

    if( m_settings.m_Zone_45_Only )
        m_OrientEdgesOpt->SetSelection( 1 );

    m_FillModeCtrl->SetSelection( m_settings.m_FillMode ? 1 : 0 );

    AddUnitSymbol( *m_ClearanceValueTitle, g_UserUnit );
    msg = StringFromValue( g_UserUnit, m_settings.m_ZoneClearance );
    m_ZoneClearanceCtrl->SetValue( msg );

    AddUnitSymbol( *m_MinThicknessValueTitle, g_UserUnit );
    msg = StringFromValue( g_UserUnit, m_settings.m_ZoneMinThickness );
    m_ZoneMinThicknessCtrl->SetValue( msg );

    switch( m_settings.GetPadConnection() )
    {
    case PAD_ZONE_CONN_THT_THERMAL:   // Thermals only for THT pads
        m_PadInZoneOpt->SetSelection( 2 );
        break;

    case PAD_ZONE_CONN_NONE:        // Pads are not covered
        m_PadInZoneOpt->SetSelection( 3 );
        break;

    default:
    case PAD_ZONE_CONN_THERMAL:     // Use thermal relief for pads
        m_PadInZoneOpt->SetSelection( 1 );
        break;

    case PAD_ZONE_CONN_FULL:        // pads are covered by copper
        m_PadInZoneOpt->SetSelection( 0 );
        break;
    }

    // Antipad and spokes are significant only for thermals
    if( m_settings.GetPadConnection() != PAD_ZONE_CONN_THERMAL &&
        m_settings.GetPadConnection() != PAD_ZONE_CONN_THT_THERMAL )
    {
        m_AntipadSizeValue->Enable( false );
        m_CopperWidthValue->Enable( false );
    }
    else
    {
        m_AntipadSizeValue->Enable( true );
        m_CopperWidthValue->Enable( true );
    }

    m_PriorityLevelCtrl->SetValue( m_settings.m_ZonePriority );

    AddUnitSymbol( *m_AntipadSizeText, g_UserUnit );
    AddUnitSymbol( *m_CopperBridgeWidthText, g_UserUnit );
    PutValueInLocalUnits( *m_AntipadSizeValue, m_settings.m_ThermalReliefGap );
    PutValueInLocalUnits( *m_CopperWidthValue, m_settings.m_ThermalReliefCopperBridge );

    m_cornerSmoothingChoice->SetSelection( m_settings.GetCornerSmoothingType() );

    PutValueInLocalUnits( *m_cornerSmoothingCtrl, m_settings.GetCornerRadius() );

    switch( m_settings.m_Zone_HatchingStyle )
    {
    case CPolyLine::NO_HATCH:
        m_OutlineAppearanceCtrl->SetSelection( 0 );
        break;

    case CPolyLine::DIAGONAL_EDGE:
        m_OutlineAppearanceCtrl->SetSelection( 1 );
        break;

    case CPolyLine::DIAGONAL_FULL:
        m_OutlineAppearanceCtrl->SetSelection( 2 );
        break;
    }

    m_ArcApproximationOpt->SetSelection(
        m_settings.m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF ? 1 : 0 );

    // Create one column in m_LayerSelectionCtrl
    wxListItem column0;
    column0.SetId( 0 );
    m_LayerSelectionCtrl->InsertColumn( 0, column0 );

    wxImageList* imageList = new wxImageList( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
    m_LayerSelectionCtrl->AssignImageList( imageList, wxIMAGE_LIST_SMALL );

    int ctrlWidth = 0;  // Min width for m_LayerSelectionCtrl to show the layers names
    int imgIdx = 0;

    LSET cu_set = LSET::AllCuMask( board->GetCopperLayerCount() );

    for( LSEQ cu_stack = cu_set.UIOrder();  cu_stack;  ++cu_stack, imgIdx++ )
    {
        LAYER_ID layer = *cu_stack;

        m_LayerId.push_back( layer );

        msg = board->GetLayerName( layer );

        msg.Trim();

        EDA_COLOR_T layerColor = board->GetLayerColor( layer );

        imageList->Add( makeLayerBitmap( layerColor ) );

        int itemIndex = m_LayerSelectionCtrl->InsertItem(
                m_LayerSelectionCtrl->GetItemCount(), msg, imgIdx );

        if( m_settings.m_CurrentZone_Layer == layer )
            m_LayerSelectionCtrl->Select( itemIndex );

        wxSize tsize( GetTextSize( msg, m_LayerSelectionCtrl ) );
        ctrlWidth = std::max( ctrlWidth, tsize.x );
    }

    // The most easy way to ensure the right size is to use wxLIST_AUTOSIZE
    // unfortunately this option does not work well both on
    // wxWidgets 2.8 ( column width too small), and
    // wxWidgets 2.9 ( column width too large)
    ctrlWidth += LAYER_BITMAP_SIZE_X + 25;      // Add bitmap width + margin between bitmap and text
    m_LayerSelectionCtrl->SetColumnWidth( 0, ctrlWidth );

    ctrlWidth += 25;        // add small margin between text and window borders
                            // and room for vertical scroll bar
    m_LayerSelectionCtrl->SetMinSize( wxSize( ctrlWidth, -1 ) );

    wxString netNameDoNotShowFilter = wxT( "Net-*" );
    if( m_Config )
    {
        int opt = m_Config->Read( ZONE_NET_SORT_OPTION_KEY, 1l );
        m_NetDisplayOption->SetSelection( opt );
        m_Config->Read( ZONE_NET_FILTER_STRING_KEY, netNameDoNotShowFilter );
    }
    else
        m_NetDisplayOption->SetSelection( 1 );

    m_ShowNetNameFilter->SetValue( m_netNameShowFilter );
    initListNetsParams();

    // Build list of nets:
    m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
    buildAvailableListOfNets();

    wxCommandEvent event;
    OnCornerSmoothingModeChoice( event );
}
示例#4
0
void tSidebarControlVolts::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Assert(painter != 0 && option != 0);
    tSidebarControl::paint(painter, option, widget);

    tMercuryStyle* style = GetMercuryStyle();
    if( style == 0 || m_FontValue.isNull() || m_FontText.isNull() )
    {
        return;
    }

    QRect contentRect(option->rect);
    contentRect.adjust(5, 1, -5, -2);

    painter->setPen(style->GetColor(tMercuryStyle::eColorRoleIndicatorText));

    QSize iconSize(contentRect.width() / 3, contentRect.height() / 3);
    QSize textSize = GetTextSize(contentRect.size());

    const int topLine = contentRect.top() + contentRect.height() / 4;
    const int bottomLine = contentRect.bottom() - contentRect.height() / 4;
    const int centerX = contentRect.center().x();

    QSize iconImageSize(WidgetUtil::FitSize(m_BatteryIcon->defaultSize(), QSize(iconSize.width() * 2 / 3, iconSize.height())));
    m_BatteryIcon->render(painter,
        QRectF(centerX - iconSize.width() / 6 - iconImageSize.width() / 2, topLine - iconImageSize.height() / 2,
        iconImageSize.width(), iconImageSize.height())
        );
    painter->setFont(m_FontText->GetFont());
    painter->drawText(centerX + iconSize.width() / 6, topLine - iconSize.height() / 2, iconSize.width() / 3, iconSize.height(),
        Qt::AlignCenter, m_Unit);

    painter->setFont(m_FontValue->GetFont());
    if( m_Count == 4 )
    {
        painter->drawText(contentRect.left() + contentRect.width() / 6 - textSize.width() / 2, topLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value1);
        painter->drawText(contentRect.left() + contentRect.width() / 3 - textSize.width() / 2, bottomLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value2);
        painter->drawText(contentRect.right() - contentRect.width() / 3 - textSize.width() / 2, bottomLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value3);
        painter->drawText(contentRect.right() - contentRect.width() / 6 - textSize.width() / 2, topLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value4);
    }
    else if( m_Count == 3 )
    {
        painter->drawText(contentRect.left() + contentRect.width() / 6 - textSize.width() / 2, topLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value1);
        painter->drawText(centerX - textSize.width() / 2, bottomLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value2);
        painter->drawText(contentRect.right() - contentRect.width() / 6 - textSize.width() / 2, topLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value3);
    }
    else if( m_Count == 2 )
    {
        painter->drawText(contentRect.left() + contentRect.width() / 4 - textSize.width() / 2, bottomLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value1);
        painter->drawText(contentRect.right() - contentRect.width() / 4 - textSize.width() / 2, bottomLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value2);
    }
    else if( m_Count == 1 )
    {
        painter->drawText(centerX - textSize.width() / 2, bottomLine - textSize.height() / 2,
            textSize.width(), textSize.height(), Qt::AlignCenter, m_Value1);
    }
}