void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
{
ePtr<gFont> fnt;
painter.clip(eRect(offset, m_itemsize));
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;
/* get local listbox style, if present */
if (m_listbox)
local_style = m_listbox->getLocalStyle();
if (local_style)
{
border_size = local_style->m_border_size;
border_color = local_style->m_border_color;
fnt = local_style->m_font;
if (selected)
{
/* if we have a local background color set, use that. */
if (local_style->m_background_color_selected_set)
painter.setBackgroundColor(local_style->m_background_color_selected);
/* same for foreground */
if (local_style->m_foreground_color_selected_set)
painter.setForegroundColor(local_style->m_foreground_color_selected);
}
else
{
/* if we have a local background color set, use that. */
if (local_style->m_background_color_set)
painter.setBackgroundColor(local_style->m_background_color);
/* same for foreground */
if (local_style->m_foreground_color_set)
painter.setForegroundColor(local_style->m_foreground_color);
}
}
if (!fnt) fnt = new gFont("Regular", 20);
/* if we have no transparent background */
if (!local_style || !local_style->m_transparent_background)
{
/* blit background picture, if available (otherwise, clear only) */
if (local_style && local_style->m_background && cursorValid)
{
if (validitem) painter.blit(local_style->m_background, offset, eRect(), 0);
}
else
painter.clear();
} else
{
if (local_style->m_background && cursorValid)
{
if (validitem) painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
}
else if (selected && !local_style->m_selection)
painter.clear();
}
if (validitem)
{
int gray = 0;
ePyObject item = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference!
painter.setFont(fnt);
/* the user can supply tuples, in this case the first one will be displayed. */
if (PyTuple_Check(item))
{
if (PyTuple_Size(item) == 1)
gray = 1;
item = PyTuple_GET_ITEM(item, 0);
}
if (selected && local_style && local_style->m_selection)
painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHATEST);
if (item == Py_None)
{
/* seperator */
int half_height = m_itemsize.height() / 2;
painter.fill(eRect(offset.x() + half_height, offset.y() + half_height - 2, m_itemsize.width() - m_itemsize.height(), 4));
} else
{
const char *string = PyString_Check(item) ? PyString_AsString(item) : "<not-a-string>";
ePoint text_offset = offset;
if (gray)
painter.setForegroundColor(gRGB(0x808080));
int flags = 0;
if (local_style)
{
text_offset += local_style->m_text_offset;
if (local_style->m_valign == eListboxStyle::alignTop)
flags |= gPainter::RT_VALIGN_TOP;
else if (local_style->m_valign == eListboxStyle::alignCenter)
flags |= gPainter::RT_VALIGN_CENTER;
else if (local_style->m_valign == eListboxStyle::alignBottom)
//.........这里部分代码省略.........
请发表评论