Ejemplo n.º 1
0
    void DropDown::drawButton(Graphics *graphics)
    {
        Color faceColor, highlightColor, shadowColor;
        int offset;
        int alpha = getBaseColor().a;

        if (mPushed)
        {
            faceColor = getBaseColor() - 0x303030;
            faceColor.a = alpha;
            highlightColor = faceColor - 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor + 0x303030;
            shadowColor.a = alpha;
            offset = 1;
        }
        else
        {
            faceColor = getBaseColor();
            faceColor.a = alpha;
            highlightColor = faceColor + 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor - 0x303030;
            shadowColor.a = alpha;
            offset = 0;
        }

        int h;
        if (mDroppedDown)
        {
            h = mOldH;
        }
        else
        {
            h = getHeight();
        }
        int x = getWidth() - h;
        int y = 0;

        graphics->setColor(faceColor);
        graphics->fillRectangle(Rectangle(x+1, y+1, h-2, h-2));

        graphics->setColor(highlightColor);
        graphics->drawLine(x, y, x+h-1, y);
        graphics->drawLine(x, y+1, x, y+h-1);

        graphics->setColor(shadowColor);
        graphics->drawLine(x+h-1, y+1, x+h-1, y+h-1);
        graphics->drawLine(x+1, y+h-1, x+h-2, y+h-1);

        graphics->setColor(getForegroundColor());

        int i;
        int hh = h / 3;
        int hx = x + h / 2;
        int hy = y + (h * 2) / 3;
        for (i=0; i<hh; i++)
        {
            graphics->drawLine(hx - i + offset,
                               hy - i + offset,
                               hx + i + offset,
                               hy - i + offset);
        }
    }
Ejemplo n.º 2
0
    void ImageButton::draw(Graphics* graphics)
    {
        gcn::Color faceColor = getBaseColor();
        gcn::Color highlightColor, shadowColor;
        int alpha = getBaseColor().a;

        if (isPressed())
        {
            faceColor = faceColor - 0x303030;
            faceColor.a = alpha;
            highlightColor = faceColor - 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor + 0x303030;
            shadowColor.a = alpha;
        }
        else
        {
            highlightColor = faceColor + 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor - 0x303030;
            shadowColor.a = alpha;
        }

        graphics->setColor(faceColor);
        graphics->fillRectangle(Rectangle(1, 
                                          1, 
                                          getDimension().width - 1, 
                                          getHeight() - 1));

        graphics->setColor(highlightColor);
        graphics->drawLine(0, 0, getWidth() - 1, 0);
        graphics->drawLine(0, 1, 0, getHeight() - 1);

        graphics->setColor(shadowColor);
        graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
        graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

        graphics->setColor(getForegroundColor());

        const int textX = (getWidth() - (mImage ? mImage->getWidth() : 0) ) / 2;
        const int textY = (getHeight() - (mImage ? mImage->getHeight() : 0) ) / 2;

        if (isPressed())
        {
            if(mImage) {
                graphics->setColor(getForegroundColor());
                graphics->drawImage(mImage, textX + 1, textY + 1);
            }
        }
        else
        {
            if(mImage)
                graphics->drawImage(mImage, textX, textY);

            if (isFocused())
            {
                graphics->drawRectangle(Rectangle(2, 
                                                  2, 
                                                  getWidth() - 4,
                                                  getHeight() - 4));
            }
        }
    }
Ejemplo n.º 3
0
 void TextField::drawCaret(Graphics* graphics, int x)
 {
     graphics->setColor(getForegroundColor());
     graphics->drawLine(x, getHeight() - 2, x, 1);
 }
Ejemplo n.º 4
0
    void Button::draw(Graphics* graphics)
    {
        Color faceColor = getBaseColor();
        Color highlightColor, shadowColor;
        int alpha = getBaseColor().a;

        if (isPressed())
        {
            faceColor = faceColor - 0x303030;
            faceColor.a = alpha;
            highlightColor = faceColor - 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor + 0x303030;
            shadowColor.a = alpha;
        }
        else
        {
            highlightColor = faceColor + 0x303030;
            highlightColor.a = alpha;
            shadowColor = faceColor - 0x303030;
            shadowColor.a = alpha;
        }

        graphics->setColor(faceColor);
        graphics->fillRectangle(1, 1, getDimension().width-1, getHeight() - 1);

        graphics->setColor(highlightColor);
        graphics->drawLine(0, 0, getWidth() - 1, 0);
        graphics->drawLine(0, 1, 0, getHeight() - 1);

        graphics->setColor(shadowColor);
        graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
        graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

        graphics->setColor(getForegroundColor());

        int textX;
        int textY = getHeight() / 2 - getFont()->getHeight() / 2;

        switch (getAlignment())
        {
          case Graphics::Left:
              textX = mSpacing;
              break;
          case Graphics::Center:
              textX = getWidth() / 2;
              break;
          case Graphics::Right:
              textX = getWidth() - mSpacing;
              break;
          default:
              throw GCN_EXCEPTION("Unknown alignment.");
        }

        graphics->setFont(getFont());

        if (isPressed())
        {
            graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
        }
        else
        {
            graphics->drawText(getCaption(), textX, textY, getAlignment());

            if (isFocused())
            {
                graphics->drawRectangle(2, 2, getWidth() - 4,
                                        getHeight() - 4);
            }
        }
    }
Ejemplo n.º 5
0
 void TextBox::drawCaret(Graphics* graphics, int x, int y)
 {
     graphics->setColor(getForegroundColor());
     graphics->drawLine(x, y, x, y + getFont()->getHeight());
 }
Ejemplo n.º 6
0
    void ListBox::draw(Graphics* graphics)
    {
        graphics->setColor(getBackgroundColor());
        graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));

        if (mListModel == NULL)
        {
            return;
        }

        graphics->setColor(getForegroundColor());
        graphics->setFont(getFont());
         
        // Check the current clip area so we don't draw unnecessary items
        // that are not visible.
        const ClipRectangle currentClipArea = graphics->getCurrentClipArea();
        int rowHeight = getRowHeight();
        
		// Calculate the number of rows to draw by checking the clip area.
		// The addition of two makes covers a partial visible row at the top
		// and a partial visible row at the bottom.
		int numberOfRows = currentClipArea.height / rowHeight + 2;

        if (numberOfRows > mListModel->getNumberOfElements())
        {
            numberOfRows = mListModel->getNumberOfElements();
        }

		// Calculate which row to start drawing. If the list box 
		// has a negative y coordinate value we should check if
		// we should drop rows in the begining of the list as
		// they might not be visible. A negative y value is very
		// common if the list box for instance resides in a scroll
		// area and the user has scrolled the list box downwards.
		int startRow;    	
		if (getY() < 0)
		{
			startRow = -1 * (getY() / rowHeight);
		}
		else
		{
			startRow = 0;
		}

		int i;
		// The y coordinate where we start to draw the text is
		// simply the y coordinate multiplied with the font height.
		int y = rowHeight * startRow;
        for (i = startRow; i < startRow + numberOfRows; ++i)
        {
            if (i == mSelected)
            {
                graphics->setColor(getSelectionColor());
                graphics->fillRectangle(Rectangle(0, y, getWidth(), rowHeight));
                graphics->setColor(getForegroundColor());
            }
			
			// If the row height is greater than the font height we
			// draw the text with a center vertical alignment.
			if (rowHeight > getFont()->getHeight())
			{
				graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2);
			}
			else
			{
				graphics->drawText(mListModel->getElementAt(i), 1, y);
			}

            y += rowHeight;
        }
    }
Ejemplo n.º 7
0
    void Window::draw(Graphics* graphics)
    {
        Color faceColor = getBaseColor();
        Color highlightColor, shadowColor;
        int alpha = getBaseColor().a;
        //int width = getWidth() + getBorderSize() * 2 - 1;
        //int height = getHeight() + getBorderSize() * 2 - 1;
        highlightColor = faceColor + 0x303030;
        highlightColor.a = alpha;
        shadowColor = faceColor - 0x303030;
        shadowColor.a = alpha;

        Rectangle d = getChildrenArea();

        // Fill the background around the content
        graphics->setColor(faceColor);
        // Fill top
        graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1));
        // Fill left
        graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1));
        // Fill right
        graphics->fillRectangle(Rectangle(d.x + d.width + 1,
                                          d.y - 1,
                                          getWidth() - d.x - d.width - 1,
                                          getHeight() - d.y + 1));
        // Fill bottom
        graphics->fillRectangle(Rectangle(d.x - 1,
                                          d.y + d.height + 1,
                                          d.width + 2,
                                          getHeight() - d.height - d.y - 1));

        if (isOpaque())
        {
            graphics->fillRectangle(d);
        }

        // Construct a rectangle one pixel bigger than the content
        d.x -= 1;
        d.y -= 1;
        d.width += 2;
        d.height += 2;

        // Draw a border around the content
        graphics->setColor(shadowColor);
        // Top line
        graphics->drawLine(d.x,
                           d.y,
                           d.x + d.width - 2,
                           d.y);

        // Left line
        graphics->drawLine(d.x,
                           d.y + 1,
                           d.x,
                           d.y + d.height - 1);

        graphics->setColor(highlightColor);
        // Right line
        graphics->drawLine(d.x + d.width - 1,
                           d.y,
                           d.x + d.width - 1,
                           d.y + d.height - 2);
        // Bottom line
        graphics->drawLine(d.x + 1,
                           d.y + d.height - 1,
                           d.x + d.width - 1,
                           d.y + d.height - 1);

        drawChildren(graphics);

        int textX;
        int textY;

        textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2;

        switch (getAlignment())
        {
          case Graphics::LEFT:
              textX = 4;
              break;
          case Graphics::CENTER:
              textX = getWidth() / 2;
              break;
          case Graphics::RIGHT:
              textX = getWidth() - 4;
              break;
          default:
              throw GCN_EXCEPTION("Unknown alignment.");
        }

        graphics->setColor(getForegroundColor());
        graphics->setFont(getFont());
        graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1));
        graphics->drawText(getCaption(), textX, textY, getAlignment());
        graphics->popClipArea();
    }
Ejemplo n.º 8
0
    void RadioButton::drawBox(Graphics *graphics)
    {
        int h;

        if (getHeight()%2 == 0)
        {
            h = getHeight() - 4;
        }
        else
        {
            h = getHeight() - 3;
        }

        int alpha = getBaseColor().a;
        Color faceColor = getBaseColor();
        faceColor.a = alpha;
        Color highlightColor = faceColor + 0x303030;
        highlightColor.a = alpha;
        Color shadowColor = faceColor - 0x303030;
        shadowColor.a = alpha;

        graphics->setColor(getBackgroundColor());

        int i;
        int hh = (h + 1) / 2;

        for (i = 1; i <= hh; ++i)
        {
            graphics->drawLine(hh - i + 1,
                               i,
                               hh + i - 1,
                               i);
        }

        for (i = 1; i < hh; ++i)
        {
            graphics->drawLine(hh - i + 1,
                               h - i,
                               hh + i - 1,
                               h - i);
        }

        graphics->setColor(shadowColor);
        graphics->drawLine(hh, 0, 0, hh);
        graphics->drawLine(hh + 1, 1, h - 1, hh - 1);

        graphics->setColor(highlightColor);
        graphics->drawLine(1, hh + 1, hh, h);
        graphics->drawLine(hh + 1, h - 1, h, hh);

        graphics->setColor(getForegroundColor());

        int hhh = hh - 3;
        if (mSelected)
        {
            for (i = 0; i < hhh; ++i)
            {
                graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i);
            }
            for (i = 0; i < hhh; ++i)
            {
                graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 -  i);
            }

        }
    }
Ejemplo n.º 9
0
void eProgress::redrawWidget(gPainter *target, const eRect &area)
{
	switch (direction)
	{
		case 0:
		{
			int range = size.width() - border * 2;
			if (sliderPixmap) range -= sliderPixmap->x;

			int st = start * range / 100;
			if (st < 0) st = 0;
			if (st > range) st = range;

			int dh = perc * range / 100;
			if (dh < 0) dh = 0;
			if ((dh + st) > range) dh = range - st;

			if (pixmap)
			{
				target->blit(*pixmap, ePoint(0, 0), eRect(0, 0, border + dh + st, size.height()), gPixmap::blitAlphaTest);
			}

			if (sliderPixmap)
			{
				int x = border + st + dh;
				int y = (size.height() - sliderPixmap->y) / 2;
				if (x < 0) x = 0;
				if (y < 0) y = 0;
				if (x > size.width() - sliderPixmap->x) x = size.width() - sliderPixmap->x;
				if (y > size.height() - sliderPixmap->y) y = size.height() - sliderPixmap->y;
				target->blit(*sliderPixmap, ePoint(x, y), area, gPixmap::blitAlphaTest);
			}
			else
			{
				if (left >= 0)
				{
					target->setForegroundColor(left);
					target->fill(eRect(border + st, border, dh, size.height() - border * 2));
				}
				target->setForegroundColor(right);
				target->fill(eRect(border + dh + st, border, size.width() - border * 2 - dh - st, size.height() - border * 2));
				if (st)
				{
					target->fill(eRect(border, border, st, size.height() - border * 2));
				}
			}
			break;
		}
		case 1:
		{
			int range = size.height() - border * 2;
			if (sliderPixmap) range -= sliderPixmap->y;

			int st = start * range / 100;
			if (st < 0) st = 0;
			if (st > range) st = range;

			int dh = perc * range / 100;
			if (dh < 0) dh = 0;
			if ((dh + st) > range) dh = range - st;

			if (pixmap)
			{
				target->blit(*pixmap, ePoint(0, 0), eRect(0, 0, size.width(), border + dh + st), gPixmap::blitAlphaTest);
			}

			if (sliderPixmap)
			{
				int x = (size.width() - sliderPixmap->x) / 2;
				int y = border + st + dh;
				if (x < 0) x = 0;
				if (y < 0) y = 0;
				if (x > size.width() - sliderPixmap->x) x = size.width() - sliderPixmap->x;
				if (y > size.height() - sliderPixmap->y) y = size.height() - sliderPixmap->y;
				target->blit(*sliderPixmap, ePoint(x, y), area, gPixmap::blitAlphaTest);
			}
			else
			{
				if (left >= 0)
				{
					target->setForegroundColor(left);
					target->fill(eRect(border, border+st, size.width() - border * 2, dh));
				}
				target->setForegroundColor(right);
				target->fill(eRect(border, border+dh+st, size.width() - border * 2, size.height() - border * 2 - dh - st));
				if (st)
				{
					target->fill(eRect(border, border, size.width() - border * 2, st));
				}
			}
			break;
		}
	}
	if (border)
	{
		/* draw border */
		target->setForegroundColor(getForegroundColor());
		target->fill(eRect(0, 0, size.width(), border));
		target->fill(eRect(0, border, border, size.height() - border));
		target->fill(eRect(border, size.height() - border, size.width() - border, border));
		target->fill(eRect(size.width() - border, border, border, size.height() - border));
	}
}