Commit fdbbf96d authored by Aloshi's avatar Aloshi

Added scrolling to ComponentList.

--no-exit works again.
Changed default screen dim time from 30 seconds to 120 seconds.
parent c525d994
......@@ -106,7 +106,7 @@ You can use `--help` to view a list of command-line options. Briefly outlined he
--draw-framerate - draw the framerate.
--no-exit - do not display 'exit' in the ES menu.
--debug - print additional output to the console, primarily about input.
--dimtime [seconds] - delay before dimming the screen and entering sleep mode. Default is 30, use 0 for never.
--dimtime [seconds] - delay before dimming the screen and entering sleep mode. Default is 120, use 0 for never.
--windowed - run ES in a window.
--scrape - run the interactive command-line metadata scraper.
```
......
......@@ -37,7 +37,7 @@ void Settings::setDefaults()
mBoolMap["DisableGamelistWrites"] = false;
mBoolMap["ScrapeRatings"] = true;
mIntMap["DIMTIME"] = 30*1000;
mIntMap["DIMTIME"] = 120*1000;
mIntMap["ScraperResizeWidth"] = 400;
mIntMap["ScraperResizeHeight"] = 0;
......
......@@ -5,6 +5,7 @@
ComponentList::ComponentList(Window* window) : IList<ComponentListRow, void*>(window, LIST_SCROLL_STYLE_SLOW, LIST_NEVER_LOOP)
{
mSelectorBarOffset = 0;
mCameraOffset = 0;
}
void ComponentList::addRow(const ComponentListRow& row)
......@@ -67,23 +68,31 @@ void ComponentList::onCursorChanged(const CursorState& state)
{
mSelectorBarOffset += getRowHeight(mEntries.at(i).data);
}
mCameraOffset = mSelectorBarOffset - (mSize.y() / 2);
if(mCameraOffset < 0)
mCameraOffset = 0;
else if(mCameraOffset + mSize.y() > getTotalRowHeight())
mCameraOffset = getTotalRowHeight() - mSize.y();
}
void ComponentList::render(const Eigen::Affine3f& parentTrans)
{
Eigen::Affine3f trans = parentTrans * getTransform();
// clip our entries inside our bounds
// clip everything to be inside our bounds
Eigen::Vector3f dim(mSize.x(), mSize.y(), 0);
dim = trans * dim - trans.translation();
Renderer::pushClipRect(Eigen::Vector2i((int)trans.translation().x(),
(int)trans.translation().y()), Eigen::Vector2i((int)dim.x(), (int)dim.y()));
// scroll the camera
trans.translate(Eigen::Vector3f(0, -mCameraOffset, 0));
// draw our entries
renderChildren(trans);
Renderer::popClipRect();
// draw selector bar
Renderer::setMatrix(trans);
......@@ -105,9 +114,11 @@ void ComponentList::render(const Eigen::Affine3f& parentTrans)
y += getRowHeight(mEntries.at(i).data);
}
Renderer::drawRect(0, (int)y, (int)mSize.x(), 1, 0xC6C7C688);
Renderer::popClipRect();
}
float ComponentList::getRowHeight(const ComponentListRow& row)
float ComponentList::getRowHeight(const ComponentListRow& row) const
{
// returns the highest component height found in the row
float height = 0;
......@@ -120,6 +131,17 @@ float ComponentList::getRowHeight(const ComponentListRow& row)
return height;
}
float ComponentList::getTotalRowHeight() const
{
float height = 0;
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
{
height += getRowHeight(it->data);
}
return height;
}
void ComponentList::updateElementPosition(const ComponentListRow& row)
{
float yOffset = 0;
......
......@@ -42,7 +42,9 @@ private:
void updateElementPosition(const ComponentListRow& row);
void updateElementSize(const ComponentListRow& row);
float getRowHeight(const ComponentListRow& row);
float getRowHeight(const ComponentListRow& row) const;
float getTotalRowHeight() const;
float mSelectorBarOffset;
float mCameraOffset;
};
......@@ -5,6 +5,7 @@ MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(w
{
mBackground.setImagePath(":/frame.png");
mTitle.setFont(Font::get(FONT_SIZE_LARGE));
mTitle.setText(title);
mTitle.setCentered(true);
......
......@@ -5,6 +5,8 @@
#include "../Sound.h"
#include "../Log.h"
#include "GuiMsgBoxYesNo.h"
#include <initializer_list>
#include "../Settings.h"
GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "Main Menu")
{
......@@ -14,41 +16,57 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "Main Men
unsigned int color;
bool add_arrow;
std::function<void()> func;
MenuEntry(const char* n, unsigned int c, bool a, std::function<void()> f) : name(n), color(c), add_arrow(a), func(f) {};
};
MenuEntry entries[] = {
{ "GENERAL SETTINGS", 0x777777FF, true,
std::vector<MenuEntry> entries;
entries.push_back(
MenuEntry("GENERAL SETTINGS", 0x777777FF, true,
[this] { mWindow->pushGui(new GuiSettingsMenu(mWindow)); }
},
{ "SCRAPE NOW", 0x777777FF, true,
)
);
entries.push_back(
MenuEntry("SCRAPE NOW", 0x777777FF, true,
[this] { mWindow->pushGui(new GuiScraperStart(mWindow)); }
},
{ "RESTART SYSTEM", 0x990000FF, false,
)
);
entries.push_back(
MenuEntry("RESTART SYSTEM", 0x990000FF, false,
[this] {
mWindow->pushGui(new GuiMsgBoxYesNo(mWindow, "Do you really want to restart the system?",
[] {
if(system("sudo shutdown -r now") != 0)
LOG(LogWarning) << "Restart terminated with non-zero result!";
}));
}
},
{ "SHUTDOWN SYSTEM", 0x990000FF, false,
})
);
entries.push_back(
MenuEntry("SHUTDOWN SYSTEM", 0x990000FF, false,
[this] {
mWindow->pushGui(new GuiMsgBoxYesNo(mWindow, "Do you really want to shutdown the system?",
[] {
if(system("sudo shutdown -h now") != 0)
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
}));
}
},
{ "EXIT EMULATIONSTATION", 0x990000FF, false,
[] {
SDL_Event ev;
ev.type = SDL_QUIT;
SDL_PushEvent(&ev);
}
}
};
})
);
if(!Settings::getInstance()->getBool("DONTSHOWEXIT"))
{
entries.push_back(
MenuEntry("EXIT EMULATIONSTATION", 0x990000FF, false,
[] {
SDL_Event ev;
ev.type = SDL_QUIT;
SDL_PushEvent(&ev);
})
);
}
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);
......@@ -58,7 +76,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "Main Men
// populate the list
ComponentListRow row;
for(int i = 0; i < (sizeof(entries) / sizeof(entries[0])); i++)
for(unsigned int i = 0; i < entries.size(); i++)
{
row.elements.clear();
row.addElement(std::make_shared<TextComponent>(mWindow, entries[i].name, font, entries[i].color), true);
......
......@@ -71,7 +71,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
std::cout << "--draw-framerate display the framerate\n";
std::cout << "--no-exit don't show the exit option in the menu\n";
std::cout << "--debug even more logging\n";
std::cout << "--dimtime [seconds] time to wait before dimming the screen (default 30, use 0 for never)\n";
std::cout << "--dimtime [seconds] time to wait before dimming the screen (default 120, use 0 for never)\n";
std::cout << "--scrape scrape using command line interface\n";
std::cout << "--windowed not fullscreen, should be used in conjunction with -w and -h\n";
std::cout << "--help summon a sentient, angry tuba\n\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment