From 5aeb08cb0707499c9fe57ef6a021771d2af1cf29 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Sun, 10 Jul 2022 17:21:05 -0400 Subject: [PATCH] feat: add timestamps to console messages --- CHANGES.md | 1 + src/gui/set/console_panel.cpp | 57 +++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8970462e..d86949cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Features: * Add ability to change scale (relative to template) of internally stored images. * Impose some rudimentary constraints on the Image Slice Window's initial size. * Merge String capitilization changes by @SoaringMoon. + * Add timestamps to console messages. Bug fixes: * Make viewer image rotate button operate clockwise to match dropdown options. (#9) diff --git a/src/gui/set/console_panel.cpp b/src/gui/set/console_panel.cpp index a9665d7b..50e4d2ea 100644 --- a/src/gui/set/console_panel.cpp +++ b/src/gui/set/console_panel.cpp @@ -25,7 +25,8 @@ DECLARE_POINTER_TYPE(ConsoleMessage); class ConsoleMessage : public IntrusivePtrBase { public: MessageType type; - String text; // string message + String text; // string message + wxDateTime timestamp; Bitmap bitmap; // image message instead of string ScriptValueP value; // other valued message (images? cards?) // location of error messages @@ -38,7 +39,7 @@ public: int bottom() const { return top+height; } ConsoleMessage(MessageType type, String const& text = _(""), bool joined_to_previous = false) - : type(type), text(text), line_number(-1), joined_to_previous(joined_to_previous), top(-1), height(-1) + : type(type), text(text), timestamp(wxDateTime::Now()), line_number(-1), joined_to_previous(joined_to_previous), top(-1), height(-1) {} }; @@ -244,10 +245,12 @@ private: wxAutoBufferedPaintDC dc(this); PrepareDC(dc); draw(dc); - } + } + void draw(wxDC& dc) const { clearDC(dc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - dc.SetFont(*wxNORMAL_FONT); + dc.SetFont(*wxNORMAL_FONT); + FOR_EACH_CONST(msg, messages) { draw(dc, *msg); } @@ -280,16 +283,31 @@ private: // draw background dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(lerp(bg,color, 0.05)); - dc.DrawRectangle(left,top,width,msg.height); - + dc.DrawRectangle(left,top,width,msg.height); + + // draw foreground + dc.SetTextForeground(fg); + + // draw timestamp + dc.DrawText(msg.timestamp.FormatISOTime(), left + TIMESTAMP_PADDING, top + TEXT_PADDING_TOP); + + wxSize timestamp_size = dc.GetTextExtent("55:55:55"); + int timestamp_resolved_width = timestamp_size.GetWidth(); + + left += timestamp_resolved_width; + left += TIMESTAMP_PADDING * 2; + + // draw line right of timestamp + dc.SetPen(lerp(bg, fg, 0.3)); + dc.DrawLine(left, top, left, top + msg.height); + // draw icon if (icons[msg.type].Ok()) { - dc.DrawBitmap(icons[msg.type], left + ICON_PADDING,top + ICON_PADDING); + dc.DrawBitmap(icons[msg.type], left + ICON_PADDING_LEFT,top + ICON_PADDING); } // draw text - dc.SetTextForeground(fg); - int text_left = TEXT_PADDING_LEFT; + int text_left = left + TEXT_PADDING_LEFT; int text_top = top + TEXT_PADDING_TOP; // find line breaks in the text String::const_iterator begin = msg.text.begin(); @@ -313,11 +331,11 @@ private: if (msg.bitmap.Ok()) { dc.DrawBitmap(msg.bitmap, text_left, text_top); text_top += msg.bitmap.GetHeight(); - } - + } + // draw line below item dc.SetPen(lerp(bg,fg, 0.3)); - dc.DrawLine(left, top+msg.height, left+width, top+msg.height); + dc.DrawLine(0, top + msg.height, 0 + width, top + msg.height); } int item_height(wxDC& dc, ConsoleMessage const& msg) const { @@ -338,6 +356,11 @@ private: } if (begin != msg.text.end()) { text_height += dc.GetCharHeight() + TEXT_LINE_SPACING; + } + + // account for the height of a timestamp even if there is no other text content. + if (text_height == 0) { + text_height = dc.GetCharHeight() + TEXT_LINE_SPACING; } // height of bitmap @@ -347,10 +370,12 @@ private: } // --------------------------------------------------- : Layout - - static constexpr int LIST_SPACING = 1; - static constexpr int ICON_PADDING = 3; - static constexpr int TEXT_PADDING_LEFT = ICON_PADDING + 16 + 4; + + static constexpr int LIST_SPACING = 1; + static constexpr int TIMESTAMP_PADDING = 3; + static constexpr int ICON_PADDING = 3; + static constexpr int ICON_PADDING_LEFT = TIMESTAMP_PADDING + 3; + static constexpr int TEXT_PADDING_LEFT = ICON_PADDING_LEFT + 16 + 4; static constexpr int TEXT_PADDING_RIGHT = 4; static constexpr int TEXT_PADDING_TOP = 4; static constexpr int TEXT_PADDING_BOTTOM = 2;