ide: Laydes Ctrl+Wheel zooming

This commit is contained in:
Mirek Fidler 2023-02-21 20:23:15 +01:00
parent e4cc4cf3f5
commit 14af0c7c3f
3 changed files with 17 additions and 2 deletions

View file

@ -275,6 +275,7 @@ public:
virtual void LeftDown(Point p, dword keyflags) override; virtual void LeftDown(Point p, dword keyflags) override;
virtual void LeftRepeat(Point p, dword keyflags) override; virtual void LeftRepeat(Point p, dword keyflags) override;
virtual void MouseMove(Point p, dword keyflags) override; virtual void MouseMove(Point p, dword keyflags) override;
virtual void MouseWheel(Point p, int zdelta, dword keyflags) override;
virtual void LeftUp(Point p, dword keyflags) override; virtual void LeftUp(Point p, dword keyflags) override;
virtual void RightDown(Point p, dword keyflags) override; virtual void RightDown(Point p, dword keyflags) override;
virtual void Layout() override; virtual void Layout() override;

View file

@ -92,6 +92,7 @@ void LayDes::SetSb()
double scale = GetScale(); double scale = GetScale();
sb.SetTotal(scale * sz); sb.SetTotal(scale * sz);
sb.SetPage(sb.GetReducedViewSize()); sb.SetPage(sb.GetReducedViewSize());
sb.SetLine(DPI(8));
} }
void LayDes::Scroll() void LayDes::Scroll()
@ -281,9 +282,21 @@ void LayDes::Paint2(Draw& w)
DrawFrame(w, dragrect.Normalized(), LtRed); DrawFrame(w, dragrect.Normalized(), LtRed);
} }
void LayDes::MouseWheel(Point p, int zdelta, dword keyflags)
{
if(keyflags & K_CTRL) {
Zoom = clamp(Zoom - sgn(zdelta), 0, 15);
Refresh();
SetBar();
SetSb();
}
else
sb.WheelY(zdelta);
}
double LayDes::GetScale() double LayDes::GetScale()
{ {
return decode(Zoom, 1, 0.75, 2, 0.5, 1); return (20 - Zoom) / 20.0;
} }
void LayDes::Paint(Draw& w) void LayDes::Paint(Draw& w)
@ -299,6 +312,7 @@ void LayDes::Paint(Draw& w)
if(Zoom) { if(Zoom) {
DrawPainter sw(w, sz); DrawPainter sw(w, sz);
sw.Co();
sw.Clear(SColorPaper()); sw.Clear(SColorPaper());
sw.Offset(-sb.Get()); sw.Offset(-sb.Get());
sw.Offset(MARGIN, MARGIN); sw.Offset(MARGIN, MARGIN);

View file

@ -198,7 +198,7 @@ void LayDes::OptionBar(Bar& bar)
im.zoom = GetScale(); im.zoom = GetScale();
bar.Add("Zoom " + AsString(GetScale() * 100) + "%", MakeImage(im), bar.Add("Zoom " + AsString(GetScale() * 100) + "%", MakeImage(im),
[=] { [=] {
Zoom = (Zoom + 1) % 3; Zoom = Zoom < 5 ? 5 : Zoom < 10 ? 10 : 0;
Refresh(); Refresh();
SetBar(); SetBar();
SetSb(); SetSb();