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