Draw: attempt at workaround of iml / clang optimisation bug, cosmetics

This commit is contained in:
Mirek Fidler 2024-10-21 22:48:00 +02:00
parent 81d8461744
commit 509e32c7f4
5 changed files with 32 additions and 24 deletions

View file

@ -144,7 +144,7 @@ protected:
void RefreshAll();
int LowChar(int c) const { return 0x25af /*c + 0x2400*/; }
int GetCharWidth(int c) const { return font[c < 32 ? LowChar(c) : c]; }
int GetTextCx(const wchar *text, int n, bool password, Font fnt) const;
int GetTextCx(const wchar *text, int n, bool password) const;
void Paints(Draw& w, int& x, int fcy, const wchar *&txt,
Color ink, Color paper, int n, bool pwd, Font fnt, Color underline, bool showspaces);
int GetStringCx(const wchar *text, int n);

View file

@ -148,7 +148,7 @@ void EditField::CancelMode()
dropcaret.Clear();
}
int EditField::GetTextCx(const wchar *txt, int n, bool password, Font fnt) const
int EditField::GetTextCx(const wchar *txt, int n, bool password) const
{
if(password)
return n * font['*'];
@ -161,7 +161,7 @@ int EditField::GetTextCx(const wchar *txt, int n, bool password, Font fnt) const
int EditField::GetCaret(int cursor) const
{
return GetTextCx(text, cursor, password, font);
return GetTextCx(text, cursor, password);
}
int EditField::GetViewHeight(Font font)
@ -250,7 +250,7 @@ void EditField::Paints(Draw& w, int& x, int fcy, const wchar *&txt,
bool showspaces)
{
if(n < 0) return;
int cx = GetTextCx(txt, n, password, font);
int cx = GetTextCx(txt, n, password);
w.DrawRect(x, 0, cx, fcy, paper);
if(password) {
String h;

View file

@ -49,18 +49,30 @@ void Iml::Init(int n)
void Iml::Reset()
{
int n = map.GetCount();
map.Clear();
Init(n);
for(IImage& m : map)
m.loaded = false;
}
static StaticMutex sImlLock;
void Iml::Set(int i, const Image& img)
{
{ // TODO: MT
map[i].image = img;
map[i].loaded = true;
}
static StaticMutex sImlLock;
Image Iml::Get(int i)
{
IImage& m = map[i];
if(!m.loaded) {
Mutex::Lock __(sImlLock);
if(!m.loaded) {
m.image = MakeImlImage(GetId(i), [&](int mode, const String& id) { return GetRaw(mode, id); }, global_flags);
m.loaded = true;
}
}
return m.image;
}
ImageIml Iml::GetRaw(int mode, int i)
{
@ -141,19 +153,6 @@ Image MakeImlImage(const String& id, Function<ImageIml(int, const String& id)> G
return im.image;
}
Image Iml::Get(int i)
{
IImage& m = map[i];
if(!m.loaded) {
Mutex::Lock __(sImlLock);
if(!m.loaded) {
m.image = MakeImlImage(GetId(i), [&](int mode, const String& id) { return GetRaw(mode, id); }, global_flags);
m.loaded = true;
}
}
return m.image;
}
Iml::Iml(const char **name, int n)
: name(name)
{

View file

@ -39,8 +39,8 @@ public:
static void Reset() { Iml().Reset(); }
#define IMAGE_BEGIN(n) static UPP::Image n() { return Get(I_##n); }
#define IMAGE_ID(n) static UPP::Image n() { return Get(I_##n); }
#define IMAGE_BEGIN(n) static UPP::Image n();
#define IMAGE_ID(n) static UPP::Image n();
#include IMAGEFILE
#undef IMAGE_BEGIN
#undef IMAGE_ID

View file

@ -151,6 +151,15 @@ struct COMBINE(IMAGECLASS, __Reg) {
static COMBINE(IMAGECLASS, __Reg) COMBINE(IMAGECLASS, ___Reg);
#undef IMAGE_BEGIN
#undef IMAGE_ID
#define IMAGE_BEGIN(n) UPP::Image IMAGECLASS::n() { return Get(I_##n); }
#define IMAGE_ID(n) UPP::Image IMAGECLASS::n() { return Get(I_##n); }
#include IMAGEFILE
#undef IMAGE_BEGIN
#undef IMAGE_ID
#undef IMAGE_BEGIN_DATA
#undef IMAGE_DATA
#undef IMAGE_END_DATA