This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DragImagEditPainter.cs
46 lines (44 loc) · 2.02 KB
/
DragImagEditPainter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Controls;
using DevExpress.Utils.Drawing;
namespace CustomImageEditor {
public class DragImagEditPainter : BaseEditPainter {
protected override void DrawContent(ControlGraphicsInfoArgs info) {
base.DrawContent(info);
DrawImage(info);
}
protected virtual void DrawImage(ControlGraphicsInfoArgs info) {
DragImageEditViewInfo vi = info.ViewInfo as DragImageEditViewInfo;
if(!(vi.EditValue is EditValueInstance)) {
vi.PaintAppearance.DrawString(info.Cache, "incorrect editvalue", new Rectangle(new Point(vi.Bounds.Location.X +5,vi.Bounds.Location.Y),vi.Bounds.Size), vi.PaintAppearance.GetStringFormat(vi.DefaultTextOptions));
return;
}
Size imageSize = Size.Empty;
try { if(vi.Image != null) imageSize = vi.Image.Size; }
catch { }
if(vi.Image == null || imageSize.IsEmpty) {
string text = Localizer.Active.GetLocalizedString(StringId.DataEmpty);
if(vi.Item.NullText != null && vi.Item.NullText.Length > 0) text = vi.Item.NullText;
vi.PaintAppearance.DrawString(info.Cache, text, vi.Bounds, vi.PaintAppearance.GetStringFormat(vi.DefaultTextOptions));
return;
}
int x, y;
Rectangle r = vi.Bounds;
x = -vi.HorizontOffset;
y = -vi.VerticalOffset;
GraphicsClipState state = info.Cache.ClipInfo.SaveAndSetClip(vi.ContentRect);
try {
info.Cache.Paint.DrawImage(info.Graphics, vi.Image,
new Rectangle(r.X + x, r.Y + y, vi.Image.Width, vi.Image.Height),
new Rectangle(0, 0, vi.Image.Width, vi.Image.Height), true);
}
finally {
info.Cache.ClipInfo.RestoreClipRelease(state);
}
}
}
}