CtrlCore: ViewDraw, DrawDragRect (RectTracker now works)

git-svn-id: svn://ultimatepp.org/upp/trunk@12146 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-08-04 13:44:35 +00:00
parent 603594c138
commit 0844d3a884
7 changed files with 117 additions and 41 deletions

View file

@ -129,6 +129,15 @@ public:
~BackDraw();
};
struct DrawDragRectInfo {
Rect rect1, rect2, clip;
int n;
Color color;
int type;
int animation;
};
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
Color color, uint64 pattern);
@ -144,7 +153,7 @@ struct CocoTop;
struct MMCtrl;
struct MMImp;
#define GUIPLATFORM_CTRL_TOP_DECLS CocoTop *coco = NULL;
#define GUIPLATFORM_CTRL_TOP_DECLS CocoTop *coco = NULL; One<DrawDragRectInfo> dr;
#define GUIPLATFORM_CTRL_DECLS_INCLUDE <CtrlCore/CocoCtrl.h>

View file

@ -53,7 +53,7 @@ void Upp::CocoInit(int argc, const char **argv, const char **envptr)
Font::SetFace(0, Upp::ToString((CFStringRef)[sysfont familyName]), Font::TTF);
Font::SetDefaultFont(StdFont(fround([sysfont pointSize])));
GUI_DblClickTime_Write(NSEvent.doubleClickInterval);
GUI_DblClickTime_Write(1000 * NSEvent.doubleClickInterval);
}
void Upp::CocoExit()
@ -310,4 +310,22 @@ void Upp::AppendClipboardUnicodeText(const WString& s)
AppendClipboardText(s.ToString());
}
Upp::ViewDraw::ViewDraw(Ctrl *ctrl)
{
EnterGuiMutex();
ASSERT(ctrl->top->coco);
Rect tr = ctrl->GetTopCtrl()->GetScreenRect();
Rect r = ctrl->GetScreenView();
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithWindow:ctrl->top->coco->window];
Init([gc CGContext], tr.GetHeight());
Clipoff(Rect(r.TopLeft() - tr.TopLeft(), r.GetSize()));
}
Upp::ViewDraw::~ViewDraw()
{
End();
CGContextFlush(cgHandle);
LeaveGuiMutex();
}
#endif

View file

@ -3,6 +3,10 @@ private:
friend struct MMCtrl;
friend struct MMImp;
friend void DrawDragRect(Ctrl& q, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
Color color, int type, int animation);
friend void FinishDragRect(Ctrl& q);
static int WndCaretTime;
static bool WndCaretVisible;
static void AnimateCaret();

View file

@ -9,6 +9,7 @@ void SystemDraw::Init(void *cgContext, int cy)
handle = cgContext;
top = cy;
Push();
CGContextSetBlendMode(cgHandle, kCGBlendModeNormal);
CGContextSetTextPosition(cgHandle, 0, 0);
CGContextSetTextDrawingMode(cgHandle, kCGTextFill);
}

View file

