New : implementation of Log::Notify. Displays the message as a

notification on top of the screen before logging.
This commit is contained in:
brunoherbelin
2020-05-19 00:05:30 +02:00
parent e3e212d11b
commit b86b76fa54
5 changed files with 105 additions and 27 deletions

66
Log.cpp
View File

@@ -152,6 +152,26 @@ void Log::ShowLogWindow(bool* p_open)
logs.Draw( ICON_FA_LIST_UL " Logs", 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; static list<string> warnings;
@@ -164,18 +184,57 @@ void Log::Warning(const char* fmt, ...)
buf.appendfv(fmt, args); buf.appendfv(fmt, args);
va_end(args); va_end(args);
// will display a warning dialog
warnings.push_back(buf.c_str()); warnings.push_back(buf.c_str());
// always log
Log::Info("Warning - %s\n", buf.c_str()); 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; return;
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
float width = io.DisplaySize.x * 0.4f; float width = io.DisplaySize.x * 0.4f;
float pos = io.DisplaySize.x * 0.3f;
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::End();
ImGui::PopStyleColor(2);
ImGui::PopStyleVar();
// stop showing after timeout
if ( notifications_timeout > IMGUI_NOTIFICATION_DURATION )
notifications.clear();
}
if (show_warnings) {
ImGui::OpenPopup("Warning"); ImGui::OpenPopup("Warning");
if (ImGui::BeginPopupModal("Warning", NULL, ImGuiWindowFlags_AlwaysAutoResize)) if (ImGui::BeginPopupModal("Warning", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{ {
@@ -204,6 +263,9 @@ void Log::Render()
} }
} }
}
void Log::Error(const char* fmt, ...) void Log::Error(const char* fmt, ...)
{ {
ImGuiTextBuffer buf; ImGuiTextBuffer buf;

3
Log.h
View File

@@ -5,13 +5,14 @@ namespace Log
{ {
// log // log
void Info(const char* fmt, ...); void Info(const char* fmt, ...);
void Notify(const char* fmt, ...);
void Warning(const char* fmt, ...); void Warning(const char* fmt, ...);
void Error(const char* fmt, ...); void Error(const char* fmt, ...);
// Draw logs // Draw logs
void ShowLogWindow(bool* p_open = nullptr); void ShowLogWindow(bool* p_open = nullptr);
void Render(); void Render(bool showNofitications = true, bool showWarnings = true);
} }
#endif // __LOG_H_ #endif // __LOG_H_

View File

@@ -37,11 +37,11 @@ static void loadSession(const std::string& filename, Session *session)
if (!creator.load(filename)) { if (!creator.load(filename)) {
// error loading // 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 { else {
// loaded ok // 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; sessionThreadFilename_ = filename;
@@ -102,7 +102,7 @@ static void saveSession(const std::string& filename, Session *session)
XMLSaveDoc(&xmlDoc, filename); XMLSaveDoc(&xmlDoc, filename);
// loaded ok // loaded ok
Log::Info("Session %s saved.", filename.c_str()); Log::Notify("Session %s saved.", filename.c_str());
// all ok // all ok
sessionThreadFilename_ = filename; sessionThreadFilename_ = filename;
@@ -212,6 +212,9 @@ void Mixer::deleteSource(Source *s)
// in case.. // in case..
unsetCurrentSource(); unsetCurrentSource();
// keep name
std::string name = s->name();
// remove source Nodes from all views // remove source Nodes from all views
mixing_.scene.fg()->detatch( s->group(View::MIXING) ); mixing_.scene.fg()->detatch( s->group(View::MIXING) );
geometry_.scene.fg()->detatch( s->group(View::GEOMETRY) ); geometry_.scene.fg()->detatch( s->group(View::GEOMETRY) );
@@ -219,6 +222,8 @@ void Mixer::deleteSource(Source *s)
// delete source // delete source
session_->deleteSource(s); session_->deleteSource(s);
Log::Notify("Source %s deleted.", name.c_str());
} }
void Mixer::renameSource(Source *s, const std::string &newname) void Mixer::renameSource(Source *s, const std::string &newname)

View File

@@ -303,6 +303,15 @@ void GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair<Node
if (UserInterface::manager().keyboardModifier()) if (UserInterface::manager().keyboardModifier())
S_resize.y = S_resize.x; S_resize.y = S_resize.x;
sourceNode->scale_ = start_scale * S_resize; 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 // picking on the resizing handles left or right
else if ( pick.first == s->handleNode(Handles::RESIZE_H) ) { else if ( pick.first == s->handleNode(Handles::RESIZE_H) ) {

View File

@@ -33,6 +33,7 @@
#define IMGUI_TITLE_PREVIEW ICON_FA_LAPTOP " Preview" #define IMGUI_TITLE_PREVIEW ICON_FA_LAPTOP " Preview"
#define IMGUI_TITLE_DELETE ICON_FA_BROOM " Delete?" #define IMGUI_TITLE_DELETE ICON_FA_BROOM " Delete?"
#define IMGUI_RIGHT_ALIGN -3.5f * ImGui::GetTextLineHeightWithSpacing() #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_BGROUND 0.2f, 0.2f, 0.2f
#define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f #define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f