mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
New : implementation of Log::Notify. Displays the message as a
notification on top of the screen before logging.
This commit is contained in:
108
Log.cpp
108
Log.cpp
@@ -152,6 +152,26 @@ void Log::ShowLogWindow(bool* p_open)
|
||||
logs.Draw( ICON_FA_LIST_UL " Logs", p_open);
|
||||
}
|
||||
|
||||
static list<string> notifications;
|
||||
static float notifications_timeout = 0.f;
|
||||
|
||||
void Log::Notify(const char* fmt, ...)
|
||||
{
|
||||
ImGuiTextBuffer buf;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
buf.appendfv(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
// will display a notification
|
||||
notifications.push_back(buf.c_str());
|
||||
notifications_timeout = 0.f;
|
||||
|
||||
// always log
|
||||
Log::Info("%s\n", buf.c_str());
|
||||
}
|
||||
|
||||
|
||||
static list<string> warnings;
|
||||
|
||||
@@ -164,44 +184,86 @@ void Log::Warning(const char* fmt, ...)
|
||||
buf.appendfv(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
// will display a warning dialog
|
||||
warnings.push_back(buf.c_str());
|
||||
|
||||
// always log
|
||||
Log::Info("Warning - %s\n", buf.c_str());
|
||||
}
|
||||
|
||||
void Log::Render()
|
||||
void Log::Render(bool showNofitications, bool showWarnings)
|
||||
{
|
||||
if (warnings.empty())
|
||||
bool show_warnings = !warnings.empty() & showWarnings;
|
||||
bool show_notification = !notifications.empty() & showNofitications;
|
||||
|
||||
if (!show_notification && !show_warnings)
|
||||
return;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
float width = io.DisplaySize.x * 0.4f;
|
||||
float pos = io.DisplaySize.x * 0.3f;
|
||||
|
||||
ImGui::OpenPopup("Warning");
|
||||
if (ImGui::BeginPopupModal("Warning", NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
ImGuiToolkit::Icon(9, 4);
|
||||
ImGui::SameLine(0, 10);
|
||||
ImGui::SetNextItemWidth(width);
|
||||
ImGui::TextColored(ImVec4(1.0f,0.6f,0.0f,1.0f), "%ld error(s) occured.\n\n", warnings.size());
|
||||
ImGui::Dummy(ImVec2(width, 0));
|
||||
if (show_notification){
|
||||
notifications_timeout += io.DeltaTime;
|
||||
float height = ImGui::GetTextLineHeightWithSpacing() * notifications.size();
|
||||
float y = -height + MIN( notifications_timeout * height * 10.f, height );
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 3.0);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(COLOR_NAVIGATOR, 1.f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(COLOR_NAVIGATOR, 1.f));
|
||||
|
||||
ImGui::SetNextWindowPos( ImVec2(pos, y), ImGuiCond_Always );
|
||||
ImGui::SetNextWindowSize( ImVec2(width, height), ImGuiCond_Always );
|
||||
ImGui::SetNextWindowBgAlpha(0.8f); // Transparent background
|
||||
if (ImGui::Begin("##notification", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav ))
|
||||
{
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + width);
|
||||
for (list<string>::iterator it=notifications.begin(); it != notifications.end(); ++it) {
|
||||
ImGui::Text( ICON_FA_INFO " %s\n", (*it).c_str());
|
||||
}
|
||||
ImGui::PopTextWrapPos();
|
||||
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + width);
|
||||
for (list<string>::iterator it=warnings.begin(); it != warnings.end(); ++it) {
|
||||
ImGui::Text("%s \n", (*it).c_str());
|
||||
ImGui::Separator();
|
||||
}
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Dummy(ImVec2(width * 0.8f, 0)); ImGui::SameLine(); // right align
|
||||
if (ImGui::Button(" Ok ", ImVec2(width * 0.2f, 0))) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
// messages have been seen
|
||||
warnings.clear();
|
||||
}
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetItemDefaultFocus();
|
||||
ImGui::EndPopup();
|
||||
// stop showing after timeout
|
||||
if ( notifications_timeout > IMGUI_NOTIFICATION_DURATION )
|
||||
notifications.clear();
|
||||
}
|
||||
|
||||
if (show_warnings) {
|
||||
ImGui::OpenPopup("Warning");
|
||||
if (ImGui::BeginPopupModal("Warning", NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
ImGuiToolkit::Icon(9, 4);
|
||||
ImGui::SameLine(0, 10);
|
||||
ImGui::SetNextItemWidth(width);
|
||||
ImGui::TextColored(ImVec4(1.0f,0.6f,0.0f,1.0f), "%ld error(s) occured.\n\n", warnings.size());
|
||||
ImGui::Dummy(ImVec2(width, 0));
|
||||
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + width);
|
||||
for (list<string>::iterator it=warnings.begin(); it != warnings.end(); ++it) {
|
||||
ImGui::Text("%s \n", (*it).c_str());
|
||||
ImGui::Separator();
|
||||
}
|
||||
ImGui::PopTextWrapPos();
|
||||
|
||||
ImGui::Dummy(ImVec2(width * 0.8f, 0)); ImGui::SameLine(); // right align
|
||||
if (ImGui::Button(" Ok ", ImVec2(width * 0.2f, 0))) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
// messages have been seen
|
||||
warnings.clear();
|
||||
}
|
||||
|
||||
ImGui::SetItemDefaultFocus();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Log::Error(const char* fmt, ...)
|
||||
|
||||
3
Log.h
3
Log.h
@@ -5,13 +5,14 @@ namespace Log
|
||||
{
|
||||
// log
|
||||
void Info(const char* fmt, ...);
|
||||
void Notify(const char* fmt, ...);
|
||||
void Warning(const char* fmt, ...);
|
||||
void Error(const char* fmt, ...);
|
||||
|
||||
// Draw logs
|
||||
void ShowLogWindow(bool* p_open = nullptr);
|
||||
|
||||
void Render();
|
||||
void Render(bool showNofitications = true, bool showWarnings = true);
|
||||
}
|
||||
|
||||
#endif // __LOG_H_
|
||||
|
||||
11
Mixer.cpp
11
Mixer.cpp
@@ -37,11 +37,11 @@ static void loadSession(const std::string& filename, Session *session)
|
||||
|
||||
if (!creator.load(filename)) {
|
||||
// error loading
|
||||
Log::Info("Failed to load Session file %s.", filename.c_str());
|
||||
Log::Notify("Failed to load Session file %s.", filename.c_str());
|
||||
}
|
||||
else {
|
||||
// loaded ok
|
||||
Log::Info("Session %s loaded. %d source(s) created.", filename.c_str(), session->numSource());
|
||||
Log::Notify("Session %s loaded. %d source(s) created.", filename.c_str(), session->numSource());
|
||||
}
|
||||
|
||||
sessionThreadFilename_ = filename;
|
||||
@@ -102,7 +102,7 @@ static void saveSession(const std::string& filename, Session *session)
|
||||
XMLSaveDoc(&xmlDoc, filename);
|
||||
|
||||
// loaded ok
|
||||
Log::Info("Session %s saved.", filename.c_str());
|
||||
Log::Notify("Session %s saved.", filename.c_str());
|
||||
|
||||
// all ok
|
||||
sessionThreadFilename_ = filename;
|
||||
@@ -212,6 +212,9 @@ void Mixer::deleteSource(Source *s)
|
||||
// in case..
|
||||
unsetCurrentSource();
|
||||
|
||||
// keep name
|
||||
std::string name = s->name();
|
||||
|
||||
// remove source Nodes from all views
|
||||
mixing_.scene.fg()->detatch( s->group(View::MIXING) );
|
||||
geometry_.scene.fg()->detatch( s->group(View::GEOMETRY) );
|
||||
@@ -219,6 +222,8 @@ void Mixer::deleteSource(Source *s)
|
||||
|
||||
// delete source
|
||||
session_->deleteSource(s);
|
||||
|
||||
Log::Notify("Source %s deleted.", name.c_str());
|
||||
}
|
||||
|
||||
void Mixer::renameSource(Source *s, const std::string &newname)
|
||||
|
||||
9
View.cpp
9
View.cpp
@@ -303,6 +303,15 @@ void GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair<Node
|
||||
if (UserInterface::manager().keyboardModifier())
|
||||
S_resize.y = S_resize.x;
|
||||
sourceNode->scale_ = start_scale * S_resize;
|
||||
|
||||
// glm::vec3 factor = S_resize * glm::vec3(0.5f, 0.5f, 1.f);
|
||||
//// glm::vec3 factor = S_resize * glm::vec3(1.f, 1.f, 1.f);
|
||||
//// factor *= glm::sign( glm::vec3(pick.second, 1.f) );
|
||||
// sourceNode->scale_ = start_scale + factor;
|
||||
|
||||
// sourceNode->translation_ = start_translation + factor;
|
||||
//// sourceNode->translation_ = start_translation + S_resize * factor;
|
||||
|
||||
}
|
||||
// picking on the resizing handles left or right
|
||||
else if ( pick.first == s->handleNode(Handles::RESIZE_H) ) {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#define IMGUI_TITLE_PREVIEW ICON_FA_LAPTOP " Preview"
|
||||
#define IMGUI_TITLE_DELETE ICON_FA_BROOM " Delete?"
|
||||
#define IMGUI_RIGHT_ALIGN -3.5f * ImGui::GetTextLineHeightWithSpacing()
|
||||
#define IMGUI_NOTIFICATION_DURATION 1.5f
|
||||
|
||||
#define COLOR_BGROUND 0.2f, 0.2f, 0.2f
|
||||
#define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f
|
||||
|
||||
Reference in New Issue
Block a user