3535#include " BaseTheme.h"
3636#include " ofMain.h"
3737
38+ #include " TextEditor.h"
39+ #include " imgui_stdlib.h"
40+
41+ struct MosaicCommand {
42+ std::string command;
43+ std::string description;
44+ };
45+
3846class MosaicTheme : public ofxImGui ::BaseTheme{
3947
4048public:
@@ -60,17 +68,44 @@ class MosaicLoggerChannel : public ofBaseLoggerChannel
6068{
6169public:
6270
63- ImVector<char *> Items;
64- bool scrollToBottom;
71+ ImVector<char *> Items;
72+ TextEditor console;
73+
74+ bool scrollToBottom;
75+ bool recoverFocus;
76+ std::string log_command;
77+ float retinaScale;
78+
79+ ofEvent<std::string> commandEvent;
6580
6681 MosaicLoggerChannel () {
6782 scrollToBottom = true ;
83+ recoverFocus = false ;
84+ log_command = " " ;
85+ retinaScale = 1 .0f ;
86+
87+ console.SetShowWhitespaces (false );
88+ console.SetText (" " );
89+ console.SetReadOnly (true );
90+ console.SetShowLineNumbers (false );
91+ console.SetPalette (TextEditor::GetConsolePalette ());
92+ console.SetLanguageDefinition (TextEditor::LanguageDefinition::SimpleConsole ());
93+ }
94+
95+ void setRetinaScale (float s){
96+ retinaScale = s;
97+ }
98+
99+ void setCommand (string comm){
100+ log_command = comm;
68101 }
69102
70103 void log ( ofLogLevel level, const std::string & module , const std::string & message ){
71104 std::ostringstream oss;
72105 oss << ofGetTimestampString (" %H:%M:%S:%i" ) << " " ;
73- oss << " [" << ofGetLogLevelName (level, true ) << " ] " ;
106+ if (ofGetLogLevelName (level, true ) != " notice " ){
107+ oss << " [" << ofGetLogLevelName (level, true ) << " ] " ;
108+ }
74109 if (module != " " ) {
75110 oss << module << " : " ;
76111 }
@@ -88,7 +123,9 @@ class MosaicLoggerChannel : public ofBaseLoggerChannel
88123 // Compose the message.
89124 std::ostringstream oss;
90125 oss << ofGetTimestampString (" %H:%M:%S:%i" ) << " " ;
91- oss << " [" << ofGetLogLevelName (level, true ) << " ] " ;
126+ if (ofGetLogLevelName (level, true ) != " notice " ){
127+ oss << " [" << ofGetLogLevelName (level, true ) << " ] " ;
128+ }
92129 if (module != " " ) {
93130 oss << module << " : " ;
94131 }
@@ -103,6 +140,8 @@ class MosaicLoggerChannel : public ofBaseLoggerChannel
103140 free (Items[i]);
104141 }
105142 Items.clear ();
143+
144+ console.SetText (" " );
106145 }
107146
108147 void AddLog (const char * fmt, ...) IM_FMTARGS(2 ){
@@ -113,6 +152,7 @@ class MosaicLoggerChannel : public ofBaseLoggerChannel
113152 buf[IM_ARRAYSIZE (buf)-1 ] = 0 ;
114153 va_end (args);
115154 Items.push_back (strdup (buf));
155+ console.InsertText (strdup (buf));
116156 scrollToBottom = true ;
117157 }
118158
@@ -138,24 +178,30 @@ class MosaicLoggerChannel : public ofBaseLoggerChannel
138178 ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2 (4 ,1 )); // Tighten spacing
139179
140180 ImVec4 col_default_text = ImGui::GetStyleColorVec4 (ImGuiCol_Text);
141- for (int i = 0 ; i < Items.Size ; i++){
142- const char * item = Items[i];
143- ImVec4 col = col_default_text;
144- if (strstr (item, " [notice" )) col = ImGui::GetStyleColorVec4 (ImGuiCol_Text);
145- else if (strstr (item, " [warning" )) col = ImColor (1 .0f ,0 .5f ,0 .0f ,1 .0f );
146- else if (strstr (item, " [ error" )) col = ImColor (1 .0f ,0 .176f ,0 .176f ,1 .0f );
147- else if (strstr (item, " [silent" )) col = ImColor (1 .0f ,0 .78f ,0 .58f ,1 .0f );
148- else if (strncmp (item, " # " , 2 ) == 0 ) col = ImColor (1 .0f ,0 .78f ,0 .58f ,1 .0f );
149-
150- // force verbose
151- if (strstr (item, " [verbose]" )){
152- col = ImColor (0 .235f ,1 .0f ,0 .235f ,1 .0f );
153- }
154181
155- ImGui::PushStyleColor (ImGuiCol_Text, col);
156- ImGui::TextUnformatted (item);
157- ImGui::PopStyleColor ();
182+ console.Render (" Console" ,ImVec2 (-1.0 , -36 *retinaScale));
183+ ImGui::Spacing ();
184+ ImGui::Separator ();
185+ ImGui::Spacing ();
186+
187+ if (recoverFocus){
188+ recoverFocus = false ;
189+ ImGui::SetKeyboardFocusHere ();
190+ }
191+ ImGui::PushStyleColor (ImGuiCol_TextSelectedBg,ImVec4 (1 ,1 ,1 ,0.05 ));
192+ ImGui::PushItemWidth (-1 );
193+ if (ImGui::InputTextWithHint (" ###command" ," Send a command..." ,&log_command,ImGuiInputTextFlags_EnterReturnsTrue)){
194+ if (log_command != " " ){
195+ ofNotifyEvent (commandEvent,log_command);
196+ }
197+ // clear previuos command
198+ log_command = " " ;
199+ // focus on input command again
200+ ImGui::SetKeyboardFocusHere (-1 );
158201 }
202+ ImGui::PopItemWidth ();
203+ ImGui::PopStyleColor ();
204+
159205
160206 if (scrollToBottom){
161207 scrollToBottom = false ;
0 commit comments