mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Partial implementation of UIList
This commit is contained in:
parent
5ac5632e59
commit
f523c32044
3 changed files with 378 additions and 103 deletions
|
@ -21,66 +21,31 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
#include "ui_local.h"
|
||||
#include "localization.h"
|
||||
|
||||
griditemtype_t UIListCtrlItem::getListItemType
|
||||
(
|
||||
int which
|
||||
) const
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return TYPE_STRING;
|
||||
}
|
||||
|
||||
str UIListCtrlItem::getListItemString
|
||||
(
|
||||
int which
|
||||
) const
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return "";
|
||||
}
|
||||
|
||||
int UIListCtrlItem::getListItemValue
|
||||
(
|
||||
int which
|
||||
) const
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UIListCtrlItem::DrawListItem
|
||||
(
|
||||
int,
|
||||
UIRect2D const &,
|
||||
bool, UIFont *
|
||||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
}
|
||||
|
||||
qboolean UIListCtrlItem::IsHeaderEntry
|
||||
(
|
||||
void
|
||||
) const
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return qfalse;
|
||||
}
|
||||
static UISize2D s_columnpadding;
|
||||
|
||||
CLASS_DECLARATION( UIListBase, UIListCtrl, NULL )
|
||||
{
|
||||
{ &W_SizeChanged, &UIListCtrl::OnSizeChanged },
|
||||
{ &W_LeftMouseDown, &UIListCtrl::MousePressed },
|
||||
{ &W_LeftMouseUp, &UIListCtrl::MouseReleased },
|
||||
{ &W_LeftMouseDragged, &UIListCtrl::MouseDragged },
|
||||
{ &W_MouseEntered, &UIListCtrl::MouseEntered },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
UIListCtrl::UIListCtrl()
|
||||
{
|
||||
// FIXME: stub
|
||||
m_clickState.point.x = m_clickState.point.y = 0;
|
||||
m_sizestate.column = 0;
|
||||
m_iLastSortColumn = 0;
|
||||
m_bDrawHeader = qtrue;
|
||||
m_headerfont = NULL;
|
||||
|
||||
Connect(this, W_SizeChanged, W_SizeChanged);
|
||||
m_background_color = UColor(0.02f, 0.07f, 0.005f, 1.0f);
|
||||
m_foreground_color = UHudColor;
|
||||
}
|
||||
|
||||
int UIListCtrl::StringCompareFunction
|
||||
|
@ -124,7 +89,11 @@ void UIListCtrl::Draw
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
if (m_bDrawHeader) {
|
||||
DrawColumns();
|
||||
}
|
||||
|
||||
DrawContent();
|
||||
}
|
||||
|
||||
int UIListCtrl::getHeaderHeight
|
||||
|
@ -133,8 +102,19 @@ int UIListCtrl::getHeaderHeight
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return 0;
|
||||
if (!m_bDrawHeader) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_headerfont) {
|
||||
return (int)(m_headerfont->getHeight(m_bVirtual) + (s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1]);
|
||||
}
|
||||
|
||||
if (m_font) {
|
||||
return (int)(m_font->getHeight(m_bVirtual) + (s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1]);
|
||||
}
|
||||
|
||||
return (int)((s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1]);
|
||||
}
|
||||
|
||||
void UIListCtrl::MousePressed
|
||||
|
@ -161,7 +141,11 @@ void UIListCtrl::MouseReleased
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_sizestate.column = 0;
|
||||
|
||||
if (uWinMan.getFirstResponder() == this) {
|
||||
uWinMan.setFirstResponder(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void UIListCtrl::MouseEntered
|
||||
|
@ -170,7 +154,7 @@ void UIListCtrl::MouseEntered
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
uWinMan.ActivateControl(this);
|
||||
}
|
||||
|
||||
void UIListCtrl::OnSizeChanged
|
||||
|
@ -179,7 +163,13 @@ void UIListCtrl::OnSizeChanged
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
if (!m_vertscroll) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_vertscroll->InitFrame(this, m_frame.size.width - 16.0, 0.0, 16.0, m_frame.size.height, -1);
|
||||
m_vertscroll->setPageHeight((m_frame.size.height - getHeaderHeight()) / m_font->getHeight(m_bVirtual));
|
||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||
}
|
||||
|
||||
void UIListCtrl::DrawColumns
|
||||
|
@ -188,7 +178,57 @@ void UIListCtrl::DrawColumns
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
int atleft;
|
||||
int i;
|
||||
int height;
|
||||
UIFont* pFont;
|
||||
UColor columnColor, textColor;
|
||||
|
||||
atleft = 0;
|
||||
columnColor = UColor(0.07f, 0.06f, 0.005f, 1.0f);
|
||||
textColor = UHudColor;
|
||||
|
||||
pFont = m_headerfont;
|
||||
if (!pFont) pFont = m_font;
|
||||
|
||||
height = (s_columnpadding.height + s_columnpadding.height) * m_vVirtualScale[1] + pFont->getHeight(m_bVirtual);
|
||||
pFont->setColor(textColor);
|
||||
|
||||
for (i = 1; i <= m_columnlist.NumObjects(); i++)
|
||||
{
|
||||
const columndef_t& column = m_columnlist.ObjectAt(i);
|
||||
|
||||
DrawBoxWithSolidBorder(
|
||||
UIRect2D(atleft, 0, column.width + m_vVirtualScale[1], height),
|
||||
columnColor,
|
||||
textColor,
|
||||
1,
|
||||
3,
|
||||
m_local_alpha
|
||||
);
|
||||
|
||||
pFont->Print(
|
||||
atleft / m_vVirtualScale[0] + s_columnpadding.width,
|
||||
s_columnpadding.height,
|
||||
Sys_LV_CL_ConvertString(column.title.c_str()),
|
||||
-1,
|
||||
m_bVirtual
|
||||
);
|
||||
|
||||
atleft += column.width;
|
||||
}
|
||||
|
||||
if (m_frame.size.width > atleft)
|
||||
{
|
||||
DrawBoxWithSolidBorder(
|
||||
UIRect2D(atleft, 0, m_frame.size.width - atleft + 1.0, height),
|
||||
columnColor,
|
||||
textColor,
|
||||
1,
|
||||
3,
|
||||
m_local_alpha
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void UIListCtrl::DrawContent
|
||||
|
@ -197,7 +237,110 @@ void UIListCtrl::DrawContent
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
int item;
|
||||
int height, headerheight, iItemHeight;
|
||||
UIFont* pFont;
|
||||
int top;
|
||||
UColor selColor, selText;
|
||||
UColor backColor, textColor;
|
||||
|
||||
height = m_font->getHeight(m_bVirtual);
|
||||
selColor = UColor(0.21f, 0.18f, 0.015f, 1.0f);
|
||||
selText = UColor(0.9f, 0.8f, 0.6f, 1.0f);
|
||||
backColor = m_background_color;
|
||||
textColor = m_foreground_color;
|
||||
|
||||
if (m_headerfont) {
|
||||
headerheight = m_headerfont->getHeight(m_bVirtual);
|
||||
} else {
|
||||
headerheight = 0;
|
||||
}
|
||||
|
||||
selColor.a = m_local_alpha;
|
||||
selText.a = m_local_alpha;
|
||||
backColor.a = m_local_alpha;
|
||||
textColor.a = m_local_alpha;
|
||||
top = getHeaderHeight();
|
||||
if (m_vertscroll) {
|
||||
item = m_vertscroll->getTopItem() + 1;
|
||||
} else {
|
||||
item = 1;
|
||||
}
|
||||
|
||||
for (; item <= m_itemlist.NumObjects(); item++)
|
||||
{
|
||||
UIListCtrlItem* theitem;
|
||||
int col;
|
||||
int atleft;
|
||||
UColor* itemBg;
|
||||
UColor* itemText;
|
||||
|
||||
theitem = m_itemlist.ObjectAt(item);
|
||||
atleft = 0;
|
||||
|
||||
if (item == m_currentItem)
|
||||
{
|
||||
itemBg = &selColor;
|
||||
itemText = &selText;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemBg = &backColor;
|
||||
itemText = &textColor;
|
||||
}
|
||||
|
||||
if (theitem->IsHeaderEntry() && m_headerfont) {
|
||||
pFont = m_headerfont;
|
||||
iItemHeight = headerheight;
|
||||
} else {
|
||||
pFont = m_font;
|
||||
iItemHeight = height;
|
||||
}
|
||||
|
||||
pFont->setColor(*itemText);
|
||||
for (col = 1; col <= m_columnlist.NumObjects(); col++)
|
||||
{
|
||||
columndef_t& column = m_columnlist.ObjectAt(col);
|
||||
UIRect2D drawRect(atleft, top, column.width, iItemHeight);
|
||||
griditemtype_t itemtype = theitem->getListItemType(column.name);
|
||||
|
||||
switch (itemtype)
|
||||
{
|
||||
case TYPE_STRING:
|
||||
DrawBox(drawRect, *itemBg, m_local_alpha);
|
||||
pFont->Print(
|
||||
drawRect.pos.x / m_vVirtualScale[0] + 1.0,
|
||||
drawRect.pos.y / m_vVirtualScale[1],
|
||||
Sys_LV_CL_ConvertString(theitem->getListItemString(column.name)),
|
||||
-1,
|
||||
m_bVirtual
|
||||
);
|
||||
break;
|
||||
case TYPE_OWNERDRAW:
|
||||
theitem->DrawListItem(column.name, drawRect, item == m_currentItem, pFont);
|
||||
break;
|
||||
}
|
||||
|
||||
atleft += column.width;
|
||||
}
|
||||
|
||||
if (m_frame.size.width > atleft)
|
||||
{
|
||||
DrawBox(
|
||||
atleft,
|
||||
top,
|
||||
m_frame.size.width - atleft,
|
||||
height,
|
||||
*itemBg,
|
||||
m_local_alpha
|
||||
);
|
||||
}
|
||||
|
||||
top += iItemHeight;
|
||||
if (iItemHeight + top > m_frame.size.height) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UIListCtrl::FrameInitialized
|
||||
|
@ -206,7 +349,8 @@ void UIListCtrl::FrameInitialized
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
UIListBase::FrameInitialized();
|
||||
OnSizeChanged(NULL);
|
||||
}
|
||||
|
||||
void UIListCtrl::SetDrawHeader
|
||||
|
@ -215,7 +359,7 @@ void UIListCtrl::SetDrawHeader
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_bDrawHeader = bDrawHeader;
|
||||
}
|
||||
|
||||
void UIListCtrl::AddItem
|
||||
|
@ -224,7 +368,10 @@ void UIListCtrl::AddItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_itemlist.AddObject(item);
|
||||
if (m_vertscroll) {
|
||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||
}
|
||||
}
|
||||
|
||||
void UIListCtrl::InsertItem
|
||||
|
@ -233,7 +380,26 @@ void UIListCtrl::InsertItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
if (where > 0 && where <= m_itemlist.NumObjects())
|
||||
{
|
||||
int i;
|
||||
|
||||
m_itemlist.AddObject(NULL);
|
||||
|
||||
for (i = m_itemlist.NumObjects(); i > where; i++) {
|
||||
m_itemlist.SetObjectAt(i, m_itemlist.ObjectAt(i - 1));
|
||||
}
|
||||
|
||||
m_itemlist.SetObjectAt(where, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_itemlist.AddObject(item);
|
||||
}
|
||||
|
||||
if (m_vertscroll) {
|
||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||
}
|
||||
}
|
||||
|
||||
int UIListCtrl::FindItem
|
||||
|
@ -242,8 +408,7 @@ int UIListCtrl::FindItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return 0;
|
||||
return m_itemlist.IndexOfObject(item);
|
||||
}
|
||||
|
||||
UIListCtrlItem *UIListCtrl::GetItem
|
||||
|
@ -252,8 +417,7 @@ UIListCtrlItem *UIListCtrl::GetItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return NULL;
|
||||
return m_itemlist.ObjectAt(item);
|
||||
}
|
||||
|
||||
void UIListCtrl::AddColumn
|
||||
|
@ -266,7 +430,15 @@ void UIListCtrl::AddColumn
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
columndef_t column;
|
||||
|
||||
column.title = title;
|
||||
column.name = name;
|
||||
column.width = width;
|
||||
column.numeric = numeric;
|
||||
column.reverse_sort = reverse_sort;
|
||||
|
||||
m_columnlist.AddObject(column);
|
||||
}
|
||||
|
||||
void UIListCtrl::RemoveAllColumns
|
||||
|
@ -275,7 +447,7 @@ void UIListCtrl::RemoveAllColumns
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_columnlist.ClearObjectList();
|
||||
}
|
||||
|
||||
int UIListCtrl::getNumItems
|
||||
|
@ -284,8 +456,7 @@ int UIListCtrl::getNumItems
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return 0;
|
||||
return m_itemlist.NumObjects();
|
||||
}
|
||||
|
||||
void UIListCtrl::DeleteAllItems
|
||||
|
@ -294,7 +465,14 @@ void UIListCtrl::DeleteAllItems
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_itemlist.ClearObjectList();
|
||||
m_currentItem = 0;
|
||||
|
||||
if (m_vertscroll)
|
||||
{
|
||||
m_vertscroll->setNumItems(0);
|
||||
m_vertscroll->setTopItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
void UIListCtrl::DeleteItem
|
||||
|
@ -303,7 +481,15 @@ void UIListCtrl::DeleteItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_itemlist.RemoveObjectAt(which);
|
||||
|
||||
if (m_vertscroll) {
|
||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||
}
|
||||
|
||||
if (m_currentItem > getNumItems()) {
|
||||
TrySelectItem(getNumItems());
|
||||
}
|
||||
}
|
||||
|
||||
void UIListCtrl::SortByColumn
|
||||
|
@ -321,7 +507,7 @@ void UIListCtrl::SortByLastSortColumn
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
SortByColumn(m_iLastSortColumn);
|
||||
}
|
||||
|
||||
void UIListCtrl::setCompareFunction
|
||||
|
@ -330,7 +516,7 @@ void UIListCtrl::setCompareFunction
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_comparefunction = func;
|
||||
}
|
||||
|
||||
void UIListCtrl::setHeaderFont
|
||||
|
@ -339,5 +525,13 @@ void UIListCtrl::setHeaderFont
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
if (m_headerfont) {
|
||||
delete m_headerfont;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
m_headerfont = new UIFont(name);
|
||||
} else {
|
||||
m_headerfont = NULL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue