Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ add_executable(videoframevr
src/mpv_gl_context.cpp
src/notices.cpp
src/offline.cpp
src/options.cpp
src/oshash.cpp
src/performance_readout.cpp
src/photo_preloader.cpp
Expand All @@ -146,6 +147,7 @@ add_executable(videoframevr
src/script_player.cpp
src/see_through.cpp
src/seek_preview.cpp
src/setting_commands.cpp
src/settings.cpp
src/setup_intro.cpp
src/setup_placement.cpp
Expand Down
533 changes: 98 additions & 435 deletions src/main.cpp

Large diffs are not rendered by default.

41 changes: 25 additions & 16 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1000,27 +1000,29 @@ class Menu {
void drawKeyboard(cairo_t* cr) const; // its well (its keys are buttons)
// Redraws a key, its shadow around it.
void keyChanged(double x, double y, double w);
// Typing into the folder's (or the library's) search: the keyboard shows
// under its results. On Stash's pages, into what stashText() is; in
// setup, its SMB form.
// The field typed into: setup's (setupText()), the SMB form's, a place's
// name, a preset's name, the funscript address, Stash's (stashText()), or
// else the folder's (or the library's) search. filterText(), setFilter(),
// submitText() and stopEditing() each do what theirs does.
enum class TextTarget { Setup, SmbForm, PlaceName, PresetName, ScriptAddress, Stash, Search };
TextTarget textTarget() const {
if (setup_ && setupText()) return TextTarget::Setup;
if (smbForm_.kind != SmbForm::Kind::None) return TextTarget::SmbForm;
if (page_ == Page::Places) return TextTarget::PlaceName;
if (page_ == Page::VideoSettings && presetName_.open) return TextTarget::PresetName;
if (page_ == Page::Settings && scriptAddress_.open) return TextTarget::ScriptAddress;
return stashTextPage() ? TextTarget::Stash : TextTarget::Search;
}
// Typing into it: the keyboard shows (under the search's results). In
// setup, only into its own fields.
bool editingFilter() const {
if (setup_) return (smbForm_.kind != SmbForm::Kind::None || setupText()) && editing_;
return (page_ == Page::Files || page_ == Page::Library || page_ == Page::Network ||
page_ == Page::Places || stashTextPage() ||
(page_ == Page::VideoSettings && presetName_.open) ||
(page_ == Page::Settings && scriptAddress_.open)) &&
editing_;
return editing_ && (textTarget() != TextTarget::Search || page_ == Page::Files ||
page_ == Page::Library || page_ == Page::Network);
}
bool editing_ = false;
void setFilter(const std::string& text);
const std::string& filterText() const {
if (setup_ && setupText()) return *setupText();
if (smbForm_.kind != SmbForm::Kind::None) return smbForm_.text[smbForm_.field];
if (page_ == Page::Places) return placeRename_.text;
if (page_ == Page::VideoSettings && presetName_.open) return presetName_.text;
if (page_ == Page::Settings && scriptAddress_.open) return scriptAddress_.text;
return stashTextPage() ? stashText() : page_ == Page::Library ? libraryFilter_ : fileFilter_;
}
const std::string& filterText() const;
// The text cursor in the field typed into: a byte of filterText(), kept
// with the text it was placed in. In other text (another field, or this
// one changed from elsewhere) it is at the end.
Expand Down Expand Up @@ -1707,6 +1709,13 @@ class Menu {
// Clamps the scroll position to `count` rows of which `rows` fit, and
// returns the first and last (exclusive) row to lay out.
void clampScroll(int count, int rows, int& first, int& end);
// A grid's cells, `columns` across from x0 to the scroll bar, `gap` apart:
// their width.
double gridCellWidth(double x0, int columns, double gap) const;
// Its `count` cells in rows rowH apart from listTop_, `rows` on screen (0:
// as many as fit above listBottom_, at least one), scrolling by rows: the
// first and last (exclusive) cell to lay out.
void gridRows(int count, int columns, double rowH, int& first, int& end, int rows = 0);
// A list of rows (not cards) with the keyboard up under it ends on its
// last whole row (visibleRows_ of rowHeight_ from listTop_).
void endOnWholeRow();
Expand Down
31 changes: 20 additions & 11 deletions src/menu_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,20 @@ void Menu::clampScroll(int count, int rows, int& first, int& end) {
end = std::min(count, scrollOffset_ + std::max(rows, static_cast<int>(shown)) + 1);
}

double Menu::gridCellWidth(double x0, int columns, double gap) const {
return (listRight_ - kScrollbarRoom - x0 - (columns - 1) * gap) / columns;
}

void Menu::gridRows(int count, int columns, double rowH, int& first, int& end, int rows) {
rowHeight_ = rowH;
visibleRows_ = rows > 0 ? rows : std::max(1, static_cast<int>((listBottom_ - listTop_) / rowH));
listCount_ = (count + columns - 1) / columns;
int firstRow, endRow;
clampScroll(listCount_, visibleRows_, firstRow, endRow);
first = firstRow * columns;
end = std::min(count, endRow * columns);
}

void Menu::endOnWholeRow() {
if (editingFilter())
listBottom_ = std::min(listBottom_, listTop_ + visibleRows_ * rowHeight_ - kRowGap);
Expand All @@ -388,7 +402,7 @@ void Menu::addList(const std::vector<ListItem>& items, double x0, double rowH, i
b.panel = kBrowser;
b.x = x0;
b.y = listTop_ + (i - scrollOffset_ - scrollFraction_) * rowH;
b.w = listRight_ - x0 - 30;
b.w = listRight_ - x0 - kScrollbarRoom;
b.h = rowH - kRowGap;
b.radius = kit::kCorner;
b.label = items[i].label;
Expand Down Expand Up @@ -456,15 +470,10 @@ void Menu::addList(const std::vector<ListItem>& items, double x0, double rowH, i
void Menu::addGallery(const std::vector<ListItem>& items, double x0, int rows) {
constexpr int columns = kGalleryColumns;
constexpr double gap = kGalleryGap, rowH = kGalleryRowH;
const double cardW = (listRight_ - 30 - x0 - (columns - 1) * gap) / columns;
const double cardW = gridCellWidth(x0, columns, gap);
const int count = static_cast<int>(items.size());
visibleRows_ = rows;
rowHeight_ = rowH;
listCount_ = (count + columns - 1) / columns;
int firstRow, endRow;
clampScroll(listCount_, visibleRows_, firstRow, endRow);
const int first = firstRow * columns;
const int end = std::min(count, endRow * columns);
int first, end;
gridRows(count, columns, rowH, first, end, rows);
for (int i = first; i < end; ++i) {
const int cell = i - first;
Button b;
Expand Down Expand Up @@ -526,7 +535,7 @@ void Menu::addScrollbar() {
if (listCount_ <= visibleRows_) return;
Button bar;
bar.panel = kBrowser;
bar.x = listRight_ - kScrollbarW / 2 - (30 - kit::kSpace - kScrollTrackW / 2);
bar.x = listRight_ - kScrollbarW / 2 - (kScrollbarRoom - kit::kSpace - kScrollTrackW / 2);
bar.y = listTop_;
bar.w = kScrollbarW;
bar.h = listBottom_ - listTop_;
Expand Down Expand Up @@ -889,7 +898,7 @@ void Menu::layoutFilesPage() {
listTop_ = kListTop;
listColumns_ = true;
addList(fileItems(), listX, kFileRowH, editing ? kEditingFileRows : kFileRows);
if (listCount_ > 0) layoutListHeader(listX, listRight_ - listX - 30);
if (listCount_ > 0) layoutListHeader(listX, listRight_ - listX - kScrollbarRoom);
}
if (editing) layoutKeyboard();
layoutFileTools();
Expand Down
2 changes: 1 addition & 1 deletion src/menu_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void Menu::layoutLibraryPage() {
listColumns_ = true;
addList(libraryListItems(), listLeft_, kFileRowH,
static_cast<int>((listBottom_ - listTop_) / kFileRowH));
if (listCount_ > 0) layoutListHeader(listLeft_, listRight_ - listLeft_ - 30);
if (listCount_ > 0) layoutListHeader(listLeft_, listRight_ - listLeft_ - kScrollbarRoom);
}
if (editing) layoutKeyboard();
layoutFileTools();
Expand Down
2 changes: 1 addition & 1 deletion src/menu_list_parts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ void Menu::drawEmptyPage(cairo_t* cr, Icon icon, const std::string& heading,
constexpr double kIcon = 72, kIconGap = 20, kHintGap = 8, kHintMaxW = 880;
constexpr int kHeadingSize = 30, kHintSize = 24, kHeadingLines = 2, kHintLines = 3;
const Palette& pal = palette();
const double x0 = listLeft_ + kit::kSpace, x1 = listRight_ - 30 - kit::kSpace;
const double x0 = listLeft_ + kit::kSpace, x1 = listRight_ - kScrollbarRoom - kit::kSpace;
const double cx = (x0 + x1) / 2, w = x1 - x0;
double hintW = std::min(w, kHintMaxW);
if (!hint.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/menu_offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void Menu::layoutOfflinePage() {
listCount_ = units;
int first, end;
clampScroll(listCount_, visibleRows_, first, end);
const double x0 = listLeft_, rowW = listRight_ - 30 - x0;
const double x0 = listLeft_, rowW = listRight_ - kScrollbarRoom - x0;
constexpr double rowH = kFileRowH - kRowGap;
// The drive column: as wide as the longest drive name in it needs, the
// columns taking at most half the row.
Expand Down
121 changes: 76 additions & 45 deletions src/menu_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,44 +157,63 @@ void Menu::moveCursor(int chars) {
dirty_ = true;
}

// The folder's (or the library's) search words. Its results start over at
// the very top.
void Menu::setFilter(const std::string& text) {
if (setup_ && setupText()) {
SetupPages::setText(*this, text);
return;
}
if (smbForm_.kind != SmbForm::Kind::None) {
typedIntoSmbForm(text);
return;
}
if (page_ == Page::Places) {
placeRename_.text = text;
typedChanged();
return;
const std::string& Menu::filterText() const {
switch (textTarget()) {
case TextTarget::Setup:
return *setupText();
case TextTarget::SmbForm:
return smbForm_.text[smbForm_.field];
case TextTarget::PlaceName:
return placeRename_.text;
case TextTarget::PresetName:
return presetName_.text;
case TextTarget::ScriptAddress:
return scriptAddress_.text;
case TextTarget::Stash:
return stashText();
case TextTarget::Search:
break;
}
if (page_ == Page::Settings && scriptAddress_.open) {
scriptAddress_.text = text.substr(0, 200);
typedChanged();
return;
}
if (page_ == Page::VideoSettings && presetName_.open) {
// Whether Save turns into Replace, or is refused, shows with each key.
// At most 40 characters.
if (!g_utf8_validate(text.data(), static_cast<gssize>(text.size()), nullptr)) return;
const glong chars = std::min<glong>(40, g_utf8_strlen(text.c_str(), -1));
const PresetNameCheck before = checkPresetName();
presetName_.text = text.substr(0, g_utf8_offset_to_pointer(text.c_str(), chars) - text.c_str());
if (checkPresetName() == before)
return page_ == Page::Library ? libraryFilter_ : fileFilter_;
}

void Menu::setFilter(const std::string& text) {
switch (textTarget()) {
case TextTarget::Setup:
SetupPages::setText(*this, text);
return;
case TextTarget::SmbForm:
typedIntoSmbForm(text);
return;
case TextTarget::PlaceName:
placeRename_.text = text;
typedChanged();
else
browserChanged(0, kKeyboardY - 12);
return;
}
if (stashTextPage()) {
StashPages::setText(*this, text);
return;
return;
case TextTarget::ScriptAddress:
scriptAddress_.text = text.substr(0, 200);
typedChanged();
return;
case TextTarget::PresetName: {
// Whether Save turns into Replace, or is refused, shows with each key.
// At most 40 characters.
if (!g_utf8_validate(text.data(), static_cast<gssize>(text.size()), nullptr)) return;
const glong chars = std::min<glong>(40, g_utf8_strlen(text.c_str(), -1));
const PresetNameCheck before = checkPresetName();
presetName_.text = text.substr(0, g_utf8_offset_to_pointer(text.c_str(), chars) - text.c_str());
if (checkPresetName() == before)
typedChanged();
else
browserChanged(0, kKeyboardY - 12);
return;
}
case TextTarget::Stash:
StashPages::setText(*this, text);
return;
case TextTarget::Search:
break;
}
// The folder's (or the library's) search words. Its results start over at
// the very top.
std::string& filter = page_ == Page::Library ? libraryFilter_ : fileFilter_;
if (text == filter) return;
filter = text;
Expand All @@ -204,24 +223,36 @@ void Menu::setFilter(const std::string& text) {
dirty_ = true;
}

// Enter (or Done). Setup's panel decides for all its fields.
MenuCommand Menu::submitText() {
if (setup_) return SetupPages::submit(*this);
if (smbForm_.kind != SmbForm::Kind::None) return submitSmbForm();
if (page_ == Page::Places && !placeRename_.path.empty()) {
savePlaceName();
return {};
switch (textTarget()) {
case TextTarget::SmbForm:
return submitSmbForm();
case TextTarget::PlaceName:
if (placeRename_.path.empty()) break;
savePlaceName();
return {};
case TextTarget::PresetName:
return submitPresetName();
case TextTarget::ScriptAddress:
return submitScriptAddress();
case TextTarget::Stash:
if (editingFilter()) return StashPages::submitText(*this);
break;
case TextTarget::Setup:
case TextTarget::Search:
break;
}
if (page_ == Page::VideoSettings && presetName_.open) return submitPresetName();
if (page_ == Page::Settings && scriptAddress_.open) return submitScriptAddress();
if (editingFilter() && stashTextPage()) return StashPages::submitText(*this);
if (editingFilter()) stopEditing();
stopEditing();
return {};
}

void Menu::stopEditing() {
if (editingFilter() && stashTextPage() && !scriptAddress_.open) {
if (!editingFilter()) return;
if (textTarget() == TextTarget::Stash) {
StashPages::stopEditing(*this);
} else if (editingFilter()) {
} else {
// The keyboard goes; the words and what they found stay.
editing_ = false;
dirty_ = true;
Expand Down
2 changes: 1 addition & 1 deletion src/menu_stash_home.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void StashPages::layoutHome(Menu& m) {
}

// Where each part goes, from the top of the shelves down.
const double w = m.listRight_ - 30 - x0;
const double w = m.listRight_ - kScrollbarRoom - x0;
const double tileW = (w - (kSceneColumns - 1) * kTileGap) / kSceneColumns;
const double tileH = cardHeight(tileW);
const double cardW = (w - (kPerformerColumns - 1) * kTileGap) / kPerformerColumns;
Expand Down
10 changes: 3 additions & 7 deletions src/menu_stash_performers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,13 @@ void StashPages::layoutPerformerGrid(Menu& m, double x0, double top) {
StashPerformersState& ps = state(m).performers;
const StashCatalog& c = *catalog(m);
const StashStrings& t = strings().stash;
const double cardW = (m.listRight_ - 30 - x0 - (kColumns - 1) * kTileGap) / kColumns;
const double cardW = m.gridCellWidth(x0, kColumns, kTileGap);
const double pictureW = cardW - 2 * kCardIn;
const double rowH = performerCardHeight(cardW) + kTileGap;
const int count = static_cast<int>(ps.shown.size());
m.listTop_ = top;
m.rowHeight_ = rowH;
m.visibleRows_ = std::max(1, static_cast<int>((m.listBottom_ - top) / rowH));
m.listCount_ = (count + kColumns - 1) / kColumns;
int firstRow, endRow;
m.clampScroll(m.listCount_, m.visibleRows_, firstRow, endRow);
const int first = firstRow * kColumns, end = std::min(count, endRow * kColumns);
int first, end;
m.gridRows(count, kColumns, rowH, first, end);
const int32_t now = today();
for (int i = first; i < end; ++i) {
const int cell = i - first, index = ps.shown[i];
Expand Down
Loading