-
-
Notifications
You must be signed in to change notification settings - Fork 564
Display world screenshot previews and progress #2349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
19b45a5
058899e
692d5a0
c38af90
78094b3
24dc82f
5cd4f74
9be8c3d
bbd65fe
9a9d115
c0ba8e5
3c5ecec
7cdf956
062c452
827d922
1149313
8a23ab0
91ea207
17e2259
08efd94
3c421d5
41bed28
492395c
78df407
d8a7c73
9612857
610a448
8763b68
026573e
7a2edb1
82ef7a9
82564d4
4006ed8
7030989
7bfb703
828eb04
d8e4f8b
a6367ff
cf698d8
955e88e
30792f1
211155e
a4f4be5
247d32f
9860163
60efe14
475aa60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,9 @@ | |
| #include "util/gettext.hpp" | ||
| #include "util/string_util.hpp" | ||
|
|
||
| static const size_t MAX_TITLE_CHARS = 30; | ||
| static const std::vector<std::string> IMAGE_EXTENSIONS = { ".jpg", ".png", ".surface" }; | ||
|
|
||
| FileSystemMenu::FileSystemMenu(std::string* filename, const std::vector<std::string>& extensions, | ||
| const std::string& basedir, bool path_relative_to_basedir, std::function<void(const std::string&)> callback, | ||
| const std::function<void (MenuItem&)>& item_processor) : | ||
|
|
@@ -65,7 +68,13 @@ FileSystemMenu::refresh_items() | |
| m_files.clear(); | ||
| m_directory = FileSystem::normalize(m_directory); | ||
|
|
||
| add_label(m_directory); | ||
| // Make sure label doesn't get too long. | ||
| std::string title = m_directory; | ||
| const bool title_large = title.size() > MAX_TITLE_CHARS; | ||
| while (title.size() > MAX_TITLE_CHARS) | ||
| title = title.substr(title.size() - MAX_TITLE_CHARS); | ||
|
|
||
| add_label((title_large ? "..." : "") + title); | ||
| add_hl(); | ||
|
|
||
| int item_id = 0; | ||
|
|
@@ -109,8 +118,11 @@ FileSystemMenu::refresh_items() | |
| for (const auto& item : m_files) | ||
| { | ||
| MenuItem& menu_item = add_entry(item_id, item); | ||
|
|
||
| if (in_basedir && m_item_processor) | ||
| m_item_processor(menu_item); | ||
| if (is_image(item)) | ||
| menu_item.set_preview(FileSystem::join(m_directory, item)); | ||
|
|
||
| item_id++; | ||
| } | ||
|
|
@@ -124,6 +136,7 @@ FileSystemMenu::refresh_items() | |
|
|
||
| // Re-center menu | ||
| on_window_resize(); | ||
| align_for_previews(25.f); | ||
| } | ||
|
|
||
| bool | ||
|
|
@@ -132,12 +145,20 @@ FileSystemMenu::has_right_suffix(const std::string& file) const | |
| if (m_extensions.empty()) | ||
| return true; | ||
|
|
||
| for (const auto& extension : m_extensions) { | ||
| for (const auto& extension : m_extensions) | ||
| if (StringUtil::has_suffix(file, extension)) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| bool | ||
| FileSystemMenu::is_image(const std::string& file) const | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smells like unsound logic anyway. sdl image might have something to check this? try running it through and seeing if a valid surface is returned if it doesnt.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. granted, thats kinda rare. plus, what about .jpeg and whatever? maybe im looking at this wrong |
||
| { | ||
| for (const auto& extension : IMAGE_EXTENSIONS) | ||
| if (StringUtil::has_suffix(file, extension)) | ||
| return true; | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| #include "supertux/globals.hpp" | ||
| #include "supertux/resources.hpp" | ||
| #include "video/drawing_context.hpp" | ||
| #include "video/surface.hpp" | ||
|
|
||
| static const float HELP_TEXT_WIDTH = 800.f; | ||
|
|
||
|
|
@@ -30,7 +31,8 @@ MenuItem::MenuItem(const std::string& text, int id, const std::optional<Color>& | |
| m_text(text), | ||
| m_help(), | ||
| m_font(Resources::normal_font), | ||
| m_text_color(text_color) | ||
| m_text_color(text_color), | ||
| m_preview() | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -50,6 +52,12 @@ MenuItem::set_help(const std::string& help_text) | |
| } | ||
| } | ||
|
|
||
| void | ||
| MenuItem::set_preview(const std::string& preview_file) | ||
| { | ||
| m_preview = Surface::from_file(preview_file); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error check |
||
| } | ||
|
|
||
| void | ||
| MenuItem::draw(DrawingContext& context, const Vector& pos, int menu_width, bool active) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std array or just a C style array. Try std stringview