2016-03-27 11:49:47 +02:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 2015 the OpenMoHAA team
|
|
|
|
|
|
|
|
This file is part of OpenMoHAA source code.
|
|
|
|
|
|
|
|
OpenMoHAA source code is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
OpenMoHAA source code is distributed in the hope that it will be
|
|
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenMoHAA source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_local.h"
|
|
|
|
|
|
|
|
CLASS_DECLARATION( UIWidget, UIListBase, NULL )
|
|
|
|
{
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
UIListBase::UIListBase()
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
m_currentItem = 0;
|
|
|
|
m_vertscroll = 0;
|
|
|
|
m_bUseVertScroll = 1;
|
|
|
|
AllowActivate(true);
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBase::TrySelectItem
|
|
|
|
(
|
|
|
|
int which
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
// FIXME: stub
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean UIListBase::KeyEvent
|
|
|
|
(
|
|
|
|
int key,
|
|
|
|
unsigned int time
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
// FIXME: stub
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBase::FrameInitialized
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
if (m_vertscroll) {
|
|
|
|
delete 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);
|
|
|
|
m_vertscroll->setTopItem(0);
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int UIListBase::getCurrentItem
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
return m_currentItem;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int UIListBase::getNumItems
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
return -1;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBase::DeleteAllItems
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBase::DeleteItem
|
|
|
|
(
|
|
|
|
int which
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIVertScroll *UIListBase::GetScrollBar
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
return m_vertscroll;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBase::SetUseScrollBar
|
|
|
|
(
|
|
|
|
qboolean bUse
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ListItem::ListItem()
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
index = -1;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ListItem::ListItem
|
|
|
|
(
|
|
|
|
str string,
|
|
|
|
int index,
|
|
|
|
str command
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
this->string = string;
|
|
|
|
this->index = index;
|
|
|
|
this->command = command;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
2023-05-20 02:15:52 +02:00
|
|
|
Event EV_UIListBase_ItemSelected
|
|
|
|
(
|
|
|
|
"listbase_item_selected",
|
|
|
|
EV_DEFAULT,
|
|
|
|
"i",
|
|
|
|
"index",
|
|
|
|
"Signaled when an item is selected"
|
|
|
|
);
|
|
|
|
|
|
|
|
Event EV_UIListBase_ItemDoubleClicked
|
|
|
|
(
|
|
|
|
"listbase_item_doubleclicked",
|
|
|
|
EV_DEFAULT,
|
|
|
|
"i",
|
|
|
|
"index",
|
|
|
|
"Signaled when an item is double clicked"
|
|
|
|
);
|
|
|
|
|
|
|
|
Event EV_Layout_AddListItem
|
|
|
|
(
|
|
|
|
"additem",
|
|
|
|
EV_DEFAULT,
|
|
|
|
"sS",
|
|
|
|
"itemname command",
|
|
|
|
"Add an item to the list"
|
|
|
|
);
|
|
|
|
|
|
|
|
Event EV_Layout_AddConfigstringListItem
|
|
|
|
(
|
|
|
|
"addconfigstringitem",
|
|
|
|
EV_DEFAULT,
|
|
|
|
"iS",
|
|
|
|
"index command",
|
|
|
|
"Add an item to the list that uses a configstring"
|
|
|
|
);
|
|
|
|
|
|
|
|
Event EV_UIListBox_DeleteAllItems
|
|
|
|
(
|
|
|
|
"deleteallitems",
|
|
|
|
EV_DEFAULT,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
"Delete all the items from the widget"
|
|
|
|
);
|
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
CLASS_DECLARATION( UIListBase, UIListBox, NULL )
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
{ &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 },
|
2016-03-27 11:49:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
UIListBox::UIListBox()
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
m_clickState.point.x = 0.0;
|
|
|
|
m_clickState.point.y = 0.0;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::Draw
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
// FIXME: stub
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::MousePressed
|
|
|
|
(
|
|
|
|
Event *ev
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
// FIXME: stub
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::MouseReleased
|
|
|
|
(
|
|
|
|
Event *ev
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::DeleteAllItems
|
|
|
|
(
|
|
|
|
Event *ev
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
m_itemlist.ClearObjectList();
|
|
|
|
m_currentItem = 0;
|
|
|
|
|
|
|
|
if (m_vertscroll)
|
|
|
|
{
|
|
|
|
m_vertscroll->setNumItems(0);
|
|
|
|
m_vertscroll->setTopItem(0);
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::SetListFont
|
|
|
|
(
|
|
|
|
Event *ev
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
LayoutFont(ev);
|
|
|
|
|
|
|
|
if (m_vertscroll) {
|
|
|
|
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameInitialized();
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::TrySelectItem
|
|
|
|
(
|
|
|
|
int which
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
UIListBase::TrySelectItem(which);
|
|
|
|
|
|
|
|
if (!getNumItems()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_cvarname.length())
|
|
|
|
{
|
|
|
|
uii.Cvar_Set(m_cvarname.c_str(), m_itemlist.ObjectAt(m_currentItem)->string.c_str());
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::AddItem
|
|
|
|
(
|
|
|
|
const char *item,
|
|
|
|
const char *command
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
ListItem* li;
|
|
|
|
|
|
|
|
li = new ListItem();
|
|
|
|
if (!li) {
|
|
|
|
uii.Sys_Error(ERR_DROP, "Couldn't create list item\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
li->string = item;
|
|
|
|
if (command) {
|
|
|
|
li->command = command;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_itemlist.AddObject(li);
|
|
|
|
|
|
|
|
if (!m_currentItem) {
|
|
|
|
m_currentItem = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_vertscroll) {
|
|
|
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::AddItem
|
|
|
|
(
|
|
|
|
int index,
|
|
|
|
const char *command
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
ListItem* li;
|
|
|
|
|
|
|
|
li = new ListItem();
|
|
|
|
if (!li) {
|
|
|
|
uii.Sys_Error(ERR_DROP, "Couldn't create list item\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::FrameInitialized
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
UIListBase::FrameInitialized();
|
|
|
|
|
|
|
|
if (m_vertscroll) {
|
|
|
|
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
|
|
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::LayoutAddListItem
|
|
|
|
(
|
|
|
|
Event *ev
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
if (ev->NumArgs() != 2) {
|
|
|
|
AddItem(ev->GetString(1), NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddItem(ev->GetString(1), ev->GetString(2).c_str());
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::LayoutAddConfigstringListItem
|
|
|
|
(
|
|
|
|
Event *ev
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 02:15:52 +02:00
|
|
|
if (ev->NumArgs() != 2) {
|
|
|
|
AddItem(ev->GetInteger(1), NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddItem(ev->GetInteger(1), ev->GetString(2).c_str());
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
str UIListBox::getItemText
|
|
|
|
(
|
|
|
|
int which
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
return m_itemlist.ObjectAt(which)->string;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int UIListBox::getNumItems
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
return m_itemlist.NumObjects();
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::DeleteAllItems
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
m_itemlist.ClearObjectList();
|
|
|
|
m_currentItem = 0;
|
|
|
|
|
|
|
|
if (m_vertscroll)
|
|
|
|
{
|
|
|
|
m_vertscroll->setNumItems(0);
|
|
|
|
m_vertscroll->setTopItem(0);
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIListBox::DeleteItem
|
|
|
|
(
|
|
|
|
int which
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2023-05-20 01:19:17 +02:00
|
|
|
m_itemlist.RemoveObjectAt(which);
|
|
|
|
|
|
|
|
if (m_vertscroll) {
|
|
|
|
m_vertscroll->setNumItems(m_itemlist.NumObjects());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_currentItem > getNumItems()) {
|
|
|
|
TrySelectItem(getNumItems());
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|