Skip to content

Commit

Permalink
ide: PDB Color, RGBA support
Browse files Browse the repository at this point in the history
git-svn-id: svn://ultimatepp.org/upp/trunk@13731 f0d560ea-af0d-0410-9eb7-867de7ffcac7
  • Loading branch information
cxl committed Dec 3, 2019
1 parent fef24c6 commit 90b9b0e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 16 deletions.
9 changes: 8 additions & 1 deletion uppsrc/ide/Debuggers/Pdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ struct Pdb : Debugger, ParentCtrl {
String text;
Color ink;
bool mark;

Size GetSize() const;
};

struct Visual {
Expand Down Expand Up @@ -257,7 +259,10 @@ struct Pdb : Debugger, ParentCtrl {
int64 data_count; // number of entries
Vector<String> data_type; // type of data items (usuallt type_param)
Vector<adr_t> data_ptr; // pointer to items (data_count.GetCount() * data_type.GetCount() items)
String text;
Visual text;

void Text(const char *s, Color color = SRed) { text.Cat(s, color); }
void SetNull() { Text("Null", SCyan); }
};

VectorMap<String, Tuple<int, Event<Val, const Vector<String>&, int64, int, Pdb::Pretty&>>> pretty;
Expand Down Expand Up @@ -403,6 +408,8 @@ struct Pdb : Debugger, ParentCtrl {
void PrettyArrayMap(Val val, const Vector<String>& tparam, int64 from, int count, Pretty& p);
void PrettyDate(Pdb::Val val, const Vector<String>& tparam, int64 from, int count, Pdb::Pretty& p);
void PrettyTime(Pdb::Val val, const Vector<String>& tparam, int64 from, int count, Pdb::Pretty& p);
void PrettyColor(Pdb::Val val, const Vector<String>&, int64 from, int count, Pdb::Pretty& p);
void PrettyRGBA(Pdb::Val val, const Vector<String>&, int64 from, int count, Pdb::Pretty& p);
void PrettyValueArray_(adr_t a, Pdb::Pretty& p);
void PrettyValueArray(Pdb::Val val, const Vector<String>&, int64 from, int count, Pdb::Pretty& p);
void PrettyValue(Pdb::Val val, const Vector<String>& tparam, int64 from, int count, Pretty& p);
Expand Down
54 changes: 44 additions & 10 deletions uppsrc/ide/Debuggers/Pretty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

// THIS is currently hardwired to the current version of U++ Core...

// TODO: from->int64

void Pdb::PrettyString(Pdb::Val val, const Vector<String>& tparam, int64 from, int count, Pdb::Pretty& p)
{
bool small = IntAt(val, "chr", 14) == 0;
Expand Down Expand Up @@ -99,10 +97,10 @@ void Pdb::PrettyDate(Pdb::Val val, const Vector<String>&, int64 from, int count,
int year = GetIntAttr(val, "year");
p.kind = SINGLE_VALUE;
if(year < -20000)
p.text = "Null";
p.SetNull();
else
if(day >= 0 && day <= 31 && month >= 1 && month <= 12 && year > 1900 && year < 3000)
p.text = Format("%04d/%02d/%02d", year, month, day);
p.Text(Format("%04d/%02d/%02d", year, month, day));
}

void Pdb::PrettyTime(Pdb::Val val, const Vector<String>&, int64 from, int count, Pdb::Pretty& p)
Expand All @@ -115,11 +113,43 @@ void Pdb::PrettyTime(Pdb::Val val, const Vector<String>&, int64 from, int count,
int second = GetIntAttr(val, "second");
p.kind = SINGLE_VALUE;
if(year < -20000)
p.text = "Null";
p.SetNull();
else
if(day >= 1 && day <= 31 && month >= 1 && month <= 12 && year > 1900 && year < 3000 &&
hour >= 0 && hour <= 24 && minute >= 0 && minute < 60 && second >= 0 && second < 60)
p.text = Format("%04d/%02d/%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
p.Text(Format("%04d/%02d/%02d %02d:%02d:%02d", year, month, day, hour, minute, second));
}

void Pdb::PrettyColor(Pdb::Val val, const Vector<String>&, int64 from, int count, Pdb::Pretty& p)
{
dword color = GetIntAttr(val, "color");
Color c = Color::FromRaw(color);
if(IsNull(c))
p.SetNull();
else {
p.Text("\1", c);
p.Text(" ");
p.Text(ColorToHtml(c));
}
p.kind = SINGLE_VALUE;
}

void Pdb::PrettyRGBA(Pdb::Val val, const Vector<String>&, int64 from, int count, Pdb::Pretty& p)
{
RGBA rc;
rc.r = GetIntAttr(val, "r");
rc.g = GetIntAttr(val, "g");
rc.b = GetIntAttr(val, "b");
rc.a = 255;

Color c(rc);

p.Text("\1", c);
p.Text(" ");
p.Text(ColorToHtml(c));
p.Text(", a: " + AsString(GetIntAttr(val, "a")));

p.kind = SINGLE_VALUE;
}

void Pdb::PrettyValueArray_(adr_t a, Pdb::Pretty& p)
Expand Down Expand Up @@ -176,11 +206,12 @@ void Pdb::PrettyValue(Pdb::Val val, const Vector<String>&, int64 from, int count
}
p.data_ptr << a;
if(st == 3) {
p.text = "void";
p.Text("void", SCyan);
return;
}
String t = decode(st, 1, "int", 2, "double", 4, "Upp::Date", 5, "Upp::Time",
10, "int64", 11, "bool", "");
10, "int64", 11, "bool", 39, "Upp::Color",
"");
if(t.GetCount())
p.data_type << t;
}
Expand Down Expand Up @@ -270,6 +301,8 @@ bool Pdb::PrettyVal(Pdb::Val val, int64 from, int count, Pretty& p)
if(pretty.GetCount() == 0) {
pretty.Add("Upp::Date", { 0, THISFN(PrettyDate) });
pretty.Add("Upp::Time", { 0, THISFN(PrettyTime) });
pretty.Add("Upp::Color", { 0, THISFN(PrettyColor) });
pretty.Add("Upp::RGBA", { 0, THISFN(PrettyRGBA) });
pretty.Add("Upp::ValueArray", { 0, THISFN(PrettyValueArray) });
pretty.Add("Upp::ValueMap", { 0, THISFN(PrettyValueMap) });
pretty.Add("Upp::Value", { 0, THISFN(PrettyValue) });
Expand Down Expand Up @@ -336,8 +369,9 @@ bool Pdb::VisualisePretty(Visual& result, Pdb::Val val, dword flags)
if(p.kind == SINGLE_VALUE) {
Pretty p;
PrettyVal(val, 0, 1, p);
if(p.text.GetCount())
result.Cat(p.text, SRed);
if(p.text.part.GetCount())
for(const VisualPart& vp : p.text.part)
result.Cat(vp.text, vp.ink);
else
if(p.data_type.GetCount() && p.data_ptr.GetCount())
Visualise(result, MakeVal(p.data_type[0], p.data_ptr[0]), flags);
Expand Down
23 changes: 18 additions & 5 deletions uppsrc/ide/Debuggers/Visualise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void Pdb::Visualise(Visual& result, Pdb::Val val, dword flags)
}
if(val.type < 0) { // Display primitive type
#define RESULTINT(x, type) case x: CatInt(result, (type)val.ival, flags); break;
#define RESULTINTN(x, type, t2) case x: if(IsNull((t2)val.ival)) result.Cat("Null ", Magenta); CatInt(result, (type)val.ival, flags); break;
#define RESULTINTN(x, type, t2) case x: if(IsNull((t2)val.ival)) result.Cat("Null ", SCyan); CatInt(result, (type)val.ival, flags); break;
switch(val.type) {
RESULTINT(BOOL1, bool)
RESULTINT(UINT1, byte)
Expand All @@ -177,7 +177,7 @@ void Pdb::Visualise(Visual& result, Pdb::Val val, dword flags)
case DBL:
case FLT:
if(IsNull(val.fval))
result.Cat("Null", SMagenta);
result.Cat("Null", SCyan);
else
if(IsInf(val.fval))
result.Cat("INF", SMagenta);
Expand Down Expand Up @@ -326,14 +326,19 @@ Pdb::Visual Pdb::Visualise(const String& exp, dword flags)
return r;
}

Size Pdb::VisualPart::GetSize() const
{
return GetTextSize(*text < 32 ? "MM" : ~text, StdFont());
}

Size Pdb::VisualDisplay::GetStdSize(const Value& q) const
{
if(!IsType<Visual>(q))
return StdDisplay().GetStdSize(q);
Size sz(0, GetStdFontCy());
if(IsType<Visual>(q))
for(const VisualPart& p : ValueTo<Visual>(q).part)
sz.cx += GetTextSize(p.text, StdFont()).cx;
sz.cx += p.GetSize().cx;
return sz;
}

Expand All @@ -348,10 +353,18 @@ void Pdb::VisualDisplay::Paint(Draw& w, const Rect& r, const Value& q,
int y = r.top + (r.Height() - Draw::GetStdFontCy()) / 2;
bool blue = (style & (Display::CURSOR|Display::FOCUS)) == (Display::CURSOR|Display::FOCUS);
for(const VisualPart& p : ValueTo<Visual>(q).part) {
Size sz = GetTextSize(p.text, StdFont());
Size sz = p.GetSize();
w.DrawRect(x, y, sz.cx, r.Height(),
blue || !p.mark ? paper : HighlightSetup::GetHlStyle(HighlightSetup::PAPER_SELWORD).color);
w.DrawText(x, y, p.text, StdFont(), blue ? ink : p.ink);
if(*p.text == '\1') { // Color support
Rect r = RectC(x, y, sz.cx, sz.cy);
r.Deflate(DPI(1));
w.DrawRect(r, SBlack);
r.Deflate(DPI(1));
w.DrawRect(r, p.ink);
}
else
w.DrawText(x, y, p.text, StdFont(), blue ? ink : p.ink);
x += sz.cx;
}
w.DrawRect(x, y, r.right - x, r.Height(), paper);
Expand Down

0 comments on commit 90b9b0e

Please sign in to comment.