Skip to content

Commit

Permalink
Merge branch 'Developer' into Python3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Ev0-BH committed Jan 20, 2024
2 parents 87210b8 + 1850857 commit 51cad4d
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 34 deletions.
49 changes: 49 additions & 0 deletions lib/gui/elistbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <lib/gui/eslider.h>
#include <lib/actions/action.h>

int eListbox::defaultItemRadius[2] = {0,0};
int eListbox::defaultItemRadiusEdges[2] = {0,0};

eListbox::eListbox(eWidget *parent) :
eWidget(parent), m_scrollbar_mode(showNever), m_prev_scrollbar_page(-1),
m_content_changed(false), m_enabled_wrap_around(false), m_scrollbar_width(10), m_scrollbar_height(10),
Expand All @@ -12,6 +15,14 @@ eListbox::eListbox(eWidget *parent) :
memset(static_cast<void*>(&m_style), 0, sizeof(m_style));
m_style.m_text_offset = ePoint(1,1);

for (int x = 0; x < 2; x++)
{
if (eListbox::defaultItemRadius[x] && eListbox::defaultItemRadiusEdges[x])
setItemCornerRadiusInternal(eListbox::defaultItemRadius[x], eListbox::defaultItemRadiusEdges[x], x);
else
setItemCornerRadiusInternal(0, 0, x);
}

allowNativeKeys(true);
}

Expand Down Expand Up @@ -550,6 +561,25 @@ int eListbox::event(int event, void *data, void *data2)
gRegion entryrect = m_orientation == orVertical ? eRect(0, 0, size().width(), m_itemheight) : eRect(0, 0, m_itemwidth, size().height());
const gRegion &paint_region = *(gRegion*)data;

if (!isTransparent())
{
int cornerRadius = getCornerRadius();
int cornerRadiusEdges = getCornerRadiusEdges();
painter.clip(paint_region);
style->setStyle(painter, eWindowStyle::styleListboxNormal);
if (m_style.m_background_color_set)
painter.setBackgroundColor(m_style.m_background_color);

if (cornerRadius && cornerRadiusEdges)
{
painter.setRadius(cornerRadius, cornerRadiusEdges);
painter.drawRectangle(eRect(ePoint(0, 0), size()));
}
else
painter.clear();
painter.clippop();
}

int xoffset = 0;
int yoffset = 0;
if (m_scrollbar && m_scrollbar_mode == showLeft)
Expand Down Expand Up @@ -987,3 +1017,22 @@ struct eListboxStyle *eListbox::getLocalStyle(void)
m_style.m_transparent_background = isTransparent();
return &m_style;
}

void eListbox::setItemCornerRadiusInternal(int radius, int edges, int index)
{
m_style.m_itemCornerRadius[index] = radius;
m_style.m_itemCornerRadiusEdges[index] = edges;
}

void eListbox::setItemCornerRadius(int radius, int edges)
{
for (int x = 0; x < 2; x++)
{
setItemCornerRadiusInternal(radius, edges, x);
}
}

void eListbox::setItemCornerRadiusSelected(int radius, int edges)
{
setItemCornerRadiusInternal(radius, edges, 1);
}
27 changes: 27 additions & 0 deletions lib/gui/elistbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ struct eListboxStyle
int m_valign, m_halign, m_border_size, m_scrollbarborder_width;
ePtr<gFont> m_font, m_secondfont;
ePoint m_text_offset;
int m_itemCornerRadius[2];
int m_itemCornerRadiusEdges[2];
int cornerRadius(int mode)
{
return m_itemCornerRadius[mode];
}
int cornerRadiusEdges(int mode)
{
return m_itemCornerRadiusEdges[mode];
}
};
#endif

Expand Down Expand Up @@ -188,6 +198,20 @@ class eListbox: public eWidget
int getScrollbarHeight() { return m_scrollbar_height; }
int getMaxItemTextWidth() { return m_content->getMaxItemTextWidth(); }

void setItemCornerRadius(int radius, int edges);
void setItemCornerRadiusSelected(int radius, int edges);

static void setDefaultItemRadius(int radius, int radiusEdges)
{
defaultItemRadius[0] = radius;
defaultItemRadiusEdges[0] = radiusEdges;
}
static void setDefaultItemRadiusSelected(int radius, int radiusEdges)
{
defaultItemRadius[1] = radius;
defaultItemRadiusEdges[1] = radiusEdges;
}

