Skip to content

Commit

Permalink
Graphics (#3073)
Browse files Browse the repository at this point in the history
Graphics
* add support for 3 gradient colors
* use uint8_t instead of int for some properties

[eSlider/eListbox]
* add slider/scrollbar background gradient

[skin]
* add scrollbarForegroundGradient, scrollbarBackgroundGradient attribute
* remove scrollbarGradient, gradient attribute
* improve parseGradient

Co-authored-by: @zKhadiri
Co-authored-by: @IanSav
  • Loading branch information
jbleyel committed Oct 8, 2023
1 parent 3734682 commit 97588ad
Show file tree
Hide file tree
Showing 18 changed files with 731 additions and 541 deletions.
644 changes: 359 additions & 285 deletions lib/gdi/drawing.cpp

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions lib/gdi/drawing.h
Expand Up @@ -34,13 +34,15 @@ For more details about the CC BY-NC-SA 4.0 License, please visit:
#define __drawing__

#include "gpixmap.h"
#include <vector>

void duplicate_32fc(uint32_t *out, const uint32_t in, size_t size);
uint32_t* createGradientBuffer(int graSize, const gRGB &startColor, const gRGB &endColor);
void drawAngleTl(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, int direction, const eRect &cornerRect, const CornerData &cornerData);
void drawAngleTr(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, int direction, const eRect &cornerRect, const CornerData &cornerData);
void drawAngleBl(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, int direction, const eRect &cornerRect, const CornerData &cornerData);
void drawAngleBr(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, int direction, const eRect &cornerRect, const CornerData &cornerData);
uint32_t *createGradientBuffer2(int graSize, const gRGB &startColor, const gRGB &endColor);
uint32_t *createGradientBuffer3(int graSize, const std::vector<gRGB> &colors);
void drawAngleTl(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, uint8_t direction, const eRect &cornerRect, const CornerData &cornerData);
void drawAngleTr(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, uint8_t direction, const eRect &cornerRect, const CornerData &cornerData);
void drawAngleBl(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, uint8_t direction, const eRect &cornerRect, const CornerData &cornerData);
void drawAngleBr(gUnmanagedSurface *surface, const uint32_t *src, const eRect &area, uint8_t direction, const eRect &cornerRect, const CornerData &cornerData);

void drawAngle32Tl(gUnmanagedSurface *surface, const gPixmap &pixmap, const eRect &area, const eRect &cornerRect, const CornerData &cornerData, int flag);
void drawAngle32Tr(gUnmanagedSurface *surface, const gPixmap &pixmap, const eRect &area, const eRect &cornerRect, const CornerData &cornerData, int flag);
Expand Down
21 changes: 13 additions & 8 deletions lib/gdi/gpixmap.cpp
Expand Up @@ -461,7 +461,7 @@ static void convert_palette(uint32_t *pal, const gPalette &clut)

#define FIX 0x10000

void gPixmap::drawRectangle(const gRegion &region, const eRect &area, const gRGB &backgroundColor, const gRGB &borderColor, int borderWidth, const gRGB &startColor, const gRGB &endColor, int direction, int radius, int edges, bool alphablend, int gradientFullSize)
void gPixmap::drawRectangle(const gRegion &region, const eRect &area, const gRGB &backgroundColor, const gRGB &borderColor, int borderWidth, const std::vector<gRGB> &gradientColors, uint8_t direction, int radius, uint8_t edges, bool alphablend, int gradientFullSize)
{
if (surface->bpp < 32)
{
Expand All @@ -472,15 +472,20 @@ void gPixmap::drawRectangle(const gRegion &region, const eRect &area, const gRGB
#ifdef GPIXMAP_DEBUG
Stopwatch s;
#endif
const int GRADIENT_VERTICAL = 1;
const uint8_t GRADIENT_VERTICAL = 1;
uint32_t backColor = backgroundColor.argb();
backColor ^= 0xFF000000;
uint32_t borderCol = borderColor.argb();
borderCol ^= 0xFF000000;
uint32_t *gradientBuf = nullptr;

const int gradientSize = (gradientFullSize) ? gradientFullSize : (direction == GRADIENT_VERTICAL) ? area.height() : area.width();
gradientBuf = createGradientBuffer(gradientSize, !direction ? backgroundColor : startColor, !direction ? backgroundColor : endColor);
if(!direction)
gradientBuf = createGradientBuffer2(gradientSize, backgroundColor, backgroundColor);
else if(gradientColors.at(1) == gradientColors.at(2))
gradientBuf = createGradientBuffer2(gradientSize, gradientColors.at(0), gradientColors.at(1));
else
gradientBuf = createGradientBuffer3(gradientSize, gradientColors);

CornerData cornerData(radius, edges, area.width(), area.height(), borderWidth, borderCol);

Expand Down Expand Up @@ -753,7 +758,7 @@ void gPixmap::drawRectangle(const gRegion &region, const eRect &area, const gRGB
free(gradientBuf);
}

void gPixmap::blitRounded32Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag)
void gPixmap::blitRounded32Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag)
{
CornerData cornerData(cornerRadius, edges, pos.width(), pos.height(), 0, 0xFF000000);
int corners = 0;
Expand Down Expand Up @@ -998,7 +1003,7 @@ void gPixmap::blitRounded32Bit(const gPixmap &src, const eRect &pos, const eRect
}
}

void gPixmap::blitRounded32BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag)
void gPixmap::blitRounded32BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag)
{
CornerData cornerData(cornerRadius, edges, pos.width(), pos.height(), 0, 0xFF000000);
int corners = 0;
Expand Down Expand Up @@ -1291,7 +1296,7 @@ void gPixmap::blitRounded32BitScaled(const gPixmap &src, const eRect &pos, const
}
}

