.developing rainbow

git-svn-id: svn://ultimatepp.org/upp/trunk@3628 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-07-09 19:33:19 +00:00
parent 7014a272f3
commit 931bf5b92f
16 changed files with 317 additions and 81 deletions

View file

@ -0,0 +1,11 @@
uses
CtrlLib,
Framebuffer,
WinFb;
file
main.cpp;
mainconfig
"" = "GUI SSE2 WINFB";

View file

@ -0,0 +1,6 @@
#ifndef _DrawDragRect_icpp_init_stub
#define _DrawDragRect_icpp_init_stub
#include "CtrlLib/init"
#include "Framebuffer/init"
#include "WinFb/init"
#endif

View file

@ -0,0 +1,70 @@
#include <CtrlLib/CtrlLib.h>
#include <RichEdit/RichEdit.h>
using namespace Upp;
struct App : public Ctrl {
uint64 pattern;
int pos;
int a;
int dir;
void Paint(Draw& w)
{
DDUMP(pattern);
Size sz = GetSize();
w.DrawRect(sz, White());
DrawDragRect((SystemDraw&)w,
Rect(0, 0, 0, 0),
RectC(10, 10, a, a / 3),
Size(800, 600),
1,
Black(),
pattern);
}
void Animate() {
pattern = I64(0xf0f0) >> (pos++ & 7);
if(Random() % 100 == 0)
dir = (int)Random() % 3 - 1;
a += dir;
if(a < 0) {
a = 0;
dir = -dir;
}
if(a > 1000) {
a = 1000;
dir = -dir;
}
// if(++a > 900)
// a = 0;
DrawDragRect(*this,
Rect(0, 0, 0, 0),
RectC(10, 10, a, a / 3),
Size(800, 600),
1,
Black(),
pattern);
PostCallback(THISBACK(Animate));
}
typedef App CLASSNAME;
App()
{
pattern = I64(9732030564846854595);
pos = 0;
a = 200;
dir = 1;
PostCallback(THISBACK(Animate));
SetCaret(0, 0, 20, 20);
}
};
GUI_APP_MAIN
{
App app;
Ctrl::SetDesktop(app);
app.SetFocus();
Ctrl::EventLoop();
}

View file

@ -1,13 +1,17 @@
class ViewDraw : public SystemDraw {
ImageBuffer ib;
Vector<Rect> dummy_invalid;
public:
ViewDraw(Ctrl *ctrl) : SystemDraw(ib, dummy_invalid) { _DBG_ }
~ViewDraw() {}
ViewDraw(Ctrl *ctrl);
~ViewDraw();
};
/*
class ViewDraw : public SystemDraw {
Vector<Rect> dummy;
public:
ViewDraw(Ctrl *) : SystemDraw(Ctrl::framebuffer, dummy) { dummy.Add(Rect(10, 10, 100, 100)); }
};
*/
class DHCtrl : Ctrl {};
#include FRAMEBUFFER_INCLUDE

View file

@ -6,36 +6,44 @@ NAMESPACE_UPP
#define LLOG(x) // LOG(x)
static VectorMap<String, ClipData> fbClipboard;
void ClearClipboard()
{
GuiLock __;
}
void AppendClipboard(int format, const byte *data, int length)
{
GuiLock __;
}
void AppendClipboard(const char *format, const byte *data, int length)
{
GuiLock __;
}
void AppendClipboard(const char *format, const String& data)
{
GuiLock __;
AppendClipboard(format, data, data.GetLength());
fbClipboard.Clear();
}
void AppendClipboard(const char *format, const Value& data, String (*render)(const Value&))
{
GuiLock __;
ClipData& cd = fbClipboard.GetAdd(format);
cd.data = data;
cd.render = render;
}
static String sRawRender(const Value& v)
{
return v;
}
void AppendClipboard(const char *format, const String& data)
{
GuiLock __;
AppendClipboard(format, data, sRawRender);
}
void AppendClipboard(const char *format, const byte *data, int length)
{
GuiLock __;
AppendClipboard(format, String(data, length));
}
String ReadClipboard(const char *format)
{
GuiLock __;
return Null;
int q = fbClipboard.Find(format);
return q >= 0 ? (*fbClipboard[q].render)(fbClipboard[q].data) : String();
}
void AppendClipboardText(const String& s)
@ -125,22 +133,26 @@ String GetTextClip(const String& text, const String& fmt)
String ReadClipboardText()
{
return ReadClipboardUnicodeText().ToString();
String w = ReadClipboard("text");
return w.GetCount() ? w : ReadClipboardUnicodeText().ToString();
}
WString ReadClipboardUnicodeText()
{
return Null;
String w = ReadClipboard("wtext");
if(w.GetCount())
return WString(~w, w.GetLength() / 2);
return ReadClipboard("text").ToWString();
}
bool IsClipboardAvailable(const char *id)
{
return false;
return fbClipboard.Find(id) >= 0;
}
bool IsClipboardAvailableText()
{
return false;
return IsClipboardAvailable("text") || IsClipboardAvailable("wtext");
}
const char *ClipFmtsImage()
@ -223,12 +235,12 @@ Vector<String> GetFiles(PasteClip& clip)
bool PasteClip::IsAvailable(const char *fmt) const
{
return false;
return IsClipboardAvailable(fmt);
}
String PasteClip::Get(const char *fmt) const
{
return Null;
return ReadClipboard(fmt);
}
void PasteClip::GuiPlatformConstruct()

