mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-29 06:07:57 +03:00
Formatted uilistbox source files
This commit is contained in:
parent
b120fc6f2f
commit
3d4832ca85
2 changed files with 307 additions and 434 deletions
|
@ -22,133 +22,120 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
#include "ui_local.h"
|
#include "ui_local.h"
|
||||||
|
|
||||||
CLASS_DECLARATION( UIWidget, UIListBase, NULL )
|
CLASS_DECLARATION(UIWidget, UIListBase, NULL) {
|
||||||
{
|
{NULL, NULL}
|
||||||
{ NULL, NULL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UIListBase::UIListBase()
|
UIListBase::UIListBase()
|
||||||
{
|
{
|
||||||
m_currentItem = 0;
|
m_currentItem = 0;
|
||||||
m_vertscroll = 0;
|
m_vertscroll = 0;
|
||||||
m_bUseVertScroll = 1;
|
m_bUseVertScroll = 1;
|
||||||
AllowActivate(true);
|
AllowActivate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBase::TrySelectItem
|
void UIListBase::TrySelectItem(int which)
|
||||||
(
|
|
||||||
int which
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int numitems;
|
int numitems;
|
||||||
|
|
||||||
numitems = getNumItems();
|
numitems = getNumItems();
|
||||||
if (!numitems) {
|
if (!numitems) {
|
||||||
m_currentItem = 0;
|
m_currentItem = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_currentItem != which)
|
if (m_currentItem != which) {
|
||||||
{
|
int previous = m_currentItem;
|
||||||
int previous = m_currentItem;
|
|
||||||
|
|
||||||
m_currentItem = which;
|
m_currentItem = which;
|
||||||
if (which > numitems) {
|
if (which > numitems) {
|
||||||
m_currentItem = numitems;
|
m_currentItem = numitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_currentItem <= 0) {
|
if (m_currentItem <= 0) {
|
||||||
m_currentItem = 1;
|
m_currentItem = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous != m_currentItem) {
|
if (previous != m_currentItem) {
|
||||||
Event ev(EV_UIListBase_ItemSelected);
|
Event ev(EV_UIListBase_ItemSelected);
|
||||||
ev.AddInteger(m_currentItem);
|
ev.AddInteger(m_currentItem);
|
||||||
SendSignal(ev);
|
SendSignal(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_vertscroll)
|
if (m_vertscroll) {
|
||||||
{
|
if (m_currentItem < m_vertscroll->getTopItem() + 1) {
|
||||||
if (m_currentItem < m_vertscroll->getTopItem() + 1) {
|
if (m_currentItem - 1 >= 0) {
|
||||||
if (m_currentItem - 1 >= 0) {
|
m_vertscroll->setTopItem(m_currentItem - 1);
|
||||||
m_vertscroll->setTopItem(m_currentItem - 1);
|
} else {
|
||||||
} else {
|
m_vertscroll->setTopItem(0);
|
||||||
m_vertscroll->setTopItem(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (m_currentItem >= m_vertscroll->getTopItem() + m_vertscroll->getPageHeight() + 1) {
|
if (m_currentItem >= m_vertscroll->getTopItem() + m_vertscroll->getPageHeight() + 1) {
|
||||||
if (m_currentItem - m_vertscroll->getPageHeight() >= 0) {
|
if (m_currentItem - m_vertscroll->getPageHeight() >= 0) {
|
||||||
m_vertscroll->setTopItem(m_currentItem - m_vertscroll->getPageHeight());
|
m_vertscroll->setTopItem(m_currentItem - m_vertscroll->getPageHeight());
|
||||||
} else {
|
} else {
|
||||||
m_vertscroll->setTopItem(0);
|
m_vertscroll->setTopItem(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qboolean UIListBase::KeyEvent
|
qboolean UIListBase::KeyEvent(int key, unsigned int time)
|
||||||
(
|
|
||||||
int key,
|
|
||||||
unsigned int time
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int offsetitem;
|
int offsetitem;
|
||||||
qboolean key_rec;
|
qboolean key_rec;
|
||||||
int itemindex;
|
int itemindex;
|
||||||
|
|
||||||
offsetitem = 0;
|
offsetitem = 0;
|
||||||
key_rec = qfalse;
|
key_rec = qfalse;
|
||||||
|
|
||||||
switch (key)
|
switch (key) {
|
||||||
{
|
case K_UPARROW:
|
||||||
case K_UPARROW:
|
case K_LEFTARROW:
|
||||||
case K_LEFTARROW:
|
|
||||||
offsetitem = -1;
|
offsetitem = -1;
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
case K_DOWNARROW:
|
case K_DOWNARROW:
|
||||||
case K_RIGHTARROW:
|
case K_RIGHTARROW:
|
||||||
offsetitem = 1;
|
offsetitem = 1;
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
case K_PGDN:
|
case K_PGDN:
|
||||||
if (GetScrollBar())
|
if (GetScrollBar()) {
|
||||||
{
|
itemindex = GetScrollBar()->getTopItem() + GetScrollBar()->getPageHeight();
|
||||||
itemindex = GetScrollBar()->getTopItem() + GetScrollBar()->getPageHeight();
|
if (getCurrentItem() == itemindex) {
|
||||||
if (getCurrentItem() == itemindex) {
|
|
||||||
offsetitem = GetScrollBar()->getPageHeight();
|
offsetitem = GetScrollBar()->getPageHeight();
|
||||||
} else {
|
} else {
|
||||||
TrySelectItem(itemindex);
|
TrySelectItem(itemindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
case K_PGUP:
|
case K_PGUP:
|
||||||
if (GetScrollBar())
|
if (GetScrollBar()) {
|
||||||
{
|
if (getCurrentItem() - 1 == GetScrollBar()->getTopItem()) {
|
||||||
if (getCurrentItem() - 1 == GetScrollBar()->getTopItem()) {
|
offsetitem = -GetScrollBar()->getPageHeight();
|
||||||
offsetitem = -GetScrollBar()->getPageHeight();
|
} else {
|
||||||
} else {
|
TrySelectItem(GetScrollBar()->getTopItem() + 1);
|
||||||
TrySelectItem(GetScrollBar()->getTopItem() + 1);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
case K_HOME:
|
case K_HOME:
|
||||||
TrySelectItem(1);
|
TrySelectItem(1);
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
case K_END:
|
case K_END:
|
||||||
TrySelectItem(getNumItems());
|
TrySelectItem(getNumItems());
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
case K_MWHEELDOWN:
|
case K_MWHEELDOWN:
|
||||||
if (GetScrollBar()) {
|
if (GetScrollBar()) {
|
||||||
GetScrollBar()->AttemptScrollTo(GetScrollBar()->getTopItem() + 2);
|
GetScrollBar()->AttemptScrollTo(GetScrollBar()->getTopItem() + 2);
|
||||||
}
|
}
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
|
@ -158,404 +145,284 @@ qboolean UIListBase::KeyEvent
|
||||||
}
|
}
|
||||||
key_rec = qtrue;
|
key_rec = qtrue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offsetitem) {
|
if (offsetitem) {
|
||||||
TrySelectItem(getCurrentItem() + offsetitem);
|
TrySelectItem(getCurrentItem() + offsetitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
return key_rec;
|
return key_rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBase::FrameInitialized
|
void UIListBase::FrameInitialized(void)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (m_vertscroll) {
|
if (m_vertscroll) {
|
||||||
delete m_vertscroll;
|
delete m_vertscroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vertscroll = new UIVertScroll();
|
m_vertscroll = new UIVertScroll();
|
||||||
m_vertscroll->InitFrame(this, m_frame.size.width - 16.0, 0.0, 16.0, m_frame.size.height, -1);
|
m_vertscroll->InitFrame(this, m_frame.size.width - 16.0, 0.0, 16.0, m_frame.size.height, -1);
|
||||||
m_vertscroll->setTopItem(0);
|
m_vertscroll->setTopItem(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIListBase::getCurrentItem
|
int UIListBase::getCurrentItem(void)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
return m_currentItem;
|
return m_currentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIListBase::getNumItems
|
int UIListBase::getNumItems(void)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBase::DeleteAllItems
|
void UIListBase::DeleteAllItems(void) {}
|
||||||
(
|
|
||||||
void
|
void UIListBase::DeleteItem(int which) {}
|
||||||
)
|
|
||||||
|
UIVertScroll *UIListBase::GetScrollBar(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
return m_vertscroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBase::DeleteItem
|
void UIListBase::SetUseScrollBar(qboolean bUse)
|
||||||
(
|
|
||||||
int which
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
}
|
m_bUseVertScroll = bUse;
|
||||||
|
|
||||||
UIVertScroll *UIListBase::GetScrollBar
|
if (bUse) {
|
||||||
(
|
if (!m_vertscroll) {
|
||||||
void
|
m_vertscroll = new UIVertScroll();
|
||||||
)
|
}
|
||||||
|
|
||||||
{
|
m_vertscroll->InitFrame(this, m_frame.size.width - 16.0, 0.0, 16.0, m_frame.size.height, -1);
|
||||||
return m_vertscroll;
|
} else {
|
||||||
}
|
if (m_vertscroll) {
|
||||||
|
delete m_vertscroll;
|
||||||
void UIListBase::SetUseScrollBar
|
m_vertscroll = NULL;
|
||||||
(
|
}
|
||||||
qboolean bUse
|
}
|
||||||
)
|
|
||||||
|
|
||||||
{
|
|
||||||
m_bUseVertScroll = bUse;
|
|
||||||
|
|
||||||
if (bUse)
|
|
||||||
{
|
|
||||||
if (!m_vertscroll) {
|
|
||||||
m_vertscroll = new UIVertScroll();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_vertscroll->InitFrame(this, m_frame.size.width - 16.0, 0.0, 16.0, m_frame.size.height, -1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_vertscroll) {
|
|
||||||
delete m_vertscroll;
|
|
||||||
m_vertscroll = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListItem::ListItem()
|
ListItem::ListItem()
|
||||||
{
|
{
|
||||||
index = -1;
|
index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListItem::ListItem
|
ListItem::ListItem(str string, int index, str command)
|
||||||
(
|
|
||||||
str string,
|
|
||||||
int index,
|
|
||||||
str command
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
this->string = string;
|
this->string = string;
|
||||||
this->index = index;
|
this->index = index;
|
||||||
this->command = command;
|
this->command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
Event EV_UIListBase_ItemSelected
|
Event
|
||||||
(
|
EV_UIListBase_ItemSelected("listbase_item_selected", EV_DEFAULT, "i", "index", "Signaled when an item is selected");
|
||||||
"listbase_item_selected",
|
|
||||||
EV_DEFAULT,
|
Event EV_UIListBase_ItemDoubleClicked(
|
||||||
"i",
|
"listbase_item_doubleclicked", EV_DEFAULT, "i", "index", "Signaled when an item is double clicked"
|
||||||
"index",
|
|
||||||
"Signaled when an item is selected"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Event EV_UIListBase_ItemDoubleClicked
|
Event EV_Layout_AddListItem("additem", EV_DEFAULT, "sS", "itemname command", "Add an item to the list");
|
||||||
(
|
|
||||||
"listbase_item_doubleclicked",
|
Event EV_Layout_AddConfigstringListItem(
|
||||||
EV_DEFAULT,
|
"addconfigstringitem", EV_DEFAULT, "iS", "index command", "Add an item to the list that uses a configstring"
|
||||||
"i",
|
|
||||||
"index",
|
|
||||||
"Signaled when an item is double clicked"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Event EV_Layout_AddListItem
|
Event EV_UIListBox_DeleteAllItems("deleteallitems", EV_DEFAULT, NULL, NULL, "Delete all the items from the widget");
|
||||||
(
|
|
||||||
"additem",
|
|
||||||
EV_DEFAULT,
|
|
||||||
"sS",
|
|
||||||
"itemname command",
|
|
||||||
"Add an item to the list"
|
|
||||||
);
|
|
||||||
|
|
||||||
Event EV_Layout_AddConfigstringListItem
|
CLASS_DECLARATION(UIListBase, UIListBox, NULL) {
|
||||||
(
|
{&W_LeftMouseDown, &UIListBox::MousePressed },
|
||||||
"addconfigstringitem",
|
{&W_LeftMouseUp, &UIListBox::MouseReleased },
|
||||||
EV_DEFAULT,
|
{&EV_Layout_AddListItem, &UIListBox::LayoutAddListItem },
|
||||||
"iS",
|
{&EV_Layout_AddConfigstringListItem, &UIListBox::LayoutAddConfigstringListItem},
|
||||||
"index command",
|
{&EV_UIListBox_DeleteAllItems, &UIListBox::DeleteAllItems },
|
||||||
"Add an item to the list that uses a configstring"
|
{&EV_Layout_Font, &UIListBox::SetListFont },
|
||||||
);
|
{NULL, NULL }
|
||||||
|
|
||||||
Event EV_UIListBox_DeleteAllItems
|
|
||||||
(
|
|
||||||
"deleteallitems",
|
|
||||||
EV_DEFAULT,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
"Delete all the items from the widget"
|
|
||||||
);
|
|
||||||
|
|
||||||
CLASS_DECLARATION( UIListBase, UIListBox, NULL )
|
|
||||||
{
|
|
||||||
{ &W_LeftMouseDown, &UIListBox::MousePressed },
|
|
||||||
{ &W_LeftMouseUp, &UIListBox::MouseReleased },
|
|
||||||
{ &EV_Layout_AddListItem, &UIListBox::LayoutAddListItem },
|
|
||||||
{ &EV_Layout_AddConfigstringListItem, &UIListBox::LayoutAddConfigstringListItem },
|
|
||||||
{ &EV_UIListBox_DeleteAllItems, &UIListBox::DeleteAllItems },
|
|
||||||
{ &EV_Layout_Font, &UIListBox::SetListFont },
|
|
||||||
{ NULL, NULL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UIListBox::UIListBox()
|
UIListBox::UIListBox()
|
||||||
{
|
{
|
||||||
m_clickState.point.x = 0.0;
|
m_clickState.point.x = 0.0;
|
||||||
m_clickState.point.y = 0.0;
|
m_clickState.point.y = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::Draw
|
void UIListBox::Draw(void)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
// FIXME: stub
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::MousePressed
|
void UIListBox::MousePressed(Event *ev)
|
||||||
(
|
|
||||||
Event *ev
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// FIXME: stub
|
// FIXME: stub
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::MouseReleased
|
void UIListBox::MouseReleased(Event *ev) {}
|
||||||
(
|
|
||||||
Event *ev
|
void UIListBox::DeleteAllItems(Event *ev)
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
m_itemlist.ClearObjectList();
|
||||||
|
m_currentItem = 0;
|
||||||
|
|
||||||
|
if (m_vertscroll) {
|
||||||
|
m_vertscroll->setNumItems(0);
|
||||||
|
m_vertscroll->setTopItem(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::DeleteAllItems
|
void UIListBox::SetListFont(Event *ev)
|
||||||
(
|
|
||||||
Event *ev
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
m_itemlist.ClearObjectList();
|
LayoutFont(ev);
|
||||||
m_currentItem = 0;
|
|
||||||
|
|
||||||
if (m_vertscroll)
|
if (m_vertscroll) {
|
||||||
{
|
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
||||||
m_vertscroll->setNumItems(0);
|
}
|
||||||
m_vertscroll->setTopItem(0);
|
|
||||||
}
|
FrameInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::SetListFont
|
void UIListBox::TrySelectItem(int which)
|
||||||
(
|
|
||||||
Event *ev
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
LayoutFont(ev);
|
UIListBase::TrySelectItem(which);
|
||||||
|
|
||||||
if (m_vertscroll) {
|
if (!getNumItems()) {
|
||||||
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameInitialized();
|
if (m_cvarname.length()) {
|
||||||
|
uii.Cvar_Set(m_cvarname.c_str(), m_itemlist.ObjectAt(m_currentItem)->string.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::TrySelectItem
|
void UIListBox::AddItem(const char *item, const char *command)
|
||||||
(
|
|
||||||
int which
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
UIListBase::TrySelectItem(which);
|
ListItem *li;
|
||||||
|
|
||||||
if (!getNumItems()) {
|
li = new ListItem();
|
||||||
return;
|
if (!li) {
|
||||||
}
|
uii.Sys_Error(ERR_DROP, "Couldn't create list item\n");
|
||||||
|
}
|
||||||
|
|
||||||
if (m_cvarname.length())
|
li->string = item;
|
||||||
{
|
if (command) {
|
||||||
uii.Cvar_Set(m_cvarname.c_str(), m_itemlist.ObjectAt(m_currentItem)->string.c_str());
|
li->command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_itemlist.AddObject(li);
|
||||||
|
|
||||||
|
if (!m_currentItem) {
|
||||||
|
m_currentItem = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_vertscroll) {
|
||||||
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::AddItem
|
void UIListBox::AddItem(int index, const char *command)
|
||||||
(
|
|
||||||
const char *item,
|
|
||||||
const char *command
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ListItem* li;
|
ListItem *li;
|
||||||
|
|
||||||
li = new ListItem();
|
li = new ListItem();
|
||||||
if (!li) {
|
if (!li) {
|
||||||
uii.Sys_Error(ERR_DROP, "Couldn't create list item\n");
|
uii.Sys_Error(ERR_DROP, "Couldn't create list item\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
li->string = item;
|
li->index = index;
|
||||||
if (command) {
|
if (command) {
|
||||||
li->command = command;
|
li->command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_itemlist.AddObject(li);
|
m_itemlist.AddObject(li);
|
||||||
|
|
||||||
if (!m_currentItem) {
|
if (!m_currentItem) {
|
||||||
m_currentItem = 1;
|
m_currentItem = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_vertscroll) {
|
if (m_vertscroll) {
|
||||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::AddItem
|
void UIListBox::FrameInitialized(void)
|
||||||
(
|
|
||||||
int index,
|
|
||||||
const char *command
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ListItem* li;
|
UIListBase::FrameInitialized();
|
||||||
|
|
||||||
li = new ListItem();
|
if (m_vertscroll) {
|
||||||
if (!li) {
|
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
||||||
uii.Sys_Error(ERR_DROP, "Couldn't create list item\n");
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||||
}
|
}
|
||||||
|
|
||||||
li->index = index;
|
|
||||||
if (command) {
|
|
||||||
li->command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_itemlist.AddObject(li);
|
|
||||||
|
|
||||||
if (!m_currentItem) {
|
|
||||||
m_currentItem = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_vertscroll) {
|
|
||||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::FrameInitialized
|
void UIListBox::LayoutAddListItem(Event *ev)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
UIListBase::FrameInitialized();
|
if (ev->NumArgs() != 2) {
|
||||||
|
AddItem(ev->GetString(1), NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_vertscroll) {
|
AddItem(ev->GetString(1), ev->GetString(2).c_str());
|
||||||
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
|
||||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::LayoutAddListItem
|
void UIListBox::LayoutAddConfigstringListItem(Event *ev)
|
||||||
(
|
|
||||||
Event *ev
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (ev->NumArgs() != 2) {
|
if (ev->NumArgs() != 2) {
|
||||||
AddItem(ev->GetString(1), NULL);
|
AddItem(ev->GetInteger(1), NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddItem(ev->GetString(1), ev->GetString(2).c_str());
|
AddItem(ev->GetInteger(1), ev->GetString(2).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::LayoutAddConfigstringListItem
|
str UIListBox::getItemText(int which)
|
||||||
(
|
|
||||||
Event *ev
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (ev->NumArgs() != 2) {
|
return m_itemlist.ObjectAt(which)->string;
|
||||||
AddItem(ev->GetInteger(1), NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AddItem(ev->GetInteger(1), ev->GetString(2).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str UIListBox::getItemText
|
int UIListBox::getNumItems(void)
|
||||||
(
|
|
||||||
int which
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
return m_itemlist.ObjectAt(which)->string;
|
return m_itemlist.NumObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIListBox::getNumItems
|
void UIListBox::DeleteAllItems(void)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
return m_itemlist.NumObjects();
|
m_itemlist.ClearObjectList();
|
||||||
|
m_currentItem = 0;
|
||||||
|
|
||||||
|
if (m_vertscroll) {
|
||||||
|
m_vertscroll->setNumItems(0);
|
||||||
|
m_vertscroll->setTopItem(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIListBox::DeleteAllItems
|
void UIListBox::DeleteItem(int which)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
m_itemlist.ClearObjectList();
|
m_itemlist.RemoveObjectAt(which);
|
||||||
m_currentItem = 0;
|
|
||||||
|
|
||||||
if (m_vertscroll)
|
if (m_vertscroll) {
|
||||||
{
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
||||||
m_vertscroll->setNumItems(0);
|
}
|
||||||
m_vertscroll->setTopItem(0);
|
|
||||||
}
|
if (m_currentItem > getNumItems()) {
|
||||||
}
|
TrySelectItem(getNumItems());
|
||||||
|
}
|
||||||
void UIListBox::DeleteItem
|
|
||||||
(
|
|
||||||
int which
|
|
||||||
)
|
|
||||||
|
|
||||||
{
|
|
||||||
m_itemlist.RemoveObjectAt(which);
|
|
||||||
|
|
||||||
if (m_vertscroll) {
|
|
||||||
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_currentItem > getNumItems()) {
|
|
||||||
TrySelectItem(getNumItems());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
===========================================================================
|
===========================================================================
|
||||||
Copyright (C) 2015 the OpenMoHAA team
|
Copyright (C) 2023 the OpenMoHAA team
|
||||||
|
|
||||||
This file is part of OpenMoHAA source code.
|
This file is part of OpenMoHAA source code.
|
||||||
|
|
||||||
|
@ -26,71 +26,77 @@ extern Event EV_Layout_AddListItem;
|
||||||
extern Event EV_UIListBase_ItemDoubleClicked;
|
extern Event EV_UIListBase_ItemDoubleClicked;
|
||||||
extern Event EV_UIListBase_ItemSelected;
|
extern Event EV_UIListBase_ItemSelected;
|
||||||
|
|
||||||
class UIListBase : public UIWidget {
|
class UIListBase : public UIWidget
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
int m_currentItem;
|
int m_currentItem;
|
||||||
class UIVertScroll *m_vertscroll;
|
class UIVertScroll *m_vertscroll;
|
||||||
qboolean m_bUseVertScroll;
|
qboolean m_bUseVertScroll;
|
||||||
public:
|
|
||||||
CLASS_PROTOTYPE( UIListBase );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void TrySelectItem( int which );
|
|
||||||
qboolean KeyEvent( int key, unsigned int time ) override;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UIListBase();
|
CLASS_PROTOTYPE(UIListBase);
|
||||||
|
|
||||||
void FrameInitialized( void ) override;
|
protected:
|
||||||
int getCurrentItem( void );
|
virtual void TrySelectItem(int which);
|
||||||
virtual int getNumItems( void );
|
qboolean KeyEvent(int key, unsigned int time) override;
|
||||||
virtual void DeleteAllItems( void );
|
|
||||||
virtual void DeleteItem( int which );
|
public:
|
||||||
UIVertScroll *GetScrollBar( void );
|
UIListBase();
|
||||||
void SetUseScrollBar( qboolean bUse );
|
|
||||||
|
void FrameInitialized(void) override;
|
||||||
|
int getCurrentItem(void);
|
||||||
|
virtual int getNumItems(void);
|
||||||
|
virtual void DeleteAllItems(void);
|
||||||
|
virtual void DeleteItem(int which);
|
||||||
|
UIVertScroll *GetScrollBar(void);
|
||||||
|
void SetUseScrollBar(qboolean bUse);
|
||||||
};
|
};
|
||||||
typedef class UIListBase UIListBase;
|
typedef class UIListBase UIListBase;
|
||||||
class ListItem : public Class {
|
|
||||||
|
class ListItem : public Class
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
str string;
|
str string;
|
||||||
str command;
|
str command;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListItem();
|
ListItem();
|
||||||
ListItem( str string, int index, str command );
|
ListItem(str string, int index, str command);
|
||||||
};
|
};
|
||||||
|
|
||||||
class UIListBox : public UIListBase {
|
class UIListBox : public UIListBase
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
Container<ListItem *> m_itemlist;
|
Container<ListItem *> m_itemlist;
|
||||||
struct {
|
|
||||||
int time;
|
struct {
|
||||||
int selected;
|
int time;
|
||||||
UIPoint2D point;
|
int selected;
|
||||||
} m_clickState;
|
UIPoint2D point;
|
||||||
|
} m_clickState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLASS_PROTOTYPE( UIListBox );
|
CLASS_PROTOTYPE(UIListBox);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Draw( void ) override;
|
void Draw(void) override;
|
||||||
void MousePressed( Event *ev );
|
void MousePressed(Event *ev);
|
||||||
void MouseReleased( Event *ev );
|
void MouseReleased(Event *ev);
|
||||||
void DeleteAllItems( Event *ev );
|
void DeleteAllItems(Event *ev);
|
||||||
void SetListFont( Event *ev );
|
void SetListFont(Event *ev);
|
||||||
void TrySelectItem( int which ) override;
|
void TrySelectItem(int which) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UIListBox();
|
UIListBox();
|
||||||
|
|
||||||
void AddItem( const char *item, const char *command );
|
void AddItem(const char *item, const char *command);
|
||||||
void AddItem( int index, const char *command );
|
void AddItem(int index, const char *command);
|
||||||
void FrameInitialized( void ) override;
|
void FrameInitialized(void) override;
|
||||||
void LayoutAddListItem( Event *ev );
|
void LayoutAddListItem(Event *ev);
|
||||||
void LayoutAddConfigstringListItem( Event *ev );
|
void LayoutAddConfigstringListItem(Event *ev);
|
||||||
str getItemText( int which );
|
str getItemText(int which);
|
||||||
int getNumItems( void ) override;
|
int getNumItems(void) override;
|
||||||
void DeleteAllItems( void ) override;
|
void DeleteAllItems(void) override;
|
||||||
void DeleteItem( int which ) override;
|
void DeleteItem(int which) override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue