From 58b54f31b6ff2ef9ca2fce5a08dc8d9cb3bb4a14 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Tue, 18 Nov 2025 09:56:17 +0100 Subject: [PATCH] CtrlLib, ide, RichEdit: Beginner info improved --- uppsrc/CtrlLib/BeginnerInfo.cpp | 117 ++++++++++++++++++ uppsrc/CtrlLib/CtrlLib.upp | 1 + uppsrc/CtrlLib/CtrlUtil.cpp | 20 --- uppsrc/CtrlLib/CtrlUtil.h | 9 +- uppsrc/RichEdit/DiagramEditor.cpp | 5 +- uppsrc/ide/Assist.cpp | 3 +- uppsrc/ide/IconDes/Paint.cpp | 4 +- uppsrc/ide/LayDes/laydes.cpp | 3 +- .../ide/app.tpp/EditorBeginnerInfo_en-us.tpp | 2 - .../ide/app.tpp/EditorBeginnerInfo_en-us.tppi | 7 +- 10 files changed, 134 insertions(+), 37 deletions(-) create mode 100644 uppsrc/CtrlLib/BeginnerInfo.cpp diff --git a/uppsrc/CtrlLib/BeginnerInfo.cpp b/uppsrc/CtrlLib/BeginnerInfo.cpp new file mode 100644 index 000000000..87eb5f61d --- /dev/null +++ b/uppsrc/CtrlLib/BeginnerInfo.cpp @@ -0,0 +1,117 @@ +#include "CtrlLib.h" + +namespace Upp { + +void PaintBeginnerInfo(Draw& w, const Rect& cr, const char *qtf) +{ + RichText text = ParseQTF(qtf); + text.ApplyZoom(GetRichTextStdScreenZoom()); + + int u = 2 * GetStdFontCy() + DPI(4); + + Size sz = cr.GetSize(); + + int cx = min(text.GetWidth(), sz.cx - 2 * u); + int cy = text.GetHeight(cx); + + Rect r = RectC(cr.left + sz.cx - cx - u, cr.top + sz.cy - cy - u, cx + DPI(8), cy + DPI(8)); + DrawRoundRect(w, r, DPI(4), Blend(SYellow(), SWhite(), 225), 1, Gray()); + text.Paint(w, r.left + DPI(4), r.top + DPI(4), cx); +} + +void PaintBeginnerInfoTopic(Draw& w, Size sz, const char *topic) +{ + PaintBeginnerInfo(w, sz, GetTopic(topic)); +} + +void PaintBeginnerInfo(Ctrl *ctrl, Draw& w, const Rect& cr, const char *qtf, const char *key) +{ + static Index done_keys; + + if(done_keys.Find(key) >= 0) + return; + + struct Record : Moveable { + Ptr ctrl; + String key; + Point mousepos; + int tm; + }; + + static Vector records; + + static auto Sweep = [] { + for(const Record& r : records) + if(!r.ctrl) + done_keys.FindAdd(r.key); + records.RemoveIf([&](int i) { return !records[i].ctrl; }); + }; + + int i = FindMatch(records, [&](const Record& r) { return r.ctrl == ctrl; }); + if(i < 0) { + Record& r = records.Add(); + r.ctrl = ctrl; + r.key = key; + r.mousepos = GetMousePos(); + r.tm = msecs(); + } + + typedef bool (*MouseHook)(Ctrl *ctrl, bool inframe, int event, Point p, + int zdelta, dword keyflags); + typedef bool (*KeyHook)(Ctrl *ctrl, dword key, int count); + typedef bool (*StateHook)(Ctrl *ctrl, int reason); + typedef void (*PaintHook)(Ctrl *ctrl, Draw& draw, const Rect& clip); + + static auto Stop = [](bool testmousepos = false) { + int tm = msecs(); + Point mousepos; + if(testmousepos) + mousepos = GetMousePos(); + for(Record& r : records) { + if(testmousepos && Distance(r.mousepos, mousepos) < DPI(10)) + continue; + if(tm - r.tm > 250) { + if(r.ctrl) { + r.ctrl->Refresh(); + r.ctrl = nullptr; + } + } + } + Sweep(); + }; + + ONCELOCK { + Ctrl::InstallKeyHook([](Ctrl *, dword, int) -> bool { + Stop(); + return false; + }); + Ctrl::InstallMouseHook([](Ctrl *ctrl, bool inframe, int event, Point p, + int zdelta, dword keyflags) -> bool { + if(event == Ctrl::MOUSEMOVE) + Stop(true); + else + if(event != Ctrl::CURSORIMAGE) + Stop(); + return false; + }); + } + + PaintBeginnerInfo(w, cr, qtf); +} + +void PaintBeginnerInfo(Ctrl *ctrl, Draw& w, const char *qtf, const char *key) +{ + PaintBeginnerInfo(ctrl, w, ctrl->GetSize(), qtf, key); +} + +void PaintBeginnerInfoTopic(Ctrl *ctrl, Draw& w, const Rect& cr, const char *topic) +{ + PaintBeginnerInfo(ctrl, w, cr, GetTopic(topic), topic); +} + +void PaintBeginnerInfoTopic(Ctrl *ctrl, Draw& w, const char *topic) +{ + PaintBeginnerInfo(ctrl, w, ctrl->GetSize(), GetTopic(topic), topic); +} + +} \ No newline at end of file diff --git a/uppsrc/CtrlLib/CtrlLib.upp b/uppsrc/CtrlLib/CtrlLib.upp index 1a3fd7c7f..88bdc3739 100644 --- a/uppsrc/CtrlLib/CtrlLib.upp +++ b/uppsrc/CtrlLib/CtrlLib.upp @@ -106,6 +106,7 @@ file TrayIconGtk.cpp, Update.cpp, CtrlUtil.cpp, + BeginnerInfo.cpp, Ctrl.iml, Ctrl.lay, CtrlLib.t, diff --git a/uppsrc/CtrlLib/CtrlUtil.cpp b/uppsrc/CtrlLib/CtrlUtil.cpp index b80c2a141..800be5ccb 100644 --- a/uppsrc/CtrlLib/CtrlUtil.cpp +++ b/uppsrc/CtrlLib/CtrlUtil.cpp @@ -543,24 +543,4 @@ void DrawRoundRect(Draw& w, int x, int y, int cx, int cy, int radius, Color fill DrawRoundRect(w, RectC(x, y, cx, cy), radius, fill, stroke_width, stroke); } -void PaintBeginnerInfo(Draw& w, Size sz, const char *qtf) -{ - RichText text = ParseQTF(qtf); - text.ApplyZoom(GetRichTextStdScreenZoom()); - - int u = 2 * GetStdFontCy() + DPI(4); - - int cx = min(text.GetWidth(), sz.cx - 2 * u); - int cy = text.GetHeight(cx); - - Rect r = RectC(sz.cx - cx - u, sz.cy - cy - u, cx + DPI(8), cy + DPI(8)); - DrawRoundRect(w, r, DPI(4), Blend(SYellow(), SWhite(), 225), 1, Gray()); - text.Paint(w, r.left + DPI(4), r.top + DPI(4), cx); -} - -void PaintBeginnerInfoTopic(Draw& w, Size sz, const char *topic) -{ - PaintBeginnerInfo(w, sz, GetTopic(topic)); -} - } diff --git a/uppsrc/CtrlLib/CtrlUtil.h b/uppsrc/CtrlLib/CtrlUtil.h index fc8533ddd..581b3886d 100644 --- a/uppsrc/CtrlLib/CtrlUtil.h +++ b/uppsrc/CtrlLib/CtrlUtil.h @@ -537,8 +537,13 @@ void DrawRoundRect(Draw& w, const Rect& r, int radius, Color fill, void DrawRoundRect(Draw& w, int x, int y, int cx, int cy, int radius, Color fill, int stroke_width, Color stroke); -void PaintBeginnerInfo(Draw& w, Size sz, const char *qtf); -void PaintBeginnerInfoTopic(Draw& w, Size sz, const char *topic); +void PaintBeginnerInfo(Draw& w, const Rect& cr, const char *qtf); +void PaintBeginnerInfoTopic(Draw& w, Size sz, const char *topic); + +void PaintBeginnerInfo(Ctrl *ctrl, Draw& w, const Rect& cr, const char *qtf, const char *key); +void PaintBeginnerInfo(Ctrl *ctrl, Draw& w, const char *qtf, const char *key); +void PaintBeginnerInfoTopic(Ctrl *ctrl, Draw& w, const Rect& cr, const char *topic); +void PaintBeginnerInfoTopic(Ctrl *ctrl, Draw& w, const char *topic); void Set(ArrayCtrl& array, int ii, IdCtrls& m); void Get(ArrayCtrl& array, int ii, IdCtrls& m); diff --git a/uppsrc/RichEdit/DiagramEditor.cpp b/uppsrc/RichEdit/DiagramEditor.cpp index bcd5f6629..4cc3d2cec 100644 --- a/uppsrc/RichEdit/DiagramEditor.cpp +++ b/uppsrc/RichEdit/DiagramEditor.cpp @@ -141,10 +141,7 @@ void DiagramEditor::Paint(Draw& w) if(!fast) paint_ms = msecs() - t0; - if(data.item.GetCount() == 0) - PaintBeginnerInfo(w, GetSize(), - "Right-click to insert item(s)&" - "Double-click to edit text"); + PaintBeginnerInfo(this, w, "Right-click to insert item(s)&Double-click to edit text", "#DiagramEditor"); } void DiagramEditor::Sync() diff --git a/uppsrc/ide/Assist.cpp b/uppsrc/ide/Assist.cpp index 9bca0fec3..292b84358 100644 --- a/uppsrc/ide/Assist.cpp +++ b/uppsrc/ide/Assist.cpp @@ -84,8 +84,7 @@ void AssistEditor::EndBeginnerInfo() void AssistEditor::Paint(Draw& w) { CodeEditor::Paint(w); - if(show_beginner_info) - PaintBeginnerInfoTopic(w, GetSize(), "ide/app/EditorBeginnerInfo_en-us"); + PaintBeginnerInfoTopic(this, w, "ide/app/EditorBeginnerInfo_en-us"); } class IndexSeparatorFrameCls : public CtrlFrame { diff --git a/uppsrc/ide/IconDes/Paint.cpp b/uppsrc/ide/IconDes/Paint.cpp index 9213dd665..44cb42221 100644 --- a/uppsrc/ide/IconDes/Paint.cpp +++ b/uppsrc/ide/IconDes/Paint.cpp @@ -110,7 +110,7 @@ void IconDes::Paint(Draw& w) Size sz = GetSize(); if(!IsCurrent()) { w.DrawRect(sz, SColorPaper()); - PaintBeginnerInfoTopic(w, GetSize(), "ide/app/ImlBeginnerInfo_en-us"); + PaintBeginnerInfoTopic(this, w, "ide/app/ImlBeginnerInfo_en-us"); return; } const Image& image = Current().image; @@ -268,4 +268,6 @@ void IconDes::Paint(Draw& w) PaintHotSpot(image.GetHotSpot(), LtRed()); PaintHotSpot(image.Get2ndSpot(), LtBlue()); } + + PaintBeginnerInfoTopic(this, w, "ide/app/ImlBeginnerInfo_en-us"); } diff --git a/uppsrc/ide/LayDes/laydes.cpp b/uppsrc/ide/LayDes/laydes.cpp index 0e0ef7ac2..4badf91f3 100644 --- a/uppsrc/ide/LayDes/laydes.cpp +++ b/uppsrc/ide/LayDes/laydes.cpp @@ -340,8 +340,7 @@ void LayDes::Paint(Draw& w) } } - if(list.GetCount() == 0) - PaintBeginnerInfoTopic(w, GetSize(), "ide/app/LayBeginnerInfo_en-us"); + PaintBeginnerInfoTopic(this, w, "ide/app/LayBeginnerInfo_en-us"); } void LayDes::SaveState() diff --git a/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tpp b/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tpp index ed6dbefa2..f31151f8b 100644 --- a/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tpp +++ b/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tpp @@ -70,8 +70,6 @@ topic "Ctrl+Tab - cycle through files"; :: [s0; [2 Previous file tab.]] :: [s0;%- [*@(0.0.255)2 Ctrl`+Alt`+Right]] :: [s0; [2 Next file tab.]] -:: [s0;%- [*@(0.0.255)2 Ctrl`+Tab]] -:: [s0; [2 Cycle files.]] :: [s0;%- [*@(0.0.255)2 Shift`+Ctrl`+0][*2 ... ][*@(0.0.255)2 Shift`+Ctrl`+9]] :: [s0; [2 Bookmark position.]] :: [s0;%- [*@(0.0.255)2 Ctrl`+0][*2 ... ][*@(0.0.255)2 Ctrl`+9]] diff --git a/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tppi b/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tppi index 1b08009d6..92f9cf03d 100644 --- a/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tppi +++ b/uppsrc/ide/app.tpp/EditorBeginnerInfo_en-us.tppi @@ -1,7 +1,6 @@ TITLE("Ctrl+Tab - cycle through files") COMPRESSED -120,156,149,86,235,78,219,48,20,126,21,75,192,196,160,132,56,205,5,218,105,162,183,141,73,27,67,116,108,211,170,108,205,197,105,172,166,118,229,184,116,8,193,179,207,113,25,52,109,18,167,253,81,181,177,191,203,113,206,119,146,209,165,217,246,207,154,237,35,19,236,239,195,134,190,167,59,103,182,9,77,199,52,45,163,233,88,166,105,232,166,9,161,248,13,45,199,118,156,22,199,60,65,238,72,130,142,33,116,4,206,104,24,123,208,50,237,158,209,235,103,123,187,157,174,222,49,236,158,213,52,251,246,7,8,7,125,216,108,165,11,255,25,42,16,122,166,164,248,180,250,40,242,22,9,119,71,15,127,30,15,6,87,39,183,67,48,74,245,246,215,243,246,211,211,147,6,109,93,111,95,28,234,154,174,25,150,245,214,0,111,4,243,195,131,153,33,197,146,254,14,218,78,251,125,246,245,251,226,80,236,200,118,105,208,210,223,74,18,48,58,90,199,246,56,75,198,199,223,60,223,117,91,173,255,27,196,229,251,32,65,32,194,9,74,181,151,149,131,147,13,240,32,13,242,176, -97,76,151,167,49,14,17,240,41,231,116,6,230,30,65,146,224,194,40,166,88,233,255,114,51,116,3,184,249,197,78,194,199,199,93,47,152,166,115,47,64,107,82,6,184,37,33,173,112,54,140,113,36,176,149,236,207,123,42,68,110,80,165,200,138,253,103,37,123,31,37,136,231,89,123,11,174,36,237,21,147,174,22,63,145,20,49,158,231,164,243,123,144,10,173,128,99,74,0,142,64,136,34,76,80,216,0,193,130,49,68,56,72,196,95,64,121,140,216,18,167,72,233,224,123,101,89,5,22,174,189,148,87,209,22,156,196,234,82,137,111,42,236,6,177,199,188,128,35,182,131,241,78,78,98,40,185,129,151,36,74,224,237,60,143,12,24,77,18,176,152,43,129,125,186,36,69,208,80,92,87,130,175,189,9,18,202,21,183,251,146,206,242,199,214,69,19,76,0,141,128,56,19,153,209,90,34,210,101,133,204,128,132,57,21,241,127,39,141,242,251,43,230,1,225,56,194,226,54,70,76,12,5,209,145,41,101,128,83,128,72,168,228,45,142,166,146,218,207,14,137,96,50,81,10,124, -70,209,70,39,51,116,135,233,34,5,75,202,212,254,110,240,36,206,227,175,208,95,94,15,59,30,109,3,103,30,15,98,225,27,248,162,245,167,72,61,43,198,110,177,251,29,136,242,243,223,0,63,98,68,214,99,153,190,198,18,147,236,200,215,22,89,86,127,221,81,188,145,177,47,244,14,201,193,116,250,202,87,25,184,28,217,86,238,138,232,20,33,148,211,191,220,155,232,187,169,200,142,76,64,181,179,53,162,98,95,57,170,58,174,10,2,117,131,102,155,84,42,150,141,170,94,186,99,23,142,173,130,100,163,238,194,176,149,177,143,34,161,2,175,194,109,135,75,0,35,202,150,94,101,186,36,54,27,122,64,81,126,45,142,202,242,213,207,163,194,250,95,140,200,118,224,158,95,143,167,100,216,212,38,217,12,122,189,247,188,92,234,116,249,16,1,154,166,149,188,27,172,182,157,231,31,89,148,78,103,30,155,130,57,77,113,150,75,165,211,114,153,34,126,209,21,217,204,127,86,65,97,29,29,121,160,229,50,114,185,72,101,237,176,31,31,197,187,119,182,232,186,255,0,235,208, -121,176, +120,156,149,86,235,78,219,48,24,125,21,75,192,196,160,132,56,205,5,218,105,162,183,141,73,27,67,116,108,211,170,108,205,197,105,172,166,118,229,184,116,8,193,179,207,113,25,52,109,18,167,253,81,53,177,207,197,246,119,62,119,116,105,182,253,179,102,251,200,4,251,251,176,161,239,233,206,153,109,66,211,49,77,203,104,58,150,105,26,186,105,66,40,126,67,203,177,29,167,197,49,79,144,59,146,160,99,8,29,129,51,26,198,30,180,76,187,103,244,250,217,220,110,167,171,119,12,187,103,53,205,190,253,1,194,65,31,54,91,233,194,127,134,10,132,158,41,41,62,173,62,138,188,69,194,221,209,195,159,199,131,193,213,201,237,16,140,82,189,253,245,188,253,244,244,164,65,91,215,219,23,135,186,166,107,134,101,189,53,192,27,193,252,240,96,102,72,49,164,191,131,182,211,126,159,125,253,190,56,20,51,178,89,26,180,244,183,146,4,140,142,214,177,61,206,146,241,241,55,207,119,221,86,235,255,4,241,250,62,72,16,136,112,130,82,237,101,228,224,100,3,60,72,131,60,108, +24,211,229,105,140,67,4,124,202,57,157,129,185,71,144,36,184,48,138,41,86,250,191,220,12,221,0,110,126,176,147,240,241,113,215,11,166,233,220,11,208,154,148,1,110,73,72,43,156,13,99,28,9,108,37,251,243,156,10,145,27,84,41,178,98,255,89,201,222,71,9,226,121,214,222,130,43,73,123,197,164,171,193,79,36,69,140,231,57,233,252,30,164,66,43,224,152,18,128,35,16,162,8,19,20,54,64,176,96,12,17,14,18,241,8,40,143,17,91,226,20,41,29,124,175,92,86,129,133,107,47,229,85,180,5,59,177,122,85,226,155,10,187,65,236,49,47,224,136,237,96,188,147,147,24,74,110,224,37,137,18,120,59,207,35,3,70,147,4,44,230,74,96,159,46,73,17,52,20,239,149,224,107,111,130,132,114,197,113,95,210,89,126,219,186,104,130,9,160,17,16,123,34,51,90,75,68,186,172,144,25,144,48,167,34,158,119,210,40,63,95,209,15,8,199,17,22,199,24,49,209,20,68,69,166,148,1,78,1,34,161,146,183,56,154,74,106,63,219,36,130,201,68,41,240,25, +69,27,149,204,208,29,166,139,20,44,41,83,251,187,193,147,56,143,191,66,127,121,61,236,120,180,13,156,121,60,136,133,111,224,139,210,159,34,117,175,24,187,197,238,119,32,202,247,127,3,252,136,17,89,143,101,250,26,75,76,178,45,95,27,100,217,250,235,182,226,141,140,125,161,119,72,54,166,211,87,190,202,192,229,200,182,114,87,68,167,8,161,236,254,229,222,68,221,77,69,118,100,2,170,157,173,17,21,251,202,81,213,113,85,16,168,27,52,219,164,82,177,108,172,234,165,58,118,225,216,90,144,44,212,93,24,182,50,246,81,36,84,224,85,184,237,112,9,96,68,217,210,171,76,151,196,102,77,15,40,150,95,139,163,114,249,234,251,168,112,253,47,70,100,57,112,207,175,199,83,210,108,106,144,228,146,163,203,139,0,104,154,86,114,191,175,166,157,231,175,29,74,167,51,143,77,193,156,166,56,203,150,210,114,185,76,17,191,56,217,172,111,63,171,160,176,142,142,220,148,114,25,57,92,164,178,182,97,143,143,226,255,115,54,232,186,255,0,36,122,105,27,