Esempio n. 1
0
void WindowTree::onRenderItem( RenderContext & context, const RectInt & window, PointInt & pos, Item * pItem )
{
	WindowStyle * pStyle = windowStyle();
	ASSERT( pStyle );
	Font * pFont = windowStyle()->font();
	ASSERT( pFont );

	// get the depth of this item
	int depth = itemDepth( pItem );
	// determine the X position based on it's depth
	pos.x = window.left + (depth * m_Indent);
	// get the size of the label text
	SizeInt labelSize( pFont->size( pItem->sLabel ) );
	// determine the height of this item
	int height = (int)(labelSize.height + TREE_ITEM_BUFFER);
	RectInt itemRect( window.left, pos.y, window.right, pos.y + height );

	// check if this item is highlighted or not
	if ( m_CursorInWindow && itemRect.inRect( m_LastCursorPosition ) )
		onHighlight( pItem );

	PrimitiveMaterial::push( context.display(), WHITE, PrimitiveMaterial::ALPHA );

	if ( pItem->dwFlags & BUTTON )
	{
		bool expanded = (pItem->dwFlags & EXPANDED) != 0;
		Color backColor( expanded ? pStyle->backColor() * TREE_SHADE_COLOR : pStyle->backColor() );
		Color shadeColor( expanded ? pStyle->borderColor() * TREE_LIGHT_COLOR : pStyle->borderColor() * TREE_SHADE_COLOR );
		Color lightColor( expanded ? pStyle->borderColor() * TREE_SHADE_COLOR : pStyle->borderColor() * TREE_LIGHT_COLOR );

		// render the button
		pushBackground( context, itemRect, backColor, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER );
		pushBorder( context, itemRect, lightColor, shadeColor, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER );

		// draw glow around this object if the mouse is currently over this button
		if ( m_pCursorOver == pItem )
			pushGlow( context, itemRect, TREE_GLOW_SIZE, TREE_GLOW_INNER, TREE_GLOW_OUTER, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER );

		// place the label in the center of the button
		PointInt labelPos( itemRect.center() - PointInt( labelSize.width / 2, labelSize.height / 2 ) );
		// draw the label
		Font::push( context.display(), pFont, labelPos, pItem->sLabel, pItem->cColor );
	}
	else
	{
		if ( m_pSelected == pItem )
			pushBackground( context, itemRect, pStyle->highColor(), 0, 0 );
		if ( m_pCursorOver == pItem )
			pushGlow( context, itemRect, TREE_GLOW_SIZE, TREE_GLOW_INNER, TREE_GLOW_OUTER, 0, 0 );

		PointInt labelPos( pos.x, (int)(pos.y + (TREE_ITEM_BUFFER / 2)) );
		// render the label text`
		Font::push( context.display(), pFont, labelPos, pItem->sLabel, pItem->cColor );

	}


	// move y down
	pos.y += (int)(height + WINDOW_TREE_SPACING);
}
void EconomyGraph::draw( Painter& painter ){
   
    Color white;
    white.parse( "white" );
    
    Rect2D background( 0, 0, getWidth(), getHeight() );
    int mgX = border;
    int mgY = 3*border;
    int mgW = getConfig()->monthgraphW; 
    int mgH = getConfig()->monthgraphH;
    
    painter.setFillColor( white );
    painter.fillRectangle( background );

    Vector2 labelPos( 2 * border, border-1 );
    
    //Draw HistoryLineGraph
    painter.drawTexture( labelTextureEconomy, labelPos ); 
    Rect2D currentGraph( mgX, mgY, mgX + mgW, mgY + mgH );
    drawHistoryLineGraph( painter, currentGraph );

    //Draw Sustainability Bars
    labelPos.y += 2 * border + mgH; 
    painter.drawTexture( labelTextureSustainability, labelPos ); 
    currentGraph.move( Vector2( 0, 2 * border + mgH ) );
    drawSustBarGraph( painter, currentGraph);

    //Draw FPS-Window
    labelPos.y += 2 * border + mgH; 
    painter.drawTexture( labelTextureFPS, labelPos ); 
    currentGraph.move( Vector2( 0, 2 * border + mgH ) );
    currentGraph.setHeight( mgH/2 );
    drawFPSGraph( painter, currentGraph );
}
Esempio n. 3
0
void MailListView::writeConfig( QSettings *conf)
{
    QString temp;
    if (!singleColumnMode()) {
        for (int x = 0; x < columnCount(); x++) {
            temp.setNum(x);
            conf->setValue("querycol" + temp, columnWidth(x) );
            conf->setValue("querycollabelpos" + temp, labelPos(x) );
        }
        conf->setValue( "querycolsort", sortedColumn() );
        conf->setValue( "querycolsortascending", isAscending() );
        conf->setValue( "arrivaldate", arrivalDate() );
        conf->setValue( "showheader", horizontalHeader()->isHidden() );
    }
}
Esempio n. 4
0
void LabelPainter::changeLabels(glm::mat4 MVP) {
	clearRenderer();
	mouseHandler::clearLabel();

	if (_labels.size() > 0) {
		sortLabels(&_labels);
		vector<Label> viewLabels;

		int windowW,windowH;
		context::getWindowSize(&windowW, &windowH);
		int i = 0;

		glm::mat4 T = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 0.0f));
		glm::mat4 S = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f, 0.5f, 1.0f));

		glm::mat4 MVP2 = S * T * MVP; // transforms world to 0..1-0..1 coordinates

		vector<int> x_topX;
		vector<int> y_topX;

		//select view labels
		while (i < _labels.size()) {
			glm::vec4 labelPos(_labels[i].x, _labels[i].y, 0.0f, 1.0f);
			labelPos = MVP2 * labelPos;

			if (labelPos.x >= 0.0f && labelPos.x <= 1.0f && labelPos.y >= 0.0f && labelPos.y <= 1.0f) {
				//inside
				viewLabels.push_back(_labels[i]);
				x_topX.push_back(labelPos.x * (float)windowW);
				y_topX.push_back(labelPos.y * (float)windowH);
			}

			i++;
		}

		if (viewLabels.size() > 0) {
			float maxW = viewLabels.front().weight;
			float minW = viewLabels.back().weight;
			float div = maxW - minW;

			vector<int> topX2RenderIndex;

			//add them to the correct renderer
			for (int i = 0; i < viewLabels.size(); i++) {

				float normedVal;
	
				if (div != 0) {
					normedVal = (viewLabels[i].weight - minW)  / div;
				} else {
					normedVal = 0.5f;
				}
		
				ScaleOptions* so = &context::_scaleOptions[2];
				float pointsX[4] = {so->_controlPoints[0][0], so->_controlPoints[1][0], so->_controlPoints[2][0], so->_controlPoints[3][0]};
				float pointsY[4] = {so->_controlPoints[0][1], so->_controlPoints[1][1], so->_controlPoints[2][1], so->_controlPoints[3][1]};
	
				float scaled = scale(normedVal, so->_linearMode, so->_exponent, pointsX, pointsY);

				int index = min(4, (int)floor(scaled * 5.0f));
				_renderer[index]->addText(viewLabels[i].text, normedVal);
				topX2RenderIndex.push_back(index);
			}	
				
			//calculate new positions
			vector<labelOrderCom::MovedBox>* newPos = NULL;

			if (ORDER_LABELS) {
				labelOrderCom::prepare();

				int off[5] = {0,0,0,0,0};
				for (int i = 0; i < viewLabels.size(); i++) {
					int rI = topX2RenderIndex[i];
					PreparedText* label = _renderer[rI]->getTexts()->at(off[rI]);
					labelOrderCom::add(x_topX[i], y_topX[i], label->_textPixWidth, label->_textPixHeight);
					off[rI]++;
				}
				newPos = labelOrderCom::transmit();

				for (int i = 0; i < newPos->size(); i++) {
					x_topX[newPos->at(i).id] =  newPos->at(i).x;
					y_topX[newPos->at(i).id] =  newPos->at(i).y;
				}
			}
	
			//set new positions
			int off[5] = {0,0,0,0,0};
			for (int i = 0; i < viewLabels.size(); i++) {
				int rI = topX2RenderIndex[i];

				float x = (float)x_topX[i] / (float)windowW;
				float y =  (float)y_topX[i] / (float)windowH;

				_renderer[rI]->setCenter(off[rI], x, y);

				float w = _renderer[rI]->getTexts()->at(off[rI])->_textPixWidth;
				float h = _renderer[rI]->getTexts()->at(off[rI])->_textPixHeight;

				//update click listener
				float left = x - ((float) w / (float) windowW) / 2.0f;
				float right = x + ((float) w / (float) windowW) / 2.0f;
				float bottom = y - ((float) h / (float) windowH) / 2.0f;
				float up = y + ((float) h / (float) windowH) / 2.0f;

				mouseHandler::registerLabel(bottom, left, up, right, viewLabels[i].id);

				off[rI]++;
			}
	
			delete newPos;
		}
	}
}
void
BRadioButton::Draw(BRect updateRect)
{
	// its size depends on the text height
	font_height fontHeight;
	GetFontHeight(&fontHeight);

	if (be_control_look != NULL) {
		rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);

		uint32 flags = be_control_look->Flags(this);
		if (fOutlined)
			flags |= BControlLook::B_CLICKED;

		BRect knobRect(_KnobFrame(fontHeight));
		BRect rect(knobRect);
		be_control_look->DrawRadioButton(this, rect, updateRect, base, flags);

		BRect labelRect(Bounds());
		labelRect.left = knobRect.right
			+ be_control_look->DefaultLabelSpacing();

		be_control_look->DrawLabel(this, Label(), labelRect, updateRect,
			base, flags);
		return;
	}

	float textHeight = ceilf(fontHeight.ascent + fontHeight.descent);

	// layout the rect for the dot
	BRect rect = _KnobFrame(fontHeight);

	BPoint labelPos(rect.right + floorf(textHeight / 2.0),
		floorf((rect.top + rect.bottom + textHeight) / 2.0
			- fontHeight.descent + 0.5) + 1.0);

	// if the focus is changing, just redraw the focus indicator
	if (IsFocusChanging()) {
		if (IsFocus())
			SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
		else
			SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));

		BPoint underLine = labelPos;
		underLine.y += fontHeight.descent;
		StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0));

		return;
	}

	// colors
	rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
	rgb_color lightenmax;
	rgb_color lighten1;
	rgb_color darken1;
	rgb_color darken2;
	rgb_color darken3;
	rgb_color darkenmax;

	rgb_color naviColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR);
	rgb_color knob;
	rgb_color knobDark;
	rgb_color knobLight;

	if (IsEnabled()) {
		lightenmax	= tint_color(bg, B_LIGHTEN_MAX_TINT);
		lighten1	= tint_color(bg, B_LIGHTEN_1_TINT);
		darken1		= tint_color(bg, B_DARKEN_1_TINT);
		darken2		= tint_color(bg, B_DARKEN_2_TINT);
		darken3		= tint_color(bg, B_DARKEN_3_TINT);
		darkenmax	= tint_color(bg, B_DARKEN_MAX_TINT);

		knob		= naviColor;
		knobDark	= tint_color(naviColor, B_DARKEN_3_TINT);
		knobLight	= tint_color(naviColor, 0.15);
	} else {
		lightenmax	= tint_color(bg, B_LIGHTEN_2_TINT);
		lighten1	= bg;
		darken1		= bg;
		darken2		= tint_color(bg, B_DARKEN_1_TINT);
		darken3		= tint_color(bg, B_DARKEN_2_TINT);
		darkenmax	= tint_color(bg, B_DISABLED_LABEL_TINT);

		knob		= tint_color(naviColor, B_LIGHTEN_2_TINT);
		knobDark	= tint_color(naviColor, B_LIGHTEN_1_TINT);
		knobLight	= tint_color(naviColor, (B_LIGHTEN_2_TINT
			+ B_LIGHTEN_MAX_TINT) / 2.0);
	}

	// dot
	if (Value() == B_CONTROL_ON) {
		// full
		SetHighColor(knobDark);
		FillEllipse(rect);

		SetHighColor(knob);
		FillEllipse(BRect(rect.left + 2, rect.top + 2, rect.right - 3,
			rect.bottom - 3));

		SetHighColor(knobLight);
		FillEllipse(BRect(rect.left + 3, rect.top + 3, rect.right - 5,
			rect.bottom - 5));
	} else {
		// empty
		SetHighColor(lightenmax);
		FillEllipse(rect);
	}

	rect.InsetBy(-1.0, -1.0);

	// outer circle
	if (fOutlined) {
		// indicating "about to change value"
		SetHighColor(darken3);
		StrokeEllipse(rect);
	} else {
		SetHighColor(darken1);
		StrokeArc(rect, 45.0, 180.0);
		SetHighColor(lightenmax);
		StrokeArc(rect, 45.0, -180.0);
	}

	rect.InsetBy(1, 1);

	// inner circle
	SetHighColor(darken3);
	StrokeArc(rect, 45.0, 180.0);
	SetHighColor(bg);
	StrokeArc(rect, 45.0, -180.0);

	// for faster font rendering, we can restore B_OP_COPY
	SetDrawingMode(B_OP_COPY);

	// label
	SetHighColor(darkenmax);
	DrawString(Label(), labelPos);

	// underline label if focused
	if (IsFocus()) {
		SetHighColor(naviColor);
		BPoint underLine = labelPos;
		underLine.y += fontHeight.descent;
		StrokeLine(underLine, underLine + BPoint(StringWidth(Label()), 0.0));
	}
}
Esempio n. 6
0
void WindowButton::onRender( RenderContext & context, const RectInt & window )
{
	int baseAlpha = m_Alpha * 255;
	int alpha = Clamp( baseAlpha + (enabled() ? (m_ButtonDown ? DOWN_ALPHA : m_CursorOver ? OVER_ALPHA : 0) : DISABLED_ALPHA) , 0, 255 );

	// update the image frame
	if ( m_Button.valid() )
	{
		static RectFloat buttonUV( 0, 0, 1, 1 );

		// get the button color
		//Color buttonColor( m_ButtonDown ? windowStyle()->highColor() : windowStyle()->color() );
		Color buttonColor( m_ButtonDown ? m_Color * 2.0f : m_Color );
		buttonColor.m_A = alpha;

		if ( m_bGreyed )
			buttonColor.greyscale(BUTTON_GREYED_SCALE);

		// if the button has multiple frames, set the time to display the correct frame
		if ( m_Button->frames() > 1 )
		{
			ASSERT( m_Button->fps() > 0 );

			int frame = 0;
			if ( m_Button->frames() == 2 )
				frame = m_ButtonDown ? 1 : 0;
			else
				frame = m_ButtonDown ? 1 : m_CursorOver ? 2 : 0;

			m_Time = (1.0f / m_Button->fps()) * frame;
		}

		RectInt buttonRect( window );
		if ( (m_Style & LOCK_ICON_SIZE) != 0 )
		{
			int nDiffuse = m_Button->findTexture( PrimitiveSurface::DIFFUSE );
			if ( nDiffuse >= 0 )
			{
				SizeInt buttonSize( m_Button->texture( nDiffuse ).m_pImage->size() );
				// keep button original size
				buttonRect.setWidth( buttonSize.width );
				buttonRect.setHeight( buttonSize.height );
			}
		}

		// flush the button material, so we can have different frames for each button
		m_Button->flushMaterial();
		// save then change the context time
		float fContextTime = context.time();
		context.setTime( m_Time );
		// push the button material
		Material::push( context, m_Button );
		// draw the button
		PrimitiveWindow::push( context.display(), buttonRect, buttonUV, buttonColor );
		// restore the context time
		context.setTime( fContextTime );
	}

	// display the label
	if ( m_Label.length() > 0 )
	{
		String sLabel = m_Label;

		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		Color cLabel = labelColor();
		if ( m_Style & EFFECT_FADEIN && visibleTime() < BUTTON_FADE_IN_TIME )
			cLabel.a = (visibleTime() / BUTTON_FADE_IN_TIME) * 255;
		else
			cLabel.a = 255;

		SizeInt labelSize( pFont->size( sLabel ) );
		PointInt labelPos( window.m_Left + ((window.width() / 2) - (labelSize.width / 2)),
			window.m_Top + ((window.height() / 2) - (labelSize.height / 2)) );

		Font::push( context.display(), pFont, labelPos, sLabel, cLabel );
	}

	// display hotkey in lower right corner
	if ( (m_Style & SHOW_HOTKEY) != 0 && m_HotKey != 0 )
	{
		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		Color color( ((m_CursorOver || m_ButtonDown) && enabled()) ? 
			windowStyle()->highColor() : windowStyle()->color() );

		if ( m_Style & EFFECT_FADEIN && visibleTime() < BUTTON_FADE_IN_TIME )
			color.a = (visibleTime() / BUTTON_FADE_IN_TIME) * 255;
		else
			color.a = 255;

		if ( m_bGreyed )
			color.greyscale(BUTTON_GREYED_SCALE);

		String sKey( Keyboard::keyShortText( Keyboard::unmap( m_HotKey ) ) );
		SizeInt textSize( pFont->size( sKey ) );
		PointInt textPos( window.m_Right - textSize.width, 
			window.m_Bottom - textSize.height );
		
		Font::push( context.display(), pFont, textPos, sKey, color );
	}
}
void CSyncAllPane::initialize() {

    initializeFonts();

    int labelStringID = IDS_SYNCALL;
    int iconLogoID    = IDI_LOGO;
    int iconSyncAllID = IDI_SYNC_ALL_BLUE;
    int iconCancelID  = IDI_CANCEL;

    clicked = false;            // true when mouse click-down
    mouseOver = false;
    
    //
    // Get Windows dpi and fix objects size
    //
    HDC hdc = ::GetDC(0);
    dpiX = ::GetDeviceCaps(hdc, LOGPIXELSX);
    dpiY = ::GetDeviceCaps(hdc, LOGPIXELSY);
    ::ReleaseDC(0, hdc);

    size.cx     = PANE_SIZE_X;     // original size of bitmap
    size.cy     = PANE_SIZE_Y;
    iconSize.cx = ICON_SIZE_X;     // original size of icon
    iconSize.cy = ICON_SIZE_Y;
    if (dpiX != 96) {
        size.cx     = (int) (size.cx     * (dpiX/96.0));
        size.cy     = (int) (size.cy     * (dpiY/96.0));
        iconSize.cx = (int) (iconSize.cx * (dpiX/96.0));
        iconSize.cy = (int) (iconSize.cy * (dpiY/96.0));
    }


    // Create the pane
    CPoint pos(X_SPACE_LEFT, Y_SPACE_TOP);
    Create(_T("pane"), SS_BITMAP|SS_NOTIFY|WS_VISIBLE, CRect(pos, size), syncForm);


    // Create label
    CPoint labelPos(pos.x + (int)(size.cx*0.20), 
                    pos.y + (int)(size.cy*0.35));
    CSize labelSize((int)(size.cx*0.90), 
                    (int)(size.cy*0.70));
    labelText.LoadString(labelStringID); 
    label.Create(labelText, WS_CHILD|SS_NOTIFY|WS_VISIBLE, CRect(labelPos, labelSize), syncForm);
    label.SetFont(&fontBold);

    // set this unique ID, so the text can be colored from CSyncForm::OnCtlColor()
    label.SetDlgCtrlID(IDC_MAIN_SYNCALL_LABEL);


    // Create icons
    iconLogo    = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(iconLogoID));
    iconSyncAll = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(iconSyncAllID));
    iconCancel  = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(iconCancelID));
    
    CPoint leftIconPos(pos.x + (int)(size.cx*0.05), 
                         pos.y + (size.cy - iconSize.cy)/2);
    leftIcon.Create(_T("left_icon"), SS_ICON|WS_CHILD|WS_VISIBLE|SS_NOTIFY|WS_EX_TRANSPARENT, 
                      CRect(leftIconPos, iconSize), syncForm);

    CPoint statusIconPos(pos.x + (int)(size.cx*0.85), 
                         pos.y + (size.cy - iconSize.cy)/2);
    statusIcon.Create(_T("status_icon"), SS_ICON|WS_CHILD|WS_VISIBLE|SS_NOTIFY, 
                      CRect(statusIconPos, iconSize), syncForm);
    
    // init to normal state
    state = SYNCALL_PANE_STATE_NORMAL;
    leftIcon.SetIcon(iconLogo);
    refresh();
}