void gPixmap::blitRounded8Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag)
void gPixmap::blitRounded8Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag)
{

int corners = 0;
Expand Down Expand Up @@ -1449,7 +1454,7 @@ void gPixmap::blitRounded8Bit(const gPixmap &src, const eRect &pos, const eRect
}
}

void gPixmap::blitRounded8BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag)
void gPixmap::blitRounded8BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag)
{
int corners = 0;
uint32_t pal[256];
Expand Down Expand Up @@ -1737,7 +1742,7 @@ void gPixmap::blitRounded8BitScaled(const gPixmap &src, const eRect &pos, const
}
}

void gPixmap::blit(const gPixmap &src, const eRect &_pos, const gRegion &clip, int cornerRadius, int edges, int flag)
void gPixmap::blit(const gPixmap &src, const eRect &_pos, const gRegion &clip, int cornerRadius, uint8_t edges, int flag)
{
bool accel = (surface->data_phys && src.surface->data_phys);
bool accumulate = accel && (gAccel::getInstance()->accumulate() >= 0);
Expand Down
15 changes: 8 additions & 7 deletions lib/gdi/gpixmap.h
Expand Up @@ -10,6 +10,7 @@
#include <lib/gdi/fb.h>
#include <byteswap.h>
#include <unordered_map>
#include <vector>

struct gRGB
{
Expand Down Expand Up @@ -239,19 +240,19 @@ class gPixmap: public iObject
void fill(const gRegion &clip, const gColor &color);
void fill(const gRegion &clip, const gRGB &color);

void blit(const gPixmap &src, const eRect &pos, const gRegion &clip, int cornerRadius, int edges, int flags=0);
void blit(const gPixmap &src, const eRect &pos, const gRegion &clip, int cornerRadius, uint8_t edges, int flags=0);

void blitRounded32Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag);
void blitRounded32BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag);
void blitRounded8Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag);
void blitRounded8BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, int edges, int flag);
void blitRounded32Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag);
void blitRounded32BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag);
void blitRounded8Bit(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag);
void blitRounded8BitScaled(const gPixmap &src, const eRect &pos, const eRect &clip, int cornerRadius, uint8_t edges, int flag);

void mergePalette(const gPixmap &target);
void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
void line(const gRegion &clip, ePoint start, ePoint end, gRGB color);
void line(const gRegion &clip, ePoint start, ePoint end, unsigned int color);

void drawRectangle(const gRegion &region, const eRect &area, const gRGB &backgroundColor, const gRGB &borderColor, int borderWidth, const gRGB &startColor, const gRGB &endColor, int direction, int cornerRadius, int edges, bool alphablend, int gradientFullSize = 0);
void drawRectangle(const gRegion &region, const eRect &area, const gRGB &backgroundColor, const gRGB &borderColor, int borderWidth, const std::vector<gRGB> &gradientColors, uint8_t direction, int radius, uint8_t edges, bool alphablend, int gradientFullSize = 0);

};
SWIG_TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
Expand Down Expand Up @@ -286,7 +287,7 @@ struct CornerData

std::unordered_map<int, double> RadiusData;

