mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
.SlaveGui
git-svn-id: svn://ultimatepp.org/upp/trunk@11899 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6a0b714258
commit
285719ebb3
29 changed files with 6398 additions and 2 deletions
|
|
@ -38,9 +38,9 @@ void Ctrl::InitFB()
|
|||
Ctrl::GlobalBackBuffer();
|
||||
Ctrl::InitTimer();
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
// #ifdef PLATFORM_POSIX
|
||||
SetStdFont(ScreenSans(12)); //FIXME general handling
|
||||
#endif
|
||||
// #endif
|
||||
ChStdSkin();
|
||||
|
||||
static StaticRect x;
|
||||
|
|
|
|||
51
rainbow/SlaveGui/After.h
Normal file
51
rainbow/SlaveGui/After.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class ViewDraw : public SystemDraw {
|
||||
public:
|
||||
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 {};
|
||||
|
||||
void FBInit();
|
||||
void FBDeInit();
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#define GUI_APP_MAIN \
|
||||
void GuiMainFn_(); \
|
||||
\
|
||||
extern "C" int main(int argc, char *argv[]) { \
|
||||
UPP::AppInit__(argc, (const char **)argv); \
|
||||
FBInit(); \
|
||||
GuiMainFn_(); \
|
||||
UPP::Ctrl::CloseTopCtrls(); \
|
||||
FBDeInit(); \
|
||||
return UPP::GetExitCode(); \
|
||||
} \
|
||||
\
|
||||
void GuiMainFn_()
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
#define GUI_APP_MAIN \
|
||||
void GuiMainFn_(); \
|
||||
\
|
||||
extern "C" int main(int argc, const char **argv, const char **envptr) { \
|
||||
UPP::AppInit__(argc, argv, envptr); \
|
||||
FBInit(); \
|
||||
GuiMainFn_(); \
|
||||
UPP::Ctrl::CloseTopCtrls(); \
|
||||
FBDeInit(); \
|
||||
return UPP::GetExitCode(); \
|
||||
} \
|
||||
\
|
||||
void GuiMainFn_()
|
||||
#endif
|
||||
21
rainbow/SlaveGui/ChSysInit.cpp
Normal file
21
rainbow/SlaveGui/ChSysInit.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
void ChSysInit()
|
||||
{
|
||||
CtrlImg::Reset();
|
||||
CtrlsImg::Reset();
|
||||
ChReset();
|
||||
}
|
||||
|
||||
void ChHostSkin()
|
||||
{
|
||||
ChSysInit();
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
238
rainbow/SlaveGui/Clip.cpp
Normal file
238
rainbow/SlaveGui/Clip.cpp
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) // LOG(x)
|
||||
|
||||
static VectorMap<String, ClipData> fbClipboard;
|
||||
|
||||
void ClearClipboard()
|
||||
{
|
||||
GuiLock __;
|
||||
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 __;
|
||||
int q = fbClipboard.Find(format);
|
||||
return q >= 0 ? (*fbClipboard[q].render)(fbClipboard[q].data) : String();
|
||||
}
|
||||
|
||||
void AppendClipboardText(const String& s)
|
||||
{
|
||||
AppendClipboard("text", ToSystemCharset(s));
|
||||
}
|
||||
|
||||
void AppendClipboardUnicodeText(const WString& s)
|
||||
{
|
||||
AppendClipboard("wtext", (byte *)~s, 2 * s.GetLength());
|
||||
}
|
||||
|
||||
const char *ClipFmtsText()
|
||||
{
|
||||
return "wtext;text";
|
||||
}
|
||||
|
||||
String GetString(PasteClip& clip)
|
||||
{
|
||||
GuiLock __;
|
||||
if(clip.Accept("wtext")) {
|
||||
String s = ~clip;
|
||||
return WString((const wchar *)~s, wstrlen((const wchar *)~s)).ToString();
|
||||
}
|
||||
if(clip.IsAvailable("text"))
|
||||
return ~clip;
|
||||
return Null;
|
||||
}
|
||||
|
||||
WString GetWString(PasteClip& clip)
|
||||
{
|
||||
GuiLock __;
|
||||
if(clip.Accept("wtext")) {
|
||||
String s = ~clip;
|
||||
return WString((const wchar *)~s, wstrlen((const wchar *)~s));
|
||||
}
|
||||
if(clip.IsAvailable("text"))
|
||||
return (~clip).ToWString();
|
||||
return Null;
|
||||
}
|
||||
|
||||
|
||||
bool AcceptText(PasteClip& clip)
|
||||
{
|
||||
return clip.Accept(ClipFmtsText());
|
||||
}
|
||||
|
||||
static String sText(const Value& data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
static String sWText(const Value& data)
|
||||
{
|
||||
return Unicode__(WString(data));
|
||||
}
|
||||
|
||||
void Append(VectorMap<String, ClipData>& data, const String& text)
|
||||
{
|
||||
data.GetAdd("text", ClipData(text, sText));
|
||||
data.GetAdd("wtext", ClipData(text, sWText));
|
||||
}
|
||||
|
||||
void Append(VectorMap<String, ClipData>& data, const WString& text)
|
||||
{
|
||||
data.GetAdd("text", ClipData(text, sText));
|
||||
data.GetAdd("wtext", ClipData(text, sWText));
|
||||
}
|
||||
|
||||
String GetTextClip(const WString& text, const String& fmt)
|
||||
{
|
||||
if(fmt == "text")
|
||||
return text.ToString();
|
||||
if(fmt == "wtext")
|
||||
return Unicode__(text);
|
||||
return Null;
|
||||
}
|
||||
|
||||
String GetTextClip(const String& text, const String& fmt)
|
||||
{
|
||||
if(fmt == "text")
|
||||
return text;
|
||||
if(fmt == "wtext")
|
||||
return Unicode__(text.ToWString());
|
||||
return Null;
|
||||
}
|
||||
|
||||
String ReadClipboardText()
|
||||
{
|
||||
String w = ReadClipboard("text");
|
||||
return w.GetCount() ? w : ReadClipboardUnicodeText().ToString();
|
||||
}
|
||||
|
||||
WString ReadClipboardUnicodeText()
|
||||
{
|
||||
String w = ReadClipboard("wtext");
|
||||
if(w.GetCount())
|
||||
return WString((const wchar *)~w, w.GetLength() / 2);
|
||||
return ReadClipboard("text").ToWString();
|
||||
}
|
||||
|
||||
bool IsClipboardAvailable(const char *id)
|
||||
{
|
||||
return fbClipboard.Find(id) >= 0;
|
||||
}
|
||||
|
||||
bool IsClipboardAvailableText()
|
||||
{
|
||||
return IsClipboardAvailable("text") || IsClipboardAvailable("wtext");
|
||||
}
|
||||
|
||||
const char *ClipFmtsImage()
|
||||
{
|
||||
static const char *q;
|
||||
ONCELOCK {
|
||||
static String s = "dib;" + ClipFmt<Image>();
|
||||
q = s;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
bool AcceptImage(PasteClip& clip)
|
||||
{
|
||||
GuiLock __;
|
||||
return clip.Accept(ClipFmtsImage());
|
||||
}
|
||||
|
||||
Image GetImage(PasteClip& clip)
|
||||
{
|
||||
GuiLock __;
|
||||
Image m;
|
||||
if(Accept<Image>(clip)) {
|
||||
LoadFromString(m, ~clip);
|
||||
if(!m.IsEmpty())
|
||||
return m;
|
||||
}
|
||||
return Null;
|
||||
}
|
||||
|
||||
Image ReadClipboardImage()
|
||||
{
|
||||
GuiLock __;
|
||||
PasteClip d = Ctrl::Clipboard();
|
||||
return GetImage(d);
|
||||
}
|
||||
|
||||
String sImage(const Value& image)
|
||||
{
|
||||
Image img = image;
|
||||
return StoreAsString(const_cast<Image&>(img));
|
||||
}
|
||||
|
||||
String GetImageClip(const Image& img, const String& fmt)
|
||||
{
|
||||
GuiLock __;
|
||||
if(img.IsEmpty()) return Null;
|
||||
if(fmt == ClipFmt<Image>())
|
||||
return sImage(img);
|
||||
return Null;
|
||||
}
|
||||
|
||||
void AppendClipboardImage(const Image& img)
|
||||
{
|
||||
GuiLock __;
|
||||
if(img.IsEmpty()) return;
|
||||
AppendClipboard(ClipFmt<Image>(), img, sImage);
|
||||
}
|
||||
|
||||
bool AcceptFiles(PasteClip& clip)
|
||||
{
|
||||
if(clip.Accept("files")) {
|
||||
clip.SetAction(DND_COPY);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsAvailableFiles(PasteClip& clip)
|
||||
{
|
||||
return clip.IsAvailable("files");
|
||||
}
|
||||
|
||||
Vector<String> GetFiles(PasteClip& clip)
|
||||
{
|
||||
GuiLock __;
|
||||
Vector<String> f;
|
||||
return f;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
81
rainbow/SlaveGui/Ctrl.cpp
Normal file
81
rainbow/SlaveGui/Ctrl.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
#define LLOG(x) // DLOG(x)
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
void Ctrl::GuiPlatformConstruct()
|
||||
{
|
||||
}
|
||||
|
||||
void Ctrl::GuiPlatformRemove()
|
||||
{
|
||||
}
|
||||
|
||||
void Ctrl::GuiPlatformGetTopRect(Rect& r) const
|
||||
{
|
||||
}
|
||||
|
||||
bool Ctrl::GuiPlatformRefreshFrameSpecial(const Rect& r)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Ctrl::GuiPlatformSetFullRefreshSpecial()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Ctrl::PaintCaret(SystemDraw& w)
|
||||
{
|
||||
}
|
||||
|
||||
String GuiPlatformGetKeyDesc(dword key)
|
||||
{
|
||||
return Null;
|
||||
}
|
||||
|
||||
void Ctrl::GuiPlatformSelection(PasteClip&)
|
||||
{
|
||||
}
|
||||
|
||||
void GuiPlatformAdjustDragImage(ImageBuffer&)
|
||||
{
|
||||
}
|
||||
|
||||
bool GuiPlatformHasSizeGrip()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiPlatformGripResize(TopWindow *q)
|
||||
{
|
||||
q->GripResize();
|
||||
}
|
||||
|
||||
Color GuiPlatformGetScreenPixel(int x, int y)
|
||||
{
|
||||
return Null;
|
||||
}
|
||||
|
||||
void GuiPlatformAfterMenuPopUp()
|
||||
{
|
||||
}
|
||||
|
||||
String Ctrl::Name() const {
|
||||
GuiLock __;
|
||||
#ifdef CPU_64
|
||||
String s = String(typeid(*this).name()) + " : 0x" + FormatIntHex(this);
|
||||
#else
|
||||
String s = String(typeid(*this).name()) + " : " + Format("0x%x", (int) this);
|
||||
#endif
|
||||
if(IsChild())
|
||||
s << "(parent " << String(typeid(*parent).name()) << ")";
|
||||
return s;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
74
rainbow/SlaveGui/Ctrl.h
Normal file
74
rainbow/SlaveGui/Ctrl.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//$ class Ctrl {
|
||||
private:
|
||||
static Ptr<Ctrl> desktop;
|
||||
static Vector<Ctrl *> topctrl;
|
||||
static bool invalid;
|
||||
|
||||
static Point fbCursorPos;
|
||||
static Image fbCursorImage;
|
||||
static bool sdlMouseIsIn;
|
||||
|
||||
static Rect fbCaretRect;
|
||||
static int fbCaretTm;
|
||||
|
||||
static bool fbEndSession;
|
||||
static int64 fbEventLoop;
|
||||
static int64 fbEndSessionLoop;
|
||||
|
||||
static void CursorSync();
|
||||
|
||||
int FindTopCtrl() const;
|
||||
static Rect GetClipBound(const Vector<Rect>& inv, const Rect& r);
|
||||
static void DoPaint();
|
||||
static void SyncTopWindows();
|
||||
|
||||
// static void AddInvalid(const Rect& rect);
|
||||
|
||||
void DestroyWnd();
|
||||
|
||||
void NewTop() { top = new Top; top->owner_window = NULL; }
|
||||
void PutForeground();
|
||||
static void MouseEventFB(Ptr<Ctrl> t, int event, Point p, int zdelta);
|
||||
|
||||
static void DrawLine(const Vector<Rect>& clip, int x, int y, int cx, int cy, bool horz,
|
||||
const byte *pattern, int animation);
|
||||
static void DragRectDraw0(const Vector<Rect>& clip, const Rect& rect, int n,
|
||||
const byte *pattern, int animation);
|
||||
|
||||
friend struct PaintProxy__;
|
||||
friend class TopWindowFrame;
|
||||
friend class SystemDraw;
|
||||
friend struct DnDLoop;
|
||||
|
||||
void SetOpen(bool b) { isopen = b; }
|
||||
|
||||
protected:
|
||||
static int PaintLock;
|
||||
|
||||
public:
|
||||
static void DoMouseFB(int event, Point p, int zdelta = 0);
|
||||
static bool DoKeyFB(dword key, int cnt);
|
||||
|
||||
static void InitFB();
|
||||
static void ExitFB();
|
||||
static void EndSession();
|
||||
|
||||
static void SetDesktop(Ctrl& q);
|
||||
static Ctrl *GetDesktop() { return desktop; }
|
||||
static void SetDesktopSize(Size sz);
|
||||
|
||||
static void Invalidate() { invalid = true; }
|
||||
|
||||
void DragRectDraw(const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
|
||||
Color color, int type, int animation);
|
||||
|
||||
static Ctrl *FindMouseTopCtrl();
|
||||
|
||||
static void PaintScene(SystemDraw& draw);
|
||||
static void PaintCaretCursor(SystemDraw& draw);
|
||||
|
||||
static bool SystemCursor;
|
||||
|
||||
enum { DRAWDRAGRECT_SCREEN = 0x8000 };
|
||||
|
||||
//$ };
|
||||
81
rainbow/SlaveGui/Cursor.cpp
Normal file
81
rainbow/SlaveGui/Cursor.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) LOG(x)
|
||||
#define LDUMP(x) //DDUMP(x)
|
||||
|
||||
void Ctrl::SetMouseCursor(const Image& image)
|
||||
{
|
||||
GuiLock __;
|
||||
SlaveGuiPtr->SetMouseCursor(image);
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct RectSDL {
|
||||
SDL_Rect sr;
|
||||
|
||||
operator SDL_Rect *() { return &sr; }
|
||||
|
||||
RectSDL(const Rect& r)
|
||||
{
|
||||
sr.x = r.left;
|
||||
sr.y = r.top;
|
||||
sr.w = r.GetWidth();
|
||||
sr.h = r.GetHeight();
|
||||
}
|
||||
};
|
||||
|
||||
SDL_Texture *SDLTextureFromImage(SDL_Renderer *renderer, const Image& m)
|
||||
{
|
||||
Size isz = m.GetSize();
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STATIC, isz.cx, isz.cy);
|
||||
if(texture) {
|
||||
SDL_UpdateTexture(texture, RectSDL(isz), ~m, isz.cx * sizeof(RGBA));
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
SDL_Cursor *sdl_cursor;
|
||||
SDL_Surface *sdl_cursor_surface;
|
||||
Buffer<RGBA> data;
|
||||
|
||||
if(image.GetSerialId() != fbCursorImage.GetSerialId()) {
|
||||
fbCursorImage = image;
|
||||
fbCursorPos = Null;
|
||||
SDL_ShowCursor(SystemCursor);
|
||||
if(SystemCursor) {
|
||||
if(sdl_cursor)
|
||||
SDL_FreeCursor(sdl_cursor);
|
||||
if(sdl_cursor_surface)
|
||||
SDL_FreeSurface(sdl_cursor_surface);
|
||||
|
||||
int64 a = image.GetAuxData();
|
||||
if(a)
|
||||
sdl_cursor = SDL_CreateSystemCursor(SDL_SystemCursor(a - 1));
|
||||
else {
|
||||
sdl_cursor = NULL;
|
||||
data.Alloc(image.GetLength());
|
||||
Copy(data, image, image.GetLength());
|
||||
sdl_cursor_surface = SDL_CreateRGBSurfaceFrom(~data, image.GetWidth(), image.GetHeight(),
|
||||
32, sizeof(RGBA) * image.GetWidth(),
|
||||
0xff0000, 0xff00, 0xff, 0xff000000);
|
||||
Point h = image.GetHotSpot();
|
||||
if(sdl_cursor_surface)
|
||||
sdl_cursor = SDL_CreateColorCursor(sdl_cursor_surface, h.x, h.y);
|
||||
}
|
||||
if(sdl_cursor)
|
||||
SDL_SetCursor(sdl_cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
150
rainbow/SlaveGui/DnD.cpp
Normal file
150
rainbow/SlaveGui/DnD.cpp
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) // DLOG(x)
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
Ptr<Ctrl> sDnDSource;
|
||||
|
||||
Ctrl * Ctrl::GetDragAndDropSource()
|
||||
{
|
||||
return sDnDSource;
|
||||
}
|
||||
|
||||
struct DnDLoop : LocalLoop {
|
||||
const VectorMap<String, ClipData> *data;
|
||||
Vector<String> fmts;
|
||||
|
||||
Image move, copy, reject;
|
||||
Ptr<Ctrl> target;
|
||||
int action;
|
||||
byte actions;
|
||||
|
||||
void Sync();
|
||||
String GetData(const String& f);
|
||||
void DnD(bool paste);
|
||||
|
||||
virtual void LeftUp(Point, dword);
|
||||
virtual bool Key(dword, int);
|
||||
virtual void MouseMove(Point p, dword);
|
||||
virtual Image CursorImage(Point, dword);
|
||||
};
|
||||
|
||||
Ptr<DnDLoop> dndloop;
|
||||
|
||||
bool PasteClip::IsAvailable(const char *fmt) const
|
||||
{
|
||||
GuiLock __;
|
||||
return dnd ? dndloop && FindIndex(dndloop->fmts, fmt) >= 0
|
||||
: IsClipboardAvailable(fmt);
|
||||
}
|
||||
|
||||
String DnDLoop::GetData(const String& f)
|
||||
{
|
||||
GuiLock __;
|
||||
int i = data->Find(f);
|
||||
String d;
|
||||
if(i >= 0)
|
||||
d = (*data)[i].Render();
|
||||
else
|
||||
if(sDnDSource)
|
||||
d = sDnDSource->GetDropData(f);
|
||||
return d;
|
||||
}
|
||||
|
||||
String PasteClip::Get(const char *fmt) const
|
||||
{
|
||||
return dnd ? dndloop ? dndloop->GetData(fmt) : String() : ReadClipboard(fmt);
|
||||
}
|
||||
|
||||
void PasteClip::GuiPlatformConstruct()
|
||||
{
|
||||
dnd = false;
|
||||
}
|
||||
|
||||
void DnDLoop::DnD(bool paste)
|
||||
{
|
||||
PasteClip d;
|
||||
d.paste = paste;
|
||||
d.accepted = false;
|
||||
d.allowed = (byte)actions;
|
||||
d.action = GetCtrl() ? DND_COPY : DND_MOVE;
|
||||
d.dnd = true;
|
||||
if(target)
|
||||
target->DnD(GetMousePos(), d);
|
||||
action = d.IsAccepted() ? d.GetAction() : DND_NONE;
|
||||
}
|
||||
|
||||
void DnDLoop::Sync()
|
||||
{
|
||||
GuiLock __;
|
||||
Ptr<Ctrl> t = FindMouseTopCtrl();
|
||||
if(t != target)
|
||||
if(target)
|
||||
target->DnDLeave();
|
||||
target = t;
|
||||
DnD(false);
|
||||
}
|
||||
|
||||
void DnDLoop::LeftUp(Point, dword)
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("DnDLoop::LeftUp");
|
||||
DnD(true);
|
||||
EndLoop();
|
||||
}
|
||||
|
||||
void DnDLoop::MouseMove(Point p, dword)
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("DnDLoop::MouseMove");
|
||||
Sync();
|
||||
}
|
||||
|
||||
bool DnDLoop::Key(dword, int)
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("DnDLoop::Key");
|
||||
Sync();
|
||||
return false;
|
||||
}
|
||||
|
||||
Image DnDLoop::CursorImage(Point, dword)
|
||||
{
|
||||
GuiLock __;
|
||||
return action == DND_MOVE ? move : action == DND_COPY ? copy : reject;
|
||||
}
|
||||
|
||||
int Ctrl::DoDragAndDrop(const char *fmts, const Image& sample, dword actions,
|
||||
const VectorMap<String, ClipData>& data)
|
||||
{
|
||||
GuiLock __;
|
||||
DnDLoop d;
|
||||
d.actions = (byte)actions;
|
||||
d.reject = actions & DND_EXACTIMAGE ? CtrlCoreImg::DndNone() : MakeDragImage(CtrlCoreImg::DndNone(), sample);
|
||||
if(actions & DND_COPY)
|
||||
d.copy = actions & DND_EXACTIMAGE ? sample : MakeDragImage(CtrlCoreImg::DndCopy(), sample);
|
||||
if(actions & DND_MOVE)
|
||||
d.move = actions & DND_EXACTIMAGE ? sample : MakeDragImage(CtrlCoreImg::DndMoveX11(), sample);
|
||||
d.SetMaster(*this);
|
||||
d.data = &data;
|
||||
d.action = DND_NONE;
|
||||
d.fmts = Split(fmts, ';');
|
||||
dndloop = &d;
|
||||
sDnDSource = this;
|
||||
d.Run();
|
||||
sDnDSource = NULL;
|
||||
SyncCaret();
|
||||
LLOG("DoDragAndDrop finished");
|
||||
return d.action;
|
||||
}
|
||||
|
||||
void Ctrl::SetSelectionSource(const char *fmts) {}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
92
rainbow/SlaveGui/DrawDragRect.cpp
Normal file
92
rainbow/SlaveGui/DrawDragRect.cpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include "Local.h"
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
struct DrawDragRectInfo {
|
||||
Rect rect1, rect2, clip;
|
||||
int n;
|
||||
int type;
|
||||
int animation;
|
||||
};
|
||||
|
||||
void DrawDragLine(SystemDraw& w, bool horz, int x, int y, int len, int n, const int *pattern, int animation)
|
||||
{
|
||||
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, InvertColor());
|
||||
x += d;
|
||||
}
|
||||
else {
|
||||
w.DrawRect(x, y, n, segment, InvertColor());
|
||||
y += d;
|
||||
}
|
||||
len -= d;
|
||||
ch = !ch;
|
||||
}
|
||||
w.End();
|
||||
}
|
||||
|
||||
void DrawDragFrame(SystemDraw& w, const Rect& r, int n, const int *pattern, int animation)
|
||||
{
|
||||
DrawDragLine(w, true, r.left, r.top, r.GetWidth(), n, pattern, animation);
|
||||
DrawDragLine(w, false, r.left, r.top + n, r.GetHeight() - 2 * n, n, pattern, animation);
|
||||
DrawDragLine(w, false, r.right - n, r.top + n, r.GetHeight() - 2 * n, n, pattern, animation);
|
||||
DrawDragLine(w, true, r.left, r.bottom - n, r.GetWidth(), n, pattern, animation);
|
||||
}
|
||||
|
||||
void DrawDragRect(Ctrl& q, const DrawDragRectInfo& f)
|
||||
{
|
||||
SystemDraw w;
|
||||
Ctrl::PaintScene(w);
|
||||
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)];
|
||||
DrawDragFrame(w, f.rect1, f.n, dash, f.animation);
|
||||
DrawDragFrame(w, f.rect2, f.n, dash, f.animation);
|
||||
w.End();
|
||||
Ctrl::PaintCaretCursor(w);
|
||||
SDL_GL_SwapWindow(screen.win);
|
||||
}
|
||||
|
||||
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) {
|
||||
Point off = q.GetScreenView().TopLeft();
|
||||
DrawDragRectInfo f;
|
||||
f.rect1 = rect1.Offseted(off);
|
||||
f.rect2 = rect2.Offseted(off);
|
||||
f.clip = (clip & q.GetSize()).Offseted(off);
|
||||
f.n = n;
|
||||
f.type = type;
|
||||
f.animation = animation;
|
||||
DrawDragRect(*top, f);
|
||||
}
|
||||
}
|
||||
|
||||
void FinishDragRect(Ctrl& q)
|
||||
{
|
||||
SystemDraw w;
|
||||
Ctrl::PaintScene(w);
|
||||
Ctrl::PaintCaretCursor(w);
|
||||
SDL_GL_SwapWindow(screen.win);
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
424
rainbow/SlaveGui/Event.cpp
Normal file
424
rainbow/SlaveGui/Event.cpp
Normal file
|
|
@ -0,0 +1,424 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) LOG(x)
|
||||
#define LDUMP(x) //DDUMP(x)
|
||||
|
||||
static Point fbmousepos;
|
||||
|
||||
int SDLwidth;
|
||||
int SDLheight;
|
||||
|
||||
Point GetMousePos() {
|
||||
return fbmousepos;
|
||||
}
|
||||
|
||||
dword mouseb = 0;
|
||||
dword modkeys = 0;
|
||||
|
||||
enum KM {
|
||||
KM_NONE = 0x00,
|
||||
|
||||
KM_LSHIFT= 0x01,
|
||||
KM_RSHIFT= 0x02,
|
||||
KM_LCTRL = 0x04,
|
||||
KM_RCTRL = 0x08,
|
||||
KM_LALT = 0x10,
|
||||
KM_RALT = 0x20,
|
||||
|
||||
KM_CAPS = 0x40,
|
||||
KM_NUM = 0x80,
|
||||
|
||||
KM_CTRL = KM_LCTRL | KM_RCTRL,
|
||||
KM_SHIFT = KM_LSHIFT | KM_RSHIFT,
|
||||
KM_ALT = KM_LALT | KM_RALT,
|
||||
};
|
||||
|
||||
bool GetMouseLeft() { return mouseb & (1<<0); }
|
||||
bool GetMouseRight() { return mouseb & (1<<1); }
|
||||
bool GetMouseMiddle() { return mouseb & (1<<2); }
|
||||
bool GetShift() { return modkeys & KM_SHIFT; }
|
||||
bool GetCtrl() { return modkeys & KM_CTRL; }
|
||||
bool GetAlt() { return modkeys & KM_ALT; }
|
||||
bool GetCapsLock() { return modkeys & KM_CAPS; }
|
||||
|
||||
#if 0
|
||||
|
||||
dword fbKEYtoK(dword chr) {
|
||||
if(chr == SDLK_TAB)
|
||||
chr = K_TAB;
|
||||
else
|
||||
if(chr == SDLK_SPACE)
|
||||
chr = K_SPACE;
|
||||
else
|
||||
if(chr == SDLK_RETURN)
|
||||
chr = K_RETURN;
|
||||
else
|
||||
chr = chr + K_DELTA;
|
||||
if(chr == K_ALT_KEY || chr == K_CTRL_KEY || chr == K_SHIFT_KEY)
|
||||
return chr;
|
||||
if(GetCtrl()) chr |= K_CTRL;
|
||||
if(GetAlt()) chr |= K_ALT;
|
||||
if(GetShift()) chr |= K_SHIFT;
|
||||
return chr;
|
||||
}
|
||||
|
||||
dword lastbdowntime[8] = {0};
|
||||
dword isdblclick[8] = {0};
|
||||
|
||||
void Ctrl::HandleSDLEvent(SDL_Event* event)
|
||||
{
|
||||
LLOG("HandleSDLEvent " << event->type);
|
||||
SDL_Event next_event;
|
||||
dword keycode;
|
||||
switch(event->type) {
|
||||
// case SDL_ACTIVEEVENT: //SDL_ActiveEvent
|
||||
// break;
|
||||
case SDL_TEXTINPUT: {
|
||||
//send respective keyup things as char events as well
|
||||
WString text = FromUtf8(event->text.text);
|
||||
for(int i = 0; i < text.GetCount(); i++) {
|
||||
int c = text[i];
|
||||
if(c != 127)
|
||||
Ctrl::DoKeyFB(c, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
switch(event->key.keysym.sym) {
|
||||
case SDLK_LSHIFT: modkeys |= KM_LSHIFT; break;
|
||||
case SDLK_RSHIFT: modkeys |= KM_RSHIFT; break;
|
||||
case SDLK_LCTRL: modkeys |= KM_LCTRL; break;
|
||||
case SDLK_RCTRL: modkeys |= KM_RCTRL; break;
|
||||
case SDLK_LALT: modkeys |= KM_LALT; break;
|
||||
case SDLK_RALT: modkeys |= KM_RALT; break;
|
||||
}
|
||||
|
||||
keycode = fbKEYtoK((dword)event->key.keysym.sym);
|
||||
|
||||
if(keycode != K_SPACE) { //dont send space on keydown
|
||||
static int repeat_count;
|
||||
SDL_PumpEvents();
|
||||
if(SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYDOWN) &&
|
||||
next_event.key.keysym.sym == event->key.keysym.sym) {
|
||||
repeat_count++; // Keyboard repeat compression
|
||||
break;
|
||||
}
|
||||
Ctrl::DoKeyFB(keycode, 1 + repeat_count);
|
||||
repeat_count = 0;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP: //SDL_KeyboardEvent
|
||||
switch(event->key.keysym.sym) {
|
||||
case SDLK_LSHIFT: modkeys &= ~KM_LSHIFT; break;
|
||||
case SDLK_RSHIFT: modkeys &= ~KM_RSHIFT; break;
|
||||
case SDLK_LCTRL: modkeys &= ~KM_LCTRL; break;
|
||||
case SDLK_RCTRL: modkeys &= ~KM_RCTRL; break;
|
||||
case SDLK_LALT: modkeys &= ~KM_LALT; break;
|
||||
case SDLK_RALT: modkeys &= ~KM_RALT; break;
|
||||
}
|
||||
|
||||
Ctrl::DoKeyFB(fbKEYtoK((dword)event->key.keysym.sym) | K_KEYUP, 1);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
SDL_PumpEvents();
|
||||
if(SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0)
|
||||
break; // MouseMove compression
|
||||
Ctrl::DoMouseFB(Ctrl::MOUSEMOVE, Point(event->motion.x, event->motion.y));
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, GetMousePos(), sgn(event->wheel.y) * 120);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
Point p(event->button.x, event->button.y);
|
||||
int bi = event->button.button;
|
||||
dword ct = SDL_GetTicks();
|
||||
if(isdblclick[bi] && (abs(int(ct) - int(lastbdowntime[bi])) < 400))
|
||||
{
|
||||
switch(bi)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: Ctrl::DoMouseFB(Ctrl::LEFTDOUBLE, p); break;
|
||||
case SDL_BUTTON_RIGHT: Ctrl::DoMouseFB(Ctrl::RIGHTDOUBLE, p); break;
|
||||
case SDL_BUTTON_MIDDLE: Ctrl::DoMouseFB(Ctrl::MIDDLEDOUBLE, p); break;
|
||||
}
|
||||
isdblclick[bi] = 0; //reset, to go ahead sending repeats
|
||||
}
|
||||
else
|
||||
{
|
||||
lastbdowntime[bi] = ct;
|
||||
isdblclick[bi] = 0; //prepare for repeat
|
||||
switch(bi)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: mouseb |= (1<<0); Ctrl::DoMouseFB(Ctrl::LEFTDOWN, p); break;
|
||||
case SDL_BUTTON_RIGHT: mouseb |= (1<<1); Ctrl::DoMouseFB(Ctrl::RIGHTDOWN, p); break;
|
||||
case SDL_BUTTON_MIDDLE: mouseb |= (1<<2); Ctrl::DoMouseFB(Ctrl::MIDDLEDOWN, p); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
int bi = event->button.button;
|
||||
isdblclick[bi] = 1; //indicate maybe a dblclick
|
||||
|
||||
Point p(event->button.x, event->button.y);
|
||||
switch(bi)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: mouseb &= ~(1<<0); Ctrl::DoMouseFB(Ctrl::LEFTUP, p); break;
|
||||
case SDL_BUTTON_RIGHT: mouseb &= ~(1<<1); Ctrl::DoMouseFB(Ctrl::RIGHTUP, p); break;
|
||||
case SDL_BUTTON_MIDDLE: mouseb &= ~(1<<2); Ctrl::DoMouseFB(Ctrl::MIDDLEUP, p); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
/* case SDL_VIDEORESIZE: //SDL_ResizeEvent
|
||||
{
|
||||
width = event->resize.w;
|
||||
height = event->resize.h;
|
||||
|
||||
SDL_FreeSurface(screen);
|
||||
screen = CreateScreen(width, height, bpp, videoflags);
|
||||
ASSERT(screen);
|
||||
Ctrl::SetFramebufferSize(Size(width, height));
|
||||
}
|
||||
break;
|
||||
case SDL_VIDEOEXPOSE: //SDL_ExposeEvent
|
||||
break;*/
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event->window.event) {
|
||||
case SDL_WINDOWEVENT_SHOWN:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_HIDDEN:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
SDLwidth = event->window.data1;
|
||||
SDLheight = event->window.data2;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESTORED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
sdlMouseIsIn = true;
|
||||
Invalidate();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
sdlMouseIsIn = false;
|
||||
Invalidate();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
break;
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT: //SDL_QuitEvent
|
||||
Ctrl::EndSession();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Ctrl::MouseEventFB(Ptr<Ctrl> t, int event, Point p, int zdelta)
|
||||
{
|
||||
if(!t->IsEnabled())
|
||||
return;
|
||||
Rect rr = t->GetRect();
|
||||
if((event & Ctrl::ACTION) == DOWN) {
|
||||
Ptr<Ctrl> q = t;
|
||||
TopWindowFrame *wf = dynamic_cast<TopWindowFrame *>(~t);
|
||||
if(wf)
|
||||
q = wf->window;
|
||||
if(q) q->ClickActivateWnd();
|
||||
if(q) q->SetForeground();
|
||||
if(ignoreclick)
|
||||
return;
|
||||
}
|
||||
if(t)
|
||||
t->DispatchMouse(event, p - rr.TopLeft(), zdelta);
|
||||
if(t)
|
||||
t->PostInput();
|
||||
}
|
||||
|
||||
Ctrl *Ctrl::FindMouseTopCtrl()
|
||||
{
|
||||
for(int i = topctrl.GetCount() - 1; i >= 0; i--) {
|
||||
Ctrl *t = topctrl[i];
|
||||
if(t->GetRect().Contains(fbmousepos))
|
||||
return t->IsEnabled() ? t : NULL;
|
||||
}
|
||||
return desktop->IsEnabled() ? desktop : NULL;
|
||||
}
|
||||
|
||||
void Ctrl::DoMouseFB(int event, Point p, int zdelta)
|
||||
{
|
||||
fbmousepos = p;
|
||||
int a = event & Ctrl::ACTION;
|
||||
if(a == Ctrl::UP && Ctrl::ignoreclick) {
|
||||
EndIgnore();
|
||||
return;
|
||||
}
|
||||
else
|
||||
if(a == Ctrl::DOWN && ignoreclick)
|
||||
return;
|
||||
LLOG("### Mouse event: " << event << " position " << p << " zdelta " << zdelta << ", capture " << Upp::Name(captureCtrl));
|
||||
if(captureCtrl)
|
||||
MouseEventFB(captureCtrl->GetTopCtrl(), event, p, zdelta);
|
||||
else
|
||||
for(int i = topctrl.GetCount() - 1; i >= 0; i--) {
|
||||
Ptr<Ctrl> t = topctrl[i];
|
||||
Rect rr = t->GetRect();
|
||||
if(rr.Contains(p)) {
|
||||
MouseEventFB(t, event, p, zdelta);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Ctrl *desktop = GetDesktop();
|
||||
if(desktop) {
|
||||
desktop->DispatchMouse(event, p, zdelta);
|
||||
desktop->PostInput();
|
||||
}
|
||||
}
|
||||
|
||||
bool Ctrl::DoKeyFB(dword key, int cnt)
|
||||
{
|
||||
LLOG("DoKeyFB " << GetKeyDesc(key) << ", " << cnt);
|
||||
|
||||
bool b = DispatchKey(key, cnt);
|
||||
SyncCaret();
|
||||
Ctrl *desktop = GetDesktop();
|
||||
if(desktop)
|
||||
desktop->PostInput();
|
||||
return b;
|
||||
}
|
||||
|
||||
void Ctrl::SetCaret(int x, int y, int cx, int cy)
|
||||
{
|
||||
GuiLock __;
|
||||
caretx = x;
|
||||
carety = y;
|
||||
caretcx = cx;
|
||||
caretcy = cy;
|
||||
fbCaretTm = GetTickCount();
|
||||
SyncCaret();
|
||||
}
|
||||
|
||||
void Ctrl::SyncCaret()
|
||||
{
|
||||
CursorSync();
|
||||
}
|
||||
|
||||
void Ctrl::CursorSync()
|
||||
{
|
||||
LLOG("@ 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();
|
||||
if(fbCursorPos != p && !SystemCursor || cr != fbCaretRect) {
|
||||
fbCaretRect = cr;
|
||||
fbCursorPos = p;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
bool Ctrl::ProcessEvent(bool *quit)
|
||||
{
|
||||
LLOG("@ ProcessEvent");
|
||||
ASSERT(IsMainThread());
|
||||
if(!GetMouseLeft() && !GetMouseRight() && !GetMouseMiddle())
|
||||
ReleaseCtrlCapture();
|
||||
bool ret = SlaveGuiPtr->ProcessEvent(quit);
|
||||
#if 0
|
||||
SDL_Event event;
|
||||
if(SDL_PollEvent(&event)) {
|
||||
if(event.type == SDL_QUIT && quit)
|
||||
*quit = true;
|
||||
HandleSDLEvent(&event);
|
||||
ret = true;
|
||||
}
|
||||
#endif
|
||||
DefferedFocusSync();
|
||||
SyncCaret();
|
||||
SyncTopWindows();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Ctrl::ProcessEvents(bool *quit)
|
||||
{
|
||||
//LOGBLOCK("@ ProcessEvents");
|
||||
// MemoryCheckDebug();
|
||||
bool ret = ProcessEvent(quit);
|
||||
while(ProcessEvent(quit) && (!LoopCtrl || LoopCtrl->InLoop()));
|
||||
TimeStop tm;
|
||||
LLOG("TimerProc invoked at " << msecs());
|
||||
TimerProc(GetTickCount());
|
||||
LLOG("TimerProc elapsed: " << tm);
|
||||
SweepMkImageCache();
|
||||
DoPaint();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Ctrl::EventLoop(Ctrl *ctrl)
|
||||
{
|
||||
GuiLock __;
|
||||
ASSERT(IsMainThread());
|
||||
ASSERT(LoopLevel == 0 || ctrl);
|
||||
LoopLevel++;
|
||||
LLOG("Entering event loop at level " << LoopLevel << LOG_BEGIN);
|
||||
Ptr<Ctrl> ploop;
|
||||
if(ctrl) {
|
||||
ploop = LoopCtrl;
|
||||
LoopCtrl = ctrl;
|
||||
ctrl->inloop = true;
|
||||
}
|
||||
|
||||
bool quit = false;
|
||||
int64 loopno = ++EventLoopNo;
|
||||
ProcessEvents(&quit);
|
||||
while(loopno > EndSessionLoopNo && !quit && (ctrl ? ctrl->IsOpen() && ctrl->InLoop() : GetTopCtrls().GetCount()))
|
||||
{
|
||||
// LLOG(GetSysTime() << " % " << (unsigned)msecs() % 10000 << ": EventLoop / GuiSleep");
|
||||
SyncCaret();
|
||||
GuiSleep(20);
|
||||
// LLOG(GetSysTime() << " % " << (unsigned)msecs() % 10000 << ": EventLoop / ProcessEvents");
|
||||
ProcessEvents(&quit);
|
||||
// LLOG(GetSysTime() << " % " << (unsigned)msecs() % 10000 << ": EventLoop / after ProcessEvents");
|
||||
LDUMP(loopno);
|
||||
LDUMP(fbEndSessionLoop);
|
||||
}
|
||||
|
||||
if(ctrl)
|
||||
LoopCtrl = ploop;
|
||||
LoopLevel--;
|
||||
LLOG(LOG_END << "Leaving event loop ");
|
||||
}
|
||||
|
||||
void Ctrl::GuiSleep(int ms)
|
||||
{
|
||||
GuiLock __;
|
||||
ASSERT(IsMainThread());
|
||||
LLOG("GuiSleep");
|
||||
int level = LeaveGuiMutexAll();
|
||||
SlaveGuiPtr->WaitEvent(ms);
|
||||
#if 0
|
||||
SDL_WaitEventTimeout(NULL, ms);
|
||||
#endif
|
||||
EnterGuiMutex(level);
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
63
rainbow/SlaveGui/FB.iml
Normal file
63
rainbow/SlaveGui/FB.iml
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(Arrow)
|
||||
IMAGE_ID(IBeam)
|
||||
IMAGE_ID(Wait)
|
||||
IMAGE_ID(No)
|
||||
IMAGE_ID(SizeAll)
|
||||
IMAGE_ID(SizeHorz)
|
||||
IMAGE_ID(SizeRight)
|
||||
IMAGE_ID(SizeLeft)
|
||||
IMAGE_ID(SizeVert)
|
||||
IMAGE_ID(SizeTopLeft)
|
||||
IMAGE_ID(SizeTop)
|
||||
IMAGE_ID(SizeTopRight)
|
||||
IMAGE_ID(SizeBottomLeft)
|
||||
IMAGE_ID(SizeBottom)
|
||||
IMAGE_ID(SizeBottomRight)
|
||||
IMAGE_ID(overlap)
|
||||
IMAGE_ID(maximize)
|
||||
IMAGE_ID(close)
|
||||
IMAGE_ID(bgtitle)
|
||||
IMAGE_ID(title)
|
||||
IMAGE_ID(border)
|
||||
IMAGE_ID(Hand)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,90,61,104,20,65,20,30,77,162,9,92,144,248,135,160,133,117,42,177,18,21,4,171,84,65,76,22,4,149)
|
||||
IMAGE_DATA(136,17,37,49,66,4,13,40,72,34,4,145,128,120,133,196,20,49,30,24,11,207,104,33,105,196,4,114,133,34,66,68)
|
||||
IMAGE_DATA(52,129,67,20,65,4,145,52,218,217,61,103,214,157,117,118,110,126,222,91,247,240,135,157,229,177,55,51,223,247,230,205)
|
||||
IMAGE_DATA(247,222,206,94,244,88,129,109,98,162,173,97,171,196,13,184,5,12,223,128,200,129,114,153,196,129,239,223,183,195,244,244)
|
||||
IMAGE_DATA(22,44,7,190,125,219,13,95,191,238,131,169,169,29,24,14,172,172,28,128,47,95,186,225,243,231,195,48,62,190,223,199)
|
||||
IMAGE_DATA(129,79,159,122,225,227,199,83,240,225,195,25,120,255,254,28,20,139,7,93,28,120,247,238,60,188,125,123,1,170,213,97)
|
||||
IMAGE_DATA(88,90,186,2,175,95,95,131,177,177,99,54,14,44,47,143,194,155,55,87,225,213,171,235,240,242,229,4,188,120,113,7)
|
||||
IMAGE_DATA(158,63,159,134,209,209,126,19,135,99,138,176,184,120,131,227,38,225,217,179,123,176,176,176,16,217,3,24,30,30,208,57)
|
||||
IMAGE_DATA(220,215,4,199,77,194,211,167,119,160,82,121,24,98,75,165,146,196,169,22,226,43,149,91,220,74,48,63,127,23,230,230)
|
||||
IMAGE_DATA(238,195,227,199,143,156,251,125,242,228,54,92,188,120,58,246,51,52,52,232,196,15,13,245,169,243,194,96,112,112,64,141)
|
||||
IMAGE_DATA(33,129,55,105,208,223,127,210,170,167,97,44,92,163,183,247,152,109,13,83,131,158,158,35,148,186,13,215,8,130,110,210)
|
||||
IMAGE_DATA(26,93,93,7,41,248,128,16,143,185,53,177,117,108,53,91,27,26,211,18,47,76,54,237,115,28,176,214,255,231,199,44)
|
||||
IMAGE_DATA(251,173,209,133,21,184,112,77,92,180,166,164,112,88,11,51,183,245,222,184,211,20,44,147,248,109,101,179,41,248,120,83)
|
||||
IMAGE_DATA(155,175,93,50,114,196,152,152,211,240,65,203,174,157,176,254,236,137,4,71,124,22,99,98,142,25,158,36,149,227,193,38)
|
||||
IMAGE_DATA(56,98,125,97,30,108,204,209,180,115,98,9,254,41,241,83,245,161,234,79,201,47,181,126,104,245,217,198,175,230,232,178)
|
||||
IMAGE_DATA(9,103,33,163,143,70,132,89,147,230,193,81,230,93,241,186,252,164,225,215,36,80,233,99,215,183,125,166,196,111,138,139)
|
||||
IMAGE_DATA(194,151,205,231,195,199,247,249,192,240,77,62,108,251,196,232,100,251,236,203,117,205,97,237,136,203,23,131,105,140,194,255)
|
||||
IMAGE_DATA(157,231,129,82,79,212,231,22,227,203,204,69,28,72,63,189,242,38,94,217,226,142,8,194,200,47,151,203,130,15,209,157)
|
||||
IMAGE_DATA(228,71,229,243,110,42,63,81,252,9,97,162,109,185,14,139,68,12,160,180,200,101,220,92,177,168,92,137,83,125,216,48)
|
||||
IMAGE_DATA(166,253,171,241,234,62,212,125,170,250,232,250,233,205,54,166,250,49,233,135,53,25,119,22,113,100,161,71,86,121,201,170)
|
||||
IMAGE_DATA(62,212,102,210,153,82,167,186,62,204,160,95,26,63,105,248,170,31,148,6,109,252,107,127,51,107,8,77,39,251,4,176)
|
||||
IMAGE_DATA(9,109,43,22,155,15,234,195,99,106,236,15,60,60,152,56,178,208,35,147,188,228,137,206,19,157,39,250,127,74,244,90)
|
||||
IMAGE_DATA(158,234,134,40,213,186,67,87,2,93,137,241,9,174,196,155,16,72,235,199,65,203,57,211,134,254,230,57,215,254,92,186)
|
||||
IMAGE_DATA(184,244,116,229,65,205,83,77,254,90,249,181,38,186,106,235,19,87,61,166,96,41,28,204,151,17,149,211,222,222,142,230)
|
||||
IMAGE_DATA(72,49,132,117,118,118,122,121,74,18,2,41,40,134,167,182,44,121,152,167,88,231,97,79,15,201,19,122,178,72,91,44)
|
||||
IMAGE_DATA(135,41,249,195,228,91,47,106,12,199,88,139,249,201,84,191,57,215,254,92,186,212,253,100,114,53,107,165,120,56,212,138)
|
||||
IMAGE_DATA(76,83,249,212,39,140,250,36,83,79,12,204,201,164,36,27,125,2,74,61,169,39,173,212,132,114,162,51,150,254,205,193)
|
||||
IMAGE_DATA(8,111,40,106,77,229,5,155,23,172,147,195,254,182,130,205,95,165,245,155,115,237,207,165,75,221,95,165,105,42,69,110)
|
||||
IMAGE_DATA(66,15,150,194,201,191,228,219,121,174,19,208,198,251,175,191,228,23,248,149,81,3,143,153,240,46,95,105,241,152,56,116)
|
||||
IMAGE_DATA(188,111,205,172,240,24,125,234,165,139,58,70,201,19,190,101,80,76,190,224,40,98,153,48,57,62,123,60,37,95,248,246)
|
||||
IMAGE_DATA(187,197,180,177,177,49,216,219,218,10,226,142,153,19,253,61,220,244,113,137,149,115,182,113,209,55,141,153,214,13,231,11)
|
||||
IMAGE_DATA(133,208,108,216,4,71,96,35,156,248,108,195,82,241,148,120,168,251,77,171,39,54,95,164,214,200,47,217,186,186,38,224)
|
||||
IMAGE_DATA(80,223,12,28,189,60,3,199,111,206,0,181,31,59,107,8,255,111,102,4,90,218,203,176,33,88,134,109,195,226,37,76)
|
||||
IMAGE_DATA(236,139,50,111,226,87,244,183,44,246,121,74,188,249,125,77,252,166,90,197,255,250,77,182,217,70,70,70,114,124,157,240)
|
||||
IMAGE_DATA(178,239,179,52,181,16,22,147,227,31,70,228,175,156,212,187,11,7,197,98,49,113,183,112,226,249,106,181,154,184,91,56)
|
||||
IMAGE_DATA(53,56,121,87,214,97,234,198,108,120,101,157,56,142,142,142,14,52,94,244,165,97,240,179,179,179,9,142,201,20,124,32)
|
||||
IMAGE_DATA(98,17,49,33,241,94,142,88,95,195,199,28,19,94,140,219,114,230,139,229,7,18,241,124,50,0,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(1184, 22)
|
||||
358
rainbow/SlaveGui/Gui.h
Normal file
358
rainbow/SlaveGui/Gui.h
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
#define GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
class SystemDraw : public Draw {
|
||||
public:
|
||||
virtual dword GetInfo() const;
|
||||
virtual Size GetPageSize() const;
|
||||
|
||||
virtual void BeginOp();
|
||||
virtual void EndOp();
|
||||
virtual void OffsetOp(Point p);
|
||||
virtual bool ClipOp(const Rect& r);
|
||||
virtual bool ClipoffOp(const Rect& r);
|
||||
virtual bool ExcludeClipOp(const Rect& r);
|
||||
virtual bool IntersectClipOp(const Rect& r);
|
||||
virtual bool IsPaintingOp(const Rect& r) const;
|
||||
virtual Rect GetPaintRect() const;
|
||||
|
||||
virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
|
||||
virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
|
||||
virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
|
||||
|
||||
virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
|
||||
const int *counts, int count_count,
|
||||
int width, Color color, Color doxor);
|
||||
virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
|
||||
const int *subpolygon_counts, int scc,
|
||||
const int *disjunct_polygon_counts, int dpcc,
|
||||
Color color, int width, Color outline,
|
||||
uint64 pattern, Color doxor);
|
||||
virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
|
||||
|
||||
virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
|
||||
virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
|
||||
Color ink, int n, const int *dx);
|
||||
|
||||
virtual Size GetNativeDpi() const;
|
||||
virtual void BeginNative();
|
||||
virtual void EndNative();
|
||||
|
||||
virtual int GetCloffLevel() const;
|
||||
|
||||
private:
|
||||
Size pageSize;
|
||||
Size nativeSize;
|
||||
Size nativeDpi;
|
||||
bool palette:1;
|
||||
bool color16:1;
|
||||
bool is_mono:1;
|
||||
int native;
|
||||
|
||||
friend class ImageDraw;
|
||||
friend class FontInfo;
|
||||
friend class Font;
|
||||
|
||||
friend void StaticExitDraw_();
|
||||
|
||||
Point actual_offset_bak;
|
||||
|
||||
struct Cloff : Moveable<Cloff> {
|
||||
Point org;
|
||||
HRGN hrgn;
|
||||
Rect drawingclip;
|
||||
};
|
||||
|
||||
Array<Cloff> cloff;
|
||||
Rect drawingclip;
|
||||
|
||||
COLORREF lastTextColor;
|
||||
Color lastColor;
|
||||
HBRUSH orgBrush;
|
||||
HBRUSH actBrush;
|
||||
HPEN orgPen;
|
||||
HPEN actPen;
|
||||
int lastPen;
|
||||
Color lastPenColor;
|
||||
|
||||
void Unselect0();
|
||||
void Cinit();
|
||||
|
||||
void LoadCaps();
|
||||
void SetPrinterMode();
|
||||
void Reset();
|
||||
void SetOrg();
|
||||
friend HPALETTE GetQlibPalette();
|
||||
void DotsMode();
|
||||
|
||||
static void InitColors();
|
||||
|
||||
friend class BackDraw;
|
||||
friend class ScreenDraw;
|
||||
friend class PrintDraw;
|
||||
|
||||
protected:
|
||||
dword style;
|
||||
HDC handle;
|
||||
Point actual_offset;
|
||||
|
||||
SystemDraw();
|
||||
void Init();
|
||||
void InitClip(const Rect& clip);
|
||||
|
||||
public:
|
||||
static Rect GetVirtualScreenArea();
|
||||
|
||||
static void SetAutoPalette(bool ap);
|
||||
static bool AutoPalette();
|
||||
bool PaletteMode() { return palette; }
|
||||
|
||||
static void Flush() { GdiFlush(); }
|
||||
|
||||
COLORREF GetColor(Color color) const;
|
||||
|
||||
Point GetOffset() const { return actual_offset; }
|
||||
|
||||
#ifndef PLATFORM_WINCE
|
||||
Point LPtoDP(Point p) const;
|
||||
Point DPtoLP(Point p) const;
|
||||
Rect LPtoDP(const Rect& r) const;
|
||||
Rect DPtoLP(const Rect& r) const;
|
||||
#endif
|
||||
|
||||
void SetColor(Color color);
|
||||
void SetDrawPen(int width, Color color);
|
||||
|
||||
Size GetSizeCaps(int i, int j) const;
|
||||
HDC BeginGdi();
|
||||
void EndGdi();
|
||||
HDC GetHandle() { return handle; }
|
||||
operator HDC() const { return handle; }
|
||||
void Unselect();
|
||||
void Attach(HDC ahandle) { handle = ahandle; Init(); }
|
||||
HDC Detach() { Unselect(); HDC h = handle; handle = NULL; return h; }
|
||||
|
||||
SystemDraw(HDC hdc);
|
||||
virtual ~SystemDraw();
|
||||
|
||||
bool CanSetSurface() { return IsGui() && IsWinNT(); }
|
||||
};
|
||||
|
||||
#ifndef PLATFORM_WINCE
|
||||
class WinMetaFile {
|
||||
Size size;
|
||||
HENHMETAFILE hemf;
|
||||
|
||||
void Init();
|
||||
|
||||
public:
|
||||
void Attach(HENHMETAFILE emf);
|
||||
HENHMETAFILE Detach();
|
||||
|
||||
void Set(const void *data, dword len);
|
||||
void Set(const String& data) { Set(~data, data.GetCount()); }
|
||||
|
||||
String Get() const;
|
||||
|
||||
operator bool() const { return hemf; }
|
||||
void SetSize(const Size& sz) { size = sz; }
|
||||
Size GetSize() const { return hemf ? size : Size(0, 0); }
|
||||
|
||||
void Clear();
|
||||
|
||||
void Paint(Draw& w, const Rect& r) const;
|
||||
void Paint(Draw& w, int x, int y, int cx, int cy) const;
|
||||
|
||||
void Serialize(Stream& s);
|
||||
|
||||
void ReadClipboard();
|
||||
void WriteClipboard() const;
|
||||
void Load(const char *file) { Set(LoadFile(file)); }
|
||||
|
||||
WinMetaFile() { Init(); }
|
||||
WinMetaFile(HENHMETAFILE hemf);
|
||||
WinMetaFile(HENHMETAFILE hemf, Size sz);
|
||||
WinMetaFile(const char *file);
|
||||
WinMetaFile(void *data, int len);
|
||||
WinMetaFile(const String& data);
|
||||
|
||||
~WinMetaFile() { Clear(); }
|
||||
|
||||
HENHMETAFILE GetHEMF() const { return hemf; }
|
||||
};
|
||||
|
||||
class WinMetaFileDraw : public SystemDraw {
|
||||
Size size;
|
||||
|
||||
public:
|
||||
bool Create(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
|
||||
bool Create(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
|
||||
WinMetaFile Close();
|
||||
|
||||
WinMetaFileDraw() {}
|
||||
WinMetaFileDraw(HDC hdc, int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
|
||||
WinMetaFileDraw(int cx, int cy, const char *app = NULL, const char *name = NULL, const char *file = NULL);
|
||||
~WinMetaFileDraw();
|
||||
};
|
||||
|
||||
void DrawWMF(Draw& w, int x, int y, int cx, int cy, const String& wmf);
|
||||
void DrawWMF(Draw& w, int x, int y, const String& wmf);
|
||||
Drawing LoadWMF(const char *path, int cx, int cy);
|
||||
Drawing LoadWMF(const char *path);
|
||||
|
||||
String AsWMF(const Drawing& iw);
|
||||
|
||||
#endif
|
||||
|
||||
class ScreenDraw : public SystemDraw {
|
||||
public:
|
||||
ScreenDraw(bool ic = false);
|
||||
~ScreenDraw();
|
||||
};
|
||||
|
||||
#ifndef PLATFORM_WINCE
|
||||
class PrintDraw : public SystemDraw {
|
||||
public:
|
||||
virtual void StartPage();
|
||||
virtual void EndPage();
|
||||
|
||||
private:
|
||||
bool aborted;
|
||||
|
||||
void InitPrinter();
|
||||
public:
|
||||
PrintDraw(HDC hdc, const char *jobname);
|
||||
~PrintDraw();
|
||||
};
|
||||
#endif
|
||||
|
||||
inline bool BitBlt(HDC ddc, Point d, HDC sdc, const Rect& s, dword rop = SRCCOPY)
|
||||
{ return BitBlt(ddc, d.x, d.y, s.Width(), s.Height(), sdc, s.left, s.top, rop); }
|
||||
|
||||
inline bool StretchBlt(HDC ddc, const Rect& r, HDC sdc, const Rect& s, dword rop = SRCCOPY)
|
||||
{ return StretchBlt(ddc, r.left, r.top, r.Width(), r.Height(), sdc, s.left, s.top, s.Width(), s.Height(), rop); }
|
||||
|
||||
inline bool PatBlt(HDC dc, const Rect& r, dword rop = PATCOPY)
|
||||
{ return PatBlt(dc, r.left, r.top, r.Width(), r.Height(), rop); }
|
||||
|
||||
inline void MoveTo(HDC hdc, Point pt) { MoveToEx(hdc, pt.x, pt.y, 0); }
|
||||
inline void LineTo(HDC hdc, Point pt) { LineTo(hdc, pt.x, pt.y); }
|
||||
|
||||
inline void DrawLine(HDC hdc, Point p, Point q) { MoveTo(hdc, p); LineTo(hdc, q); }
|
||||
inline void DrawLine(HDC hdc, int px, int py, int qx, int qy) { MoveToEx(hdc, px, py, 0); LineTo(hdc, qx, qy); }
|
||||
|
||||
#ifndef PLATFORM_WINCE
|
||||
inline void DrawArc(HDC hdc, const Rect& rc, Point p, Point q){ Arc(hdc, rc.left, rc.top, rc.right, rc.bottom, p.x, p.y, q.x, q.y); }
|
||||
#endif
|
||||
inline void DrawCircle(HDC hdc, int x, int y, int radius) { Ellipse(hdc, x - radius, y - radius, x + radius + 1, y + radius + 1); }
|
||||
inline void DrawCircle(HDC hdc, Point centre, int radius) { DrawCircle(hdc, centre.x, centre.y, radius); }
|
||||
inline void DrawEllipse(HDC hdc, const Rect& rc) { Ellipse(hdc, rc.left, rc.top, rc.right, rc.bottom); }
|
||||
|
||||
inline void DrawRect(HDC hdc, const Rect& rc) { Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom); }
|
||||
|
||||
HDC ScreenHDC();
|
||||
HPALETTE GetQlibPalette();
|
||||
|
||||
Image Win32Icon(LPCSTR id, int iconsize = 0);
|
||||
Image Win32Icon(int id, int iconsize = 0);
|
||||
Image Win32Cursor(LPCSTR id);
|
||||
Image Win32Cursor(int id);
|
||||
HICON IconWin32(const Image& img, bool cursor = false);
|
||||
Image Win32DllIcon(const char *dll, int ii, bool large);
|
||||
|
||||
class BackDraw : public SystemDraw {
|
||||
public:
|
||||
virtual bool IsPaintingOp(const Rect& r) const;
|
||||
|
||||
protected:
|
||||
HBITMAP hbmpold;
|
||||
HBITMAP hbmp;
|
||||
|
||||
Size size;
|
||||
Draw *painting;
|
||||
Point painting_offset;
|
||||
|
||||
public:
|
||||
void Put(SystemDraw& w, int x, int y);
|
||||
void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); }
|
||||
|
||||
void Create(SystemDraw& w, int cx, int cy);
|
||||
void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); }
|
||||
void Destroy();
|
||||
|
||||
void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; }
|
||||
|
||||
BackDraw();
|
||||
~BackDraw();
|
||||
};
|
||||
|
||||
class ImageDraw : public SystemDraw {
|
||||
Size size;
|
||||
|
||||
struct Section {
|
||||
HDC dc;
|
||||
HBITMAP hbmp, hbmpOld;
|
||||
RGBA *pixels;
|
||||
|
||||
void Init(int cx, int cy);
|
||||
~Section();
|
||||
};
|
||||
|
||||
Section rgb;
|
||||
Section a;
|
||||
SystemDraw alpha;
|
||||
|
||||
|
||||
bool has_alpha;
|
||||
|
||||
void Init();
|
||||
Image Get(bool pm) const;
|
||||
|
||||
public:
|
||||
Draw& Alpha();
|
||||
|
||||
operator Image() const;
|
||||
|
||||
Image GetStraight() const;
|
||||
|
||||
ImageDraw(Size sz);
|
||||
ImageDraw(int cx, int cy);
|
||||
~ImageDraw();
|
||||
};
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#define GUIPLATFORM_KEYCODES_INCLUDE "Win32Keys.h"
|
||||
|
||||
|
||||
#define GUIPLATFORM_CTRL_TOP_DECLS \
|
||||
HWND hwnd; \
|
||||
UDropTarget *dndtgt; \
|
||||
|
||||
|
||||
#define GUIPLATFORM_CTRL_DECLS_INCLUDE "Win32Ctrl.h"
|
||||
|
||||
|
||||
#define GUIPLATFORM_PASTECLIP_DECLS \
|
||||
UDropTarget *dt; \
|
||||
|
||||
#define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE "Win32Top.h"
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
inline unsigned GetHashValue(const HWND& hwnd)
|
||||
{
|
||||
return (unsigned)(intptr_t)hwnd;
|
||||
}
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#ifndef PLATFORM_WINCE
|
||||
|
||||
#include <ShellAPI.h>
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define GUIPLATFORM_INCLUDE_AFTER "Win32GuiA.h"
|
||||
47
rainbow/SlaveGui/Image.cpp
Normal file
47
rainbow/SlaveGui/Image.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include <CtrlCore/CtrlCore.h>
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LTIMING(x) // RTIMING(x)
|
||||
|
||||
void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels)
|
||||
{
|
||||
GuiLock __;
|
||||
// Empty as CanSetSurface is false
|
||||
}
|
||||
|
||||
void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff)
|
||||
{
|
||||
GuiLock __;
|
||||
// Empty as CanSetSurface is false
|
||||
}
|
||||
|
||||
#define IMAGECLASS FBImg
|
||||
#define IMAGEFILE <SDL20GL/FB.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
|
||||
#define STD_CURSOR(name, sdl) \
|
||||
Image Image::name() { static Image img; ONCELOCK { img = FBImg::name(); img.SetAuxData(sdl + 1); } return img; }
|
||||
|
||||
STD_CURSOR(Arrow, SDL_SYSTEM_CURSOR_ARROW)
|
||||
STD_CURSOR(Wait, SDL_SYSTEM_CURSOR_WAIT)
|
||||
STD_CURSOR(IBeam, SDL_SYSTEM_CURSOR_IBEAM)
|
||||
STD_CURSOR(No, SDL_SYSTEM_CURSOR_NO)
|
||||
STD_CURSOR(SizeAll, SDL_SYSTEM_CURSOR_SIZEALL)
|
||||
STD_CURSOR(SizeHorz, SDL_SYSTEM_CURSOR_SIZEWE)
|
||||
STD_CURSOR(SizeVert, SDL_SYSTEM_CURSOR_SIZENS)
|
||||
STD_CURSOR(SizeTopLeft, SDL_SYSTEM_CURSOR_SIZENWSE)
|
||||
STD_CURSOR(SizeTop, SDL_SYSTEM_CURSOR_SIZENS)
|
||||
STD_CURSOR(SizeTopRight, SDL_SYSTEM_CURSOR_SIZENESW)
|
||||
STD_CURSOR(SizeLeft, SDL_SYSTEM_CURSOR_SIZEWE)
|
||||
STD_CURSOR(SizeRight, SDL_SYSTEM_CURSOR_SIZEWE)
|
||||
STD_CURSOR(SizeBottomLeft, SDL_SYSTEM_CURSOR_SIZENWSE)
|
||||
STD_CURSOR(SizeBottom, SDL_SYSTEM_CURSOR_SIZENS)
|
||||
STD_CURSOR(SizeBottomRight, SDL_SYSTEM_CURSOR_SIZENESW)
|
||||
STD_CURSOR(Hand, SDL_SYSTEM_CURSOR_HAND)
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
123
rainbow/SlaveGui/Keys.h
Normal file
123
rainbow/SlaveGui/Keys.h
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
//handled extra in fbKEYtoK
|
||||
K_TAB = 9, //SDLK_TAB,
|
||||
|
||||
K_SPACE = 32, //SDLK_SPACE,
|
||||
|
||||
K_RETURN = 13, //SDLK_RETURN,
|
||||
K_ENTER = K_RETURN,
|
||||
|
||||
K_BACK = K_DELTA,
|
||||
K_BACKSPACE,
|
||||
|
||||
K_SHIFT_KEY,
|
||||
K_CTRL_KEY,
|
||||
K_ALT_KEY,
|
||||
K_CAPSLOCK,
|
||||
K_ESCAPE,
|
||||
K_PRIOR,
|
||||
K_PAGEUP,
|
||||
K_NEXT,
|
||||
K_PAGEDOWN,
|
||||
K_END,
|
||||
K_HOME,
|
||||
K_LEFT,
|
||||
K_UP,
|
||||
K_RIGHT,
|
||||
K_DOWN,
|
||||
K_INSERT,
|
||||
K_DELETE,
|
||||
|
||||
K_NUMPAD0,
|
||||
K_NUMPAD1,
|
||||
K_NUMPAD2,
|
||||
K_NUMPAD3,
|
||||
K_NUMPAD4,
|
||||
K_NUMPAD5,
|
||||
K_NUMPAD6,
|
||||
K_NUMPAD7,
|
||||
K_NUMPAD8,
|
||||
K_NUMPAD9,
|
||||
K_MULTIPLY,
|
||||
K_ADD,
|
||||
K_SEPARATOR,
|
||||
K_SUBTRACT,
|
||||
K_DECIMAL,
|
||||
K_DIVIDE,
|
||||
K_SCROLL,
|
||||
|
||||
K_F1,
|
||||
K_F2,
|
||||
K_F3,
|
||||
K_F4,
|
||||
K_F5,
|
||||
K_F6,
|
||||
K_F7,
|
||||
K_F8,
|
||||
K_F9,
|
||||
K_F10,
|
||||
K_F11,
|
||||
K_F12,
|
||||
|
||||
K_A,
|
||||
K_B,
|
||||
K_C,
|
||||
K_D,
|
||||
K_E,
|
||||
K_F,
|
||||
K_G,
|
||||
K_H,
|
||||
K_I,
|
||||
K_J,
|
||||
K_K,
|
||||
K_L,
|
||||
K_M,
|
||||
K_N,
|
||||
K_O,
|
||||
K_P,
|
||||
K_Q,
|
||||
K_R,
|
||||
K_S,
|
||||
K_T,
|
||||
K_U,
|
||||
K_V,
|
||||
K_W,
|
||||
K_X,
|
||||
K_Y,
|
||||
K_Z,
|
||||
K_0,
|
||||
K_1,
|
||||
K_2,
|
||||
K_3,
|
||||
K_4,
|
||||
K_5,
|
||||
K_6,
|
||||
K_7,
|
||||
K_8,
|
||||
K_9,
|
||||
|
||||
K_CTRL_LBRACKET,
|
||||
K_CTRL_RBRACKET,
|
||||
K_CTRL_MINUS,
|
||||
K_CTRL_GRAVE,
|
||||
K_CTRL_SLASH,
|
||||
K_CTRL_BACKSLASH,
|
||||
K_CTRL_COMMA,
|
||||
K_CTRL_PERIOD,
|
||||
K_CTRL_SEMICOLON,
|
||||
K_CTRL_EQUAL,
|
||||
K_CTRL_APOSTROPHE,
|
||||
|
||||
K_BREAK, // Is it really?
|
||||
|
||||
K_PLUS,
|
||||
K_MINUS,
|
||||
K_COMMA,
|
||||
K_PERIOD,
|
||||
K_SEMICOLON,
|
||||
|
||||
K_SLASH,
|
||||
K_GRAVE,
|
||||
K_LBRACKET,
|
||||
K_BACKSLASH,
|
||||
K_RBRACKET,
|
||||
K_QUOTEDBL,
|
||||
65
rainbow/SlaveGui/Local.h
Normal file
65
rainbow/SlaveGui/Local.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
class TopWindowFrame : public Ctrl {
|
||||
public:
|
||||
virtual void Layout();
|
||||
virtual void Paint(Draw& w);
|
||||
virtual Image CursorImage(Point p, dword keyflags);
|
||||
virtual void LeftDown(Point p, dword keyflags);
|
||||
virtual void LeftHold(Point p, dword keyflags);
|
||||
virtual void LeftDouble(Point p, dword keyflags);
|
||||
virtual void MouseMove(Point p, dword keyflags);
|
||||
virtual void CancelMode();
|
||||
virtual void LeftUp(Point p, dword keyflags);
|
||||
|
||||
private:
|
||||
Point dir;
|
||||
Point startpos;
|
||||
Rect startrect;
|
||||
|
||||
bool maximized;
|
||||
Rect overlapped;
|
||||
|
||||
bool holding;
|
||||
TimeCallback hold;
|
||||
|
||||
Point GetDragMode(Point p);
|
||||
Image GetDragImage(Point dragmode);
|
||||
void StartDrag();
|
||||
Rect Margins() const;
|
||||
Rect ComputeClient(Rect r);
|
||||
void Hold();
|
||||
|
||||
typedef TopWindowFrame CLASSNAME;
|
||||
|
||||
public:
|
||||
String title;
|
||||
Button close, maximize;
|
||||
Image icon;
|
||||
Size minsize;
|
||||
bool sizeable;
|
||||
TopWindow *window;
|
||||
|
||||
void SetTitle(const String& s) { title = s; Refresh(); }
|
||||
Rect GetClient() const;
|
||||
void SetClient(Rect r);
|
||||
void GripResize();
|
||||
|
||||
void Maximize();
|
||||
void Overlap();
|
||||
void ToggleMaximize();
|
||||
bool IsMaximized() const { return maximized; }
|
||||
void SyncRect();
|
||||
|
||||
TopWindowFrame();
|
||||
};
|
||||
|
||||
extern Size screen_size;
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
81
rainbow/SlaveGui/SDL.cpp
Normal file
81
rainbow/SlaveGui/SDL.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) //LOG(x)
|
||||
|
||||
dword SDLsettings;
|
||||
|
||||
void USDLSetup(dword flags)
|
||||
{
|
||||
SDLsettings = flags;
|
||||
}
|
||||
|
||||
Size screen_size;
|
||||
// SDLWindow screen;
|
||||
|
||||
SDL_TimerID waketimer_id = 0;
|
||||
Uint32 WakeCb(Uint32 interval, void *param)
|
||||
{
|
||||
//wake up message que, FIXME maybe it can be done better?
|
||||
SDL_Event event;
|
||||
event.type=SDL_USEREVENT;
|
||||
SDL_PushEvent(&event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WakeUpGuiThread()
|
||||
{
|
||||
waketimer_id = SDL_AddTimer(20, WakeCb, NULL);
|
||||
}
|
||||
|
||||
void FBInit()
|
||||
{
|
||||
GuiLock __;
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
|
||||
|
||||
Ctrl::InitFB();
|
||||
|
||||
#if 0
|
||||
if(SDL_Init(SDL_INIT_VIDEO/* | SDL_INIT_TIMER*/) < 0) //timer not needed, we post to queue directly
|
||||
{
|
||||
Cout() << Format("Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// SDL_EnableUNICODE(1); //for unicode keycode availability
|
||||
// SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL/2);
|
||||
// SDL_ShowCursor(0);
|
||||
|
||||
const SDL_VideoInfo* vi = SDL_GetVideoInfo();
|
||||
//ASSERT(vi->hw_available);
|
||||
|
||||
width = vi->current_w;
|
||||
height = vi->current_h;
|
||||
bpp = vi->vfmt->BitsPerPixel;
|
||||
ASSERT(bpp == 32);
|
||||
|
||||
//FIXME adjustable
|
||||
videoflags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_RESIZABLE;// | SDL_NOFRAME | SDL_FULLSCREEN;
|
||||
#endif
|
||||
screen_size = Size(1500, 900);
|
||||
screen.Create(Rect(Point(20, 20), screen_size), "First test");
|
||||
|
||||
Ctrl::SetDesktopSize(screen_size);
|
||||
}
|
||||
|
||||
void FBDeInit()
|
||||
{
|
||||
SDL_RemoveTimer(waketimer_id);
|
||||
Ctrl::ExitFB();
|
||||
screen.Destroy();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
118
rainbow/SlaveGui/SlaveGui.h
Normal file
118
rainbow/SlaveGui/SlaveGui.h
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#define GUI_SLAVE
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
#include <CtrlCore/stdids.h>
|
||||
#endif
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define IMAGECLASS FBImg
|
||||
#define IMAGEFILE <SlaveGui/FB.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
/*
|
||||
struct SDLWindow {
|
||||
SDL_Window *win;
|
||||
SDL_GLContext glcontext;
|
||||
int64 serial;
|
||||
|
||||
bool Create(const Rect& rect, const char *title);
|
||||
void Destroy();
|
||||
|
||||
operator bool() const { return win; }
|
||||
|
||||
SDLWindow();
|
||||
~SDLWindow();
|
||||
};
|
||||
*/
|
||||
|
||||
class SystemDraw/* : public GLDraw*/ {
|
||||
public:
|
||||
bool CanSetSurface() { return false; }
|
||||
static void Flush() {}
|
||||
};
|
||||
|
||||
struct BackDraw__ : public SystemDraw {
|
||||
BackDraw__() : SystemDraw() {}
|
||||
};
|
||||
|
||||
class BackDraw : public BackDraw__ { // Dummy only, as we are running in GlobalBackBuffer mode
|
||||
Size size;
|
||||
Draw *painting;
|
||||
Point painting_offset;
|
||||
ImageBuffer ib;
|
||||
|
||||
public:
|
||||
virtual bool IsPaintingOp(const Rect& r) const;
|
||||
|
||||
public:
|
||||
void Put(SystemDraw& w, int x, int y) {}
|
||||
void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); }
|
||||
|
||||
void Create(SystemDraw& w, int cx, int cy) {}
|
||||
void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); }
|
||||
void Destroy() {}
|
||||
|
||||
void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; }
|
||||
|
||||
BackDraw();
|
||||
~BackDraw();
|
||||
};
|
||||
|
||||
class ImageDraw : public SImageDraw {
|
||||
public:
|
||||
ImageDraw(Size sz) : SImageDraw(sz) {}
|
||||
ImageDraw(int cx, int cy) : SImageDraw(cx, cy) {}
|
||||
};
|
||||
|
||||
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
|
||||
Color color, uint64 pattern);
|
||||
|
||||
class TopWindowFrame;
|
||||
|
||||
#define GUIPLATFORM_CTRL_TOP_DECLS Ctrl *owner_window;
|
||||
|
||||
#define GUIPLATFORM_CTRL_DECLS_INCLUDE <SlaveGui/Ctrl.h>
|
||||
|
||||
#define GUIPLATFORM_PASTECLIP_DECLS \
|
||||
bool dnd; \
|
||||
friend struct DnDLoop; \
|
||||
|
||||
#define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE <SlaveGui/Top.h>
|
||||
|
||||
class PrinterJob { // Dummy only...
|
||||
NilDraw nil;
|
||||
Vector<int> pages;
|
||||
|
||||
public:
|
||||
Draw& GetDraw() { return nil; }
|
||||
operator Draw&() { return GetDraw(); }
|
||||
const Vector<int>& GetPages() const { return pages; }
|
||||
int operator[](int i) const { return 0; }
|
||||
int GetPageCount() const { return 0; }
|
||||
|
||||
bool Execute() { return false; }
|
||||
|
||||
PrinterJob& Landscape(bool b = true) { return *this; }
|
||||
PrinterJob& MinMaxPage(int minpage, int maxpage) { return *this; }
|
||||
PrinterJob& PageCount(int n) { return *this; }
|
||||
PrinterJob& CurrentPage(int currentpage) { return *this; }
|
||||
PrinterJob& Name(const char *_name) { return *this; }
|
||||
|
||||
PrinterJob(const char *name = NULL) {}
|
||||
~PrinterJob() {}
|
||||
};
|
||||
|
||||
struct SlaveGui {
|
||||
bool ProcessEvent(bool *quit);
|
||||
void WaitEvent(int ms);
|
||||
void SetMouseCursor(const Image& image);
|
||||
void Quit();
|
||||
bool IsWaitingEvent();
|
||||
};
|
||||
|
||||
extern SlaveGui *SlaveGuiPtr;
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#define GUIPLATFORM_INCLUDE_AFTER <SDL20/After.h>
|
||||
34
rainbow/SlaveGui/SlaveGui.upp
Normal file
34
rainbow/SlaveGui/SlaveGui.upp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
description "SlaveGui backend\377";
|
||||
|
||||
uses
|
||||
Painter,
|
||||
CtrlLib,
|
||||
GLDraw,
|
||||
PdfDraw;
|
||||
|
||||
library(POSIX) "SDL2 SDL2main GL";
|
||||
|
||||
library(WIN32) "SDL2.lib SDL2main.lib OpenGL32.lib";
|
||||
|
||||
file
|
||||
SlaveGui.h,
|
||||
Keys.h,
|
||||
Local.h,
|
||||
After.h,
|
||||
Window.cpp,
|
||||
Image.cpp,
|
||||
FB.iml,
|
||||
Ctrl.h,
|
||||
DrawDragRect.cpp,
|
||||
Ctrl.cpp,
|
||||
Wnd.cpp,
|
||||
Cursor.cpp,
|
||||
Event.cpp,
|
||||
Top.h,
|
||||
TopFrame.cpp,
|
||||
Top.cpp,
|
||||
Clip.cpp,
|
||||
DnD.cpp,
|
||||
ChSysInit.cpp,
|
||||
SDL.cpp;
|
||||
|
||||
149
rainbow/SlaveGui/Top.cpp
Normal file
149
rainbow/SlaveGui/Top.cpp
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) // LOG(x)
|
||||
|
||||
void TopWindow::SyncFrameRect(const Rect& r)
|
||||
{
|
||||
frame->SetClient(r);
|
||||
}
|
||||
|
||||
void TopWindow::DestroyFrame()
|
||||
{
|
||||
if(frame->IsOpen())
|
||||
frame->DestroyWnd();
|
||||
}
|
||||
|
||||
void TopWindow::GripResize()
|
||||
{
|
||||
frame->GripResize();
|
||||
}
|
||||
|
||||
void TopWindow::SyncSizeHints()
|
||||
{
|
||||
SyncCaption();
|
||||
}
|
||||
|
||||
void TopWindow::SyncTitle()
|
||||
{
|
||||
SyncCaption();
|
||||
}
|
||||
|
||||
void TopWindow::SyncCaption()
|
||||
{
|
||||
GuiLock __;
|
||||
frame->title = title.ToString();
|
||||
frame->minsize = minsize;
|
||||
frame->close.Show(!noclosebox);
|
||||
frame->maximize.Show(maximizebox);
|
||||
frame->sizeable = sizeable;
|
||||
frame->RefreshLayout();
|
||||
frame->Refresh();
|
||||
frame->close << [=] { WhenClose(); };
|
||||
frame->icon = icon;
|
||||
frame->Enable(IsEnabled());
|
||||
}
|
||||
|
||||
void TopWindow::State(int reason)
|
||||
{
|
||||
SyncCaption();
|
||||
}
|
||||
|
||||
void TopWindow::SyncRect()
|
||||
{
|
||||
frame->SyncRect();
|
||||
Rect r = frame->GetClient();
|
||||
if(r != GetRect())
|
||||
SetRect(r);
|
||||
}
|
||||
|
||||
void TopWindow::Open(Ctrl *owner)
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("Open " << Upp::Name(owner));
|
||||
Rect r = GetRect();
|
||||
if(r.IsEmpty())
|
||||
SetRect(GetDefaultWindowRect());
|
||||
else
|
||||
if(r.left == 0 && r.top == 0)
|
||||
if(owner && center == 1)
|
||||
SetRect(owner->GetRect().CenterRect(r.GetSize()));
|
||||
else
|
||||
if(center)
|
||||
SetRect(GetWorkArea().CenterRect(r.GetSize()));
|
||||
frame->SetClient(GetRect());
|
||||
frame->window = this;
|
||||
frame->PopUp(owner, false, true);
|
||||
PopUp(frame, false, true);
|
||||
popup = false;
|
||||
SetRect(frame->GetClient());
|
||||
SyncCaption();
|
||||
if(state == MAXIMIZED)
|
||||
frame->Maximize();
|
||||
}
|
||||
|
||||
void TopWindow::Open()
|
||||
{
|
||||
Open(GetActiveCtrl());
|
||||
}
|
||||
|
||||
void TopWindow::OpenMain()
|
||||
{
|
||||
Open(NULL);
|
||||
}
|
||||
|
||||
void TopWindow::Minimize(bool effect)
|
||||
{
|
||||
// state = MINIMIZED;
|
||||
}
|
||||
|
||||
TopWindow& TopWindow::FullScreen(bool b)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
void TopWindow::Maximize(bool effect)
|
||||
{
|
||||
state = MAXIMIZED;
|
||||
frame->Maximize();
|
||||
}
|
||||
|
||||
void TopWindow::Overlap(bool effect)
|
||||
{
|
||||
GuiLock __;
|
||||
state = OVERLAPPED;
|
||||
frame->Overlap();
|
||||
}
|
||||
|
||||
TopWindow& TopWindow::TopMost(bool b, bool stay_top)
|
||||
{
|
||||
GuiLock __;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool TopWindow::IsTopMost() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void TopWindow::GuiPlatformConstruct()
|
||||
{
|
||||
frame = new TopWindowFrame;
|
||||
}
|
||||
|
||||
void TopWindow::GuiPlatformDestruct()
|
||||
{
|
||||
delete frame;
|
||||
}
|
||||
|
||||
void TopWindow::SerializePlacement(Stream& s, bool reminimize)
|
||||
{
|
||||
GuiLock __;
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
16
rainbow/SlaveGui/Top.h
Normal file
16
rainbow/SlaveGui/Top.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
//$ class TopWindow {
|
||||
public:
|
||||
virtual void State(int reason);
|
||||
|
||||
private:
|
||||
TopWindowFrame *frame;
|
||||
|
||||
void SyncRect();
|
||||
void SyncFrameRect(const Rect& r);
|
||||
void DestroyFrame();
|
||||
|
||||
friend class Ctrl;
|
||||
|
||||
public:
|
||||
void GripResize();
|
||||
//$ };
|
||||
236
rainbow/SlaveGui/TopFrame.cpp
Normal file
236
rainbow/SlaveGui/TopFrame.cpp
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) // LOG(x)
|
||||
#define LDUMP(x) //DDUMP(x)
|
||||
|
||||
TopWindowFrame::TopWindowFrame()
|
||||
{
|
||||
close.SetImage(FBImg::close());
|
||||
close.EdgeStyle();
|
||||
Add(close);
|
||||
maximize.SetImage(FBImg::maximize());
|
||||
maximize.EdgeStyle();
|
||||
Add(maximize);
|
||||
maximize <<= THISBACK(ToggleMaximize);
|
||||
maximized = false;
|
||||
sizeable = false;
|
||||
holding = false;
|
||||
}
|
||||
|
||||
void TopWindowFrame::SyncRect()
|
||||
{
|
||||
if(maximized) {
|
||||
Size sz = GetWorkArea().GetSize();
|
||||
if(GetRect().GetSize() != sz)
|
||||
SetRect(sz);
|
||||
}
|
||||
}
|
||||
|
||||
void TopWindowFrame::Maximize()
|
||||
{
|
||||
if(!maximized && maximize.IsShown()) {
|
||||
maximized = true;
|
||||
overlapped = GetRect();
|
||||
SetRect(GetWorkArea().GetSize());
|
||||
maximize.SetImage(FBImg::overlap());
|
||||
}
|
||||
}
|
||||
|
||||
void TopWindowFrame::Overlap()
|
||||
{
|
||||
if(maximized && maximize.IsShown()) {
|
||||
maximized = false;
|
||||
SetRect(overlapped);
|
||||
maximize.SetImage(FBImg::maximize());
|
||||
}
|
||||
}
|
||||
|
||||
void TopWindowFrame::ToggleMaximize()
|
||||
{
|
||||
if(maximized)
|
||||
Overlap();
|
||||
else
|
||||
Maximize();
|
||||
}
|
||||
|
||||
Rect TopWindowFrame::Margins() const
|
||||
{
|
||||
return maximized ? Rect(0, 0, 0, 0) : ChMargins(FBImg::border());
|
||||
}
|
||||
|
||||
void TopWindowFrame::Paint(Draw& w)
|
||||
{
|
||||
Size sz = GetSize();
|
||||
Rect m = Margins();
|
||||
int c = GetStdFontCy() + 4;
|
||||
ChPaintEdge(w, sz, FBImg::border());
|
||||
ChPaint(w, m.left, m.top, sz.cx - m.left - m.right, GetStdFontCy() + 4,
|
||||
window->IsForeground() ? FBImg::title() : FBImg::bgtitle());
|
||||
int tx = m.left + 2;
|
||||
int tcx = sz.cx - m.left - m.right - 4 - c * (close.IsShown() + maximize.IsShown());
|
||||
if(!IsNull(icon)) {
|
||||
Image h = icon;
|
||||
if(h.GetWidth() > c || h.GetHeight() > c)
|
||||
h = Rescale(h, GetFitSize(h.GetSize(), Size(c)));
|
||||
w.DrawImage(tx, m.top + 2, h);
|
||||
tx += c;
|
||||
tcx -= c;
|
||||
}
|
||||
DrawTextEllipsis(w, tx, m.top + 2, tcx, title, "..", StdFont(), SColorHighlightText());
|
||||
}
|
||||
|
||||
void TopWindowFrame::Layout()
|
||||
{
|
||||
Size sz = GetSize();
|
||||
Rect m = Margins();
|
||||
int c = GetStdFontCy() + 4;
|
||||
int x = sz.cx - m.right;
|
||||
if(close.IsShown())
|
||||
close.SetRect(x -= c, m.top, c, c);
|
||||
if(maximize.IsShown())
|
||||
maximize.SetRect(x -= c, m.top, c, c);
|
||||
}
|
||||
|
||||
Rect TopWindowFrame::GetClient() const
|
||||
{
|
||||
Rect r = GetRect();
|
||||
Rect m = Margins();
|
||||
r.left += m.left;
|
||||
r.right -= m.right;
|
||||
r.top += m.top;
|
||||
r.bottom -= m.bottom;
|
||||
r.top += GetStdFontCy() + 4;
|
||||
return r;
|
||||
}
|
||||
|
||||
Rect TopWindowFrame::ComputeClient(Rect r)
|
||||
{
|
||||
Rect m = Margins();
|
||||
r.left -= m.left;
|
||||
r.right += m.right;
|
||||
r.top -= m.top;
|
||||
r.bottom += m.bottom;
|
||||
r.top -= GetStdFontCy() + 4;
|
||||
return r;
|
||||
}
|
||||
|
||||
void TopWindowFrame::SetClient(Rect r)
|
||||
{
|
||||
SetRect(ComputeClient(r));
|
||||
}
|
||||
|
||||
Point TopWindowFrame::GetDragMode(Point p)
|
||||
{
|
||||
Size sz = GetSize();
|
||||
Rect m = ChMargins(FBImg::border());
|
||||
Point dir;
|
||||
dir.y = p.y < m.top ? -1 : p.y > sz.cy - m.top ? 1 : 0;
|
||||
dir.x = p.x < m.left ? -1 : p.x > sz.cx - m.right ? 1 : 0;
|
||||
return dir;
|
||||
}
|
||||
|
||||
void TopWindowFrame::StartDrag()
|
||||
{
|
||||
if(maximized)
|
||||
return;
|
||||
if(!sizeable && (dir.x || dir.y))
|
||||
return;
|
||||
SetCapture();
|
||||
startrect = GetRect();
|
||||
startpos = GetMousePos();
|
||||
LLOG("START DRAG ---------------");
|
||||
}
|
||||
|
||||
void TopWindowFrame::GripResize()
|
||||
{
|
||||
dir = Point(1, 1);
|
||||
StartDrag();
|
||||
}
|
||||
|
||||
void TopWindowFrame::LeftDown(Point p, dword keyflags)
|
||||
{
|
||||
dir = GetDragMode(p);
|
||||
StartDrag();
|
||||
}
|
||||
|
||||
void TopWindowFrame::CancelMode()
|
||||
{
|
||||
holding = false;
|
||||
}
|
||||
|
||||
void TopWindowFrame::LeftUp(Point p, dword keyflags)
|
||||
{
|
||||
holding = false;
|
||||
}
|
||||
|
||||
void TopWindowFrame::Hold()
|
||||
{
|
||||
if(HasCapture()) {
|
||||
if(HasMouse() && GetMouseLeft() && holding)
|
||||
StartDrag();
|
||||
ReleaseCapture();
|
||||
holding = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TopWindowFrame::LeftHold(Point p, dword keyflags)
|
||||
{
|
||||
/* if(HasCapture() || FullWindowDrag)
|
||||
return;
|
||||
dir = GetDragMode(p);
|
||||
if(!dir.x && !dir.y)
|
||||
StartDrag();*/
|
||||
}
|
||||
|
||||
void TopWindowFrame::LeftDouble(Point p, dword keyflags)
|
||||
{
|
||||
ToggleMaximize();
|
||||
IgnoreMouseUp();
|
||||
}
|
||||
|
||||
void TopWindowFrame::MouseMove(Point, dword)
|
||||
{
|
||||
LDUMP(HasWndCapture());
|
||||
LDUMP(HasCapture());
|
||||
if(!HasCapture() || holding)
|
||||
return;
|
||||
Size msz = ComputeClient(minsize).GetSize();
|
||||
Point p = GetMousePos() - startpos;
|
||||
Rect r = startrect;
|
||||
if(dir.x == -1)
|
||||
r.left = min(r.left + p.x, startrect.right - msz.cx);
|
||||
if(dir.x == 1)
|
||||
r.right = max(r.right + p.x, startrect.left + msz.cx);
|
||||
if(dir.y == -1)
|
||||
r.top = min(r.top + p.y, startrect.bottom - msz.cy);
|
||||
if(dir.y == 1)
|
||||
r.bottom = max(r.bottom + p.y, startrect.top + msz.cy);
|
||||
if(dir.y == 0 && dir.x == 0)
|
||||
r.Offset(p);
|
||||
SetRect(r);
|
||||
}
|
||||
|
||||
Image TopWindowFrame::GetDragImage(Point dir)
|
||||
{
|
||||
static Image (*im[9])() = {
|
||||
Image::SizeTopLeft, Image::SizeLeft, Image::SizeBottomLeft,
|
||||
Image::SizeTop, Image::Arrow, Image::SizeBottom,
|
||||
Image::SizeTopRight, Image::SizeRight, Image::SizeBottomRight,
|
||||
};
|
||||
return (*im[(dir.x + 1) * 3 + (dir.y + 1)])();
|
||||
}
|
||||
|
||||
Image TopWindowFrame::CursorImage(Point p, dword)
|
||||
{
|
||||
if(!sizeable)
|
||||
return Image::Arrow();
|
||||
return GetDragImage(HasCapture() ? dir : GetDragMode(p));
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
53
rainbow/SlaveGui/Window.cpp
Normal file
53
rainbow/SlaveGui/Window.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
bool SDLWindow::Create(const Rect& rect, const char *title)
|
||||
{
|
||||
win = SDL_CreateWindow(title, rect.left, rect.top, rect.GetWidth(), rect.GetHeight(),
|
||||
SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL|SDL_WINDOW_BORDERLESS);
|
||||
if(!win)
|
||||
return false;
|
||||
MemoryIgnoreLeaksBegin();
|
||||
glcontext = SDL_GL_CreateContext(win);
|
||||
MemoryIgnoreLeaksEnd();
|
||||
if(!glcontext) {
|
||||
Destroy();
|
||||
return false;
|
||||
}
|
||||
INTERLOCKED {
|
||||
static int64 h;
|
||||
serial = h++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SDLWindow::Destroy()
|
||||
{
|
||||
if(glcontext) {
|
||||
SDL_GL_DeleteContext(glcontext);
|
||||
glcontext = NULL;
|
||||
GLDraw::ResetCache(); // TODO: Consider not reseting ALL cache data, only specific context
|
||||
}
|
||||
if(win) {
|
||||
SDL_DestroyWindow(win);
|
||||
win = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SDLWindow::SDLWindow()
|
||||
{
|
||||
glcontext = NULL;
|
||||
win = NULL;
|
||||
}
|
||||
|
||||
SDLWindow::~SDLWindow()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
540
rainbow/SlaveGui/Wnd.cpp
Normal file
540
rainbow/SlaveGui/Wnd.cpp
Normal file
|
|
@ -0,0 +1,540 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SLAVE
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) LOG(x)
|
||||
#define LDUMP(x) //DDUMP(x)
|
||||
#define LDUMPC(x) //DDUMPC(x)
|
||||
#define LTIMING(x) RTIMING(x)
|
||||
|
||||
Ptr<Ctrl> Ctrl::desktop;
|
||||
Vector<Ctrl *> Ctrl::topctrl;
|
||||
|
||||
bool Ctrl::invalid;
|
||||
|
||||
bool Ctrl::sdlMouseIsIn;
|
||||
|
||||
Point Ctrl::fbCursorPos = Null;
|
||||
Image Ctrl::fbCursorImage;
|
||||
Rect Ctrl::fbCaretRect;
|
||||
int Ctrl::fbCaretTm;
|
||||
bool Ctrl::fbEndSession;
|
||||
int Ctrl::PaintLock;
|
||||
|
||||
bool Ctrl::SystemCursor;
|
||||
|
||||
void Ctrl::SetDesktop(Ctrl& q)
|
||||
{
|
||||
desktop = &q;
|
||||
desktop->SetOpen(true);
|
||||
desktop->NewTop();
|
||||
invalid = true;
|
||||
}
|
||||
|
||||
void Ctrl::InitFB()
|
||||
{
|
||||
Ctrl::GlobalBackBuffer();
|
||||
Ctrl::InitTimer();
|
||||
|
||||
// #ifdef PLATFORM_POSIX
|
||||
SetStdFont(ScreenSans(12)); //FIXME general handling
|
||||
// #endif
|
||||
ChStdSkin();
|
||||
|
||||
static StaticRect x;
|
||||
x.Color(Cyan());
|
||||
SetDesktop(x);
|
||||
}
|
||||
|
||||
void Ctrl::EndSession()
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("Ctrl::EndSession");
|
||||
fbEndSession = true;
|
||||
EndSessionLoopNo = EventLoopNo;
|
||||
}
|
||||
|
||||
void Ctrl::ExitFB()
|
||||
{
|
||||
TopWindow::ShutdownWindows();
|
||||
Ctrl::CloseTopCtrls();
|
||||
if(fbEndSession) {
|
||||
SlaveGuiPtr->Quit();
|
||||
#if 0
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Ctrl::SetDesktopSize(Size sz)
|
||||
{
|
||||
if(desktop)
|
||||
desktop->SetRect(sz);
|
||||
invalid = true;
|
||||
SyncTopWindows();
|
||||
}
|
||||
|
||||
int Ctrl::FindTopCtrl() const
|
||||
{
|
||||
for(int i = 0; i < topctrl.GetCount(); i++)
|
||||
if(this == topctrl[i])
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Ctrl::IsAlphaSupported()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Ctrl::IsCompositedGui()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<Ctrl *> Ctrl::GetTopCtrls()
|
||||
{
|
||||
Vector<Ctrl *> ctrl;
|
||||
if(desktop)
|
||||
ctrl.Add(desktop);
|
||||
for(int i = 0; i < topctrl.GetCount(); i++)
|
||||
if(!dynamic_cast<TopWindowFrame *>(topctrl[i]))
|
||||
ctrl.Add(topctrl[i]);
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
Ctrl *Ctrl::GetOwner()
|
||||
{
|
||||
GuiLock __;
|
||||
int q = FindTopCtrl();
|
||||
if(q > 0 && topctrl[q]->top) {
|
||||
Ctrl *x = topctrl[q]->top->owner_window;
|
||||
LDUMP(Upp::Name(x));
|
||||
return dynamic_cast<TopWindowFrame *>(x) ? x->GetOwner() : x;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Ctrl *Ctrl::GetActiveCtrl()
|
||||
{
|
||||
GuiLock __;
|
||||
return focusCtrl ? focusCtrl->GetTopCtrl() : NULL;
|
||||
}
|
||||
|
||||
// Vector<Callback> Ctrl::hotkey;
|
||||
|
||||
int Ctrl::RegisterSystemHotKey(dword key, Function<void ()> cb)
|
||||
{
|
||||
/* ASSERT(key >= K_DELTA);
|
||||
int q = hotkey.GetCount();
|
||||
for(int i = 0; i < hotkey.GetCount(); i++)
|
||||
if(!hotkey[i]) {
|
||||
q = i;
|
||||
break;
|
||||
}
|
||||
hotkey.At(q) = cb;
|
||||
dword mod = 0;
|
||||
if(key & K_ALT)
|
||||
mod |= MOD_ALT;
|
||||
if(key & K_SHIFT)
|
||||
mod |= MOD_SHIFT;
|
||||
if(key & K_CTRL)
|
||||
mod |= MOD_CONTROL;
|
||||
|
||||
return RegisterHotKey(NULL, q, mod, key & 0xffff) ? q : -1;*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Ctrl::UnregisterSystemHotKey(int id)
|
||||
{
|
||||
/* if(id >= 0 && id < hotkey.GetCount()) {
|
||||
UnregisterHotKey(NULL, id);
|
||||
hotkey[id].Clear();
|
||||
}*/
|
||||
}
|
||||
|
||||
bool Ctrl::IsWaitingEvent()
|
||||
{
|
||||
return SlaveGuiPtr->IsWaitingEvent();
|
||||
#if 0
|
||||
SDL_PumpEvents();
|
||||
SDL_Event events;
|
||||
return SDL_PeepEvents(&events, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Ctrl::SyncTopWindows()
|
||||
{
|
||||
for(int i = 0; i < topctrl.GetCount(); i++) {
|
||||
TopWindow *w = dynamic_cast<TopWindow *>(topctrl[i]);
|
||||
if(w)
|
||||
w->SyncRect();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ViewDraw::ViewDraw(Ctrl *ctrl)
|
||||
{
|
||||
if(Ctrl::invalid)
|
||||
Ctrl::DoPaint();
|
||||
Ctrl::invalid = false;
|
||||
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::DoUpdate();
|
||||
}
|
||||
*/
|
||||
|
||||
Rect Ctrl::GetClipBound(const Vector<Rect>& inv, const Rect& r)
|
||||
{
|
||||
Rect ri = Null;
|
||||
for(int j = 0; j < inv.GetCount(); j++) {
|
||||
Rect rr = inv[j] & r;
|
||||
if(!rr.IsEmpty())
|
||||
ri = IsNull(ri) ? rr : rr | ri;
|
||||
}
|
||||
return ri;
|
||||
}
|
||||
|
||||
void Ctrl::PaintScene(SystemDraw& draw)
|
||||
{
|
||||
if(!desktop)
|
||||
return;
|
||||
LLOG("@ DoPaint");
|
||||
LTIMING("DoPaint paint");
|
||||
draw.Init(screen_size, (uint64)screen.glcontext);
|
||||
draw.Begin();
|
||||
Vector<Rect> invalid;
|
||||
invalid.Add(screen_size);
|
||||
for(int i = topctrl.GetCount() - 1; i >= 0; i--) {
|
||||
Rect r = topctrl[i]->GetRect();
|
||||
Rect ri = GetClipBound(invalid, r);
|
||||
if(!IsNull(ri)) {
|
||||
draw.Clipoff(r);
|
||||
topctrl[i]->UpdateArea(draw, ri - r.TopLeft());
|
||||
draw.End();
|
||||
Subtract(invalid, r);
|
||||
draw.ExcludeClip(r);
|
||||
}
|
||||
}
|
||||
Rect ri = GetClipBound(invalid, desktop->GetRect().GetSize());
|
||||
if(!IsNull(ri))
|
||||
desktop->UpdateArea(draw, ri);
|
||||
draw.End();
|
||||
}
|
||||
|
||||
void Ctrl::PaintCaretCursor(SystemDraw& draw)
|
||||
{
|
||||
if(!IsNull(fbCaretRect))
|
||||
draw.DrawRect(fbCaretRect, InvertColor);
|
||||
if(sdlMouseIsIn && !SystemCursor)
|
||||
draw.DrawImage(fbCursorPos.x, fbCursorPos.y, fbCursorImage);
|
||||
}
|
||||
|
||||
void Ctrl::DoPaint()
|
||||
{
|
||||
if(!PaintLock) {
|
||||
if(invalid && desktop) {
|
||||
invalid = false;
|
||||
SystemDraw draw;
|
||||
PaintScene(draw);
|
||||
PaintCaretCursor(draw);
|
||||
draw.Finish();
|
||||
SDL_GL_SwapWindow(screen.win);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ctrl::WndUpdate(const Rect&)
|
||||
{
|
||||
GuiLock __;
|
||||
Invalidate();
|
||||
DoPaint();
|
||||
}
|
||||
|
||||
Rect Ctrl::GetWndScreenRect() const
|
||||
{
|
||||
GuiLock __;
|
||||
return GetRect();
|
||||
}
|
||||
|
||||
void Ctrl::WndShow(bool b)
|
||||
{
|
||||
GuiLock __;
|
||||
}
|
||||
|
||||
void Ctrl::WndUpdate()
|
||||
{
|
||||
GuiLock __;
|
||||
}
|
||||
|
||||
bool Ctrl::IsWndOpen() const {
|
||||
GuiLock __;
|
||||
return FindTopCtrl() >= 0 || this == desktop;
|
||||
}
|
||||
|
||||
void Ctrl::SetAlpha(byte alpha)
|
||||
{
|
||||
GuiLock __;
|
||||
}
|
||||
|
||||
Rect Ctrl::GetWorkArea() const
|
||||
{
|
||||
GuiLock __;
|
||||
return GetVirtualScreenArea();
|
||||
}
|
||||
|
||||
void Ctrl::GetWorkArea(Array<Rect>& rc)
|
||||
{
|
||||
GuiLock __;
|
||||
Array<Rect> r;
|
||||
r.Add(GetVirtualScreenArea());
|
||||
}
|
||||
|
||||
Rect Ctrl::GetVirtualWorkArea()
|
||||
{
|
||||
return GetVirtualScreenArea();
|
||||
}
|
||||
/*
|
||||
Rect Ctrl::GetWorkArea(Point pt)
|
||||
{
|
||||
return GetVirtualScreenArea();
|
||||
}
|
||||
*/
|
||||
Rect Ctrl::GetVirtualScreenArea()
|
||||
{
|
||||
GuiLock __;
|
||||
return desktop ? desktop->GetRect() : Rect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
Rect Ctrl::GetPrimaryWorkArea()
|
||||
{
|
||||
return GetVirtualScreenArea();
|
||||
}
|
||||
|
||||
Rect Ctrl::GetPrimaryScreenArea()
|
||||
{
|
||||
return GetVirtualScreenArea();
|
||||
}
|
||||
|
||||
int Ctrl::GetKbdDelay()
|
||||
{
|
||||
GuiLock __;
|
||||
return 500;
|
||||
}
|
||||
|
||||
int Ctrl::GetKbdSpeed()
|
||||
{
|
||||
GuiLock __;
|
||||
return 1000 / 32;
|
||||
}
|
||||
|
||||
void Ctrl::DestroyWnd()
|
||||
{
|
||||
for(int i = 0; i < topctrl.GetCount(); i++)
|
||||
if(topctrl[i]->top && topctrl[i]->top->owner_window == this)
|
||||
topctrl[i]->WndDestroy();
|
||||
int q = FindTopCtrl();
|
||||
if(q >= 0) {
|
||||
Invalidate();
|
||||
topctrl.Remove(q);
|
||||
}
|
||||
if(top) {
|
||||
delete top;
|
||||
top = NULL;
|
||||
}
|
||||
isopen = false;
|
||||
TopWindow *win = dynamic_cast<TopWindow *>(this);
|
||||
if(win)
|
||||
win->DestroyFrame();
|
||||
}
|
||||
|
||||
void Ctrl::WndDestroy()
|
||||
{
|
||||
DestroyWnd();
|
||||
if(topctrl.GetCount())
|
||||
topctrl.Top()->ActivateWnd();
|
||||
}
|
||||
|
||||
void Ctrl::PutForeground()
|
||||
{
|
||||
int q = FindTopCtrl();
|
||||
if(q >= 0) {
|
||||
Invalidate();
|
||||
topctrl.Remove(q);
|
||||
topctrl.Add(this);
|
||||
}
|
||||
Vector< Ptr<Ctrl> > fw;
|
||||
for(int i = 0; i < topctrl.GetCount(); i++)
|
||||
if(topctrl[i] && topctrl[i]->top && topctrl[i]->top->owner_window == this && topctrl[i] != this)
|
||||
fw.Add(topctrl[i]);
|
||||
for(int i = 0; i < fw.GetCount(); i++)
|
||||
if(fw[i])
|
||||
fw[i]->PutForeground();
|
||||
}
|
||||
|
||||
void Ctrl::SetWndForeground()
|
||||
{
|
||||
GuiLock __;
|
||||
ASSERT(IsOpen());
|
||||
if(IsWndForeground())
|
||||
return;
|
||||
Ctrl *to = this;
|
||||
while(to->top && to->top->owner_window)
|
||||
to = to->top->owner_window;
|
||||
to->PutForeground();
|
||||
if(this != focusCtrl)
|
||||
ActivateWnd();
|
||||
}
|
||||
|
||||
bool Ctrl::IsWndForeground() const
|
||||
{
|
||||
GuiLock __;
|
||||
bool b = false;
|
||||
for(int i = 0; i < topctrl.GetCount(); i++) {
|
||||
const TopWindow *tw = dynamic_cast<const TopWindow *>(topctrl[i]);
|
||||
if(tw)
|
||||
b = tw == this;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
void Ctrl::WndEnable(bool)
|
||||
{
|
||||
GuiLock __;
|
||||
}
|
||||
|
||||
bool Ctrl::SetWndFocus()
|
||||
{
|
||||
GuiLock __;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ctrl::HasWndFocus() const
|
||||
{
|
||||
GuiLock __;
|
||||
return focusCtrl && focusCtrl->GetTopCtrl() == this;
|
||||
}
|
||||
|
||||
bool Ctrl::SetWndCapture()
|
||||
{
|
||||
GuiLock __;
|
||||
ASSERT(IsMainThread());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ctrl::ReleaseWndCapture()
|
||||
{
|
||||
GuiLock __;
|
||||
ASSERT(IsMainThread());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ctrl::HasWndCapture() const
|
||||
{
|
||||
GuiLock __;
|
||||
return captureCtrl && captureCtrl->GetTopCtrl() == this;
|
||||
}
|
||||
|
||||
void Ctrl::WndInvalidateRect(const Rect&)
|
||||
{
|
||||
GuiLock __;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void Ctrl::WndSetPos(const Rect& rect)
|
||||
{
|
||||
GuiLock __;
|
||||
TopWindow *w = dynamic_cast<TopWindow *>(this);
|
||||
if(w)
|
||||
w->SyncFrameRect(rect);
|
||||
Invalidate();
|
||||
SetWndRect(rect);
|
||||
}
|
||||
|
||||
void Ctrl::WndScrollView(const Rect& r, int dx, int dy)
|
||||
{
|
||||
GuiLock __;
|
||||
LLOG("ScrollView " << rect);
|
||||
WndInvalidateRect(r);
|
||||
}
|
||||
|
||||
void Ctrl::PopUp(Ctrl *owner, bool savebits, bool activate, bool dropshadow, bool topmost)
|
||||
{
|
||||
ASSERT(!IsChild() && !IsOpen() && FindTopCtrl() < 0);
|
||||
NewTop();
|
||||
if(owner) {
|
||||
Ctrl *owner_window = owner->GetTopWindow();
|
||||
if(!owner_window)
|
||||
owner_window = owner->GetTopCtrl();
|
||||
ASSERT(owner_window->IsOpen());
|
||||
if(owner_window != desktop) {
|
||||
owner_window->SetForeground();
|
||||
top->owner_window = owner_window;
|
||||
}
|
||||
}
|
||||
topctrl.Add(this);
|
||||
popup = isopen = true;
|
||||
RefreshLayoutDeep();
|
||||
if(activate) SetFocusWnd();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
Rect Ctrl::GetDefaultWindowRect() {
|
||||
GuiLock __;
|
||||
static int ii = 0;
|
||||
Rect rect = GetVirtualScreenArea();
|
||||
Size sz = rect.GetSize();
|
||||
rect.Deflate(sz / 10);
|
||||
rect.Offset(Size(GetStdFontCy(), 2 * GetStdFontCy()) * (++ii % 8));
|
||||
return rect;
|
||||
}
|
||||
|
||||
Vector<WString> SplitCmdLine__(const char *cmd)
|
||||
{
|
||||
Vector<WString> out;
|
||||
while(*cmd)
|
||||
if((byte)*cmd <= ' ')
|
||||
cmd++;
|
||||
else if(*cmd == '\"') {
|
||||
WString quoted;
|
||||
while(*++cmd && (*cmd != '\"' || *++cmd == '\"'))
|
||||
quoted.Cat(FromSystemCharset(String(cmd, 1)).ToWString());
|
||||
out.Add(quoted);
|
||||
}
|
||||
else {
|
||||
const char *begin = cmd;
|
||||
while((byte)*cmd > ' ')
|
||||
cmd++;
|
||||
out.Add(String(begin, cmd).ToWString());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void Ctrl::InstallPanicBox()
|
||||
{
|
||||
}
|
||||
|
||||
void Ctrl::SysEndLoop()
|
||||
{
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
14
rainbow/SlaveGuiUword/SlaveGuiUword.upp
Normal file
14
rainbow/SlaveGuiUword/SlaveGuiUword.upp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
RichEdit,
|
||||
plugin/DroidFonts,
|
||||
SlaveGui;
|
||||
|
||||
file
|
||||
main.cpp,
|
||||
test.qtf,
|
||||
help.txt;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI SLAVEGUI";
|
||||
|
||||
20
rainbow/SlaveGuiUword/help.txt
Normal file
20
rainbow/SlaveGuiUword/help.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
TIMING DoPaint paint : 8.79 s - 15.82 ms ( 8.79 s / 556 ), min: 7.00 ms, max: 69.00 ms, nesting: 1 - 556
|
||||
|
||||
--------------------------------------
|
||||
TIMING PutImage : 678.78 ms - 8.67 us (681.00 ms / 78291 ), min: 0.00 ns, max: 4.00 ms, nesting: 1 - 78291
|
||||
TIMING CreateTexture : 45.98 ms - 70.52 us (46.00 ms / 652 ), min: 0.00 ns, max: 6.00 ms, nesting: 1 - 652
|
||||
TIMING PutImage colored: 1.35 s - 5.22 us ( 1.36 s / 259617 ), min: 0.00 ns, max: 6.00 ms, nesting: 1 - 259617
|
||||
TIMING PutRect : 1.43 s - 26.50 us ( 1.43 s / 53826 ), min: 0.00 ns, max: 21.00 ms, nesting: 1 - 53826
|
||||
TIMING DoPaint paint : 4.35 s - 17.27 ms ( 4.35 s / 252 ), min: 9.00 ms, max: 71.00 ms, nesting: 1 - 252
|
||||
|
||||
---------- COMB_OPT rect -------------
|
||||
TIMING PutImage : 787.68 ms - 8.42 us (791.00 ms / 93549 ), min: 0.00 ns, max: 3.00 ms, nesting: 1 - 93549
|
||||
TIMING PutImage colored: 1.50 s - 4.80 us ( 1.51 s / 311579 ), min: 0.00 ns, max: 6.00 ms, nesting: 1 - 311579
|
||||
TIMING FlushPutRect : 1.58 s - 120.22 us ( 1.58 s / 13147 ), min: 0.00 ns, max: 16.00 ms, nesting: 1 - 13147
|
||||
TIMING PutRect : 15.71 ms - 243.65 ns (18.00 ms / 64492 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 64492
|
||||
TIMING DoPaint paint : 4.89 s - 16.25 ms ( 4.89 s / 301 ), min: 7.00 ms, max: 71.00 ms, nesting: 1 - 301
|
||||
|
||||
---------- DIRECT --------------------
|
||||
TIMING PutImage : 7.10 s - 11.21 us ( 7.12 s / 632969 ), min: 0.00 ns, max: 21.00 ms, nesting: 1 - 632969
|
||||
TIMING PutRect : 65.20 ms - 642.58 ns (68.00 ms / 101472 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 101472
|
||||
TIMING DoPaint paint : 8.75 s - 18.35 ms ( 8.75 s / 477 ), min: 9.00 ms, max: 61.00 ms, nesting: 1 - 477
|
||||
258
rainbow/SlaveGuiUword/main.cpp
Normal file
258
rainbow/SlaveGuiUword/main.cpp
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
#include <RichEdit/RichEdit.h>
|
||||
#include <PdfDraw/PdfDraw.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define IMAGECLASS UWordImg
|
||||
#define IMAGEFILE <UWord/UWord.iml>
|
||||
#include <Draw/iml.h>
|
||||
|
||||
FileSel& UWordFs()
|
||||
{
|
||||
static FileSel fs;
|
||||
return fs;
|
||||
}
|
||||
|
||||
class UWord : public TopWindow {
|
||||
public:
|
||||
virtual void DragAndDrop(Point, PasteClip& d);
|
||||
virtual void FrameDragAndDrop(Point, PasteClip& d);
|
||||
|
||||
virtual void ShutdownWindow();
|
||||
|
||||
protected:
|
||||
RichEdit editor;
|
||||
MenuBar menubar;
|
||||
ToolBar toolbar;
|
||||
StatusBar statusbar;
|
||||
String filename;
|
||||
|
||||
static LRUList& lrufile() { static LRUList l; return l; }
|
||||
|
||||
void Load(const String& filename);
|
||||
void OpenFile(const String& fn);
|
||||
void New();
|
||||
void Open();
|
||||
void Save0();
|
||||
void Save();
|
||||
void SaveAs();
|
||||
void Print();
|
||||
void About();
|
||||
void Destroy(bool shutdown);
|
||||
void SetBar();
|
||||
void FileBar(Bar& bar);
|
||||
void AboutMenu(Bar& bar);
|
||||
void MainMenu(Bar& bar);
|
||||
void MainBar(Bar& bar);
|
||||
|
||||
public:
|
||||
typedef UWord CLASSNAME;
|
||||
|
||||
static void SerializeApp(Stream& s);
|
||||
|
||||
UWord();
|
||||
};
|
||||
|
||||
void UWord::FileBar(Bar& bar)
|
||||
{
|
||||
bar.Add("New", CtrlImg::new_doc(), THISBACK(New))
|
||||
.Key(K_CTRL_N)
|
||||
.Help("Open new window");
|
||||
bar.Add("Open..", CtrlImg::open(), THISBACK(Open))
|
||||
.Key(K_CTRL_O)
|
||||
.Help("Open existing document");
|
||||
bar.Add(editor.IsModified(), "Save", CtrlImg::save(), THISBACK(Save))
|
||||
.Key(K_CTRL_S)
|
||||
.Help("Save current document");
|
||||
bar.Add("SaveAs", CtrlImg::save_as(), THISBACK(SaveAs))
|
||||
.Help("Save current document with a new name");
|
||||
bar.ToolGap();
|
||||
bar.MenuSeparator();
|
||||
bar.Add("Print..", CtrlImg::print(), THISBACK(Print))
|
||||
.Key(K_CTRL_P)
|
||||
.Help("Print document");
|
||||
if(bar.IsMenuBar()) {
|
||||
if(lrufile().GetCount())
|
||||
lrufile()(bar, THISBACK(OpenFile));
|
||||
bar.Separator();
|
||||
bar.Add("Exit", THISBACK1(Destroy, false));
|
||||
}
|
||||
}
|
||||
|
||||
void UWord::AboutMenu(Bar& bar)
|
||||
{
|
||||
bar.Add("About..", THISBACK(About));
|
||||
}
|
||||
|
||||
void UWord::MainMenu(Bar& bar)
|
||||
{
|
||||
bar.Add("File", THISBACK(FileBar));
|
||||
bar.Add("Window", callback(WindowsMenu));
|
||||
bar.Add("Help", THISBACK(AboutMenu));
|
||||
}
|
||||
|
||||
void UWord::New()
|
||||
{
|
||||
new UWord;
|
||||
}
|
||||
|
||||
void UWord::Load(const String& name)
|
||||
{
|
||||
lrufile().NewEntry(name);
|
||||
editor.SetQTF(LoadFile(name));
|
||||
filename = name;
|
||||
editor.ClearModify();
|
||||
Title(filename);
|
||||
}
|
||||
|
||||
void UWord::OpenFile(const String& fn)
|
||||
{
|
||||
if(filename.IsEmpty() && !editor.IsModified())
|
||||
Load(fn);
|
||||
else
|
||||
(new UWord)->Load(fn);
|
||||
}
|
||||
|
||||
void UWord::Open()
|
||||
{
|
||||
FileSel& fs = UWordFs();
|
||||
if(fs.ExecuteOpen())
|
||||
OpenFile(fs);
|
||||
else
|
||||
statusbar.Temporary("Loading aborted.");
|
||||
}
|
||||
|
||||
void UWord::DragAndDrop(Point, PasteClip& d)
|
||||
{
|
||||
if(AcceptFiles(d)) {
|
||||
Vector<String> fn = GetFiles(d);
|
||||
for(int i = 0; i < fn.GetCount(); i++)
|
||||
if(FileExists(fn[i]))
|
||||
OpenFile(fn[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void UWord::FrameDragAndDrop(Point p, PasteClip& d)
|
||||
{
|
||||
DragAndDrop(p, d);
|
||||
}
|
||||
|
||||
void UWord::Save0()
|
||||
{
|
||||
lrufile().NewEntry(filename);
|
||||
if(filename.IsEmpty())
|
||||
SaveAs();
|
||||
else
|
||||
if(SaveFile(filename, editor.GetQTF())) {
|
||||
statusbar.Temporary("File " + filename + " was saved.");
|
||||
ClearModify();
|
||||
}
|
||||
else
|
||||
Exclamation("Error saving the file [* " + DeQtf(filename) + "]!");
|
||||
}
|
||||
|
||||
void UWord::Save()
|
||||
{
|
||||
if(!editor.IsModified()) return;
|
||||
Save0();
|
||||
}
|
||||
|
||||
void UWord::SaveAs()
|
||||
{
|
||||
FileSel& fs = UWordFs();
|
||||
if(fs.ExecuteSaveAs()) {
|
||||
filename = fs;
|
||||
Title(filename);
|
||||
Save0();
|
||||
}
|
||||
}
|
||||
|
||||
void UWord::Print()
|
||||
{
|
||||
editor.Print();
|
||||
}
|
||||
|
||||
void UWord::About()
|
||||
{
|
||||
PromptOK("[A5 uWord]&Using [*^www://upp.sf.net^ Ultimate`+`+] technology.");
|
||||
}
|
||||
|
||||
void UWord::Destroy(bool shutdown)
|
||||
{
|
||||
if(editor.IsModified()) {
|
||||
switch((shutdown ? PromptYesNo : PromptYesNoCancel)("Do you want to save the changes to the document?")) {
|
||||
case 1:
|
||||
Save();
|
||||
break;
|
||||
case -1:
|
||||
return;
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void UWord::ShutdownWindow()
|
||||
{
|
||||
Destroy(true);
|
||||
}
|
||||
|
||||
void UWord::MainBar(Bar& bar)
|
||||
{
|
||||
FileBar(bar);
|
||||
bar.Separator();
|
||||
editor.DefaultBar(bar);
|
||||
}
|
||||
|
||||
void UWord::SetBar()
|
||||
{
|
||||
toolbar.Set(THISBACK(MainBar));
|
||||
}
|
||||
|
||||
UWord::UWord()
|
||||
{
|
||||
AddFrame(menubar);
|
||||
AddFrame(TopSeparatorFrame());
|
||||
AddFrame(toolbar);
|
||||
AddFrame(statusbar);
|
||||
Add(editor.SizePos());
|
||||
menubar.Set(THISBACK(MainMenu));
|
||||
Sizeable().Zoomable();
|
||||
WhenClose = THISBACK1(Destroy, false);
|
||||
menubar.WhenHelp = toolbar.WhenHelp = statusbar;
|
||||
static int doc;
|
||||
Title(Format("Document%d", ++doc));
|
||||
Icon(CtrlImg::File());
|
||||
editor.ClearModify();
|
||||
SetBar();
|
||||
editor.WhenRefreshBar = THISBACK(SetBar);
|
||||
OpenMain();
|
||||
ActiveFocus(editor);
|
||||
|
||||
editor <<= LoadFile(GetDataFile("test.qtf"));
|
||||
}
|
||||
|
||||
void UWord::SerializeApp(Stream& s)
|
||||
{
|
||||
int version = 1;
|
||||
s / version;
|
||||
s % UWordFs();
|
||||
if(version >= 1)
|
||||
s % lrufile();
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
Ctrl::SystemCursor = true;
|
||||
|
||||
SetLanguage(LNG_ENGLISH);
|
||||
SetDefaultCharset(CHARSET_UTF8);
|
||||
|
||||
UWordFs().Type("QTF files", "*.qtf")
|
||||
.AllFilesType()
|
||||
.DefaultExt("qtf");
|
||||
|
||||
LoadFromFile(callback(UWord::SerializeApp));
|
||||
UWord uword;
|
||||
Ctrl::EventLoop();
|
||||
StoreToFile(callback(UWord::SerializeApp));
|
||||
}
|
||||
5
rainbow/SlaveGuiUword/test.cpp
Normal file
5
rainbow/SlaveGuiUword/test.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include <xmmintrin.h>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
void Foo() {}
|
||||
2998
rainbow/SlaveGuiUword/test.qtf
Normal file
2998
rainbow/SlaveGuiUword/test.qtf
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -47,6 +47,12 @@
|
|||
#define GUIPLATFORM_INCLUDE <SDL20GL/SDL20GL.h>
|
||||
#endif
|
||||
|
||||
#ifdef flagSLAVEGUI
|
||||
#define GUIPLATFORM_KEYCODES_INCLUDE <SlaveGui/Keys.h>
|
||||
//need to make SDL_keysym.h known before K_ enum
|
||||
#define GUIPLATFORM_INCLUDE <SlaveGui/SlaveGui.h>
|
||||
#endif
|
||||
|
||||
#ifdef flagTELPP
|
||||
#define GUIPLATFORM_KEYCODES_INCLUDE <Telpp/Keys.h>
|
||||
//need to make SDL_keysym.h known before K_ enum
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue