Implemented the vertical scrollbar

This commit is contained in:
OM 2023-05-17 17:30:22 +02:00
parent 699f8b1b01
commit 55b91adb45

View file

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "ui_local.h" #include "ui_local.h"
#include "localization.h"
Event W_Scrollbar_Positioned Event W_Scrollbar_Positioned
( (
@ -91,7 +92,21 @@ void UIVertScroll::Draw
) )
{ {
// FIXME: stub DrawBoxWithSolidBorder(
getClientFrame(),
getBackgroundColor(),
m_solidbordercolor,
1,
3,
m_local_alpha
);
DrawArrow(0.0, "5", m_pressed == VS_UP_ARROW);
DrawArrow(m_frame.size.height - m_vVirtualScale[1] * 16.0, "6", m_pressed == VS_DOWN_ARROW);
if (m_numitems > m_pageheight) {
DrawThumb();
}
} }
void UIVertScroll::DrawArrow void UIVertScroll::DrawArrow
@ -102,7 +117,41 @@ void UIVertScroll::DrawArrow
) )
{ {
// FIXME: stub UIRect2D arrowRect;
UColor innerColor;
arrowRect.pos.x = 0.0;
arrowRect.pos.y = top;
arrowRect.size.width = m_frame.size.width;
arrowRect.size.height = m_vVirtualScale[1] * 16.0;
innerColor = getBackgroundColor();
m_marlett.setColor(getForegroundColor());
if (pressed)
{
innerColor = m_border_color.light;
if (m_background_color.r != 0.0 || m_background_color.g || m_background_color.b) {
m_marlett.setColor(m_border_color.light);
} else {
m_marlett.setColor(UColor(0.15, 0.196, 0.278, 1.0));
}
}
DrawBoxWithSolidBorder(arrowRect, innerColor, m_solidbordercolor, 1, 3, m_local_alpha);
if (m_numitems > m_pageheight) {
DrawMac3DBox(arrowRect, pressed, m_border_color, 1, m_local_alpha);
}
m_marlett.setAlpha(m_local_alpha);
m_marlett.PrintJustified(
arrowRect,
m_iFontAlignmentHorizontal,
m_iFontAlignmentVertical,
Sys_LV_CL_ConvertString(text),
m_bVirtual ? m_vVirtualScale : NULL
);
} }
void UIVertScroll::DrawThumb void UIVertScroll::DrawThumb
@ -111,7 +160,69 @@ void UIVertScroll::DrawThumb
) )
{ {
// FIXME: stub UIRect2D inbarrect;
float thumbHeight, thumbdiff;
UColor thumbInside;
thumbdiff = m_frame.size.height - m_vVirtualScale[1] * 32.0;
inbarrect.pos.x = 0.0;
inbarrect.pos.y = m_vVirtualScale[1] * 16.0;
inbarrect.size.width = m_frame.size.width;
inbarrect.size.height = m_frame.size.height - thumbdiff;
thumbHeight = m_pageheight * thumbdiff;
thumbRect.pos.x = 0.0;
thumbRect.pos.y = m_topitem * thumbdiff / (float)m_numitems;
thumbRect.size.width = m_frame.size.width;
thumbRect.size.height = thumbHeight / (float)m_numitems;
if (thumbRect.size.height < 6.0) {
thumbRect.size.height = 6.0;
}
thumbInside = UColor(0.15, 0.196, 0.278, 1.0);
if (thumbRect.pos.y + thumbRect.size.height - thumbdiff > 0.0) {
thumbRect.pos.y -= thumbRect.pos.y + thumbRect.size.height - thumbdiff;
}
thumbRect.pos.y = thumbRect.pos.y + inbarrect.pos.y;
DrawBoxWithSolidBorder(thumbRect, thumbInside, m_solidbordercolor, 1, 3, m_local_alpha);
DrawMac3DBox(thumbRect, m_pressed == VS_THUMB, thumbInside, true, m_local_alpha);
inbarrect.pos.x += 1.0;
inbarrect.pos.y += 1.0;
inbarrect.size.width -= 2.0;
inbarrect.size.height -= 2.0;
thumbRect.pos.x -= 1.0;
thumbRect.pos.y -= 1.0;
thumbRect.size.width -= 2.0;
thumbRect.size.height -= 2.0;
if (m_pressed == VS_PAGE_UP)
{
DrawBox(
0.0,
inbarrect.pos.y,
m_frame.size.width,
thumbRect.pos.y - inbarrect.pos.y,
m_border_color.light,
m_local_alpha
);
}
else
{
DrawBox(
0.0,
thumbRect.pos.y + thumbRect.size.height,
m_frame.size.width,
inbarrect.pos.y + inbarrect.size.height - (thumbRect.pos.y + thumbRect.size.height),
m_border_color.light,
m_local_alpha
);
}
} }
void UIVertScroll::MouseDown void UIVertScroll::MouseDown
@ -120,7 +231,70 @@ void UIVertScroll::MouseDown
) )
{ {
// FIXME: stub UIPoint2D p;
int scrollrate;
scrollrate = 0;
p.x = ev->GetFloat(1) - m_screenframe.pos.x;
p.y = ev->GetFloat(2) - m_screenframe.pos.y;
m_pressed = VS_NONE;
if (p.x < 0 || p.y < 0) {
return;
}
if (p.x > m_frame.size.width || p.y > m_frame.size.height) {
return;
}
if (m_numitems <= m_pageheight) {
return;
}
if (p.y >= 16.0)
{
if (m_frame.size.height - 16.0 >= p.y)
{
if (thumbRect.pos.y > p.y)
{
m_pressed = VS_PAGE_UP;
scrollrate = -m_pageheight;
}
else
{
if (thumbRect.pos.y + thumbRect.size.height > p.y)
{
m_pressed = VS_THUMB;
m_dragThumbState.itemOffset = m_topitem - getItemFromHeight(p.y);
m_dragThumbState.orgItem = m_topitem;
uWinMan.setFirstResponder(this);
}
else
{
m_pressed = VS_PAGE_DOWN;
scrollrate = m_pageheight;
}
}
if (!scrollrate) {
return;
}
}
else
{
m_pressed = VS_DOWN_ARROW;
scrollrate = 1;
}
}
Event* newev = new Event(EV_Scrollbar_Scroll);
newev->AddInteger(scrollrate);
newev->AddInteger(0);
CancelEventsOfType(EV_Scrollbar_Scroll);
PostEvent(newev, 0);
uWinMan.setFirstResponder(this);
} }
void UIVertScroll::MouseUp void UIVertScroll::MouseUp
@ -135,7 +309,6 @@ void UIVertScroll::MouseUp
} }
m_pressed = VS_NONE; m_pressed = VS_NONE;
// FIXME: stub
} }
void UIVertScroll::MouseDragged void UIVertScroll::MouseDragged
@ -144,7 +317,20 @@ void UIVertScroll::MouseDragged
) )
{ {
// FIXME: stub UIPoint2D p;
if (m_pressed != VS_THUMB) {
return;
}
p.x = ev->GetFloat(1) - m_screenframe.pos.x;
p.y = ev->GetFloat(2);
if (p.x < -24.0 || p.x > m_frame.size.width + 24.0) {
AttemptScrollTo(m_dragThumbState.orgItem);
} else {
AttemptScrollTo(m_dragThumbState.itemOffset + getItemFromHeight(p.y - m_screenframe.pos.y));
}
} }
void UIVertScroll::MouseEnter void UIVertScroll::MouseEnter
@ -170,7 +356,18 @@ void UIVertScroll::Scroll
) )
{ {
// FIXME: stub if (AttemptScrollTo(m_topitem + ev->GetInteger(1)))
{
float delay = 0.2;
if (ev->GetInteger(2)) {
delay = 0.1;
}
Event *newev = new Event(EV_Scrollbar_Scroll);
newev->AddInteger(ev->GetInteger(1));
newev->AddInteger(0);
PostEvent(newev, delay);
}
} }
bool UIVertScroll::AttemptScrollTo bool UIVertScroll::AttemptScrollTo
@ -213,7 +410,7 @@ void UIVertScroll::setNumItems
) )
{ {
m_numitems = 0; m_numitems = i;
} }
void UIVertScroll::setPageHeight void UIVertScroll::setPageHeight