mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: DarkTheme adjustments, CtrlLib: Color widgets, RichEdit: AllowDarkContent, DarkContent, ide: RichEdits in theide now support dark theme
This commit is contained in:
parent
20224719d5
commit
ff7102c39b
25 changed files with 287 additions and 948 deletions
|
|
@ -258,6 +258,7 @@ UWord::UWord()
|
|||
static int doc;
|
||||
Title(Format("Document%d", ++doc));
|
||||
Icon(CtrlImg::File());
|
||||
editor.AllowDarkContent();
|
||||
editor.ClearModify();
|
||||
SetBar();
|
||||
editor.WhenRefreshBar = THISBACK(SetBar);
|
||||
|
|
|
|||
|
|
@ -361,7 +361,7 @@ Color DarkTheme(Color color)
|
|||
|
||||
double target = 255 - Saturate255(int(Val() + saturation));
|
||||
if(target < 30)
|
||||
target *= (1 + (30 - target) / 30) * 1.5;
|
||||
target *= (1 / 1.5 + (29 - target) / 29) * 1.5;
|
||||
double ratio = target / 128;
|
||||
|
||||
double m = max(r, g, b);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,22 @@ s_colors[] = {
|
|||
|
||||
Color ColorPopUp::hint[18];
|
||||
|
||||
ColorPopUp& ColorPopUp::DarkContent(bool b)
|
||||
{
|
||||
wheel.DarkContent(b);
|
||||
ramp.DarkContent(b);
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColorPopUp& ColorPopUp::AllowDarkContent(bool b)
|
||||
{
|
||||
wheel.AllowDarkContent(b);
|
||||
ramp.AllowDarkContent(b);
|
||||
Refresh();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ColorPopUp_InitHint()
|
||||
{
|
||||
for(int i = 0; i < 18; i++)
|
||||
|
|
@ -193,12 +209,13 @@ void ColorPopUp::Paint(Draw& w)
|
|||
}
|
||||
|
||||
int i = 0;
|
||||
bool dark = IsDarkContent();
|
||||
for(;;) {
|
||||
for(int x = 0; x < 18 * DPI(16); x += DPI(16)) {
|
||||
if(i >= GetColorCount()) {
|
||||
if(!norampwheel) {
|
||||
Rect r(DPI(8 * 16 + 1), cy + DPI(4), DPI(10 * 16 - 1), sz.cy - DPI(4) - DPI(24));
|
||||
DrawFilledFrame(w, r, SColorText, color);
|
||||
DrawFilledFrame(w, r, SColorText, dark ? DarkThemeCached(color) : color);
|
||||
|
||||
r.Inflate(1);
|
||||
if(colori == 999) {
|
||||
|
|
@ -212,9 +229,9 @@ void ColorPopUp::Paint(Draw& w)
|
|||
}
|
||||
|
||||
Color c = RealizeColor(GetColor(i));
|
||||
DrawFilledFrame(w, x + DPI(1), y, DPI(14), DPI(14), SColorText, c);
|
||||
DrawFilledFrame(w, x + DPI(1), y, DPI(14), DPI(14), SColorText, dark ? DarkThemeCached(c) : c);
|
||||
if(i < 18 && scolors)
|
||||
w.DrawRect(x + DPI(2) + DPI(6), y + DPI(1), DPI(6), DPI(12), DarkThemeCached(c));
|
||||
w.DrawRect(x + DPI(2) + DPI(6), y + DPI(1), DPI(6), DPI(12), dark ? c : DarkThemeCached(c));
|
||||
|
||||
if(i == colori) {
|
||||
if(GetMouseLeft())
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ void ColorPusher::Paint(Draw& w)
|
|||
w.DrawRect(x + cx / 2, y, cx - cx / 2, cy, DarkTheme(c));
|
||||
}
|
||||
else
|
||||
w.DrawRect(x, y, cx, cy, color);
|
||||
w.DrawRect(x, y, cx, cy, colors.IsDarkContent() ? DarkTheme(color) : color);
|
||||
};
|
||||
if(withtext || withhex) {
|
||||
DrawColor(2, 2, sz.cy - 4, sz.cy - 4);
|
||||
|
|
@ -145,7 +145,7 @@ void ColorButton::Paint(Draw& w)
|
|||
if(IsNull(color))
|
||||
w.DrawImage(center.x + push, center.y + push, nullimage);
|
||||
else
|
||||
w.DrawImage(center.x + push, center.y + push, image, color);
|
||||
w.DrawImage(center.x + push, center.y + push, image, colors.IsDarkContent() ? DarkTheme(color) : color);
|
||||
w.DrawImage(center.x + push, center.y + push, staticimage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,41 +65,6 @@ LAYOUT(FileSelectorLayout, 652, 488)
|
|||
ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 68).BottomPosZ(8, 24))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(PaletteLayout, 216, 332)
|
||||
ITEM(Upp::TabCtrl, palette_tab, HSizePosZ(4, 4).VSizePosZ(4, 82))
|
||||
ITEM(Upp::Label, dv___1, SetLabel(t_("Color:")).LeftPosZ(4, 36).BottomPosZ(52, 24))
|
||||
ITEM(Upp::DataPusher, color, HSizePosZ(68, 32).BottomPosZ(54, 22))
|
||||
ITEM(Upp::Button, set_transparent, RightPosZ(4, 18).BottomPosZ(56, 18))
|
||||
UNTYPED(fetch_color, RightPosZ(4, 18).BottomPosZ(30, 18))
|
||||
ITEM(Upp::Label, dv___5, SetLabel(t_("R:")).LeftPosZ(4, 12).BottomPosZ(29, 19))
|
||||
ITEM(Upp::EditIntSpin, r, LeftPosZ(16, 44).BottomPosZ(29, 19))
|
||||
ITEM(Upp::Label, dv___7, SetLabel(t_("G:")).LeftPosZ(72, 12).BottomPosZ(29, 19))
|
||||
ITEM(Upp::EditIntSpin, g, LeftPosZ(84, 44).BottomPosZ(29, 19))
|
||||
ITEM(Upp::Label, dv___9, SetLabel(t_("B:")).LeftPosZ(136, 12).BottomPosZ(29, 19))
|
||||
ITEM(Upp::EditIntSpin, b, LeftPosZ(150, 42).BottomPosZ(29, 19))
|
||||
ITEM(Upp::Label, dv___11, SetLabel(t_("H:")).LeftPosZ(4, 12).BottomPosZ(5, 19))
|
||||
ITEM(Upp::EditIntSpin, h, LeftPosZ(16, 44).BottomPosZ(5, 19))
|
||||
ITEM(Upp::Label, dv___13, SetLabel(t_("S:")).LeftPosZ(72, 12).BottomPosZ(5, 19))
|
||||
ITEM(Upp::EditIntSpin, s, LeftPosZ(84, 44).BottomPosZ(5, 19))
|
||||
ITEM(Upp::Label, dv___15, SetLabel(t_("V:")).LeftPosZ(136, 12).BottomPosZ(5, 19))
|
||||
ITEM(Upp::EditIntSpin, v, LeftPosZ(148, 44).BottomPosZ(5, 19))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(PaletteSelectorLayout, 248, 320)
|
||||
ITEM(Ctrl, palette, HSizePosZ(4, 4).VSizePosZ(4, 32))
|
||||
ITEM(Upp::Button, ok, SetLabel(t_("OK")).RightPosZ(88, 80).BottomPosZ(4, 22))
|
||||
ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 80).BottomPosZ(4, 22))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(PalCtrlSizeLayout, 206, 60)
|
||||
ITEM(Upp::Label, dv___0, SetLabel(t_("&Rows:")).LeftPosZ(4, 44).TopPosZ(4, 19))
|
||||
ITEM(Upp::EditIntSpin, rows, LeftPosZ(48, 50).TopPosZ(4, 19))
|
||||
ITEM(Upp::Label, dv___2, SetLabel(t_("&Columns:")).LeftPosZ(108, 44).TopPosZ(4, 19))
|
||||
ITEM(Upp::EditIntSpin, columns, LeftPosZ(152, 50).TopPosZ(4, 19))
|
||||
ITEM(Upp::Button, ok, SetLabel(t_("OK")).RightPosZ(88, 80).BottomPosZ(4, 22))
|
||||
ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 80).BottomPosZ(4, 22))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(KeysLayout, 604, 500)
|
||||
ITEM(Upp::ArrayCtrl, group, LeftPosZ(8, 116).TopPosZ(8, 452))
|
||||
ITEM(Upp::ArrayCtrl, keys, LeftPosZ(132, 464).TopPosZ(8, 452))
|
||||
|
|
|
|||
|
|
@ -1,86 +1,7 @@
|
|||
#include "CtrlLib.h"
|
||||
|
||||
namespace Upp {
|
||||
|
||||
class FetchColorCtrl : public Button
|
||||
{
|
||||
public:
|
||||
FetchColorCtrl();
|
||||
|
||||
void SetData(const Value& v);
|
||||
Value GetData() const;
|
||||
|
||||
virtual void LeftDown(Point pt, dword keyflags);
|
||||
virtual void MouseMove(Point pt, dword keyflags);
|
||||
virtual bool Key(dword key, int repcnt);
|
||||
virtual Image CursorImage(Point pt, dword keyflags);
|
||||
|
||||
private:
|
||||
Color user_color;
|
||||
Color std_color;
|
||||
};
|
||||
|
||||
FetchColorCtrl::FetchColorCtrl()
|
||||
{
|
||||
SetImage(CtrlImg::fetch_color());
|
||||
}
|
||||
|
||||
void FetchColorCtrl::SetData(const Value& v)
|
||||
{
|
||||
if(IsNull(user_color))
|
||||
std_color = v;
|
||||
}
|
||||
|
||||
Value FetchColorCtrl::GetData() const
|
||||
{
|
||||
return Nvl(user_color, std_color);
|
||||
}
|
||||
|
||||
void FetchColorCtrl::LeftDown(Point pt, dword keyflags)
|
||||
{
|
||||
Button::LeftDown(pt, keyflags);
|
||||
SetCapture();
|
||||
SetWantFocus();
|
||||
}
|
||||
|
||||
void FetchColorCtrl::MouseMove(Point pt, dword keyflags)
|
||||
{
|
||||
if(keyflags & K_MOUSELEFT)
|
||||
{
|
||||
if(Rect(GetSize()).Contains(pt))
|
||||
{
|
||||
user_color = Null;
|
||||
Action();
|
||||
}
|
||||
else
|
||||
{
|
||||
pt += GetScreenView().TopLeft();
|
||||
user_color = GuiPlatformGetScreenPixel(pt.x, pt.y);
|
||||
Action();
|
||||
}
|
||||
}
|
||||
Button::MouseMove(pt, keyflags);
|
||||
}
|
||||
|
||||
bool FetchColorCtrl::Key(dword key, int repcnt)
|
||||
{
|
||||
if(key == K_ESCAPE && HasCapture())
|
||||
{
|
||||
ReleaseCapture();
|
||||
user_color = Null;
|
||||
Action();
|
||||
return true;
|
||||
}
|
||||
return Button::Key(key, repcnt);
|
||||
}
|
||||
|
||||
Image FetchColorCtrl::CursorImage(Point pt, dword keyflags)
|
||||
{
|
||||
if(keyflags & K_MOUSELEFT)
|
||||
return CtrlImg::fetch_color_cursor();
|
||||
return Button::CursorImage(pt, keyflags);
|
||||
}
|
||||
|
||||
|
||||
const Display& StdColorDisplayNull()
|
||||
{
|
||||
static ColorDisplayNull display(t_("(no color)"));
|
||||
|
|
@ -475,6 +396,8 @@ Image WheelRampCtrl::PaintRamp(Size size)
|
|||
for(int x = 0; x < PREC; x++) {
|
||||
int s16 = iscale(x, 65535, PREC - 1);
|
||||
Color c = HSV16toRGB(h16, s16, v16);
|
||||
if(IsDarkContent())
|
||||
c = DarkTheme(c);
|
||||
scan->r = GetRRaw(c);
|
||||
scan->g = GetGRaw(c);
|
||||
scan->b = GetBRaw(c);
|
||||
|
|
@ -510,16 +433,22 @@ Image WheelRampCtrl::PaintWheel(Size size)
|
|||
for(int y = 0; y < PREC; y++) {
|
||||
RGBA *scan = ib[y];
|
||||
for(int x = 0; x < PREC; x++) {
|
||||
*scan++ = HSV16toRGB(cwb->arg, cwb->l, v16);
|
||||
Color c = HSV16toRGB(cwb->arg, cwb->l, v16);
|
||||
if(IsDarkContent())
|
||||
c = DarkTheme(c);
|
||||
*scan++ = c;
|
||||
cwb++;
|
||||
}
|
||||
}
|
||||
|
||||
ImageDraw iw(size);
|
||||
ImagePainter iw(size);
|
||||
iw.Clear();
|
||||
Sizef s2 = (Sizef)(size) / 2;
|
||||
iw.Begin();
|
||||
iw.Ellipse(s2.cx, s2.cy, s2.cx, s2.cy).Clip();
|
||||
iw.DrawImage(size, Rescale(ib, size));
|
||||
iw.DrawEllipse(size, Null, 0, Black);
|
||||
iw.Alpha().DrawRect(size, GrayColor(0));
|
||||
iw.Alpha().DrawEllipse(size, GrayColor(255), 0, GrayColor(255));
|
||||
iw.End();
|
||||
iw.Ellipse(s2.cx, s2.cy, s2.cx - 1, s2.cy - 1).Stroke(1, SBlack());
|
||||
return iw;
|
||||
}
|
||||
|
||||
|
|
@ -539,7 +468,7 @@ void WheelRampCtrl::PaintColumn(Draw& draw)
|
|||
int factor = ClientToLevel(i);
|
||||
Color c = ramp ? HSV16toRGB(factor, 65535, 65535) : HSV16toRGB(h16, s16, factor);
|
||||
// : Color(iscale(nr, factor, 65536), iscale(ng, factor, 65536), iscale(nb, factor, 65536));
|
||||
draw.DrawRect(column_rect.left, i, size.cx, 1, c);
|
||||
draw.DrawRect(column_rect.left, i, size.cx, 1, IsDarkContent() ? DarkThemeCached(c) : c);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -898,714 +827,4 @@ static void InitColor(Color *out)
|
|||
out[15] = Color(0x00, 0xFF, 0xFF);
|
||||
};
|
||||
|
||||
PalCtrl::Config& PalCtrl::GlobalConfig()
|
||||
{
|
||||
static PalCtrl::Config x;
|
||||
return x;
|
||||
}
|
||||
|
||||
typedef Index<PalCtrl *> PalCtrlIndex;
|
||||
|
||||
PalCtrlIndex& PalCtrl::GetActive()
|
||||
{
|
||||
static PalCtrlIndex x;
|
||||
return x;
|
||||
}
|
||||
|
||||
PalCtrl::PalCtrl()
|
||||
{
|
||||
color = Null;
|
||||
color_index = -1;
|
||||
swap_index = -1;
|
||||
cellcount = Size(4, 4);
|
||||
Transparent();
|
||||
}
|
||||
|
||||
PalCtrl::~PalCtrl()
|
||||
{
|
||||
GetActive().RemoveKey(this);
|
||||
}
|
||||
|
||||
Vector<Color> PalCtrl::GetPalette()
|
||||
{
|
||||
int count = MAXSIZE;
|
||||
while(count > 0 && IsNull(GlobalConfig().current[count - 1]))
|
||||
count--;
|
||||
Vector<Color> out;
|
||||
out.SetCount(count);
|
||||
for(int i = 0; i < count; i++)
|
||||
out[i] = GlobalConfig().current[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void PalCtrl::SetPalette(const Vector<Color>& pal)
|
||||
{
|
||||
for(int n = min<int>(pal.GetCount(), MAXSIZE), i = 0; i < n; i++)
|
||||
GlobalConfig().current[i] = pal[i];
|
||||
PalCtrlIndex& active = GetActive();
|
||||
for(int c = 0; c < active.GetCount(); c++)
|
||||
active[c]->Refresh();
|
||||
}
|
||||
|
||||
void PalCtrl::SerializePalette(Stream& stream)
|
||||
{
|
||||
int version = StreamHeading(stream, 1, 1, 1, "PalCtrl::Palette");
|
||||
if(version >= 1)
|
||||
{
|
||||
int count = cellcount.cx * cellcount.cy;
|
||||
stream / count;
|
||||
for(int i = 0; i < count; i++)
|
||||
stream % GlobalConfig().current[i];
|
||||
}
|
||||
}
|
||||
|
||||
INITBLOCK
|
||||
{
|
||||
RegisterGlobalConfig("PalCtrl", callback(&PalCtrl::FlushConfig));
|
||||
}
|
||||
|
||||
void PalCtrl::Config::Serialize(Stream& stream)
|
||||
{
|
||||
if(stream.IsLoading() && stream.IsEof())
|
||||
return;
|
||||
int version = 1;
|
||||
stream / version;
|
||||
if(stream.IsError() || version < 1 || version > 1)
|
||||
{
|
||||
stream.SetError();
|
||||
return;
|
||||
}
|
||||
int count = __countof(current);
|
||||
stream / count;
|
||||
count = min<int>(count, MAXSIZE);
|
||||
for(int i = 0; i < count; i++)
|
||||
stream % current[i];
|
||||
stream % lastsize % lastfile;
|
||||
}
|
||||
|
||||
void PalCtrl::Load()
|
||||
{
|
||||
Config& gc = GlobalConfig();
|
||||
if(!gc.loaded)
|
||||
{
|
||||
gc.loaded = true;
|
||||
InitColor(gc.current);
|
||||
LoadFromGlobal(gc, "PalCtrl");
|
||||
cellcount = gc.lastsize;
|
||||
Layout();
|
||||
UpdateColorIndex();
|
||||
}
|
||||
}
|
||||
|
||||
void PalCtrl::SetData(const Value& value)
|
||||
{
|
||||
if(Color(value) != color)
|
||||
{
|
||||
color = value;
|
||||
UpdateColorIndex();
|
||||
UpdateRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
void PalCtrl::UpdateColorIndex()
|
||||
{
|
||||
Config& gc = GlobalConfig();
|
||||
if(gc.loaded)
|
||||
color_index =(int)( UPP::Find(gc.current,
|
||||
gc.current + __countof(gc.current), color, StdEqual<int>()) - gc.current);
|
||||
}
|
||||
|
||||
void PalCtrl::Layout()
|
||||
{
|
||||
cell = max((GetSize() - 2 * OGAP - (cellcount + 1) * IGAP) / cellcount, Size(2, 2));
|
||||
step = cell + IGAP;
|
||||
offset = (GetSize() - cellcount * step + IGAP) >> 1;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void PalCtrl::Paint(Draw& draw)
|
||||
{
|
||||
Load();
|
||||
|
||||
GetActive().FindAdd(this);
|
||||
draw.Begin();
|
||||
Size tcell = GetTextSize("256", StdFont());
|
||||
bool do_text = (tcell.cx <= cell.cx && tcell.cy <= cell.cy);
|
||||
for(int i = 0, n = cellcount.cx * cellcount.cy; i < n; i++)
|
||||
{
|
||||
Rect rc = IndexToClient(i);
|
||||
DrawFrame(draw, rc, White, Black);
|
||||
rc.Deflate(1);
|
||||
Color c = Nvl(GlobalConfig().current[i], SColorFace);
|
||||
draw.DrawRect(rc, c);
|
||||
if(do_text)
|
||||
{
|
||||
int brightness = 3 * c.GetR() + 6 * c.GetG() + 1 * c.GetB();
|
||||
Color ink = (brightness <= 1280 ? White : Black);
|
||||
draw.DrawText(rc.left + 2, rc.top + 2, IntStr(i + 1), StdFont(), ink);
|
||||
}
|
||||
rc.Inflate(1);
|
||||
draw.ExcludeClip(rc);
|
||||
}
|
||||
if(color_index >= 0)
|
||||
{
|
||||
Rect selected = IndexToClient(color_index);
|
||||
selected.Inflate(3);
|
||||
DrawFatFrame(draw, selected, SColorMark(), 2);
|
||||
}
|
||||
draw.End();
|
||||
}
|
||||
|
||||
void PalCtrl::LeftDown(Point pt, dword keyflags)
|
||||
{
|
||||
swap_index = ClientToIndex(pt);
|
||||
if(swap_index < 0)
|
||||
return;
|
||||
if(keyflags & K_CTRL)
|
||||
{
|
||||
set_index = swap_index;
|
||||
swap_index = -1;
|
||||
OnSetColor();
|
||||
return;
|
||||
}
|
||||
color = GlobalConfig().current[swap_index];
|
||||
color_index = swap_index;
|
||||
UpdateActionRefresh();
|
||||
SetCapture();
|
||||
}
|
||||
|
||||
void PalCtrl::LeftUp(Point pt, dword keyflags)
|
||||
{
|
||||
ReleaseCapture();
|
||||
int i = ClientToIndex(pt);
|
||||
if(i < 0 || swap_index < 0 || i == swap_index)
|
||||
{
|
||||
swap_index = -1;
|
||||
return;
|
||||
}
|
||||
Swap(GlobalConfig().current[swap_index], GlobalConfig().current[i]);
|
||||
color_index = i;
|
||||
swap_index = -1;
|
||||
UpdateActionRefresh();
|
||||
}
|
||||
|
||||
Image PalCtrl::CursorImage(Point pt, dword keyflags)
|
||||
{
|
||||
if(swap_index >= 0)
|
||||
return CtrlImg::swap_color_cursor();
|
||||
return Image::Arrow();
|
||||
}
|
||||
|
||||
void PalCtrl::RightDown(Point pt, dword keyflags)
|
||||
{
|
||||
MenuBar bar;
|
||||
set_index = ClientToIndex(pt);
|
||||
bar.Add(set_index >= 0 && !IsNull(color), t_("Set color"), THISBACK(OnSetColor))
|
||||
.Help(t_("Write current color to selected palette slot"));
|
||||
bar.Add(t_("Default palette"), THISBACK(OnStandard))
|
||||
.Help(t_("Restore default system palette"));
|
||||
bar.MenuSeparator();
|
||||
bar.Add(t_("Save as.."), THISBACK(OnSave))
|
||||
.Help(t_("Store palette information into a disk file"));
|
||||
bar.Add(t_("Load"), THISBACK(OnLoad))
|
||||
.Help(t_("Load previously saved palette"));
|
||||
bar.MenuSeparator();
|
||||
bool is_small = (cellcount.cx == 4 && cellcount.cy == 4);
|
||||
bool is_medium = (cellcount.cx == 8 && cellcount.cy == 8);
|
||||
bool is_large = (cellcount.cx == 16 && cellcount.cy == 16);
|
||||
bar.Add(t_("Small"), THISBACK(OnSizeSmall))
|
||||
.Check(is_small)
|
||||
.Help(t_("Set up palette size 4 times 4 colors"));
|
||||
bar.Add(t_("Medium"), THISBACK(OnSizeMedium))
|
||||
.Check(is_medium)
|
||||
.Help(t_("Set up palette size 8 times 8 colors"));
|
||||
bar.Add(t_("Large"), THISBACK(OnSizeLarge))
|
||||
.Check(is_large)
|
||||
.Help(t_("Set up palette size 16 times 16 colors (maximum size)"));
|
||||
bar.Add(t_("Custom..."), THISBACK(OnSizeCustom))
|
||||
.Check(!is_small && !is_medium && !is_large)
|
||||
.Help(t_("Select custom palette size"));
|
||||
bar.Execute();
|
||||
}
|
||||
|
||||
void PalCtrl::OnSetColor()
|
||||
{
|
||||
if(set_index >= 0 && set_index < cellcount.cx * cellcount.cy && !IsNull(color))
|
||||
{
|
||||
GlobalConfig().current[set_index] = color;
|
||||
UpdateRefresh();
|
||||
PalCtrlIndex& active = GetActive();
|
||||
for(int i = 0; i < active.GetCount(); i++)
|
||||
{
|
||||
PalCtrl *pal = active[i];
|
||||
if(pal->color_index == set_index && pal->color != color)
|
||||
{
|
||||
pal->UpdateColorIndex();
|
||||
pal->Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PalCtrl::OnStandard()
|
||||
{
|
||||
memcpy(GlobalConfig().current, std_palette, min(sizeof(GlobalConfig().current), sizeof(std_palette)));
|
||||
PalCtrlIndex& active = GetActive();
|
||||
for(int i = 0; i < active.GetCount(); i++)
|
||||
{
|
||||
PalCtrl *pal = active[i];
|
||||
pal->UpdateColorIndex();
|
||||
pal->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void PalCtrl::OnSave()
|
||||
{
|
||||
recent_file = SelectFileSaveAs("Palette (*.pal)\n*.pal");
|
||||
if(recent_file.GetCount())
|
||||
{
|
||||
StringStream stream;
|
||||
SerializePalette(stream);
|
||||
if(!SaveFile(recent_file, stream))
|
||||
Exclamation(Format(t_("Error writing file [* \1%s\1]."), recent_file));
|
||||
}
|
||||
}
|
||||
|
||||
void PalCtrl::OnLoad()
|
||||
{
|
||||
recent_file = SelectFileOpen("Palette (*.pal)\n*.pal");
|
||||
if(recent_file.GetCount())
|
||||
{
|
||||
FileIn fi(recent_file);
|
||||
if(!fi.IsOpen())
|
||||
{
|
||||
Exclamation(Format(t_("Error opening file [* \1%s\1]."), recent_file));
|
||||
return;
|
||||
}
|
||||
SerializePalette(fi);
|
||||
fi.Close();
|
||||
if(fi.IsError())
|
||||
{
|
||||
Exclamation(Format(t_("Error reading palette from file [* \1%s\1]."), recent_file));
|
||||
return;
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void PalCtrl::OnSizeSmall()
|
||||
{
|
||||
GlobalConfig().lastsize = cellcount = Size(4, 4);
|
||||
Layout();
|
||||
}
|
||||
|
||||
void PalCtrl::OnSizeMedium()
|
||||
{
|
||||
GlobalConfig().lastsize = cellcount = Size(8, 8);
|
||||
Layout();
|
||||
}
|
||||
|
||||
void PalCtrl::OnSizeLarge()
|
||||
{
|
||||
GlobalConfig().lastsize = cellcount = Size(16, 16);
|
||||
Layout();
|
||||
}
|
||||
|
||||
//RegisterHelpTopicObjectTitle(DlgPalCtrlSize, s_(PalCtrlSizeCustomDlgTitle))
|
||||
|
||||
void PalCtrl::OnSizeCustom()
|
||||
{
|
||||
WithPalCtrlSizeLayout<TopWindow> dlg;
|
||||
// CtrlLayoutOKCancel(dlg, DlgPalCtrlSizeHelpTitle());
|
||||
CtrlLayoutOKCancel(dlg, t_("Palette dimensions"));
|
||||
dlg.HelpTopic("DlgPalCtrlSize");
|
||||
dlg.rows <<= cellcount.cy;
|
||||
dlg.columns <<= cellcount.cx;
|
||||
dlg.rows.NotNull().MinMax(1, 16);
|
||||
dlg.columns.NotNull().MinMax(1, 16);
|
||||
if(dlg.Run() == IDOK)
|
||||
{
|
||||
cellcount.cx = ~dlg.columns;
|
||||
cellcount.cy = ~dlg.rows;
|
||||
GlobalConfig().lastsize = cellcount;
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
||||
int PalCtrl::ClientToIndex(Point pt) const
|
||||
{
|
||||
Size rel = pt - offset + (IGAP / 2);
|
||||
Point div = idivfloor(rel, step);
|
||||
if(div.x < 0 || div.x >= cellcount.cx || div.y < 0 || div.y >= cellcount.cy)
|
||||
return -1;
|
||||
return div.x * cellcount.cy + div.y;
|
||||
}
|
||||
|
||||
Rect PalCtrl::IndexToClient(int index) const
|
||||
{
|
||||
if(index < 0 || index >= cellcount.cx * cellcount.cy)
|
||||
return Rect(Null);
|
||||
return Rect(Size(index / cellcount.cy, index % cellcount.cy) * step + offset, cell);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ColorSelectorImpl::
|
||||
|
||||
class ColorSelectorImpl : public WithPaletteLayout<TopWindow>, public ColorSelector::Impl
|
||||
{
|
||||
public:
|
||||
typedef ColorSelectorImpl CLASSNAME;
|
||||
ColorSelectorImpl(ColorSelector& parent);
|
||||
virtual ~ColorSelectorImpl();
|
||||
|
||||
void Attach(Ctrl& parent);
|
||||
|
||||
virtual void Set(Color color);
|
||||
virtual Color Get() const;
|
||||
|
||||
virtual void NotNull(bool _nn = true);
|
||||
virtual bool IsNotNull() const;
|
||||
|
||||
virtual Vector<Color> GetPalette() const;
|
||||
virtual void SetPalette(const Vector<Color>& pal);
|
||||
|
||||
virtual void SerializeConfig(Stream& stream);
|
||||
|
||||
virtual Ctrl& GetCtrl() { return *this; }
|
||||
|
||||
public:
|
||||
FetchColorCtrl fetch_color;
|
||||
|
||||
private:
|
||||
void SetAction(Color color);
|
||||
void SetRaw();
|
||||
|
||||
void UpdateRGB();
|
||||
void UpdateHSV();
|
||||
|
||||
void OnRGB();
|
||||
void OnHSV();
|
||||
|
||||
// void OnColor();
|
||||
void OnSetTransparent();
|
||||
|
||||
void OnWheelCtrl();
|
||||
void OnRampCtrl();
|
||||
void OnRGBCtrl();
|
||||
void OnHSVCtrl();
|
||||
void OnPalCtrl();
|
||||
|
||||
void OnFetchColor();
|
||||
|
||||
protected:
|
||||
// WithPaletteLayout<Ctrl> dialog;
|
||||
ColorDisplayNull paint_color_display;
|
||||
|
||||
private:
|
||||
ColorSelector& parent;
|
||||
Color colorval;
|
||||
WheelRampCtrl wheel;
|
||||
WheelRampCtrl ramp;
|
||||
RGBCtrl rgb;
|
||||
HSVCtrl hsv;
|
||||
PalCtrl pal;
|
||||
};
|
||||
|
||||
ColorSelectorImpl::ColorSelectorImpl(ColorSelector& parent)
|
||||
: paint_color_display(t_("(transparent)"))
|
||||
, parent(parent), wheel(false), ramp(true)
|
||||
{
|
||||
Transparent();
|
||||
CtrlLayout(*this);
|
||||
parent << SizePos();
|
||||
|
||||
// dialog.palette_tab.Background(SLtGray);
|
||||
|
||||
palette_tab.Add(pal.HSizePos(4, 4).VSizePos(4, 4), t_("Palette"));
|
||||
pal <<= THISBACK(OnPalCtrl);
|
||||
|
||||
palette_tab.Add(wheel.HSizePos(4, 4).VSizePos(4, 4), t_("Wheel"));
|
||||
wheel <<= THISBACK(OnWheelCtrl);
|
||||
|
||||
palette_tab.Add(ramp.HSizePos(4, 4).VSizePos(4, 4), t_("Hue"));
|
||||
ramp <<= THISBACK(OnRampCtrl);
|
||||
|
||||
palette_tab.Add(rgb.HSizePos(4, 4).VSizePos(4, 4), t_("RGB"));
|
||||
rgb <<= THISBACK(OnRGBCtrl);
|
||||
|
||||
palette_tab.Add(hsv.HSizePos(4, 4).VSizePos(4, 4), t_("HSV"));
|
||||
hsv <<= THISBACK(OnHSVCtrl);
|
||||
|
||||
color.SetFrame(InsetFrame());
|
||||
color.SetDisplay(paint_color_display);
|
||||
color.NoWantFocus();
|
||||
color.SetReadOnly();
|
||||
// dialog.color.WhenAction = THISBACK(OnColor);
|
||||
|
||||
fetch_color <<= THISBACK(OnFetchColor);
|
||||
|
||||
set_transparent <<= THISBACK(OnSetTransparent);
|
||||
set_transparent.SetImage(CtrlImg::set_transparent());
|
||||
|
||||
EditIntSpin *spins[6] =
|
||||
{
|
||||
&r, &g, &b,
|
||||
&h, &s, &v,
|
||||
};
|
||||
|
||||
int i;
|
||||
for(i = 0; i < __countof(spins); i++)
|
||||
{
|
||||
spins[i] -> MinMax(0, 255);
|
||||
spins[i]->WhenAction = (i < 3 ? THISBACK(OnRGB) : THISBACK(OnHSV));
|
||||
}
|
||||
|
||||
Set(Black);
|
||||
}
|
||||
|
||||
ColorSelectorImpl::~ColorSelectorImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::SerializeConfig(Stream& stream)
|
||||
{
|
||||
int version = 2;
|
||||
stream / version;
|
||||
if(version < 2)
|
||||
stream % palette_tab;
|
||||
else {
|
||||
int t = palette_tab.Get();
|
||||
stream / t;
|
||||
palette_tab.Set(t);
|
||||
}
|
||||
Color c = colorval;
|
||||
stream % c;
|
||||
if(stream.IsLoading())
|
||||
Set(c);
|
||||
PalCtrl::SerializeConfig(stream);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::NotNull(bool _nn)
|
||||
{
|
||||
set_transparent.Enable(!_nn);
|
||||
}
|
||||
|
||||
bool ColorSelectorImpl::IsNotNull() const
|
||||
{
|
||||
return !set_transparent.IsEnabled();
|
||||
}
|
||||
|
||||
Vector<Color> ColorSelectorImpl::GetPalette() const
|
||||
{
|
||||
return pal.GetPalette();
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::SetPalette(const Vector<Color>& p)
|
||||
{
|
||||
pal.SetPalette(p);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::SetRaw()
|
||||
{
|
||||
wheel <<= ramp <<= rgb <<= hsv <<= pal <<= colorval;
|
||||
parent.WhenSetColor();
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::SetAction(Color color)
|
||||
{
|
||||
Set(color);
|
||||
parent.Action();
|
||||
}
|
||||
|
||||
Color ColorSelectorImpl::Get() const
|
||||
{
|
||||
return colorval;
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::Set(Color c)
|
||||
{
|
||||
colorval = c;
|
||||
color <<= c;
|
||||
fetch_color <<= c;
|
||||
UpdateRGB();
|
||||
UpdateHSV();
|
||||
wheel <<= ramp <<= rgb <<= hsv <<= pal <<= c;
|
||||
parent.Update();
|
||||
parent.WhenSetColor();
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::UpdateRGB()
|
||||
{
|
||||
Color c = Nvl(colorval, Black);
|
||||
r <<= c.GetR();
|
||||
g <<= c.GetG();
|
||||
b <<= c.GetB();
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::UpdateHSV()
|
||||
{
|
||||
Color c = Nvl(colorval, Black);
|
||||
double vh, vs, vv;
|
||||
RGBtoHSV(c.GetR() / 255.0, c.GetG() / 255.0, c.GetB() / 255.0, vh, vs, vv);
|
||||
h <<= fround(vh * 255);
|
||||
s <<= fround(vs * 255);
|
||||
v <<= fround(vv * 255);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnRGB()
|
||||
{
|
||||
int vr = Nvl((int)~r, 0), vg = Nvl((int)~g, 0), vb = Nvl((int)~b, 0);
|
||||
colorval = Color(vr, vg, vb);
|
||||
color <<= colorval;
|
||||
UpdateHSV();
|
||||
SetRaw();
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnHSV()
|
||||
{
|
||||
int vh = Nvl((int)~h, 0), vs = Nvl((int)~s, 0), vv = Nvl((int)~v, 0);
|
||||
double r, g, b;
|
||||
HSVtoRGB(vh / 255.0, vs / 255.0, vv / 255.0, r, g, b);
|
||||
colorval = Color(fround(255 * r), fround(255 * g), fround(255 * b));
|
||||
color <<= colorval;
|
||||
UpdateRGB();
|
||||
SetRaw();
|
||||
}
|
||||
|
||||
/*
|
||||
void ColorSelectorImpl::OnColor()
|
||||
{
|
||||
SetColor(~dialog.color);
|
||||
}
|
||||
*/
|
||||
|
||||
void ColorSelectorImpl::OnSetTransparent()
|
||||
{
|
||||
SetAction(Null);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnWheelCtrl()
|
||||
{
|
||||
SetAction(~wheel);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnRampCtrl()
|
||||
{
|
||||
SetAction(~ramp);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnRGBCtrl()
|
||||
{
|
||||
SetAction(~rgb);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnHSVCtrl()
|
||||
{
|
||||
SetAction(~hsv);
|
||||
h <<= hsv.GetHValue();
|
||||
s <<= hsv.GetSValue();
|
||||
v <<= hsv.GetVValue();
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnPalCtrl()
|
||||
{
|
||||
SetAction(~pal);
|
||||
}
|
||||
|
||||
void ColorSelectorImpl::OnFetchColor()
|
||||
{
|
||||
SetAction(~fetch_color);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ColorSelector::
|
||||
|
||||
ColorSelector::ColorSelector(bool not_null)
|
||||
{
|
||||
Transparent();
|
||||
impl = new ColorSelectorImpl(*this);
|
||||
impl->NotNull(not_null);
|
||||
}
|
||||
|
||||
class DlgSelectColor : public WithPaletteSelectorLayout<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DlgSelectColor CLASSNAME;
|
||||
DlgSelectColor();
|
||||
|
||||
virtual void Serialize(Stream& stream);
|
||||
|
||||
Color Run(Color init_color, bool not_null, const char *title, bool *ok);
|
||||
|
||||
private:
|
||||
ColorSelector selector;
|
||||
};
|
||||
|
||||
Color RunDlgSelectColor(Color init_color, bool not_null, const char *title, bool *ok)
|
||||
{ return DlgSelectColor().Run(init_color, not_null, title, ok); }
|
||||
|
||||
//RegisterHelpTopicObjectTitle(DlgSelectColor, s_(DlgColorDefaultTitle));
|
||||
|
||||
DlgSelectColor::DlgSelectColor()
|
||||
{
|
||||
palette.Transparent().NoWantFocus() << selector.SizePos();
|
||||
// CtrlLayoutOKCancel(*this, DlgSelectColorHelpTitle());
|
||||
CtrlLayoutOKCancel(*this, t_("Select color"));
|
||||
//RegisterHelpTopicObjectTitle(DlgSelectColor, );
|
||||
HelpTopic("DlgSelectColor");
|
||||
Sizeable().MaximizeBox();
|
||||
}
|
||||
|
||||
INITBLOCK
|
||||
{
|
||||
RegisterGlobalConfig("DlgSelectColor");
|
||||
}
|
||||
|
||||
void DlgSelectColor::Serialize(Stream& stream)
|
||||
{
|
||||
if(stream.IsLoading() && stream.IsEof())
|
||||
return;
|
||||
int version = 1;
|
||||
stream / version;
|
||||
if(stream.IsError() || version < 1 || version > 1) {
|
||||
stream.SetError();
|
||||
return;
|
||||
}
|
||||
SerializePlacement(stream);
|
||||
}
|
||||
|
||||
Color DlgSelectColor::Run(Color init_color, bool not_null, const char *title, bool *ok)
|
||||
{
|
||||
if(title)
|
||||
Title(title);
|
||||
selector.NotNull(not_null).Set(init_color);
|
||||
LoadFromGlobal(*this, "DlgSelectColor");
|
||||
bool is_ok = (TopWindow::Run() == IDOK);
|
||||
StoreToGlobal(*this, "DlgSelectColor");
|
||||
if(ok)
|
||||
*ok = is_ok;
|
||||
return is_ok ? selector.Get() : init_color;
|
||||
}
|
||||
|
||||
ColorCtrl::ColorCtrl(bool not_null)
|
||||
: DataPusher(NoConvert(), StdColorDisplayNull())
|
||||
{
|
||||
SetFrame(EditFieldFrame());
|
||||
AddFrame(empty);
|
||||
empty.SetImage(CtrlImg::cross());
|
||||
empty <<= THISBACK(OnClear);
|
||||
NotNull(not_null);
|
||||
}
|
||||
|
||||
ColorCtrl::~ColorCtrl() {}
|
||||
|
||||
void ColorCtrl::DoAction()
|
||||
{
|
||||
bool ok;
|
||||
Color new_color = RunDlgSelectColor(GetConvert().Format(GetData()), IsNotNull(), 0, &ok);
|
||||
if(ok)
|
||||
SetDataAction(GetConvert().Scan(new_color));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ public:
|
|||
virtual void MouseMove(Point pt, dword keyflags);
|
||||
|
||||
Event<> WhenLeftDouble;
|
||||
|
||||
WheelRampCtrl& DarkContent(bool b = true) { dark_content = b; return *this; }
|
||||
WheelRampCtrl& AllowDarkContent(bool b = true) { allow_dark_content = b; return *this; }
|
||||
bool IsDarkContent() const { return dark_content || allow_dark_content && IsDarkTheme(); }
|
||||
|
||||
private:
|
||||
void SetColor(Color color, bool set_norm, bool set_hsv);
|
||||
|
|
@ -31,6 +35,8 @@ private:
|
|||
|
||||
private:
|
||||
bool ramp;
|
||||
bool dark_content = false;
|
||||
bool allow_dark_content = false;
|
||||
Color color;
|
||||
Color normalized_color;
|
||||
int h16, s16, v16;
|
||||
|
|
@ -60,74 +66,6 @@ struct ColorRampCtrl : public WheelRampCtrl {
|
|||
ColorRampCtrl() : WheelRampCtrl(true) {}
|
||||
};
|
||||
|
||||
class ColorSelector : public Ctrl
|
||||
{
|
||||
public:
|
||||
ColorSelector(bool not_null = true);
|
||||
|
||||
ColorSelector& NotNull(bool nn = true) { impl->NotNull(nn); return *this; }
|
||||
ColorSelector& NoNotNull() { return NotNull(false); }
|
||||
bool IsNotNull() const { return impl->IsNotNull(); }
|
||||
|
||||
Color Get() const { return impl->Get(); }
|
||||
void Set(Color c) { impl->Set(c); }
|
||||
|
||||
Vector<Color> GetPalette() const { return impl->GetPalette(); }
|
||||
void SetPalette(const Vector<Color>& palette) { impl->SetPalette(palette); }
|
||||
|
||||
void SerializeConfig(Stream& stream) { impl->SerializeConfig(stream); }
|
||||
|
||||
virtual void SetData(const Value& color) { Set(color); }
|
||||
virtual Value GetData() const { return Get(); }
|
||||
|
||||
Ctrl& GetImplCtrl() { return impl->GetCtrl(); }
|
||||
|
||||
public:
|
||||
Event<> WhenSetColor;
|
||||
|
||||
public:
|
||||
class Impl
|
||||
{
|
||||
public:
|
||||
virtual ~Impl() {}
|
||||
|
||||
virtual void Set(Color c) = 0;
|
||||
virtual Color Get() const = 0;
|
||||
virtual void NotNull(bool nn) = 0;
|
||||
virtual bool IsNotNull() const = 0;
|
||||
virtual Vector<Color> GetPalette() const = 0;
|
||||
virtual void SetPalette(const Vector<Color>& pal) = 0;
|
||||
virtual void SerializeConfig(Stream& stream) = 0;
|
||||
virtual Ctrl& GetCtrl() = 0;
|
||||
|
||||
protected:
|
||||
Impl() {}
|
||||
};
|
||||
|
||||
protected:
|
||||
One<Impl> impl;
|
||||
};
|
||||
|
||||
class ColorCtrl : public DataPusher
|
||||
{
|
||||
public:
|
||||
typedef ColorCtrl CLASSNAME;
|
||||
ColorCtrl(bool not_null = true);
|
||||
virtual ~ColorCtrl();
|
||||
|
||||
ColorCtrl& NotNull(bool _nn = true) { empty.Show(!_nn); return *this; }
|
||||
ColorCtrl& NoNotNull() { return NotNull(false); }
|
||||
bool IsNotNull() const { return !empty.IsVisible(); }
|
||||
|
||||
protected:
|
||||
virtual void DoAction();
|
||||
void OnClear() { SetDataAction(Null); }
|
||||
|
||||
protected:
|
||||
FrameRight<Button> empty;
|
||||
};
|
||||
|
||||
Color RunDlgSelectColor(Color init_color = Black, bool not_null = true, const char *title = 0, bool *ok = 0);
|
||||
const Display& StdColorDisplayNull();
|
||||
|
||||
class ColorPopUp : public Ctrl {
|
||||
|
|
@ -201,6 +139,9 @@ public:
|
|||
ColorPopUp& VoidText(const char *s) { voidtext = s; Refresh(); return *this; }
|
||||
ColorPopUp& NoRampWheel(bool b = true) { norampwheel = b; return *this; }
|
||||
ColorPopUp& Hints(bool b = true) { hints = b; return *this; }
|
||||
ColorPopUp& DarkContent(bool b = true);
|
||||
ColorPopUp& AllowDarkContent(bool b = true);
|
||||
bool IsDarkContent() const { return wheel.IsDarkContent(); }
|
||||
|
||||
ColorPopUp();
|
||||
virtual ~ColorPopUp();
|
||||
|
|
@ -244,6 +185,8 @@ public:
|
|||
ColorPusher& Track(bool b = true) { track = b; return *this; }
|
||||
ColorPusher& NoTrack() { return Track(false); }
|
||||
ColorPusher& NoRampWheel(bool b = true) { colors.NoRampWheel(b); return *this; }
|
||||
ColorPusher& DarkContent(bool b = true) { colors.DarkContent(b); Refresh(); return *this; }
|
||||
ColorPusher& AllowDarkContent(bool b = true) { colors.AllowDarkContent(b); Refresh(); return *this; }
|
||||
|
||||
ColorPusher();
|
||||
virtual ~ColorPusher();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@
|
|||
#include <Painter/Painter.h>
|
||||
|
||||
namespace Upp {
|
||||
|
||||
RichObject RichEdit::Adjust(RichObject o)
|
||||
{
|
||||
if(pixel_mode)
|
||||
o.SetSize(o.GetPixelSize() * 8 / DPI(1));
|
||||
return o;
|
||||
}
|
||||
|
||||
void RichEdit::InsertImage()
|
||||
{
|
||||
|
|
@ -20,7 +27,7 @@ void RichEdit::InsertImage()
|
|||
}
|
||||
RichText clip;
|
||||
RichPara p;
|
||||
p.Cat(CreateRawImageObject(data), formatinfo);
|
||||
p.Cat(Adjust(CreateRawImageObject(data)), formatinfo);
|
||||
clip.Cat(p);
|
||||
ClipPaste(clip, "image/raw");
|
||||
}
|
||||
|
|
@ -40,7 +47,7 @@ bool RichEdit::Accept(PasteClip& d, RichText& clip, String& fmt)
|
|||
StringStream ss(data);
|
||||
if(StreamRaster::OpenAny(ss) || ext == ".svg" && IsSVG(LoadFile(fn))) {
|
||||
RichPara p;
|
||||
p.Cat(CreateRawImageObject(data), formatinfo);
|
||||
p.Cat(Adjust(CreateRawImageObject(data)), formatinfo);
|
||||
clip.Cat(p);
|
||||
fmt = "files";
|
||||
}
|
||||
|
|
@ -90,7 +97,7 @@ bool RichEdit::Accept(PasteClip& d, RichText& clip, String& fmt)
|
|||
Value data = rt.Read(d);
|
||||
if(!IsNull(data)) {
|
||||
RichPara p;
|
||||
RichObject o = RichObject(&rt, data, pagesz);
|
||||
RichObject o = Adjust(RichObject(&rt, data, pagesz));
|
||||
p.Cat(o, formatinfo);
|
||||
clip.Cat(p);
|
||||
fmt = o.GetTypeName();
|
||||
|
|
|
|||
|
|
@ -15,13 +15,17 @@ bool FontHeight::Key(dword key, int count)
|
|||
return WithDropChoice<EditDouble>::Key(key, count);
|
||||
}
|
||||
|
||||
double RichEdit::DotToPt(int dt)
|
||||
double RichEdit::DotToPt(int dot, int unit)
|
||||
{
|
||||
return 7200 * minmax(dt, 8, 8000) / 600 / 10 / 10.0;
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
return dot / 8.0;
|
||||
return 7200 * minmax(dot, 8, 8000) / 600 / 10 / 10.0;
|
||||
}
|
||||
|
||||
int RichEdit::PtToDot(double pt)
|
||||
int RichEdit::PtToDot(double pt, int unit)
|
||||
{
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
return pt * 8;
|
||||
return int((600 * pt + 71) / 72);
|
||||
}
|
||||
|
||||
|
|
@ -98,8 +102,9 @@ void RichEdit::Paint(Draw& w)
|
|||
p_size = sz;
|
||||
Rect tr = GetTextRect();
|
||||
Zoom zoom = GetZoom();
|
||||
w.DrawRect(sz, White);
|
||||
w.DrawRect(sz, IsDarkContent() ? SColorPaper() : White());
|
||||
PageY py = text.GetHeight(pagesz);
|
||||
Color showcodesa = IsDarkContent() ? DarkTheme(showcodes) : showcodes;
|
||||
{
|
||||
EditPageDraw pw(w);
|
||||
pw.x = tr.left;
|
||||
|
|
@ -122,9 +127,10 @@ void RichEdit::Paint(Draw& w)
|
|||
pi.bottom = GetPageY(sb + sz.cy);
|
||||
pi.usecache = true;
|
||||
pi.sizetracking = sizetracking;
|
||||
pi.showcodes = showcodes;
|
||||
pi.showcodes = showcodesa;
|
||||
pi.showlabels = !IsNull(showcodes) && viewborder >= 16;
|
||||
pi.hyperlink = LtBlue; // because we have white paper even in dark mode
|
||||
pi.hyperlink = IsDarkContent() ? DarkTheme(LtBlue()) : LtBlue(); // because we have white paper even in dark mode
|
||||
pi.darktheme = IsDarkContent();
|
||||
|
||||
if(spellcheck)
|
||||
pi.spellingchecker = SpellParagraph;
|
||||
|
|
@ -140,7 +146,7 @@ void RichEdit::Paint(Draw& w)
|
|||
}
|
||||
text.Paint(pw, pagesz, pi);
|
||||
}
|
||||
w.DrawRect(tr.left, GetPosY(py) - sb, 20, 3, showcodes);
|
||||
w.DrawRect(tr.left, GetPosY(py) - sb, 20, 3, showcodesa);
|
||||
if(objectpos >= 0) {
|
||||
Rect r = objectrect;
|
||||
r.Offset(tr.left, -sb);
|
||||
|
|
@ -221,9 +227,37 @@ RichEdit& RichEdit::Floating(double zoomlevel_)
|
|||
return *this;
|
||||
}
|
||||
|
||||
RichEdit& RichEdit::PixelMode()
|
||||
{
|
||||
NoRuler();
|
||||
ShowCodes(Blend(SColorHighlight(), SColorPaper()));
|
||||
ViewBorder(0);
|
||||
|
||||
RichPara::Format f;
|
||||
f.language = LNG_('C','S','C','Z');
|
||||
(Font&)f = Arial(StdFont().GetHeight() * 8 / DPI(1));
|
||||
f.tabsize = f['W'] * 8;
|
||||
RichText::FormatInfo fi;
|
||||
fi.Set(f);
|
||||
ApplyFormatInfo(fi);
|
||||
|
||||
pixel_mode = true;
|
||||
RefreshLayoutDeep();
|
||||
|
||||
height.SetFilter(CharFilterDigit);
|
||||
|
||||
unit = UNIT_PIXELMODE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RichEdit::Layout()
|
||||
{
|
||||
Size sz = GetTextRect().GetSize();
|
||||
if(pixel_mode) {
|
||||
SetPage(Size(max(sz.cx, 5) / DPI(1) * 8, INT_MAX));
|
||||
}
|
||||
else
|
||||
if(!IsNull(floating_zoom)) {
|
||||
Zoom m = GetRichTextStdScreenZoom();
|
||||
SetPage(Size(int(1 / floating_zoom * m.d / m.m * sz.cx), INT_MAX));
|
||||
|
|
@ -233,7 +267,7 @@ void RichEdit::Layout()
|
|||
SetSb();
|
||||
sb = zsc * GetZoom();
|
||||
PlaceCaret();
|
||||
if(GetSize() != p_size) {
|
||||
if(GetSize() != p_size && !pixel_mode) {
|
||||
sizetracking = true;
|
||||
KillSetTimeCallback(250, THISBACK(EndSizeTracking), TIMEID_ENDSIZETRACKING);
|
||||
}
|
||||
|
|
@ -304,6 +338,12 @@ void RichEdit::SetupRuler()
|
|||
zoom, q.grid, q.numbers, q.numbermul, q.marks);
|
||||
}
|
||||
|
||||
void RichEdit::SetupDark(ColorPusher& c) const
|
||||
{
|
||||
c.AllowDarkContent(allow_dark_content);
|
||||
c.DarkContent(dark_content);
|
||||
}
|
||||
|
||||
void RichEdit::SetupUnits()
|
||||
{
|
||||
WithUnitLayout<TopWindow> d;
|
||||
|
|
@ -312,6 +352,7 @@ void RichEdit::SetupUnits()
|
|||
for(int i = 1; i <= 10; i++)
|
||||
d.zoom.Add(10 * i, Format(t_("%d%% of width"), 10 * i));
|
||||
CtrlRetriever r;
|
||||
SetupDark(d.showcodes);
|
||||
r(d.unit, unit)(d.showcodes, showcodes)(d.zoom, zoom);
|
||||
if(d.Execute() == IDOK) {
|
||||
r.Retrieve();
|
||||
|
|
@ -792,4 +833,25 @@ RichEditWithToolBar::RichEditWithToolBar()
|
|||
extended = true;
|
||||
}
|
||||
|
||||
bool RichEdit::IsDarkContent() const
|
||||
{
|
||||
return dark_content || allow_dark_content && IsDarkTheme();
|
||||
}
|
||||
|
||||
RichEdit& RichEdit::DarkContent(bool b)
|
||||
{
|
||||
dark_content = b;
|
||||
Refresh();
|
||||
DoRefreshBar();
|
||||
return *this;
|
||||
}
|
||||
|
||||
RichEdit& RichEdit::AllowDarkContent(bool b)
|
||||
{
|
||||
allow_dark_content = b;
|
||||
Refresh();
|
||||
DoRefreshBar();
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ void ParaFormatting::Set(int unit, const RichText::FormatInfo& formatinfo, bool
|
|||
if(RichText::TABS & formatinfo.paravalid)
|
||||
for(int i = 0; i < formatinfo.tab.GetCount(); i++)
|
||||
tabs.Add(formatinfo.tab[i].pos, formatinfo.tab[i].align, formatinfo.tab[i].fillchar);
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
tabs.Disable();
|
||||
tabsize.Set(unit, RichText::TABSIZE & formatinfo.paravalid ? formatinfo.tabsize : Null);
|
||||
keepindent = formatinfo.indent != ComputeIndent();
|
||||
SetupIndent();
|
||||
|
|
@ -291,7 +293,7 @@ struct RulerStyleDisplay : Display {
|
|||
}
|
||||
};
|
||||
|
||||
ParaFormatting::ParaFormatting()
|
||||
ParaFormatting::ParaFormatting(const RichEdit& e)
|
||||
{
|
||||
CtrlLayout(*this);
|
||||
tabtype.Add(ALIGN_LEFT, t_("Left"));
|
||||
|
|
@ -347,6 +349,8 @@ ParaFormatting::ParaFormatting()
|
|||
rulerstyle.Add(RichPara::RULER_SOLID);
|
||||
rulerstyle.Add(RichPara::RULER_DOT);
|
||||
rulerstyle.Add(RichPara::RULER_DASH);
|
||||
|
||||
e.SetupDark(rulerink);
|
||||
}
|
||||
|
||||
void StyleManager::EnterStyle()
|
||||
|
|
@ -355,7 +359,7 @@ void StyleManager::EnterStyle()
|
|||
const RichStyle& s = style.Get(list.GetKey());
|
||||
f.Set(s.format);
|
||||
para.Set(unit, f);
|
||||
height <<= RichEdit::DotToPt(s.format.GetHeight());
|
||||
height <<= RichEdit::DotToPt(s.format.GetHeight(), unit);
|
||||
face <<= s.format.GetFace();
|
||||
bold = s.format.IsBold();
|
||||
italic = s.format.IsItalic();
|
||||
|
|
@ -375,7 +379,7 @@ void StyleManager::GetFont(Font& font)
|
|||
if(!IsNull(face))
|
||||
font.Face(~face);
|
||||
if(!IsNull(height))
|
||||
font.Height(RichEdit::PtToDot(~height));
|
||||
font.Height(RichEdit::PtToDot(~height, unit));
|
||||
font.Bold(bold);
|
||||
font.Italic(italic);
|
||||
font.Underline(underline);
|
||||
|
|
@ -531,7 +535,8 @@ void StyleManager::Setup(const Vector<int>& faces, int aunit)
|
|||
face.Add(faces[i]);
|
||||
}
|
||||
|
||||
StyleManager::StyleManager()
|
||||
StyleManager::StyleManager(const RichEdit& e)
|
||||
: para(e)
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, t_("Styles"));
|
||||
list.NoHeader().NoGrid();
|
||||
|
|
@ -542,6 +547,8 @@ StyleManager::StyleManager()
|
|||
list.WhenBar = THISBACK(Menu);
|
||||
list.WhenAcceptEdit = THISBACK(ReloadNextStyles);
|
||||
ink.NotNull();
|
||||
e.SetupDark(ink);
|
||||
e.SetupDark(paper);
|
||||
face <<= height <<= italic <<= bold <<= underline <<= strikeout <<= THISBACK(SetupFont);
|
||||
Vector<int> ffs;
|
||||
Vector<int> ff;
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ void RichEdit::SetFace()
|
|||
void RichEdit::SetHeight()
|
||||
{
|
||||
NextUndo();
|
||||
formatinfo.Height(PtToDot(~height));
|
||||
formatinfo.Height(PtToDot(~height, unit));
|
||||
ApplyFormat(RichText::HEIGHT);
|
||||
SetFocus();
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ void RichEdit::ShowFormat()
|
|||
face <<= Null;
|
||||
|
||||
if(formatinfo.charvalid & RichText::HEIGHT)
|
||||
height <<= DotToPt(formatinfo.GetHeight());
|
||||
height <<= DotToPt(formatinfo.GetHeight(), unit);
|
||||
else
|
||||
height <<= Null;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace Upp {
|
|||
|
||||
Size RichEdit::GetPhysicalSize(const RichObject& obj)
|
||||
{
|
||||
if(pixel_mode)
|
||||
return obj.GetPixelSize() * 8;
|
||||
if(ignore_physical_size)
|
||||
return 600 * obj.GetPixelSize() / 96;
|
||||
return obj.GetPhysicalSize();
|
||||
|
|
@ -238,6 +240,7 @@ void RichEdit::StdBar(Bar& menu)
|
|||
menu.Add(t_("Object position.."), THISBACK(AdjustObjectSize));
|
||||
menu.Separator();
|
||||
menu.Add(b, "20 %", THISBACK1(SetObjectPercent, 20)).Check(IsObjectPercent(percent, 20));
|
||||
menu.Add(b, "25 %", THISBACK1(SetObjectPercent, 25)).Check(IsObjectPercent(percent, 20));
|
||||
menu.Add(b, "30 %", THISBACK1(SetObjectPercent, 30)).Check(IsObjectPercent(percent, 30));
|
||||
menu.Add(b, "40 %", THISBACK1(SetObjectPercent, 40)).Check(IsObjectPercent(percent, 40));
|
||||
menu.Add(b, "50 %", THISBACK1(SetObjectPercent, 50)).Check(IsObjectPercent(percent, 50));
|
||||
|
|
@ -248,13 +251,18 @@ void RichEdit::StdBar(Bar& menu)
|
|||
menu.Add(b, "100 %", THISBACK1(SetObjectPercent, 100)).Check(IsObjectPercent(percent, 100));
|
||||
menu.Break();
|
||||
int delta = bar_object.GetYDelta();
|
||||
menu.Add(t_("3 pt up"), THISBACK1(SetObjectYDelta, -3)).Check(IsObjectDelta(delta, -3));
|
||||
menu.Add(t_("2 pt up"), THISBACK1(SetObjectYDelta, -2)).Check(IsObjectDelta(delta, -2));
|
||||
menu.Add(t_("1 pt up"), THISBACK1(SetObjectYDelta, -1)).Check(IsObjectDelta(delta, -1));
|
||||
auto pma = [=](String s) {
|
||||
if(pixel_mode)
|
||||
s.Replace(" pt", "");
|
||||
return s;
|
||||
};
|
||||
menu.Add(pma(t_("3 pt up")), THISBACK1(SetObjectYDelta, -3)).Check(IsObjectDelta(delta, -3));
|
||||
menu.Add(pma(t_("2 pt up")), THISBACK1(SetObjectYDelta, -2)).Check(IsObjectDelta(delta, -2));
|
||||
menu.Add(pma(t_("1 pt up")), THISBACK1(SetObjectYDelta, -1)).Check(IsObjectDelta(delta, -1));
|
||||
menu.Add(t_("Baseline"), THISBACK1(SetObjectYDelta, 0)).Check(IsObjectDelta(delta, 0));
|
||||
menu.Add(t_("1 pt down"), THISBACK1(SetObjectYDelta, 1)).Check(IsObjectDelta(delta, 1));
|
||||
menu.Add(t_("2 pt down"), THISBACK1(SetObjectYDelta, 2)).Check(IsObjectDelta(delta, 2));
|
||||
menu.Add(t_("3 pt down"), THISBACK1(SetObjectYDelta, 3)).Check(IsObjectDelta(delta, 3));
|
||||
menu.Add(pma(t_("1 pt down")), THISBACK1(SetObjectYDelta, 1)).Check(IsObjectDelta(delta, 1));
|
||||
menu.Add(pma(t_("2 pt down")), THISBACK1(SetObjectYDelta, 2)).Check(IsObjectDelta(delta, 2));
|
||||
menu.Add(pma(t_("3 pt down")), THISBACK1(SetObjectYDelta, 3)).Check(IsObjectDelta(delta, 3));
|
||||
menu.Separator();
|
||||
CopyTool(menu);
|
||||
CutTool(menu);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ namespace Upp {
|
|||
struct ParaFormatDlg : public WithParaFormatLayout<TopWindow> {
|
||||
ParaFormatting para;
|
||||
|
||||
ParaFormatDlg() {
|
||||
ParaFormatDlg(const RichEdit& e)
|
||||
: para(e)
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, t_("Paragraph format"));
|
||||
ActiveFocus(para.before);
|
||||
}
|
||||
|
|
@ -13,7 +15,7 @@ struct ParaFormatDlg : public WithParaFormatLayout<TopWindow> {
|
|||
|
||||
void RichEdit::ParaFormat()
|
||||
{
|
||||
ParaFormatDlg d;
|
||||
ParaFormatDlg d(*this);
|
||||
d.para.Set(unit, formatinfo, !IsSelection() && cursorp.level == 0);
|
||||
if(d.Execute() != IDOK || !d.para.IsChanged())
|
||||
return;
|
||||
|
|
@ -110,7 +112,7 @@ void RichEdit::SetStyle()
|
|||
void RichEdit::Styles()
|
||||
{
|
||||
NextUndo();
|
||||
StyleManager s;
|
||||
StyleManager s(*this);
|
||||
s.Setup(ffs, unit);
|
||||
s.Set(text, formatinfo.styleid);
|
||||
if(s.Execute() != IDOK || !s.IsChanged())
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ enum {
|
|||
UNIT_INCH,
|
||||
UNIT_MM,
|
||||
UNIT_CM,
|
||||
|
||||
UNIT_PIXELMODE,
|
||||
};
|
||||
|
||||
class UnitEdit : public EditField, public Convert {
|
||||
|
|
@ -103,9 +105,10 @@ private:
|
|||
static String DotAsText(int dot, int unit);
|
||||
void Spin(int delta);
|
||||
void Read(double& q, int& u) const;
|
||||
void SyncFilter();
|
||||
|
||||
public:
|
||||
UnitEdit& SetUnit(int _unit) { unit = _unit; return *this; }
|
||||
UnitEdit& SetUnit(int _unit) { unit = _unit; SyncFilter(); return *this; }
|
||||
void Set(int _unit, int d) { unit = _unit; SetData(d); }
|
||||
UnitEdit& WithSgn(bool b = true);
|
||||
|
||||
|
|
@ -125,6 +128,8 @@ struct FontHeight : public WithDropChoice<EditDouble> {
|
|||
|
||||
bool EditRichHeaderFooter(String& header_qtf, String& footer_qtf);
|
||||
|
||||
class RichEdit;
|
||||
|
||||
class ParaFormatting : public WithParaLayout<StaticRect> {
|
||||
public:
|
||||
DropList n[8];
|
||||
|
|
@ -156,7 +161,7 @@ public:
|
|||
void NewHdrFtr();
|
||||
void SyncHdrFtr();
|
||||
|
||||
ParaFormatting();
|
||||
ParaFormatting(const RichEdit& e);
|
||||
};
|
||||
|
||||
class StyleManager : public WithStylesLayout<TopWindow> {
|
||||
|
|
@ -194,7 +199,7 @@ public:
|
|||
|
||||
void Setup(const Vector<int>& faces, int aunit = UNIT_DOT);
|
||||
|
||||
StyleManager();
|
||||
StyleManager(const RichEdit& e);
|
||||
};
|
||||
|
||||
void SetupFaceList(DropList& face);
|
||||
|
|
@ -303,6 +308,10 @@ private:
|
|||
|
||||
PaintInfo paint_info;
|
||||
bool ignore_physical_size;
|
||||
|
||||
bool pixel_mode = false;
|
||||
bool dark_content = false;
|
||||
bool allow_dark_content = false;
|
||||
|
||||
static int fh[];
|
||||
|
||||
|
|
@ -623,7 +632,9 @@ private:
|
|||
void ZoomClip(RichText& text) const;
|
||||
|
||||
void InsertImage();
|
||||
|
||||
|
||||
RichObject Adjust(RichObject o);
|
||||
|
||||
void StyleKeys();
|
||||
void ApplyStyleKey(int i);
|
||||
|
||||
|
|
@ -663,8 +674,8 @@ public:
|
|||
virtual void PasteFilter(RichText& txt, const String& fmt);
|
||||
virtual void Filter(RichText& txt);
|
||||
|
||||
static double DotToPt(int dot);
|
||||
static int PtToDot(double pt);
|
||||
static double DotToPt(int dot, int unit = UNIT_DOT);
|
||||
static int PtToDot(double pt, int unit = UNIT_DOT);
|
||||
static Bits SpellParagraph(const RichPara& p);
|
||||
static void FixedLang(int lang) { fixedlang = lang; }
|
||||
|
||||
|
|
@ -802,6 +813,8 @@ public:
|
|||
void ApplyStylesheet(const RichText& r);
|
||||
void SetPage(const Size& sz) { pagesz = sz; Finish(); }
|
||||
Size GetPage() { return pagesz; }
|
||||
bool IsDarkContent() const;
|
||||
void SetupDark(ColorPusher& c) const;
|
||||
|
||||
RichEdit& NoRuler() { RemoveFrame(ruler); return *this; }
|
||||
RichEdit& SingleLine(bool b = true) { singleline = b; return *this; }
|
||||
|
|
@ -819,9 +832,12 @@ public:
|
|||
RichEdit& BulletIndent(int i) { bullet_indent = i; return *this; }
|
||||
RichEdit& PersistentFindReplace(bool b = true) { persistent_findreplace = b; return *this; }
|
||||
RichEdit& Floating(double zoomlevel_ = 1);
|
||||
RichEdit& NoFloating(double zoomlevel_ = 1) { return Floating(Null); }
|
||||
RichEdit& NoFloating() { return Floating(Null); }
|
||||
RichEdit& SetPaintInfo(const PaintInfo& pi) { paint_info = pi; return *this; }
|
||||
RichEdit& IgnorePhysicalObjectSize(bool b = true){ ignore_physical_size = b; return *this; }
|
||||
RichEdit& PixelMode();
|
||||
RichEdit& DarkContent(bool b = true);
|
||||
RichEdit& AllowDarkContent(bool b = true);
|
||||
|
||||
struct UndoInfo {
|
||||
int undoserial;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ void RichEdit::InsertTable()
|
|||
if(dlg.Run() != IDOK)
|
||||
return;
|
||||
RichTable::Format fmt;
|
||||
if(pixel_mode) {
|
||||
fmt.grid = 1;
|
||||
fmt.frame = 2;
|
||||
}
|
||||
int nx = minmax((int)~dlg.columns, 1, 20);
|
||||
for(int q = nx; q--;)
|
||||
fmt.column.Add(1);
|
||||
|
|
@ -42,6 +46,12 @@ void RichEdit::InsertTable()
|
|||
p.format.label.Clear();
|
||||
h.Cat(p);
|
||||
table.SetPick(i, j, pick(h));
|
||||
if(pixel_mode) {
|
||||
RichCell::Format fmt;
|
||||
fmt.margin.left = fmt.margin.right = 4;
|
||||
fmt.margin.top = fmt.margin.bottom = 3;
|
||||
table.SetFormat(i, j, fmt);
|
||||
}
|
||||
}
|
||||
NextUndo();
|
||||
if(cursorp.posinpara)
|
||||
|
|
@ -123,6 +133,8 @@ void RichEdit::TableProps()
|
|||
if(IsSelection() || cursorp.table == 0)
|
||||
return;
|
||||
RichEditTableProperties dlg;
|
||||
SetupDark(dlg.framecolor);
|
||||
SetupDark(dlg.gridcolor);
|
||||
dlg.Breaker(dlg.destroy, IDNO);
|
||||
RichTable::Format fmt = text.GetTableFormat(cursorp.table);
|
||||
String ratios;
|
||||
|
|
@ -327,6 +339,8 @@ void RichEdit::CellProperties()
|
|||
return;
|
||||
WithCellPropertiesLayout<TopWindow> dlg;
|
||||
CtrlLayoutOKCancel(dlg, t_("Cell properties"));
|
||||
SetupDark(dlg.color);
|
||||
SetupDark(dlg.border);
|
||||
int tab;
|
||||
Rect a;
|
||||
if(tablesel) {
|
||||
|
|
|
|||
|
|
@ -115,11 +115,13 @@ void RichEdit::FontTools(Bar& bar)
|
|||
|
||||
void RichEdit::InkTool(Bar& bar)
|
||||
{
|
||||
ink.DarkContent(IsDarkContent());
|
||||
bar.Add(!IsReadOnly(), ink);
|
||||
}
|
||||
|
||||
void RichEdit::PaperTool(Bar& bar)
|
||||
{
|
||||
paper.DarkContent(IsDarkContent());
|
||||
bar.Add(!IsReadOnly(), paper);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ namespace Upp {
|
|||
double UnitMultiplier(int unit) {
|
||||
static double m[] =
|
||||
{
|
||||
1,
|
||||
72.0 / 600,
|
||||
1.0 / 600,
|
||||
25.4 / 600,
|
||||
2.54 / 600,
|
||||
1, // DOT
|
||||
72.0 / 600, // POINT
|
||||
1.0 / 600, // INCH
|
||||
25.4 / 600, // mm
|
||||
2.54 / 600, // cm
|
||||
1 / 8.0, // PIXELMODE
|
||||
};
|
||||
ASSERT(unit >= UNIT_DOT && unit <= UNIT_CM);
|
||||
ASSERT(unit >= UNIT_DOT && unit <= UNIT_PIXELMODE);
|
||||
return m[unit];
|
||||
}
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ const char *UnitText(int unit) {
|
|||
"\"",
|
||||
"mm",
|
||||
"cm"
|
||||
"",
|
||||
};
|
||||
return txt[unit];
|
||||
}
|
||||
|
|
@ -78,6 +80,8 @@ String UnitEdit::AsText(double d, int unit)
|
|||
{
|
||||
if(IsNull(d))
|
||||
return Null;
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
return AsString(d);
|
||||
String utxt = UnitText(unit);
|
||||
if(unit == UNIT_POINT)
|
||||
d = floor(10 * d + 0.5) / 10;
|
||||
|
|
@ -127,6 +131,7 @@ void UnitEdit::Spin(int delta)
|
|||
case UNIT_MM: h = 0.5; break;
|
||||
case UNIT_CM:
|
||||
case UNIT_INCH: h = 0.05; break;
|
||||
case UNIT_PIXELMODE: h = 1; break;
|
||||
default: NEVER();
|
||||
}
|
||||
h *= delta;
|
||||
|
|
@ -148,10 +153,28 @@ int CharFilterUnitEditSgn(int c)
|
|||
return c == '-' ? c : CharFilterUnitEdit(c);
|
||||
}
|
||||
|
||||
int CharFilterUnitEditPx(int c)
|
||||
{
|
||||
return IsDigit(c) || c == '.' ? c : 0;
|
||||
}
|
||||
|
||||
int CharFilterUnitEditSgnPx(int c)
|
||||
{
|
||||
return c == '-' ? c : CharFilterUnitEditPx(c);
|
||||
}
|
||||
|
||||
void UnitEdit::SyncFilter()
|
||||
{
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
SetFilter(sgn ? CharFilterUnitEditSgnPx : CharFilterUnitEditPx);
|
||||
else
|
||||
SetFilter(sgn ? CharFilterUnitEditSgn : CharFilterUnitEdit);
|
||||
}
|
||||
|
||||
UnitEdit& UnitEdit::WithSgn(bool b)
|
||||
{
|
||||
sgn = b;
|
||||
SetFilter(b ? CharFilterUnitEditSgn : CharFilterUnitEdit);
|
||||
SyncFilter();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ Size RichImage::GetPhysicalSize(const Value& data) const
|
|||
void RichImage::Paint(const Value& data, Draw& w, Size sz, void *) const
|
||||
{
|
||||
Image x = LoadImageFromString(data);
|
||||
// Size outsz(min(sz.cx, 4 * x.GetWidth()), min(sz.cy, 4 * x.GetHeight()));
|
||||
w.DrawImage(0, 0, sz.cx, sz.cy, x);
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +241,7 @@ void RichRawImage::Paint(const Value& data, Draw& w, Size sz, void *) const
|
|||
if(r) {
|
||||
Size isz = r->GetSize();
|
||||
if(GetIsJPGFn() && GetIsJPGFn()(~r) && GetPdfDrawJPEGFn())
|
||||
GetPdfDrawJPEGFn()(w, 0, 0, sz.cx, sz.cy, data);
|
||||
GetPdfDrawJPEGFn()(w, 0, 0, sz.cx, sz.cy, data); // make sure we export jpg to pdf without reprocessing
|
||||
else
|
||||
if(isz.cx * isz.cy > sz.cx * sz.cy) { // conserve memory by scaling down from source
|
||||
ImageEncoder m;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ TopicEditor::TopicEditor()
|
|||
topics_search.SetFilter(CharFilterToUpper);
|
||||
|
||||
editor.SetPage(TopicPage());
|
||||
editor.AllowDarkContent();
|
||||
editor.WhenRefreshBar = THISBACK(SetBar);
|
||||
editor.WhenHyperlink = THISBACK(Hyperlink);
|
||||
|
||||
|
|
|
|||
|
|
@ -310,6 +310,7 @@ QtfDlgEditor::QtfDlgEditor()
|
|||
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100);
|
||||
SetMinSize(Size(min(640, r.GetWidth() - 100), min(480, r.GetHeight() - 100)));
|
||||
Title("Editor");
|
||||
editor.AllowDarkContent();
|
||||
}
|
||||
|
||||
void QTFEdit(String& text)
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ struct IdeQtfDes : IdeDesigner, RichEditWithToolBar {
|
|||
|
||||
typedef IdeQtfDes CLASSNAME;
|
||||
|
||||
IdeQtfDes() { Extended(); }
|
||||
IdeQtfDes() { Extended(); AllowDarkContent(); }
|
||||
};
|
||||
|
||||
INITIALIZE(Qtf)
|
||||
|
|
|
|||
9
upptst/DarkModeContent/DarkModeContent.upp
Normal file
9
upptst/DarkModeContent/DarkModeContent.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
13
upptst/DarkModeContent/main.cpp
Normal file
13
upptst/DarkModeContent/main.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TopWindow win;
|
||||
ColorPusher p, p1;
|
||||
p.DarkContent();
|
||||
win.Add(p.LeftPos(100, 100).TopPos(100, 50));
|
||||
win.Add(p1.LeftPos(200, 100).TopPos(100, 50));
|
||||
win.Run();
|
||||
}
|
||||
10
upptst/RichTextPixelMode/RichTextPixelMode.upp
Normal file
10
upptst/RichTextPixelMode/RichTextPixelMode.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
RichEdit;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
20
upptst/RichTextPixelMode/main.cpp
Normal file
20
upptst/RichTextPixelMode/main.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <RichEdit/RichEdit.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TopWindow win;
|
||||
RichEditWithToolBar edit;
|
||||
edit.PixelMode();
|
||||
RichEditWithToolBar edit2;
|
||||
edit2.PixelMode();
|
||||
win << edit.HSizePos().VSizePos(0, Zx(200));
|
||||
win << edit2.HSizePos().BottomPos(0, Zx(200));
|
||||
win.Sizeable();
|
||||
String fn = ConfigFile("test.qtf");
|
||||
edit.SetQTF(LoadFile(fn));
|
||||
win.Run();
|
||||
SaveFile(fn, edit.GetQTF());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue