mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Partially implemented UIListBox and UIList
This commit is contained in:
parent
c2cb15a1d1
commit
c4502469f4
3 changed files with 159 additions and 17 deletions
|
@ -24,12 +24,35 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
CLASS_DECLARATION( UIWidget, UIList, NULL )
|
||||
{
|
||||
{ &W_LeftMouseDown, &UIList::Pressed },
|
||||
{ &W_LeftMouseUp, &UIList::Released },
|
||||
{ &EV_Layout_AddListItem, &UIList::LayoutAddListItem },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
UIList::UIList()
|
||||
{
|
||||
// FIXME: stub
|
||||
m_arrow_width = 15.0;
|
||||
m_arrow_width = 0.0;
|
||||
m_currentItem = 0;
|
||||
m_next_arrow_region = 0;
|
||||
m_prev_arrow_region = 0;
|
||||
m_prev_arrow_depressed = 0;
|
||||
m_next_arrow_depressed = 0;
|
||||
|
||||
AllowActivate(true);
|
||||
|
||||
m_prev_arrow = uWinMan.RegisterShader("gfx/2d/arrow_left.tga");
|
||||
if (!m_prev_arrow) {
|
||||
uii.Sys_Printf("UIList::Ulist : Could not register shader gfx/2d/arrow_left.tga");
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_next_arrow = uWinMan.RegisterShader("gfx/2d/arrow_right.tga");
|
||||
if (!m_next_arrow) {
|
||||
uii.Sys_Printf("UIList::Ulist : Could not register shader gfx/2d/arrow_right.tga");
|
||||
}
|
||||
}
|
||||
|
||||
void UIList::Draw
|
||||
|
@ -48,8 +71,26 @@ qboolean UIList::KeyEvent
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return qfalse;
|
||||
switch (key)
|
||||
{
|
||||
case K_RIGHTARROW:
|
||||
ScrollNext();
|
||||
UpdateData();
|
||||
if (m_commandhandler) {
|
||||
m_commandhandler(m_itemlist.ObjectAt(m_currentItem)->itemname.c_str(), NULL);
|
||||
}
|
||||
return qtrue;
|
||||
case K_LEFTARROW:
|
||||
ScrollPrev();
|
||||
UpdateData();
|
||||
if (m_commandhandler) {
|
||||
m_commandhandler(m_itemlist.ObjectAt(m_currentItem)->itemname.c_str(), NULL);
|
||||
}
|
||||
return qtrue;
|
||||
default:
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UIList::CharEvent
|
||||
|
@ -58,7 +99,6 @@ void UIList::CharEvent
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
}
|
||||
|
||||
void UIList::Pressed
|
||||
|
@ -85,7 +125,10 @@ void UIList::ScrollNext
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_currentItem++;
|
||||
if (m_currentItem > m_itemlist.NumObjects()) {
|
||||
m_currentItem = m_itemlist.NumObjects();
|
||||
}
|
||||
}
|
||||
|
||||
void UIList::ScrollPrev
|
||||
|
@ -94,7 +137,10 @@ void UIList::ScrollPrev
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_currentItem--;
|
||||
if (m_currentItem < 1) {
|
||||
m_currentItem = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void UIList::FrameInitialized
|
||||
|
@ -103,7 +149,8 @@ void UIList::FrameInitialized
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_prev_arrow_region = new UIRect2D(m_clippedframe.pos.x, m_clippedframe.pos.y, m_arrow_width, m_frame.size.height);
|
||||
m_next_arrow_region = new UIRect2D(m_clippedframe.size.width - m_arrow_width + m_clippedframe.pos.x, m_clippedframe.pos.y, m_arrow_width, m_frame.size.height);
|
||||
}
|
||||
|
||||
void UIList::LayoutAddListItem
|
||||
|
@ -155,6 +202,17 @@ qboolean UIListIndex::KeyEvent
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
return qfalse;
|
||||
switch (key)
|
||||
{
|
||||
case K_RIGHTARROW:
|
||||
ScrollNext();
|
||||
UpdateData();
|
||||
return qtrue;
|
||||
case K_LEFTARROW:
|
||||
ScrollPrev();
|
||||
UpdateData();
|
||||
return qtrue;
|
||||
default:
|
||||
return qfalse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ void UIListBase::FrameInitialized
|
|||
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);
|
||||
// FIXME: stub
|
||||
}
|
||||
|
||||
int UIListBase::getCurrentItem
|
||||
|
@ -157,14 +156,66 @@ ListItem::ListItem
|
|||
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_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"
|
||||
);
|
||||
|
||||
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()
|
||||
{
|
||||
// FIXME: stub
|
||||
m_clickState.point.x = 0.0;
|
||||
m_clickState.point.y = 0.0;
|
||||
}
|
||||
|
||||
void UIListBox::Draw
|
||||
|
@ -191,7 +242,6 @@ void UIListBox::MouseReleased
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
}
|
||||
|
||||
void UIListBox::DeleteAllItems
|
||||
|
@ -200,7 +250,14 @@ void UIListBox::DeleteAllItems
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
m_itemlist.ClearObjectList();
|
||||
m_currentItem = 0;
|
||||
|
||||
if (m_vertscroll)
|
||||
{
|
||||
m_vertscroll->setNumItems(0);
|
||||
m_vertscroll->setTopItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
void UIListBox::SetListFont
|
||||
|
@ -209,7 +266,13 @@ void UIListBox::SetListFont
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
LayoutFont(ev);
|
||||
|
||||
if (m_vertscroll) {
|
||||
m_vertscroll->setPageHeight(m_frame.size.height / m_font->getHeight(m_bVirtual));
|
||||
}
|
||||
|
||||
FrameInitialized();
|
||||
}
|
||||
|
||||
void UIListBox::TrySelectItem
|
||||
|
@ -218,7 +281,16 @@ void UIListBox::TrySelectItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
void UIListBox::AddItem
|
||||
|
@ -301,7 +373,12 @@ void UIListBox::LayoutAddListItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
if (ev->NumArgs() != 2) {
|
||||
AddItem(ev->GetString(1), NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
AddItem(ev->GetString(1), ev->GetString(2).c_str());
|
||||
}
|
||||
|
||||
void UIListBox::LayoutAddConfigstringListItem
|
||||
|
@ -310,7 +387,12 @@ void UIListBox::LayoutAddConfigstringListItem
|
|||
)
|
||||
|
||||
{
|
||||
// FIXME: stub
|
||||
if (ev->NumArgs() != 2) {
|
||||
AddItem(ev->GetInteger(1), NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
AddItem(ev->GetInteger(1), ev->GetString(2).c_str());
|
||||
}
|
||||
|
||||
str UIListBox::getItemText
|
||||
|
|
|
@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#ifndef __UILISTBOX_H__
|
||||
#define __UILISTBOX_H__
|
||||
|
||||
extern Event EV_Layout_AddListItem;
|
||||
|
||||
class UIListBase : public UIWidget {
|
||||
protected:
|
||||
int m_currentItem;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue