mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Improve keyboard navigation of book/scroll windows
This commit is contained in:
parent
d58ff4a736
commit
331192f2d6
@ -52,6 +52,11 @@ namespace MWGui
|
||||
mRightPage->setNeedMouseFocus(true);
|
||||
mRightPage->eventMouseWheel += MyGUI::newDelegate(this, &BookWindow::onMouseWheel);
|
||||
|
||||
mNextPageButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
||||
mPrevPageButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
||||
mTakeButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
||||
mCloseButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
||||
|
||||
if (mNextPageButton->getSize().width == 64)
|
||||
{
|
||||
// english button has a 7 pixel wide strip of garbage on its right edge
|
||||
@ -94,6 +99,8 @@ namespace MWGui
|
||||
updatePages();
|
||||
|
||||
setTakeButtonShow(showTakeButton);
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
|
||||
}
|
||||
|
||||
void BookWindow::setTakeButtonShow(bool show)
|
||||
@ -102,6 +109,14 @@ namespace MWGui
|
||||
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
||||
}
|
||||
|
||||
void BookWindow::onKeyButtonPressed(MyGUI::Widget *sender, MyGUI::KeyCode key, MyGUI::Char character)
|
||||
{
|
||||
if (key == MyGUI::KeyCode::ArrowUp)
|
||||
prevPage();
|
||||
else if (key == MyGUI::KeyCode::ArrowDown)
|
||||
nextPage();
|
||||
}
|
||||
|
||||
void BookWindow::setInventoryAllowed(bool allowed)
|
||||
{
|
||||
mTakeButtonAllowed = allowed;
|
||||
|
@ -27,6 +27,8 @@ namespace MWGui
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
void setTakeButtonShow(bool show);
|
||||
|
||||
void onKeyButtonPressed(MyGUI::Widget* sender, MyGUI::KeyCode key, MyGUI::Char character);
|
||||
|
||||
void nextPage();
|
||||
void prevPage();
|
||||
|
||||
|
@ -406,10 +406,11 @@ namespace MWGui
|
||||
MyGUI::EditBox* box = parent->createWidget<MyGUI::EditBox>("NormalText",
|
||||
MyGUI::IntCoord(0, pag.getCurrentTop(), pag.getPageWidth(), 0), MyGUI::Align::Left | MyGUI::Align::Top,
|
||||
parent->getName() + MyGUI::utility::toString(parent->getChildCount()));
|
||||
box->setProperty("Static", "true");
|
||||
box->setProperty("MultiLine", "true");
|
||||
box->setProperty("WordWrap", "true");
|
||||
box->setProperty("NeedMouse", "false");
|
||||
box->setEditStatic(true);
|
||||
box->setEditMultiLine(true);
|
||||
box->setEditWordWrap(true);
|
||||
box->setNeedMouseFocus(false);
|
||||
box->setNeedKeyFocus(false);
|
||||
box->setMaxTextLength(text.size());
|
||||
box->setTextAlign(mBlockStyle.mAlign);
|
||||
box->setTextColour(mTextStyle.mColour);
|
||||
|
@ -156,13 +156,14 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
|
||||
MyGUI::Widget* next = keyFocusList[index];
|
||||
int vertdiff = next->getTop() - focus->getTop();
|
||||
int horizdiff = next->getLeft() - focus->getLeft();
|
||||
if (direction == D_Right && horizdiff <= 0)
|
||||
bool isVertical = std::abs(vertdiff) > std::abs(horizdiff);
|
||||
if (direction == D_Right && (horizdiff <= 0 || isVertical))
|
||||
return false;
|
||||
else if (direction == D_Left && horizdiff >= 0)
|
||||
else if (direction == D_Left && (horizdiff >= 0 || isVertical))
|
||||
return false;
|
||||
else if (direction == D_Down && vertdiff <= 0)
|
||||
else if (direction == D_Down && (vertdiff <= 0 || !isVertical))
|
||||
return false;
|
||||
else if (direction == D_Up && vertdiff >= 0)
|
||||
else if (direction == D_Up && (vertdiff >= 0 || !isVertical))
|
||||
return false;
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(keyFocusList[index]);
|
||||
|
@ -47,6 +47,9 @@ namespace MWGui
|
||||
adjustButton(mCloseButton);
|
||||
adjustButton(mTakeButton);
|
||||
|
||||
mCloseButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ScrollWindow::onKeyButtonPressed);
|
||||
mTakeButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ScrollWindow::onKeyButtonPressed);
|
||||
|
||||
center();
|
||||
}
|
||||
|
||||
@ -66,14 +69,28 @@ namespace MWGui
|
||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||
mTextView->setVisibleVScroll(false);
|
||||
if (size.height > mTextView->getSize().height)
|
||||
mTextView->setCanvasSize(MyGUI::IntSize(410, size.height));
|
||||
mTextView->setCanvasSize(mTextView->getWidth(), size.height);
|
||||
else
|
||||
mTextView->setCanvasSize(410, mTextView->getSize().height);
|
||||
mTextView->setCanvasSize(mTextView->getWidth(), mTextView->getSize().height);
|
||||
mTextView->setVisibleVScroll(true);
|
||||
|
||||
mTextView->setViewOffset(MyGUI::IntPoint(0,0));
|
||||
|
||||
setTakeButtonShow(showTakeButton);
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
|
||||
}
|
||||
|
||||
void ScrollWindow::onKeyButtonPressed(MyGUI::Widget *sender, MyGUI::KeyCode key, MyGUI::Char character)
|
||||
{
|
||||
int scroll = 0;
|
||||
if (key == MyGUI::KeyCode::ArrowUp)
|
||||
scroll = 40;
|
||||
else if (key == MyGUI::KeyCode::ArrowDown)
|
||||
scroll = -40;
|
||||
|
||||
if (scroll != 0)
|
||||
mTextView->setViewOffset(mTextView->getViewOffset() + MyGUI::IntPoint(0, scroll));
|
||||
}
|
||||
|
||||
void ScrollWindow::setTakeButtonShow(bool show)
|
||||
|
@ -26,6 +26,7 @@ namespace MWGui
|
||||
void onCloseButtonClicked (MyGUI::Widget* _sender);
|
||||
void onTakeButtonClicked (MyGUI::Widget* _sender);
|
||||
void setTakeButtonShow(bool show);
|
||||
void onKeyButtonPressed(MyGUI::Widget* sender, MyGUI::KeyCode key, MyGUI::Char character);
|
||||
|
||||
private:
|
||||
Gui::ImageButton* mCloseButton;
|
||||
|
Loading…
x
Reference in New Issue
Block a user