41 inline void color2i(ImVec4 v,
int&r,
int&g,
int&b) { r=(int)(v.x*255); g=(int)(v.y*255); b=(int)(v.z*255); }
48 int num_incoming = this->UpdateMessages();
52 m_display_messages.clear();
53 std::string last_prefix;
56 if (cvw_msg_duration_ms == 0 || curr_timestamp <= m.cm_timestamp + cvw_msg_duration_ms)
59 m_display_messages.size() != 0 && !cvw_enable_scrolling && last_prefix == std::string(m.cm_text.substr(0, m.cm_text.find(
" "))))
61 m_display_messages.pop_back();
63 m_display_messages.push_back(&m);
64 last_prefix = m.cm_text.substr(0, m.cm_text.find(
" "));
69 ImDrawList* drawlist = ImGui::GetWindowDrawList();
70 drawlist->ChannelsSplit(2);
72 if (!cvw_enable_scrolling)
75 ImVec2 cursor = ImGui::GetWindowPos() + ImVec2(0, ImGui::GetWindowHeight());
76 for (
int i = m_display_messages.size() - 1; i >= 0; --i)
79 float msg_h = ImGui::CalcTextSize(m.
cm_text.c_str()).y + (2 * cvw_background_padding.y) + cvw_line_spacing;
80 cursor -= ImVec2(0, msg_h);
81 if (cursor.y < ImGui::GetWindowPos().y)
85 this->DrawMessage(cursor, m);
91 float line_h = ImGui::CalcTextSize(
"").y + (2 * cvw_background_padding.y) + cvw_line_spacing;
92 float dummy_h = line_h * (float)m_display_messages.size();
93 ImGui::SetCursorPosY(dummy_h);
96 if (num_incoming != 0 && std::abs(ImGui::GetScrollMaxY() - ImGui::GetScrollY()) < line_h)
99 ImGui::SetScrollY(ImGui::GetScrollMaxY() + (num_incoming * line_h) + 100.f);
103 float view_height = ImGui::GetWindowHeight();
104 if (ImGui::GetScrollMaxX() > 0)
106 view_height -= ImGui::GetStyle().ScrollbarSize;
110 int msg_start = 0, msg_count = 0;
111 ImVec2 cursor = ImGui::GetWindowPos();
112 if (ImGui::GetScrollMaxY() == 0)
114 msg_count = (int)m_display_messages.size();
115 cursor += ImVec2(0, view_height - (msg_count * line_h));
119 const float scroll_rel = ImGui::GetScrollY()/ImGui::GetScrollMaxY();
120 const float scroll_offset = ((dummy_h - view_height) * scroll_rel);
121 msg_start = std::max(0, (
int)(scroll_offset/line_h));
123 msg_count = std::min((
int)(view_height / line_h)+2,
124 (
int)m_display_messages.size() - msg_start);
126 const float line_offset = scroll_offset/line_h;
127 if (cvw_smooth_scrolling)
129 cursor -= ImVec2(0, (line_offset - (
float)(
int)line_offset)*line_h);
134 if (ImGui::GetScrollMaxX() > 0)
136 cursor -= ImVec2(ImGui::GetScrollX(), 0);
140 for (
int i = msg_start; i < msg_start + msg_count; i++)
144 ImVec2 text_size = this->DrawMessage(cursor, m);
145 ImGui::SetCursorPosX(text_size.x);
147 cursor += ImVec2(0.f, line_h);
152 drawlist->ChannelsMerge();
161 unsigned long overtime = curr_timestamp - (m.
cm_timestamp + (cvw_msg_duration_ms - fadeout_interval));
163 if (overtime > fadeout_interval)
169 alpha -= (float)overtime/(
float)fadeout_interval;
173 Ogre::TexturePtr icon;
174 if (cvw_enable_icons)
180 icon = Ogre::TextureManager::getSingleton().load(m.
cm_icon,
"IconsRG");
184 else if (m.
cm_area == Console::MessageArea::CONSOLE_MSGTYPE_SCRIPT)
186 icon = Ogre::TextureManager::getSingleton().load(
"script.png",
"IconsRG");
190 icon = Ogre::TextureManager::getSingleton().load(
"information.png",
"IconsRG");
194 icon = Ogre::TextureManager::getSingleton().load(
"error.png",
"IconsRG");
198 icon = Ogre::TextureManager::getSingleton().load(
"cancel.png",
"IconsRG");
202 icon = Ogre::TextureManager::getSingleton().load(
"comment.png",
"IconsRG");
216 color2i(ImVec4(col.r, col.g, col.b, col.a), r,g,b);
230 #endif // USE_SOCKETW
233 ImVec4 base_color = ImGui::GetStyle().Colors[ImGuiCol_Text];
244 return this->DrawColoredTextWithIcon(cursor, icon, base_color, line.
ToCStr());
249 ImGui::TextDisabled(
"%s",
_LC(
"Console",
"By area:"));
250 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Logfile echo"),
"", &cvw_filter_area_echo);
251 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Scripting"),
"", &cvw_filter_area_script);
252 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Actors"),
"", &cvw_filter_area_actor);
253 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Terrain"),
"", &cvw_filter_area_terrn);
256 ImGui::TextDisabled(
"%s",
_LC(
"Console",
"By level:"));
257 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Notices"),
"", &cvw_filter_type_notice);
258 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Warnings"),
"", &cvw_filter_type_warning);
259 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Errors"),
"", &cvw_filter_type_error);
260 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Net chat"),
"", &cvw_filter_type_chat);
261 m_reload_messages |= ImGui::MenuItem(
_LC(
"Console",
"Commands"),
"", &cvw_filter_type_cmd);
267 (m.
cm_area == Console::MessageArea::CONSOLE_MSGTYPE_INFO) ||
268 (m.
cm_area == Console::MessageArea::CONSOLE_MSGTYPE_LOG && cvw_filter_area_echo) ||
269 (m.
cm_area == Console::MessageArea::CONSOLE_MSGTYPE_ACTOR && cvw_filter_area_actor) ||
270 (m.
cm_area == Console::MessageArea::CONSOLE_MSGTYPE_TERRN && cvw_filter_area_terrn) ||
271 (m.
cm_area == Console::MessageArea::CONSOLE_MSGTYPE_SCRIPT && cvw_filter_area_script);
282 return type_ok && area_ok;
287 ImDrawList* drawlist = ImGui::GetWindowDrawList();
290 drawlist->ChannelsSetCurrent(1);
291 ImVec2 text_cursor = bg_cursor + cvw_background_padding;
292 ImVec2 indent_size(0,0);
293 float text_h = ImGui::CalcTextSize(
"").y;
294 if (cvw_enable_icons && icon)
296 ImVec2 icon_size(icon->getWidth(), icon->getHeight());
297 ImVec2
tl = ImVec2(text_cursor.x, text_cursor.y + (text_h / 2) - (icon_size.y / 2));
298 ImVec2 br =
tl + icon_size;
299 drawlist->AddImage(
reinterpret_cast<ImTextureID
>(icon->getHandle()),
tl, br, ImVec2(0,0), ImVec2(1,1), ImColor(ImVec4(1,1,1,alpha)));
300 const float ICON_GAP = 8;
301 indent_size = ImVec2(icon_size.x + ICON_GAP, text_h);
302 text_cursor.x += indent_size.x;
306 ImVec2 text_size =
DrawColorMarkedText(drawlist, text_cursor, default_color, alpha, -1.f, line);
307 const ImVec2 total_text_size(indent_size.x + text_size.x, std::max(indent_size.y, text_size.y));
310 drawlist->ChannelsSetCurrent(0);
311 ImVec2 bg_rect_size = total_text_size + (cvw_background_padding * 2);
312 drawlist->AddRectFilled(bg_cursor, bg_cursor + bg_rect_size,
313 ImColor(ImVec4(0,0,0,(alpha / 2))), ImGui::GetStyle().FrameRounding);
323 if (lock.
messages.size() < m_total_messages)
325 m_reload_messages =
true;
329 if (m_reload_messages)
331 m_filtered_messages.clear();
332 m_total_messages = 0;
333 m_reload_messages =
false;
337 int orig_size = (int)m_filtered_messages.size();
338 for (
size_t i = m_total_messages; i < lock.
messages.size() ; ++i)
341 if (this->MessageFilter(m))
343 if (cvw_enable_scrolling && m.
cm_text.find(
"\n"))
346 Ogre::StringVector v = Ogre::StringUtil::split(m.
cm_text,
"\n");
347 for (Ogre::String& s: v)
349 Ogre::StringUtil::trim(s);
358 m_filtered_messages.push_back(m);
362 m_total_messages = lock.
messages.size();
364 return (
int)m_filtered_messages.size() - orig_size;