View file

@ -1,11 +1,9 @@
//$ class Ctrl {
private:
static void AddInvalid(const Rect& rect);
static Ptr<Ctrl> desktop;
static Vector<Ctrl *> topctrl;
static ImageBuffer framebuffer;
static Vector<Rect> invalid;
static Vector<Rect> invalid, update;
static Point fbCursorPos;
static Image fbCursorImage;
@ -28,15 +26,19 @@ private:
int FindTopCtrl() const;
static Rect GetClipBound(const Vector<Rect>& inv, const Rect& r);
static void DoPaint(const Vector<Rect>& invalid);
static void DoPaint();
static void DoUpdate();
static void SyncTopWindows();
static void AddInvalid(const Rect& rect);
void NewTop() { top = new Top; top->owner_window = NULL; }
void PutForeground();
static void MouseEventFB(Ptr<Ctrl> t, int event, Point p, int zdelta);
friend struct PaintProxy__;
friend class TopWindowFrame;
friend class SystemDraw;
public:
static void DoMouseFB(int event, Point p, int zdelta = 0);
@ -56,4 +58,6 @@ public:
static void SetRenderingMode(int mode);
static void AddUpdate(const Rect& rect);
//$ };

View file

@ -7,6 +7,16 @@ NAMESPACE_UPP
#define LLOG(x) // LOG(x)
#define LTIMING(x) // RTIMING(x)
SystemDraw::SystemDraw()
: BufferPainter(Ctrl::framebuffer, Ctrl::renderingMode)
{
}
SystemDraw::~SystemDraw()
{
}
void SystemDraw::Push()
{
Point p = GetOffset();
@ -64,8 +74,8 @@ bool SystemDraw::ClipoffOp(const Rect& r)
bool SystemDraw::IsPaintingOp(const Rect& r) const
{
Rect rr = r + GetOffset();
for(int i = 0; i < invalid.GetCount(); i++)
if(invalid[i].Intersects(rr))
for(int i = 0; i < Ctrl::invalid.GetCount(); i++)
if(Ctrl::invalid[i].Intersects(rr))
return true;
return true;
}

View file

@ -34,7 +34,7 @@ void Ctrl::DoMouseFB(int event, Point p, int zdelta)
else
if(a == Ctrl::DOWN && ignoreclick)
return;
LLOG("Mouse event: " << event << " position " << p << " zdelta " << zdelta << ", capture " << Upp::Name(captureCtrl));
LLOG("### Mouse event: " << event << " position " << p << " zdelta " << zdelta << ", capture " << Upp::Name(captureCtrl));
if(captureCtrl)
MouseEventFB(captureCtrl->GetTopCtrl(), event, p, zdelta);
else
@ -80,7 +80,7 @@ void Ctrl::RemoveCursor()
{
if(!IsNull(fbCursorBakPos)) {
Copy(framebuffer, fbCursorBakPos, fbCursorBak, fbCursorBak.GetSize());
AddInvalid(Rect(fbCursorBakPos, fbCursorBak.GetSize()));
AddUpdate(Rect(fbCursorBakPos, fbCursorBak.GetSize()));
}
fbCursorPos = fbCursorBakPos = Null;
fbCursorBak = Null;
@ -90,7 +90,7 @@ void Ctrl::RemoveCaret()
{
if(!IsNull(fbCaretRect)) {
Copy(framebuffer, fbCaretRect.TopLeft(), fbCaretBak, fbCaretBak.GetSize());
AddInvalid(fbCaretRect);
AddUpdate(fbCaretRect);
}
fbCaretRect = Null;
fbCaretBak = Null;
@ -113,12 +113,15 @@ void Ctrl::SyncCaret() {
void Ctrl::CursorSync()
{
DLOG("@ CursorSync");
Point p = GetMousePos() - fbCursorImage.GetHotSpot();
Rect cr = Null;
if(focusCtrl && (((GetTickCount() - fbCaretTm) / 500) & 1) == 0)
cr = (RectC(focusCtrl->caretx, focusCtrl->carety, focusCtrl->caretcx, focusCtrl->caretcy)
+ focusCtrl->GetScreenView().TopLeft()) & focusCtrl->GetScreenView();
DDUMP(GetTickCount());
if(fbCursorPos != p || cr != fbCaretRect) {
DDUMP(fbCaretRect);
RemoveCursor();
RemoveCaret();
@ -128,9 +131,9 @@ void Ctrl::CursorSync()
fbCursorBak = GetBak(tr);
fbCursorBakPos = tr.TopLeft();
fbCaretRect = cr;
if(!cr.IsEmpty()) {
fbCaretBak = GetBak(cr);
fbCaretRect = cr;
for(int y = cr.top; y < cr.bottom; y++) {
RGBA *s = framebuffer[y] + cr.left;
const RGBA *e = framebuffer[y] + cr.right;
@ -141,11 +144,12 @@ void Ctrl::CursorSync()
s++;
}
}
AddInvalid(fbCaretRect);
AddUpdate(fbCaretRect);
}
Over(framebuffer, p, fbCursorImage, sz);
AddInvalid(tr);
DLOG("Cursor: " << p << ", rect " << tr);
AddUpdate(tr);
}
}

View file

@ -19,7 +19,6 @@ public:
private:
Vector<Point> offset;
const Vector<Rect>& invalid;
void Push();
void Pop();
@ -32,15 +31,12 @@ public:
static void Flush() {}
SystemDraw(ImageBuffer& ib, const Vector<Rect>& invalid, int mode = MODE_ANTIALIASED)
: BufferPainter(ib, mode), invalid(invalid) {}
SystemDraw();
~SystemDraw();
};
struct BackDraw__ : public SystemDraw {
ImageBuffer h;
Vector<Rect> dummy_invalid;
BackDraw__() : SystemDraw(h, dummy_invalid) {}
BackDraw__() : SystemDraw() {}
};
class BackDraw : public BackDraw__ { // Dummy only, as we are running in GlobalBackBuffer mode
@ -110,6 +106,7 @@ bool FBProcessEvent(bool *quit);
void FBSleep(int ms);
bool FBEndSession();
void FBUpdate(const Rect& area);
void FBFlush();
// }

View file

@ -4,8 +4,36 @@
NAMESPACE_UPP
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, Color color, uint64 pattern)
static void sRenderLine(SystemDraw& w, int x, int y, int dx, int dy, int cx, int cy, int len, byte pattern)
{
DLOG(len);
for(int i = 0; i < len; i++)
if((128 >> (i & 7)) & pattern)
w.DrawRect(x + dx * i, y + dy * i, cx, cy, Black);
DDUMP("~sRenderLine");
}
static void sRenderRect(SystemDraw& w, const Rect& r, int n, byte pattern)
{
sRenderLine(w, r.left, r.top, 1, 0, 1, n, r.GetWidth(), pattern);
sRenderLine(w, r.left, r.bottom - 1, 1, 0, 1, n, r.GetWidth(), pattern);
sRenderLine(w, r.left, r.top, 0, 1, n, 1, r.GetHeight(), pattern);
sRenderLine(w, r.right - 1, r.top, 0, 1, n, 1, r.GetHeight(), pattern);
}
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2,
const Rect& clip, int n, Color color, uint64 pattern)
{
DLOG("@ DrawDragRect " << rect1 << " " << rect2 << ", clip: " << clip << ", pattern: " << pattern);
TIMING("DrawDrawRect");
w.Clip(clip);
w.Invert();
sRenderRect(w, rect1, n, (byte)pattern);
sRenderRect(w, rect2, n, (byte)pattern);
Ctrl::AddUpdate((rect1 | rect2).Offseted(w.GetOffset()));
// MemoryProfile mem;
// DDUMP(mem);
w.End();
}
/*

View file

@ -8,6 +8,7 @@ NAMESPACE_UPP
ImageBuffer Ctrl::framebuffer;
Vector<Rect> Ctrl::invalid;
Vector<Rect> Ctrl::update;
Ptr<Ctrl> Ctrl::desktop;
Vector<Ctrl *> Ctrl::topctrl;
@ -151,8 +152,15 @@ bool Ctrl::IsWaitingEvent()
return FBIsWaitingEvent();
}
void Ctrl::AddUpdate(const Rect& rect)
{
DLOG("@AddUpdate " << rect);
AddRefreshRect(update, rect);
}
void Ctrl::AddInvalid(const Rect& rect)
{
DLOG("@AddInvalid " << rect);
AddRefreshRect(invalid, rect);
}
@ -167,6 +175,7 @@ void Ctrl::SyncTopWindows()
bool Ctrl::ProcessEvent(bool *quit)
{
DLOG("@ ProcessEvent");
ASSERT(IsMainThread());
if(DoCall()) {
SyncTopWindows();
@ -179,6 +188,7 @@ bool Ctrl::ProcessEvent(bool *quit)
if(!GetMouseLeft() && !GetMouseRight() && !GetMouseMiddle())
ReleaseCtrlCapture();
if(FBProcessEvent(quit)) {
DLOG("FBProcesEvent returned true");
SyncTopWindows();
DefferedFocusSync();
SyncCaret();
@ -198,47 +208,107 @@ Rect Ctrl::GetClipBound(const Vector<Rect>& inv, const Rect& r)
return ri;
}
void Ctrl::DoPaint(const Vector<Rect>& invalid)
ViewDraw::ViewDraw(Ctrl *ctrl)
{
if(Ctrl::invalid.GetCount())
Ctrl::DoPaint();
Ctrl::invalid.Clear();
Ctrl::RemoveCursor();
Ctrl::RemoveCaret();
Rect r = ctrl->GetScreenView();
Ctrl::invalid.Add(r);
Ctrl::AddUpdate(r);
for(int i = max(ctrl->GetTopCtrl()->FindTopCtrl() + 1, 0); i < Ctrl::topctrl.GetCount(); i++) {
Rect rr = Ctrl::topctrl[i]->GetScreenRect();
ExcludeClip(rr);
Subtract(Ctrl::invalid, rr);
}
Offset(r.TopLeft());
}
ViewDraw::~ViewDraw()
{
Ctrl::invalid.Clear();
}
void Ctrl::DoUpdate()
{
DLOG("DoUpdate");
invalid.Clear();
CursorSync();
DDUMPC(update);
#if 0
FBUpdate(framebuffer.GetSize());
#else
for(int i = 0; i < update.GetCount(); i++) {
DDUMP(update[i]);
FBUpdate(update[i]);
}
#endif
update.Clear();
FBFlush();
// Sleep(1000);
}
void Ctrl::DoPaint()
{
DLOG("@ DoPaint");
if(invalid.GetCount() && desktop) {
DLOG("DoPaint invalid");
DDUMPC(invalid);
RemoveCursor();
RemoveCaret();
SystemDraw painter(framebuffer, invalid, renderingMode);
SystemDraw painter;
painter.Begin();
for(int i = 0; i < invalid.GetCount(); i++)
for(int i = 0; i < invalid.GetCount(); i++) {
painter.RectPath(invalid[i]);
AddUpdate(invalid[i]);
}
painter.Painter::Clip();
Vector<Rect> inv;
inv <<= invalid;
for(int i = topctrl.GetCount() - 1; i >= 0; i--) {
Rect r = topctrl[i]->GetRect();
Rect ri = GetClipBound(inv, r);
Rect ri = GetClipBound(invalid, r);
if(!IsNull(ri)) {
painter.Offset(r.TopLeft());
painter.Clipoff(r);
topctrl[i]->UpdateArea(painter, ri - r.TopLeft());
painter.End();
Subtract(inv, r);
Subtract(invalid, r);
painter.ExcludeClip(r);
}
}
Rect ri = GetClipBound(inv, framebuffer.GetSize());
Rect ri = GetClipBound(invalid, framebuffer.GetSize());
if(!IsNull(ri))
desktop->UpdateArea(painter, ri);
}
CursorSync();
for(int i = 0; i < invalid.GetCount(); i++)
FBUpdate(invalid[i]);
DoUpdate();
}
void Ctrl::WndUpdate0r(const Rect& r)
{
GuiLock __;
Rect rr = r + GetRect().TopLeft();
bool dummy;
Vector<Rect> h;
h <<= invalid;
invalid = Intersect(invalid, rr, dummy);
DoPaint();
invalid <<= h;
Subtract(invalid, rr);
FBFlush();
}
bool Ctrl::ProcessEvents(bool *quit)
{
DLOG("ProcessEvents " << LOG_BEGIN);
if(!ProcessEvent(quit))
return false;
while(ProcessEvent(quit) && (!LoopCtrl || LoopCtrl->InLoop()) && !FBEndSession());
TimerProc(GetTickCount());
SweepMkImageCache();
DoPaint(invalid);
invalid.Clear();
DoPaint();
FBFlush();
DLOG(LOG_END);
return true;
}
@ -476,15 +546,6 @@ void Ctrl::WndSetPos0(const Rect& rect)
invalid.Add(rect);
}
void Ctrl::WndUpdate0r(const Rect& r)
{
GuiLock __;
Rect rr = r + GetRect().TopLeft();
bool dummy;
DoPaint(Intersect(invalid, rr, dummy));
invalid = Subtract(invalid, rr, dummy);
}
void Ctrl::WndScrollView0(const Rect& r, int dx, int dy)
{
GuiLock __;

View file

@ -29,6 +29,14 @@ struct App : public Ctrl {
w.Clipoff(200, 50, 95, 100);
w.DrawText(0, 80, "CLIPPED", Roman(25));
w.End();
DrawDragRect((SystemDraw&)w,
Rect(0, 0, 0, 0),
Rect(23, 165, 672, 301),
Size(1163, 513),
1,
Black(),
MAKEQWORD(Random(), Random()));
}
void LeftDown(Point p, dword)
@ -85,6 +93,7 @@ GUI_APP_MAIN
{
#if EDITOR
RichEditWithToolBar app;
app.SetQTF(LoadFile(ConfigFile("test.qtf")));
#else
App app;
app.popup.PopUp();
@ -107,4 +116,7 @@ GUI_APP_MAIN
top.Open();
#endif
Ctrl::EventLoop();
#if EDITOR
SaveFile(ConfigFile("test.qtf"), app.GetQTF());
#endif
}

View file

@ -13,7 +13,8 @@ uses(SDLFB) SDLFb;
uses(WINGL) WinGl;
file
Draw.cpp;
Draw.cpp,
U:\h.txt;
mainconfig
"" = "GUI WINFB",

View file

@ -2,7 +2,7 @@
NAMESPACE_UPP
#define LLOG(x) // LOG(x)
#define LLOG(x) LOG(x)
bool GetShift() { return !!(GetKeyState(VK_SHIFT) & 0x8000); }
bool GetCtrl() { return !!(GetKeyState(VK_CONTROL) & 0x8000); }
@ -58,6 +58,12 @@ LRESULT CALLBACK fbWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd, &ps);
fbUpdate(dc, ps.rcPaint);
#if 0
Rect r = ps.rcPaint;
::PatBlt(dc, r.left, r.top, r.GetWidth(), r.GetHeight(), DSTINVERT);
Sleep(40);
::PatBlt(dc, r.left, r.top, r.GetWidth(), r.GetHeight(), DSTINVERT);
#endif
EndPaint(hwnd, &ps);
}
return 0L;

View file

@ -33,7 +33,9 @@ bool FBProcessEvent(bool *quit)
void FBSleep(int ms)
{
TimeStop tm;
MsgWaitForMultipleObjects(0, NULL, FALSE, ms, QS_ALLINPUT);
DLOG("@ FBSleep " << tm.Elapsed());
}
void FBInit(HINSTANCE hInstance)
@ -60,10 +62,13 @@ void FBInit(HINSTANCE hInstance)
// Csizeinit();
}
void fbUpdate(HDC hdc, const Rect& r)
void fbUpdate(HDC hdc, const Rect& r_)
{
const ImageBuffer& framebuffer = Ctrl::GetFrameBuffer();
Size sz = framebuffer.GetSize();
Rect r = sz;
// Rect r = r_;
DLOG("fbUpdate " << r);
Buffer<byte> data;
data.Alloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
BITMAPINFOHEADER *hi = (BITMAPINFOHEADER *) ~data;;
@ -84,7 +89,7 @@ void fbUpdate(HDC hdc, const Rect& r)
void FBUpdate(const Rect& r)
{
LLOG("FBUpdate " << r);
DLOG("FBUpdate " << r);
if(fbHWND) {
HDC hdc = GetDC(fbHWND);
fbUpdate(hdc, r);
@ -95,6 +100,13 @@ void FBUpdate(const Rect& r)
#endif
ReleaseDC(fbHWND, hdc);
}
// ::InvalidateRect(fbHWND, NULL, false);
}
void FBFlush()
{
::UpdateWindow(fbHWND);
GdiFlush();
}
END_UPP_NAMESPACE

View file

@ -2,8 +2,6 @@
#define _WinGl_After_h_
class ViewDraw : public SystemDraw {
ImageBuffer ib;
public:
ViewDraw(Ctrl *ctrl) {}
~ViewDraw() {}