#ifndef SWIG
struct eListboxStyle *getLocalStyle(void);

Expand Down Expand Up @@ -219,13 +243,16 @@ class eListbox: public eWidget
int m_orientation;
int m_items_per_page;
int m_selection_enabled;
void setItemCornerRadiusInternal(int radius, int edges, int index);

bool m_native_keys_bound;

ePtr<iListboxContent> m_content;
eSlider *m_scrollbar;
eListboxStyle m_style;
ePtr<gPixmap> m_scrollbarpixmap, m_scrollbarbackgroundpixmap;
static int defaultItemRadius[2];
static int defaultItemRadiusEdges[2];
#endif
};

Expand Down
110 changes: 98 additions & 12 deletions lib/gui/elistboxcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <lib/gdi/font.h>
#include <lib/python/python.h>
#include <lib/gdi/epng.h>
#include <lib/gui/ewindowstyleskinned.h>
/*
The basic idea is to have an interface which gives all relevant list
processing functions, and can be used by the listbox to browse trough
Expand Down Expand Up @@ -178,13 +179,16 @@ int eListboxPythonStringContent::getMaxItemTextWidth()
void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
{
ePtr<gFont> fnt;
painter.clip(eRect(offset, m_itemsize));
eRect itemRect(offset, m_itemsize);
painter.clip(itemRect);
style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
bool validitem = (m_list && cursorValid());
eListboxStyle *local_style = 0;
bool cursorValid = this->cursorValid();
gRGB border_color;
int border_size = 0;
int radius = 0;
int edges = 0;

/* get local listbox style, if present */
if (m_listbox)
Expand All @@ -194,6 +198,8 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style,
{
border_size = local_style->m_border_size;
border_color = local_style->m_border_color;
radius = local_style->cornerRadius(selected ? 1:0);
edges = local_style->cornerRadiusEdges(selected ? 1:0);
fnt = local_style->m_font;
if (selected)
{
Expand Down Expand Up @@ -228,6 +234,12 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style,
if (validitem) painter.blit(local_style->m_background, ePoint(offset.x() + (m_itemsize.width() - local_style->m_background->size().width()) / 2, offset.y()), eRect(), 0);
}
}
else if (local_style && !local_style->m_background && cursorValid && radius)
{
if(radius)
painter.setRadius(radius, edges);
painter.drawRectangle(itemRect);
}
else
painter.clear();
} else
Expand All @@ -240,7 +252,7 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style,
if (validitem) painter.blit(local_style->m_background, ePoint(offset.x() + (m_itemsize.width() - local_style->m_background->size().width()) / 2, offset.y()), eRect(), gPainter::BT_ALPHATEST);
}
}
else if (selected && !local_style->m_selection)
else if (selected && !local_style->m_selection && cursorValid && !radius && !local_style->m_background)
painter.clear();
}

Expand Down Expand Up @@ -269,6 +281,11 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style,
else
painter.blit(local_style->m_selection, ePoint(offset.x() + (m_itemsize.width() - local_style->m_selection->size().width()) / 2, offset.y()), eRect(), gPainter::BT_ALPHATEST);
}
else if (selected && local_style && radius && !local_style->m_selection) {
if(radius)
painter.setRadius(radius, edges);
painter.drawRectangle(itemRect);
}

if (item == Py_None)
{
Expand Down Expand Up @@ -401,6 +418,8 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
bool cursorValid = this->cursorValid();
gRGB border_color;
int border_size = 0;
int radius = 0;
int edges = 0;

painter.clip(itemrect);
style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
Expand All @@ -415,6 +434,8 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
border_color = local_style->m_border_color;
fnt = local_style->m_font;
fnt2 = local_style->m_secondfont;
radius = local_style->cornerRadius(selected ? 1:0);
edges = local_style->cornerRadiusEdges(selected ? 1:0);
if (selected)
{
/* if we have a local background color set, use that. */
Expand Down Expand Up @@ -444,11 +465,18 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
/* if we have no transparent background */
{
/* blit background picture, if available (otherwise, clear only) */
if (local_style && local_style->m_background && cursorValid)
if (local_style && local_style->m_background && cursorValid) {
if (m_listbox && m_listbox->getOrientation() == 1)
painter.blit(local_style->m_background, ePoint(offset.x(), offset.y() + (m_itemsize.height() - local_style->m_background->size().height()) / 2), eRect(), 0);
else
painter.blit(local_style->m_background, ePoint(offset.x() + (m_itemsize.width() - local_style->m_background->size().width()) / 2, offset.y()), eRect(), 0);
}
else if (local_style && !local_style->m_background && cursorValid && radius)
{
if(radius)
painter.setRadius(radius, edges);
painter.drawRectangle(itemrect);
}
else
painter.clear();
} else
Expand All @@ -458,7 +486,7 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
painter.blit(local_style->m_background, ePoint(offset.x(), offset.y() + (m_itemsize.height() - local_style->m_background->size().height()) / 2), eRect(), gPainter::BT_ALPHATEST);
else
painter.blit(local_style->m_background, ePoint(offset.x() + (m_itemsize.width() - local_style->m_background->size().width()) / 2, offset.y()), eRect(), gPainter::BT_ALPHATEST);
else if (selected && !local_style->m_selection)
else if (selected && !local_style->m_selection && !radius)
painter.clear();
}

Expand All @@ -478,6 +506,10 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
painter.blit(local_style->m_selection, ePoint(offset.x(), offset.y() + (m_itemsize.height() - local_style->m_selection->size().height()) / 2), eRect(), gPainter::BT_ALPHATEST);
else
painter.blit(local_style->m_selection, ePoint(offset.x() + (m_itemsize.width() - local_style->m_selection->size().width()) / 2, offset.y()), eRect(), gPainter::BT_ALPHATEST);
} else if (selected && radius && !local_style->m_selection) {
if(radius)
painter.setRadius(radius, edges);
painter.drawRectangle(itemrect);
}
/* the first tuple element is a string for the left side.
the second one will be called, and the result shall be an tuple.
Expand Down Expand Up @@ -1000,7 +1032,8 @@ int eListboxPythonMultiContent::getMaxItemTextWidth()

void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
{
gRegion itemregion(eRect(offset, m_itemsize));
eRect itemRect = eRect(offset, m_itemsize);
gRegion itemregion(itemRect);
eListboxStyle *local_style = 0;
eRect sel_clip(m_selection_clip);
bool cursorValid = this->cursorValid();
Expand All @@ -1021,8 +1054,28 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
}

painter.clip(itemregion);
clearRegion(painter, style, local_style, ePyObject(), ePyObject(), ePyObject(), ePyObject(), selected, itemregion, sel_clip, offset, m_itemsize, cursorValid, true, isverticallb);


if(local_style) {
int mode = (selected) ? 1:0;
int radius = local_style->cornerRadius(mode);
int edges = local_style->cornerRadiusEdges(mode);
if (radius) {
gRGB color = style.getColor(selected ? eWindowStyleSkinned::colListboxSelectedBackground : eWindowStyleSkinned::colListboxBackground);;
if (selected && local_style->m_background_color_selected_set)
color = local_style->m_background_color_selected;
if (!selected && local_style->m_background_color_set)
color = local_style->m_background_color;

painter.setRadius(radius, edges);
painter.setBackgroundColor(gRGB(color));
painter.drawRectangle(itemRect);
}
else
clearRegion(painter, style, local_style, ePyObject(), ePyObject(), ePyObject(), ePyObject(), selected, itemregion, sel_clip, offset, m_itemsize, cursorValid, true, isverticallb);
}
else
clearRegion(painter, style, local_style, ePyObject(), ePyObject(), ePyObject(), ePyObject(), selected, itemregion, sel_clip, offset, m_itemsize, cursorValid, true, isverticallb);

// Draw frame here so to be under the content
if (selected && !sel_clip.valid() && (!local_style || !local_style->m_selection) && (!local_style || !local_style->m_border_set))
style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
Expand Down Expand Up @@ -1128,7 +1181,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
pfnt = PyTuple_GET_ITEM(item, 5),
pflags = PyTuple_GET_ITEM(item, 6),
pstring = PyTuple_GET_ITEM(item, 7),
pforeColor, pforeColorSelected, pbackColor, pbackColorSelected, pborderWidth, pborderColor;
pforeColor, pforeColorSelected, pbackColor, pbackColorSelected, pborderWidth, pborderColor, pCornerRadius, pCornerEdges;

if (!(px && py && pwidth && pheight && pfnt && pflags && pstring))
{
Expand Down Expand Up @@ -1157,6 +1210,12 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
if (size > 13)
pborderColor = lookupColor(PyTuple_GET_ITEM(item, 13), data);

if (size > 14)
pCornerRadius = PyTuple_GET_ITEM(item, 14);

if (size > 15)
pCornerEdges = PyTuple_GET_ITEM(item, 15);

if (PyLong_Check(pstring) && data) /* if the string is in fact a number, it refers to the 'data' list. */
pstring = PyTuple_GetItem(data, PyLong_AsLong(pstring));

Expand All @@ -1173,6 +1232,11 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
int fnt = PyLong_AsLong(pfnt);
int bwidth = pborderWidth ? PyLong_AsLong(pborderWidth) : 0;

int cornerRadius = pCornerRadius ? PyLong_AsLong(pCornerRadius) : 0;
int cornerEdges = pCornerEdges ? PyLong_AsLong(pCornerEdges) : 15;
if (cornerRadius || cornerEdges)
bwidth = 0; // border not supported for rounded edges

if (m_font.find(fnt) == m_font.end())
{
eDebug("[eListboxPythonMultiContent] specified font %d was not found!", fnt);
Expand All @@ -1183,17 +1247,29 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
painter.clip(rect);

{
gRegion rc(rect);
bool mustClear = (selected && pbackColorSelected) || (!selected && pbackColor);
clearRegion(painter, style, local_style, pforeColor, pforeColorSelected, pbackColor, pbackColorSelected, selected, rc, sel_clip, offset, m_itemsize, cursorValid, mustClear, isverticallb);
if(cornerRadius && (pbackColor || pbackColorSelected))
{
if(selected && !pbackColorSelected)
pbackColorSelected = pbackColor;
unsigned int color = PyLong_AsUnsignedLongMask(selected ? pbackColorSelected : pbackColor);
painter.setBackgroundColor(gRGB(color));
painter.setRadius(cornerRadius, cornerEdges);
painter.drawRectangle(itemRect);
}
else
{
gRegion rc(rect);
bool mustClear = (selected && pbackColorSelected) || (!selected && pbackColor);
clearRegion(painter, style, local_style, pforeColor, pforeColorSelected, pbackColor, pbackColorSelected, selected, rc, sel_clip, offset, m_itemsize, cursorValid, mustClear, isverticallb);
}
}

painter.setFont(m_font[fnt]);
painter.renderText(rect, string, flags, border_color, border_size);
painter.clippop();

// draw border
if (bwidth)
if (bwidth && cornerRadius == 0)
{
eRect rect(eRect(x, y, width, height));
painter.clip(rect);
Expand Down Expand Up @@ -1381,6 +1457,8 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
int width = PyFloat_Check(pwidth) ? (int)PyFloat_AsDouble(pwidth) : PyLong_AsLong(pwidth);
int height = PyFloat_Check(pheight) ? (int)PyFloat_AsDouble(pheight) : PyLong_AsLong(pheight);
int flags = 0;
int radius = 0;
int edges = 0;
ePtr<gPixmap> pixmap;
if (SwigFromPython(pixmap, ppixmap))
{
Expand All @@ -1397,6 +1475,12 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
if (size > 8)
flags = PyLong_AsLong(PyTuple_GET_ITEM(item, 8));

if (size > 9)
radius = PyLong_AsLong(PyTuple_GET_ITEM(item, 9));

if (size > 10)
edges = PyLong_AsLong(PyTuple_GET_ITEM(item, 10));

eRect rect(x, y, width, height);
painter.clip(rect);

Expand All @@ -1406,6 +1490,8 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
clearRegion(painter, style, local_style, ePyObject(), ePyObject(), pbackColor, pbackColorSelected, selected, rc, sel_clip, offset, m_itemsize, cursorValid, mustClear, isverticallb);
}
flags |= (type == TYPE_PIXMAP_ALPHATEST) ? gPainter::BT_ALPHATEST : (type == TYPE_PIXMAP_ALPHABLEND) ? gPainter::BT_ALPHABLEND : 0;
if(radius && edges)
painter.setRadius(radius, edges);
painter.blit(pixmap, rect, rect, flags);
painter.clippop();
break;
Expand Down
Loading

0 comments on commit 51cad4d

Please sign in to comment.