add media img preview

This commit is contained in:
chatlanin 2023-04-15 15:00:03 +03:00
parent 73a3b29196
commit b1f20b6f54
5 changed files with 43 additions and 2 deletions

View File

@ -333,6 +333,8 @@ namespace rrr::layers::gui
em->execute(types::event_type::SHOW_HELP_DIALOG, nullptr);
freeze = true;
}
detect_img();
}
void navigation::released(system_event& e)
@ -433,4 +435,12 @@ namespace rrr::layers::gui
buffers::get_instance().single_cut_buffer.clear();
selected_file = cnt->get_selected_file(TYPE_WIN::NAVIGATION);
}
void navigation::detect_img()
{
if (selected_file.path.extension() == ".jpg" ||
selected_file.path.extension() == ".jpeg" ||
selected_file.path.extension() == ".png")
em->execute(types::event_type::SHOW_IMG, selected_file.path);
}
}

View File

@ -70,6 +70,7 @@ namespace rrr::layers::gui
void set_scroll();
void paste_from_copy(); // вставка после копирования
void paste_from_cut(); // вставки после вырезания
void detect_img();
};
}

View File

@ -29,7 +29,7 @@ namespace rrr::layers::gui
BEGIN_IMGUI_WIN();
auto pos = ImGui::GetCursorPos();
ImVec2 pos = ImGui::GetCursorPos();
pos.x += 17.f;
pos.y += 9.f; // небольшой отступ сверху
ImGui::SetCursorPosY(pos.y);
@ -37,6 +37,22 @@ namespace rrr::layers::gui
auto begin = data->begin() + delta;
auto end = data->end();
// потоки разные у on_event и этот
// по этому создание незя делать в switch
if (make_media)
{
make_media = false;
tx.make();
frame = cv::imread(media_path);
cv::cvtColor(frame, frame, cv::COLOR_BGR2RGBA);
tx.bind(frame);
media_show = true;
hack::log()(width, height);
}
if (media_show)
tx.draw(ImVec2(pos.x + 830.f, pos.y), ImVec2(width + 850.f, frame.rows / 1.6f));
for (files::iterator it = begin; it != end; ++it)
{
auto item = *it;
@ -98,12 +114,18 @@ namespace rrr::layers::gui
case types::event_type::NAVIGATION_DOWN:
case types::event_type::NAVIGATION_LEFT:
case types::event_type::NAVIGATION_RIGHT:
media_path.clear();
media_show = false;
selected_file = cnt->get_selected_file(TYPE_WIN::PREVIEW);
cursor_position = 0;
current_position = 0;
delta = 0;
set_scroll();
break;
case types::event_type::SHOW_IMG:
media_path = std::any_cast<std::filesystem::path>(value);
make_media = true;
break;
default:
break;
}

View File

@ -41,6 +41,13 @@ namespace rrr::layers::gui
int cursor_position = 0; // позиция курсора относительно высоты экрана
int delta = 0;
enum class MOVE_DIRECTION { UP, DOWN };
std::filesystem::path media_path;
try_engine::texture tx;
cv::Mat frame;
cv::VideoCapture cap;
bool media_show = false;
bool make_media = false;
private:
const ImVec4 dir_color = func::get_IMGUI_color<ImVec4>(91.f, 128.f, 191.f);

View File

@ -17,7 +17,8 @@ namespace rrr::types
CREATE_FILE,
SHOW_RENAME_FILE_DIALOG,
RENAME_FILE,
SHOW_HELP_DIALOG
SHOW_HELP_DIALOG,
SHOW_IMG
};
}