@ -19,9 +19,86 @@ String ToString(CFStringRef s)
return ToWString(s).ToString();
}
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, Color color, uint64 pattern)
void DrawDragLine(SystemDraw& w, bool horz, int x, int y, int len, int n, const int *pattern, Color color, int animation)
{
// TODO
if(len <= 0)
return;
if(horz)
w.Clip(x, y, len, n);
else
w.Clip(x, y, n, len);
(horz ? x : y) -= animation;
len += animation;
bool ch = false;
while(len > 0) {
int segment = pattern[ch];
int d = segment + pattern[2];
if(horz) {
w.DrawRect(x, y, segment, n, color);
x += d;
}
else {
w.DrawRect(x, y, n, segment, color);
y += d;
}
len -= d;
ch = !ch;
}
w.End();
}
void DrawDragFrame(SystemDraw& w, const Rect& r, int n, const int *pattern, Color color, int animation)
{
DrawDragLine(w, true, r.left, r.top, r.GetWidth(), n, pattern, color, animation);
DrawDragLine(w, false, r.left, r.top + n, r.GetHeight() - 2 * n, n, pattern, color, animation);
DrawDragLine(w, false, r.right - n, r.top + n, r.GetHeight() - 2 * n, n, pattern, color, animation);
DrawDragLine(w, true, r.left, r.bottom - n, r.GetWidth(), n, pattern, color, animation);
}
void DrawDragRect(Ctrl& q, const DrawDragRectInfo& f)
{
ViewDraw w(&q);
w.Clip(f.clip);
static int dashes[3][3] = {
{ 32, 32, 0 },
{ 1, 1, 1 },
{ 5, 1, 2 },
};
const int *dash = dashes[minmax(f.type, 0, 2)];
Color color = InvertColor;
DrawDragFrame(w, f.rect1, f.n, dash, color, f.animation);
DrawDragFrame(w, f.rect2, f.n, dash, color, f.animation);
w.End();
}
void DrawDragRect(Ctrl& q, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
Color color, int type, int animation)
{
Ctrl *top = q.GetTopCtrl();
if(top && top->top->coco) {
Rect sv = q.GetScreenView();
Rect tv = top->GetScreenView();
Point off = sv.TopLeft() - tv.TopLeft();
DrawDragRectInfo& f = top->top->dr.Create();
f.rect1 = rect1 + off;
f.rect2 = rect2 + off;
f.clip = (clip & q.GetSize()) + off;
f.n = n;
f.color = color;
f.type = type;
f.animation = animation;
DrawDragRect(*top, f);
}
}
void FinishDragRect(Ctrl& q)
{
Ctrl *top = q.GetTopCtrl();
if(top && top->top && top->top->dr) {
DrawDragRect(*top, *top->top->dr);
top->top->dr.Clear();
}
}
/*
@ -31,26 +108,6 @@ Size GetScreenSize()
}
*/
static uint64 sGetAniPat(uint64 src, int pos)
{
uint64 out = 0;
pos &= 7;
for(int i = 8; --i >= 0;) {
byte sr = (byte)(src >> (8 * ((7 - i - pos) & 7)));
out = (out << 8) | (byte)((sr | (sr << 8)) >> pos);
}
return out;
}
void DrawDragRect(Ctrl& q, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
Color color, int type, int animation)
{
ViewDraw w(&q);
uint64 pattern = type == DRAWDRAGRECT_DASHED ? I64(0xf0783c1e0f87c3e1) :
type == DRAWDRAGRECT_NORMAL ? I64(0x55aa55aa55aa55aa) : 0;
DrawDragRect(w, rect1, rect2, clip, n, color, sGetAniPat(pattern, animation));
}
};
#endif

View file

@ -72,16 +72,6 @@ void Ctrl::WndUpdate(const Rect& r)
}
ViewDraw::ViewDraw(Ctrl *ctrl)
{
EnterGuiMutex();
}
ViewDraw::~ViewDraw()
{
LeaveGuiMutex();
}
Vector<WString> SplitCmdLine__(const char *cmd)
{
Vector<WString> out;
@ -107,10 +97,6 @@ void Ctrl::SysEndLoop()
{
}
void FinishDragRect(Ctrl& q)
{
}
END_UPP_NAMESPACE
#endif

View file

@ -1,7 +1,6 @@
sooner:
- rect loop (ViewDraw)
- DrawDragRect
- opening FindInFiles, then selecting folder - pushing buttons does not exit dialog
- package organizer initial size too small
- minimize, maximaze
@ -20,7 +19,6 @@ sooner:
later:
- doubleclick interval: https://developer.apple.com/documentation/appkit/nsevent/1528384-doubleclickinterval?language=objc
- void WakeUpGuiThread(void)
- fullscreen mode issues
- PrinterJob
@ -50,6 +48,9 @@ void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Co
done:
- doubleclick interval: https://developer.apple.com/documentation/appkit/nsevent/1528384-doubleclickinterval?language=objc
- rect loop (ViewDraw)
- DrawDragRect
- triple click, hold...
- Ctrl+Space assist
- CT_Font caching