CornerData(int radius, int edges, int h, int w, int bw, uint32_t borderColor)
CornerData(int radius, uint8_t edges, int h, int w, int bw, uint32_t borderColor)
{
cornerRadius = checkRadiusValue(radius, h, w);
radiusSet = cornerRadius > 0;
Expand Down
12 changes: 5 additions & 7 deletions lib/gdi/grc.cpp
Expand Up @@ -358,23 +358,22 @@ void gPainter::setForegroundColor(const gRGB &color)
m_rc->submit(o);
}

void gPainter::setGradient(const gRGB &startColor, const gRGB &endColor, int orientation, bool alphablend, int fullSize)
void gPainter::setGradient(const std::vector<gRGB> &colors, uint8_t orientation, bool alphablend, int fullSize)
{
if (m_dc->islocked())
return;
gOpcode o;
o.opcode = gOpcode::setGradient;
o.dc = m_dc.grabRef();
o.parm.gradient = new gOpcode::para::pgradient;
o.parm.gradient->startColor = startColor;
o.parm.gradient->endColor = endColor;
o.parm.gradient->colors = colors;
o.parm.gradient->orientation = orientation;
o.parm.gradient->alphablend = alphablend;
o.parm.gradient->fullSize = fullSize;
m_rc->submit(o);
}

void gPainter::setRadius(int radius, int edges)
void gPainter::setRadius(int radius, uint8_t edges)
{
if (m_dc->islocked())
return;
Expand Down Expand Up @@ -830,8 +829,7 @@ void gDC::exec(const gOpcode *o)
delete o->parm.setFont;
break;
case gOpcode::setGradient:
m_gradient_start_color = o->parm.gradient->startColor;
m_gradient_end_color = o->parm.gradient->endColor;
m_gradient_colors = o->parm.gradient->colors;
m_gradient_orientation = o->parm.gradient->orientation;
m_gradient_alphablend = o->parm.gradient->alphablend;
m_gradient_fullSize = o->parm.gradient->fullSize;
Expand Down Expand Up @@ -1079,7 +1077,7 @@ void gDC::exec(const gOpcode *o)
#endif
o->parm.rectangle->area.moveBy(m_current_offset);
gRegion clip = m_current_clip & o->parm.rectangle->area;
m_pixmap->drawRectangle(clip, o->parm.rectangle->area, m_background_color_rgb, m_border_color, m_border_width, m_gradient_start_color, m_gradient_end_color, m_gradient_orientation, m_radius, m_radius_edges, m_gradient_alphablend, m_gradient_fullSize);
m_pixmap->drawRectangle(clip, o->parm.rectangle->area, m_background_color_rgb, m_border_color, m_border_width, m_gradient_colors, m_gradient_orientation, m_radius, m_radius_edges, m_gradient_alphablend, m_gradient_fullSize);
m_border_width = 0;
m_radius = 0;
m_radius_edges = 0;
Expand Down
19 changes: 10 additions & 9 deletions lib/gdi/grc.h
Expand Up @@ -14,6 +14,7 @@
#include <pthread.h>
#include <stack>
#include <list>
#include <vector>

#include <string>
#include <lib/base/elock.h>
Expand Down Expand Up @@ -136,17 +137,16 @@ struct gOpcode

struct pgradient
{
gRGB startColor;
gRGB endColor;
int orientation;
std::vector<gRGB> colors;
uint8_t orientation;
bool alphablend;
int fullSize;
} *gradient;

struct pradius
{
int radius;
int edges;
uint8_t edges;
} *radius;

struct pborder
Expand Down Expand Up @@ -295,8 +295,8 @@ class gPainter
void setForegroundColor(const gRGB &color);

void setBorder(const gRGB &borderColor, int width);
void setGradient(const gRGB &startColor, const gRGB &endColor, int orientation, bool alphablend, int fullSize = 0);
void setRadius(int radius, int edges);
void setGradient(const std::vector<gRGB> &colors, uint8_t orientation, bool alphablend, int fullSize = 0);
void setRadius(int radius, uint8_t edges);

void setFont(gFont *font);
/* flags only THESE: */
Expand Down Expand Up @@ -393,12 +393,13 @@ class gDC : public iObject
ePtr<gFont> m_current_font;
ePoint m_current_offset;

gRGB m_gradient_start_color, m_gradient_end_color;
int m_gradient_orientation;
std::vector<gRGB> m_gradient_colors;
uint8_t m_gradient_orientation;
bool m_gradient_alphablend;
int m_gradient_fullSize;

int m_radius, m_radius_edges;
int m_radius;
uint8_t m_radius_edges;

gRGB m_border_color;
int m_border_width;
Expand Down

0 comments on commit 97588ad

Please sign in to comment.