mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Implemented all UIListBox methods and implemented Draw() from BT 2.40
This commit is contained in:
parent
979af2925d
commit
8cd571c96c
1 changed files with 149 additions and 34 deletions
|
@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
#include "ui_local.h"
|
||||
#include "../qcommon/localization.h"
|
||||
|
||||
CLASS_DECLARATION(UIWidget, UIListBase, NULL) {
|
||||
{NULL, NULL}
|
||||
|
@ -30,12 +31,11 @@ UIListBase::UIListBase()
|
|||
{
|
||||
m_currentItem = 0;
|
||||
m_vertscroll = 0;
|
||||
m_bUseVertScroll = 1;
|
||||
m_bUseVertScroll = true;
|
||||
AllowActivate(true);
|
||||
}
|
||||
|
||||
void UIListBase::TrySelectItem(int which)
|
||||
|
||||
{
|
||||
int numitems;
|
||||
|
||||
|
@ -84,7 +84,6 @@ void UIListBase::TrySelectItem(int which)
|
|||
}
|
||||
|
||||
qboolean UIListBase::KeyEvent(int key, unsigned int time)
|
||||
|
||||
{
|
||||
int offsetitem;
|
||||
qboolean key_rec;
|
||||
|
@ -157,7 +156,6 @@ qboolean UIListBase::KeyEvent(int key, unsigned int time)
|
|||
}
|
||||
|
||||
void UIListBase::FrameInitialized(void)
|
||||
|
||||
{
|
||||
if (m_vertscroll) {
|
||||
delete m_vertscroll;
|
||||
|
@ -169,13 +167,11 @@ void UIListBase::FrameInitialized(void)
|
|||
}
|
||||
|
||||
int UIListBase::getCurrentItem(void)
|
||||
|
||||
{
|
||||
return m_currentItem;
|
||||
}
|
||||
|
||||
int UIListBase::getNumItems(void)
|
||||
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -185,13 +181,11 @@ void UIListBase::DeleteAllItems(void) {}
|
|||
void UIListBase::DeleteItem(int which) {}
|
||||
|
||||
UIVertScroll *UIListBase::GetScrollBar(void)
|
||||
|
||||
{
|
||||
return m_vertscroll;
|
||||
}
|
||||
|
||||
void UIListBase::SetUseScrollBar(qboolean bUse)
|
||||
|
||||
{
|
||||
m_bUseVertScroll = bUse;
|
||||
|
||||
|
@ -215,27 +209,54 @@ ListItem::ListItem()
|
|||
}
|
||||
|
||||
ListItem::ListItem(str string, int index, str command)
|
||||
|
||||
{
|
||||
this->string = string;
|
||||
this->index = index;
|
||||
this->command = command;
|
||||
}
|
||||
|
||||
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_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_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");
|
||||
);
|
||||
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 },
|
||||
|
@ -254,21 +275,125 @@ UIListBox::UIListBox()
|
|||
}
|
||||
|
||||
void UIListBox::Draw(void)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
float aty;
|
||||
int i;
|
||||
const char *str;
|
||||
UColor selectedBG(0, 1, 1, 1);
|
||||
UColor selectedColor = UBlack;
|
||||
UColor selectedBorder = UWhite;
|
||||
|
||||
aty = 0;
|
||||
|
||||
if (m_vertscroll) {
|
||||
i = m_vertscroll->getTopItem() + 1;
|
||||
} else {
|
||||
i = 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ListItem *li;
|
||||
|
||||
if (aty >= m_frame.size.height || i > m_itemlist.NumObjects()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == m_currentItem) {
|
||||
DrawBox(
|
||||
0,
|
||||
aty * m_vVirtualScale[1],
|
||||
m_frame.size.width - m_vVirtualScale[0] * 16,
|
||||
m_font->getHeight(m_bVirtual),
|
||||
selectedBG,
|
||||
1.f
|
||||
);
|
||||
m_font->setColor(selectedColor);
|
||||
} else {
|
||||
m_font->setColor(m_foreground_color);
|
||||
}
|
||||
|
||||
li = m_itemlist.ObjectAt(i);
|
||||
if (li->index > 0) {
|
||||
str = Sys_LV_CL_ConvertString(uii.GetConfigstring(li->index));
|
||||
} else {
|
||||
str = li->string;
|
||||
}
|
||||
m_font->Print(m_indent, aty, str, -1, m_bVirtual);
|
||||
|
||||
if (i == m_currentItem) {
|
||||
DrawBoxWithSolidBorder(
|
||||
UIRect2D(
|
||||
0,
|
||||
aty * m_vVirtualScale[1],
|
||||
m_frame.size.width - m_vVirtualScale[0] * 16,
|
||||
m_font->getHeight(m_bVirtual)
|
||||
),
|
||||
UWhite,
|
||||
selectedBorder,
|
||||
1,
|
||||
2,
|
||||
0.5f
|
||||
);
|
||||
}
|
||||
|
||||
aty += m_font->getHeight(false);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void UIListBox::MousePressed(Event *ev)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
UIPoint2D p;
|
||||
|
||||
p.x = ev->GetFloat(1) - m_screenframe.pos.x;
|
||||
p.y = ev->GetFloat(2) - m_screenframe.pos.y;
|
||||
|
||||
if (m_vertscroll) {
|
||||
TrySelectItem((m_vertscroll->getTopItem() + 1) + p.y / m_font->getHeight(m_bVirtual));
|
||||
} else {
|
||||
TrySelectItem(p.y / m_font->getHeight(m_bVirtual) + 1);
|
||||
}
|
||||
|
||||
if (m_clickState.time + 500 > uid.time && m_currentItem == m_clickState.selected) {
|
||||
UIPoint2D p2;
|
||||
|
||||
p2.x = m_clickState.point.x - p.x;
|
||||
if (fabs(p2.x <= 2)) {
|
||||
p2.y = m_clickState.point.y - p.y;
|
||||
if (fabs(p2.y) <= 2.f) {
|
||||
Event event(EV_UIListBase_ItemDoubleClicked);
|
||||
event.AddInteger(m_currentItem);
|
||||
SendSignal(event);
|
||||
|
||||
ListItem *li = m_itemlist.ObjectAt(m_currentItem);
|
||||
|
||||
if (!m_currentItem || !li) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_commandhandler) {
|
||||
(*m_commandhandler)(li->string, NULL);
|
||||
}
|
||||
|
||||
if (li->command.length()) {
|
||||
uii.Cmd_Stuff(va("%s \"%s\"\n", li->command.c_str(), li->string.c_str()));
|
||||
} else {
|
||||
uii.Cmd_Stuff(va("%s \"%s\"\n", m_command.c_str(), li->string.c_str()));
|
||||
}
|
||||
m_clickState.time = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_clickState.time = uid.time;
|
||||
m_clickState.selected = m_currentItem;
|
||||
m_clickState.point = p;
|
||||
}
|
||||
|
||||
void UIListBox::MouseReleased(Event *ev) {}
|
||||
|
||||
void UIListBox::DeleteAllItems(Event *ev)
|
||||
|
||||
{
|
||||
m_itemlist.ClearObjectList();
|
||||
m_currentItem = 0;
|
||||
|
@ -280,7 +405,6 @@ void UIListBox::DeleteAllItems(Event *ev)
|
|||
}
|
||||
|
||||
void UIListBox::SetListFont(Event *ev)
|
||||
|
||||
{
|
||||
LayoutFont(ev);
|
||||
|
||||
|
@ -292,7 +416,6 @@ void UIListBox::SetListFont(Event *ev)
|
|||
}
|
||||
|
||||
void UIListBox::TrySelectItem(int which)
|
||||
|
||||
{
|
||||
UIListBase::TrySelectItem(which);
|
||||
|
||||
|
@ -306,7 +429,6 @@ void UIListBox::TrySelectItem(int which)
|
|||
}
|
||||
|
||||
void UIListBox::AddItem(const char *item, const char *command)
|
||||
|
||||
{
|
||||
ListItem *li;
|
||||
|
||||
|
@ -332,7 +454,6 @@ void UIListBox::AddItem(const char *item, const char *command)
|
|||
}
|
||||
|
||||
void UIListBox::AddItem(int index, const char *command)
|
||||
|
||||
{
|
||||
ListItem *li;
|
||||
|
||||
|
@ -358,7 +479,6 @@ void UIListBox::AddItem(int index, const char *command)
|
|||
}
|
||||
|
||||
void UIListBox::FrameInitialized(void)
|
||||
|
||||
{
|
||||
UIListBase::FrameInitialized();
|
||||
|
||||
|
@ -369,7 +489,6 @@ void UIListBox::FrameInitialized(void)
|
|||
}
|
||||
|
||||
void UIListBox::LayoutAddListItem(Event *ev)
|
||||
|
||||
{
|
||||
if (ev->NumArgs() != 2) {
|
||||
AddItem(ev->GetString(1), NULL);
|
||||
|
@ -380,7 +499,6 @@ void UIListBox::LayoutAddListItem(Event *ev)
|
|||
}
|
||||
|
||||
void UIListBox::LayoutAddConfigstringListItem(Event *ev)
|
||||
|
||||
{
|
||||
if (ev->NumArgs() != 2) {
|
||||
AddItem(ev->GetInteger(1), NULL);
|
||||
|
@ -391,19 +509,16 @@ void UIListBox::LayoutAddConfigstringListItem(Event *ev)
|
|||
}
|
||||
|
||||
str UIListBox::getItemText(int which)
|
||||
|
||||
{
|
||||
return m_itemlist.ObjectAt(which)->string;
|
||||
}
|
||||
|
||||
int UIListBox::getNumItems(void)
|
||||
|
||||
{
|
||||
return m_itemlist.NumObjects();
|
||||
}
|
||||
|
||||
void UIListBox::DeleteAllItems(void)
|
||||
|
||||
{
|
||||
m_itemlist.ClearObjectList();
|
||||
m_currentItem = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue