line drawing method added to FBSurface

inactive cells are displayed as crossed out in FLAT_UI
This commit is contained in:
thrust26 2017-12-17 16:43:05 +01:00
parent 0def7adb61
commit b76566e864
4 changed files with 113 additions and 1 deletions

View File

@ -138,6 +138,18 @@ void TogglePixelWidget::drawWidget(bool hilite)
// Cross out the bits?
if(_crossBits)
{
#ifndef FLAT_UI
for(row = 1; row < 4; ++row)
s.hLine(_x, _y + (row * lineheight/4), _x + linewidth, kColor);
s.hLine(_x, _y + (row * lineheight / 4), _x + linewidth, kColor);
#else
for(col = 0; col < _cols; ++col)
{
int x = _x + col * _colWidth;
s.line(x + 1, _y + 1, x + _colWidth - 1, _y + lineheight - 1, kColor);
s.line(x + _colWidth - 1, _y + 1, x + 1, _y + lineheight - 1, kColor);
}
#endif
}
}

View File

@ -15,6 +15,8 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include <cmath>
#include "Font.hxx"
#include "Rect.hxx"
#include "FrameBuffer.hxx"
@ -57,6 +59,73 @@ void FBSurface::readPixels(uInt8* buffer, uInt32 pitch, const GUI::Rect& rect) c
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::pixel(uInt32 x, uInt32 y, uInt32 color)
{
uInt32* buffer = myPixels + y * myPitch + x;
*buffer = uInt32(myPalette[color]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, uInt32 color)
{
// draw line using Bresenham algorithm
Int32 dx = (x2 - x);
Int32 dy = (y2 - y);
if(abs(dx) >= abs(dy))
{
// x is major axis
if(dx < 0)
{
uInt32 tx = x; x = x2; x2 = tx;
uInt32 ty = y; y = y2; y2 = ty;
dx = -dx;
dy = -dy;
}
Int32 yd = dy > 0 ? 1 : -1;
dy = abs(dy);
Int32 err = dx / 2;
// now draw the line
for(; x <= x2; ++x)
{
pixel(x, y, color);
err -= dy;
if(err < 0)
{
err += dx;
y += yd;
}
}
}
else
{
// y is major axis
if(dy < 0)
{
uInt32 tx = x; x = x2; x2 = tx;
uInt32 ty = y; y = y2; y2 = ty;
dx = -dx;
dy = -dy;
}
Int32 xd = dx > 0 ? 1 : -1;
dx = abs(dx);
Int32 err = dy / 2;
// now draw the line
for(; y <= y2; ++y)
{
pixel(x, y, color);
err -= dx;
if(err < 0)
{
err += dy;
x += xd;
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::hLine(uInt32 x, uInt32 y, uInt32 x2, uInt32 color)
{

View File

@ -72,6 +72,26 @@ class FBSurface
// implement them more efficiently.
//////////////////////////////////////////////////////////////////////////
/**
This method should be called to draw a single pixel.
@param x The x coordinate
@param y The y coordinate
@param color The color of the line
*/
virtual void pixel(uInt32 x, uInt32 y, uInt32 color);
/**
This method should be called to draw a line.
@param x The first x coordinate
@param y The y coordinate
@param x2 The second x coordinate
@param xy The second y coordinate
@param color The color of the line
*/
virtual void line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, uInt32 color);
/**
This method should be called to draw a horizontal line.

View File

@ -48,16 +48,27 @@ void ColorWidget::drawWidget(bool hilite)
FBSurface& s = dialog().surface();
// Draw a thin frame around us.
#ifndef FLAT_UI
s.hLine(_x, _y, _x + _w - 1, kColor);
s.hLine(_x, _y +_h, _x + _w - 1, kShadowColor);
s.vLine(_x, _y, _y+_h, kColor);
s.vLine(_x + _w - 1, _y, _y +_h - 1, kShadowColor);
#else
s.frameRect(_x, _y, _w, _h + 1, kColor);
#endif
// Show the currently selected color
s.fillRect(_x+1, _y+1, _w-2, _h-1, isEnabled() ? _color : kWidColor);
// Cross out the grid?
if(_crossGrid)
{
#ifndef FLAT_UI
for(uInt32 row = 1; row < 4; ++row)
s.hLine(_x, _y + (row * _h/4), _x + _w - 2, kColor);
#else
s.line(_x + 1, _y + 1, _x + _w - 2, _y + _h - 1, kColor);
s.line(_x + _w - 2, _y + 1, _x + 1, _y + _h - 1, kColor);
#endif
}
}