diff --git a/rainbow/Paint/Paint.upp b/rainbow/Paint/Paint.upp index a6d5209e2..25d0f2fb1 100644 --- a/rainbow/Paint/Paint.upp +++ b/rainbow/Paint/Paint.upp @@ -5,8 +5,6 @@ uses Framebuffer, RichEdit; -uses(WINGL) WinGl; - uses(WINFB) WinFb; uses(LINUXFB) LinuxFb; diff --git a/rainbow/PaintGl/PaintGl.upp b/rainbow/PaintGl/PaintGl.upp new file mode 100644 index 000000000..b42963ead --- /dev/null +++ b/rainbow/PaintGl/PaintGl.upp @@ -0,0 +1,11 @@ +uses + CtrlLib, + Painter, + WinGl; + +file + main.cpp; + +mainconfig + "" = "GUI WINGL"; + diff --git a/rainbow/PaintGl/init b/rainbow/PaintGl/init new file mode 100644 index 000000000..84aafd54a --- /dev/null +++ b/rainbow/PaintGl/init @@ -0,0 +1,6 @@ +#ifndef _PaintGl_icpp_init_stub +#define _PaintGl_icpp_init_stub +#include "CtrlLib/init" +#include "Painter/init" +#include "WinGl/init" +#endif diff --git a/rainbow/PaintGl/main.cpp b/rainbow/PaintGl/main.cpp new file mode 100644 index 000000000..fac25ff83 --- /dev/null +++ b/rainbow/PaintGl/main.cpp @@ -0,0 +1,78 @@ +#include +#include + +using namespace Upp; + +struct App : public Ctrl { + EditString x; + ArrayCtrl a, b; + DropList dl; + + StaticRect popup; + + void Paint(Draw& w) + { + Size sz = GetSize(); + DDUMP(sz); + w.DrawRect(0, 0, sz.cx, sz.cy, SWhite); + w.DrawRect(10, 10, 30, 30, SRed); + w.DrawLine(45, 45, 80, 120, 4, Blue); + w.DrawLine(80, 90, 400, 0, PEN_DASHDOT); + w.DrawEllipse(200, 200, 50, 100, Green); + w.DrawImage(200, 10, CtrlImg::HandCursor()); + const char *text = "This text is centered"; + Size tsz = GetTextSize(text, Arial(25).Bold()); + w.DrawText((sz.cx - tsz.cx) / 2, (sz.cy - tsz.cy) / 2, text, Arial(27).Bold(), SBlue); + w.Clipoff(200, 50, 95, 100); + w.DrawText(0, 80, "CLIPPED", Roman(25)); + w.End(); + } + + void LeftDown(Point p, dword) + { + popup.SetRect(p.x, p.y, 100, 400); + } + + void InitArray(ArrayCtrl& a) + { + a.AddColumn("first"); + a.AddColumn("second"); + for(int i = 0; i < 100; i++) + a.Add(i, FormatIntRoman(i)); + } + + App() + { + x <<= "Hello world!"; + Add(x.LeftPos(100, 100).TopPos(500, 20)); + Add(a.LeftPos(300, 150).TopPos(10, 300)); + InitArray(a); + InitArray(b); + popup.SetFrame(BlackFrame()); + popup.Add(b.HSizePos(10, 10).VSizePos(10, 10)); + popup.SetRect(800, 100, 100, 400); + + Add(dl.LeftPos(10, 300).TopPos(10, 30)); + for(int i = 0; i < 100; i++) + dl.Add(i); +// Sizeable(); + } +}; + +#define EDITOR 0 + +GUI_APP_MAIN +{ +#if EDITOR + RichEditWithToolBar app; +#else + App app; +#endif + ChStdSkin(); + Ctrl::SetDesktop(app); + app.SetFocus(); +#if !EDITOR + app.popup.PopUp(); +#endif + Ctrl::EventLoop(); +} diff --git a/rainbow/WinGl/After.h b/rainbow/WinGl/After.h index 69078457a..ce764d682 100644 --- a/rainbow/WinGl/After.h +++ b/rainbow/WinGl/After.h @@ -11,12 +11,14 @@ public: ~ViewDraw() {} }; +class DHCtrl : Ctrl {}; + void InitGl(); Vector& coreCmdLine__(); Vector SplitCmdLine__(const char *cmd); -void FBInit(HINSTANCE hInstance); +int GlInit(HINSTANCE hInstance); #define GUI_APP_MAIN \ void GuiMainFn_();\ @@ -25,12 +27,17 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdSh { \ UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \ UPP::AppInitEnvironment__(); \ - UPP::GlInit(hInstance); \ - GuiMainFn_(); \ - UPP::Ctrl::CloseTopCtrls(); \ - UPP::UsrLog("---------- About to delete this log of WinGL..."); \ - UPP::DeleteUsrLog(); \ - return UPP::GetExitCode(); \ + int r = UPP::GlInit(hInstance); \ + if(r > 0) { \ + GuiMainFn_(); \ + UPP::Ctrl::CloseTopCtrls(); \ + UPP::UsrLog("---------- About to delete this log of WinGL..."); \ + UPP::DeleteUsrLog(); \ + return UPP::GetExitCode(); \ + } else { \ + Exclamation(Format("OpenGL window could not be initialized: %d", r)); \ + return r; \ + }\ } \ \ void GuiMainFn_() diff --git a/rainbow/WinGl/ChSysInit.cpp b/rainbow/WinGl/ChSysInit.cpp new file mode 100644 index 000000000..dcd99f475 --- /dev/null +++ b/rainbow/WinGl/ChSysInit.cpp @@ -0,0 +1,16 @@ +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +void ChSysInit() +{ + CtrlImg::Reset(); + CtrlsImg::Reset(); + ChReset(); +} + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/Clip.cpp b/rainbow/WinGl/Clip.cpp new file mode 100644 index 000000000..5cdb0e235 --- /dev/null +++ b/rainbow/WinGl/Clip.cpp @@ -0,0 +1,241 @@ +#include +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +#define LLOG(x) // LOG(x) + +void ClearClipboard() +{ + GuiLock __; +} + +void AppendClipboard(int format, const byte *data, int length) +{ + GuiLock __; +} + +void AppendClipboard(const char *format, const byte *data, int length) +{ + GuiLock __; +} + +void AppendClipboard(const char *format, const String& data) +{ + GuiLock __; + AppendClipboard(format, data, data.GetLength()); +} + +void AppendClipboard(const char *format, const Value& data, String (*render)(const Value&)) +{ + GuiLock __; +} + +String ReadClipboard(const char *format) +{ + GuiLock __; + return Null; +} + +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& data, const String& text) +{ + data.GetAdd("text", ClipData(text, sText)); + data.GetAdd("wtext", ClipData(text, sWText)); +} + +void Append(VectorMap& 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() +{ + return ReadClipboardUnicodeText().ToString(); +} + +WString ReadClipboardUnicodeText() +{ + return Null; +} + +bool IsClipboardAvailable(const char *id) +{ + return false; +} + +bool IsClipboardAvailableText() +{ + return false; +} + +const char *ClipFmtsImage() +{ + static const char *q; + ONCELOCK { + static String s = "dib;" + ClipFmt(); + q = s; + } + return q; +} + +bool AcceptImage(PasteClip& clip) +{ + GuiLock __; + return clip.Accept(ClipFmtsImage()); +} + +Image GetImage(PasteClip& clip) +{ + GuiLock __; + Image m; + if(Accept(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(img)); +} + +String GetImageClip(const Image& img, const String& fmt) +{ + GuiLock __; + if(img.IsEmpty()) return Null; + if(fmt == ClipFmt()) + return sImage(img); + return Null; +} + +void AppendClipboardImage(const Image& img) +{ + GuiLock __; + if(img.IsEmpty()) return; + AppendClipboard(ClipFmt(), 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 GetFiles(PasteClip& clip) +{ + GuiLock __; + Vector f; + return f; +} + +bool PasteClip::IsAvailable(const char *fmt) const +{ + return false; +} + +String PasteClip::Get(const char *fmt) const +{ + return Null; +} + +void PasteClip::GuiPlatformConstruct() +{ +} + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/Ctrl.h b/rainbow/WinGl/Ctrl.h index 6ca03df35..45b3335dc 100644 --- a/rainbow/WinGl/Ctrl.h +++ b/rainbow/WinGl/Ctrl.h @@ -1,5 +1,20 @@ //$ class Ctrl { + static Ptr desktop; + static Vector topctrl; + + static Point fbCursorPos; + static Image fbCursorImage; + + static Point fbCursorBakPos; + static Image fbCursorBak; + + static Rect fbCaretRect; + static Image fbCaretBak; + static int fbCaretTm; + + int FindTopCtrl() const; public: + static void InitGl(); static void DoMouseGl(int event, Point p, int zdelta = 0); static bool DoKeyGl(dword key, int cnt); @@ -7,7 +22,10 @@ public: static void RemoveCaret(); static void CursorSync(); - static Image GetBak(Rect& tr); void SetOpen(bool b) { isopen = b; } void SetTop() { top = new Top; } + + static void SetDesktop(Ctrl& q); + static Ctrl *GetDesktop() { return desktop; } + //$ }; diff --git a/rainbow/WinGl/Dnd.cpp b/rainbow/WinGl/Dnd.cpp new file mode 100644 index 000000000..79efd9ff0 --- /dev/null +++ b/rainbow/WinGl/Dnd.cpp @@ -0,0 +1,40 @@ +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +#define LLOG(x) // LOG(x) + +// -------------------------------------------------------------------------------------------- + +Ptr sDnDSource; + +Ctrl * Ctrl::GetDragAndDropSource() +{ + return sDnDSource; +} + +Image MakeDragImage(const Image& arrow, Image sample); + +Image MakeDragImage(const Image& arrow, const Image& arrow98, Image sample) +{ +#if PLATFORM_WIN32 + if(IsWin2K()) + return MakeDragImage(arrow, sample); + else +#endif + return arrow98; +} + +int Ctrl::DoDragAndDrop(const char *fmts, const Image& sample, dword actions, + const VectorMap& data) +{ + return DND_NONE; +} + +void Ctrl::SetSelectionSource(const char *fmts) {} + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/Draw.cpp b/rainbow/WinGl/Draw.cpp index 1693337eb..d3bf45390 100644 --- a/rainbow/WinGl/Draw.cpp +++ b/rainbow/WinGl/Draw.cpp @@ -7,6 +7,7 @@ NAMESPACE_UPP #define LLOG(x) // LOG(x) #define LTIMING(x) // RTIMING(x) +int64 Resources::currentSerialId = -1; ArrayMap Resources::textures; VectorMap Resources::fonts; @@ -99,9 +100,7 @@ OpenGLFont& Resources::GetFont(const char* fontName) OpenGLFont& Resources::StdFont(bool bold) { -// return GetFont(bold ? "tahoma14b.fnt" : "tahoma14.fnt"); -// return GetFont(bold ? "tahoma.fnt" : "tahoma.fnt"); - return GetFont(bold ? "arial.fnt" : "arial.fnt"); + return GetFont(bold ? "tahoma14b.fnt" : "tahoma14.fnt"); } dword SystemDraw::GetInfo() const @@ -208,8 +207,6 @@ void SystemDraw::FlatView() glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, drawing_size.cx, drawing_size.cy, 0, -100, 100); - //glFrustum(0, drawing_size.cx, drawing_size.cy, 0, -100, 100); - //gluPerspective(45, 1, -100, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); float dx = (float) drawing_size.cx / 2; @@ -228,7 +225,6 @@ void SystemDraw::PopContext() FlatView(); } - SystemDraw::~SystemDraw() { } diff --git a/rainbow/WinGl/DrawOp.cpp b/rainbow/WinGl/DrawOp.cpp new file mode 100644 index 000000000..b856e517b --- /dev/null +++ b/rainbow/WinGl/DrawOp.cpp @@ -0,0 +1,412 @@ +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +#pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking +#pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking + +#define LLOG(x) // LOG(x) +#define LTIMING(x) // RTIMING(x) + +void SystemDraw::PlaneEquation(double eq[4], float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) +{ + eq[0] = y1 * (z2 - z3) + + y2 * (z3 - z1) + + y3 * (z1 - z2); + + eq[1] = z1 * (x2 - x3) + + z2 * (x3 - x1) + + z3 * (x1 - x2); + + eq[2] = x1 * (y2 - y3) + + x2 * (y3 - y1) + + x3 * (y1 - y2); + + eq[3] = -(x1 * (y2 * z3 - y3 * z2) + + x2 * (y3 * z1 - y1 * z3) + + x3 * (y1 * z2 - y2 * z1)); +} + +void SystemDraw::SetClipRect(const Rect& r) +{ + clip = r; +#if CLIP_MODE != 2 + for(int i = 0; i < ci; i++) + clip &= cloff[i].drawing_clip; +#endif +} + +void SystemDraw::ScissorClip(const Rect& r) +{ + glScissor(r.left, drawing_size.cy - r.top - r.Height(), r.Width(), r.Height()); +} + +void SystemDraw::PlaneClip(const Rect& r) +{ + float cl = (float) r.left; + float ct = (float) r.top; + float cr = (float) r.right; + float cb = (float) r.bottom; + + double eq[4]; + + PlaneEquation(eq, cl, ct, 0, cl, cb, 0, cl, cb, +1.0f); + glClipPlane(GL_CLIP_PLANE0, eq); + + PlaneEquation(eq, cr, ct, 0, cr, cb, 0, cr, cb, -1.0f); + glClipPlane(GL_CLIP_PLANE1, eq); + + PlaneEquation(eq, cl, ct, 0, cr, ct, 0, cr, ct, -1.0f); + glClipPlane(GL_CLIP_PLANE2, eq); + + PlaneEquation(eq, cl, cb, 0, cr, cb, 0, cr, cb, +1.0f); + glClipPlane(GL_CLIP_PLANE3, eq); +} + +void SystemDraw::SetVec(float* v, float sx, float sy, float dx, float dy) +{ + v[0] = sx; v[1] = dy; + v[2] = sx; v[3] = sy; + v[4] = dx; v[5] = dy; + v[6] = dx; v[7] = sy; +} + +void SystemDraw::SetVec(float* v, int sx, int sy, int dx, int dy) +{ + v[0] = (float) sx; v[1] = (float) dy; + v[2] = (float) sx; v[3] = (float) sy; + v[4] = (float) dx; v[5] = (float) dy; + v[6] = (float) dx; v[7] = (float) sy; +} + +void SystemDraw::StencilClip(const Rect& r, int mode) +{ + float vtx[] = { + (float) r.left, (float) r.bottom, + (float) r.left, (float) r.top, + (float) r.right, (float) r.bottom, + (float) r.right, (float) r.top + }; + + //SetVec(vtx, r.left, r.top, r.right, r.bottom); + glVertexPointer(2, GL_FLOAT, 0, vtx); + + glColorMask(0, 0, 0, 0); + if(mode == 0) + { + ++cn; + glStencilOp(GL_KEEP, GL_INCR, GL_INCR); + glStencilFunc(GL_GEQUAL, cn, ~0); + } + else + { + --cn; + glStencilOp(GL_KEEP, GL_DECR, GL_DECR); + glStencilFunc(GL_ALWAYS, cn, ~0); + } + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glStencilFunc(GL_LEQUAL, cn, ~0); + glColorMask(1, 1, 1, 1); + + /* + if(mode == 0) + { + glColorMask(0, 0, 0, 0); + glStencilOp(GL_KEEP, GL_INCR_WRAP, GL_INCR_WRAP); + glStencilFunc(GL_EQUAL, cn, ~0); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glStencilFunc(GL_LEQUAL, ++cn, ~0); + glColorMask(1, 1, 1, 1); + //cn = cd; + } + else + { + glStencilFunc(GL_LEQUAL, --cn, ~0); + } + */ + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +} + +void SystemDraw::SetClip(const Rect& r, int mode) +{ + //glColor4ub(255, 0, 0, 10); + //glRecti(r.left, r.top, r.right, r.bottom); + SetClipRect(r); + +#if CLIP_MODE == 0 + ScissorClip(clip); +#elif CLIP_MODE == 1 + PlaneClip(clip); +#elif CLIP_MODE == 2 + StencilClip(clip, mode); +#endif +} + +void SystemDraw::BeginOp() +{ + Cloff& w = cloff[ci++]; + w.clipping = true; + w.org = drawing_offset; + w.drawing_clip = drawing_clip; +} + +void SystemDraw::EndOp() +{ + ASSERT(ci); +#if CLIP_MODE == 2 + if(cloff[ci - 1].clipping) + SetClip(drawing_clip, 1); +#endif + Cloff& w = cloff[--ci]; + drawing_offset = w.org; + drawing_clip = w.drawing_clip; +#if CLIP_MODE != 2 + if(cloff[ci].clipping) + SetClip(drawing_clip, 1); +#endif +} + +void SystemDraw::OffsetOp(Point p) +{ + BeginOp(); + cloff[ci - 1].clipping = false; + drawing_offset += p; +} + +bool SystemDraw::ClipOp(const Rect& r) +{ + BeginOp(); + drawing_clip = r + drawing_offset; + SetClip(drawing_clip); + return true; +} + +bool SystemDraw::ClipoffOp(const Rect& r) +{ + BeginOp(); + drawing_clip = r + drawing_offset; + drawing_offset += r.TopLeft(); + SetClip(drawing_clip); + return true; +} + +bool SystemDraw::ExcludeClipOp(const Rect& r) +{ + return true; +} + +bool SystemDraw::IntersectClipOp(const Rect& r) +{ + Cloff& w = cloff[ci]; + drawing_clip = r + drawing_offset; + SetClip(drawing_clip); + return true; +} + +bool SystemDraw::IsPaintingOp(const Rect& r) const +{ + return true; +} + +Rect SystemDraw::GetPaintRect() const +{ + return drawing_clip; +} + +void SystemDraw::DrawRectOp(int x, int y, int cx, int cy, Color color) +{ + if(IsNull(color)) + return; + + if(cx <= 0 || cy <= 0) return; + + float sx = (float) x + drawing_offset.x; + float sy = (float) y + drawing_offset.y; + float dx = sx + cx; + float dy = sy + cy; + +#if CLIP_MODE == 3 + float cl = (float) clip.left; + float ct = (float) clip.top; + float cr = (float) clip.right; + float cb = (float) clip.bottom; + + if(sx > cr || sy > cb) + return; + + if(dx < cl || dy < ct) + return; + + if(sx < cl) + sx = cl; + if(sy < ct) + sy = ct; + if(dx > cr) + dx = cr; + if(dy > cb) + dy = cb; +#endif + + glColor4ub(color.GetR(), color.GetG(), color.GetB(), (int) alpha); + + float vtx[] = { + sx, dy, + sx, sy, + dx, dy, + dx, sy + }; + + //SetVec(vtx, sx, sy, dx, dy); + + + glVertexPointer(2, GL_FLOAT, 0, vtx); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glColor4ub(255, 255, 255, (int) alpha); +} + +void SystemDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) +{ + if(cx <= 0 || cy <= 0) return; + + float sx = (float) x + drawing_offset.x; + float sy = (float) y + drawing_offset.y; + float dx = sx + cx; + float dy = sy + cy; + +#if CLIP_MODE == 3 + if(sx > clip.right || sy > clip.bottom) + return; + + if(dx < clip.left || dy < clip.top) + return; +#endif + + float tl = (float) src.left; + float tr = (float) src.right; + float tt = (float) src.top; + float tb = (float) src.bottom; + + float sw = (float) src.GetWidth(); + float sh = (float) src.GetHeight(); + +#if CLIP_MODE == 3 + float cl = (float) clip.left; + float ct = (float) clip.top; + float cr = (float) clip.right; + float cb = (float) clip.bottom; + + if(sx < cl) + { + float dl = cl - sx; + tl += dl * sw / (float) cx; + sx = cl; + } + + if(sy < ct) + { + float dt = ct - sy; + tt += dt * sh / (float) cy; + sy = ct; + } + + if(dx > cr) + { + float dr = dx - cr; + tr -= dr * sw / (float) cx; + dx = cr; + } + + if(dy > cb) + { + float db = dy - cb; + tb -= db * sh / (float) cy; + dy = cb; + } +#endif + + Resources::Bind(img); + + float tw = 1.f / (float) img.GetWidth(); + float th = 1.f / (float) img.GetHeight(); + + tl *= tw; + tr *= tw; + tt *= th; + tb *= th; + + if(IsNull(color)) + glColor4ub(255, 255, 255, (int) alpha); + else + glColor4ub(color.GetR(), color.GetG(), color.GetB(), (int) alpha); + //if(!IsNull(color)) + // glColor4ub(color.GetR(), color.GetG(), color.GetB(), (int) alpha); + + glEnable(GL_TEXTURE_2D); + + float vtx[] = { + sx, dy, + sx, sy, + dx, dy, + dx, sy + }; + + float crd[] = { + tl, tb, + tl, tt, + tr, tb, + tr, tt + }; + + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, crd); + glVertexPointer(2, GL_FLOAT, 0, vtx); + //SetVec(vtx, sx, sy, dx, dy); + //SetVec(crd, tl, tt, tr, tb); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + glDisable(GL_TEXTURE_2D); +} + +void SystemDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) +{ + glColor4ub(color.GetR(), color.GetG(), color.GetB(), (int) alpha); + glLineWidth((GLfloat) width); + glBegin(GL_LINES); + glVertex2i(x1 + drawing_offset.x, y1 + drawing_offset.y); + glVertex2i(x2 + drawing_offset.x, y2 + drawing_offset.y); + glEnd(); +} + +void SystemDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) +{ +} + +void SystemDraw::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) +{ +} + +void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) +{ +} + +void SystemDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) +{ +} + +void SystemDraw::SaveCurrentColor() +{ + glGetFloatv(GL_CURRENT_COLOR, current_color); +} + +void SystemDraw::RestoreLastColor() +{ + glColor4f(current_color[0], current_color[1], current_color[2], current_color[3]); +} + +END_UPP_NAMESPACE + +#endif \ No newline at end of file diff --git a/rainbow/WinGl/DrawText.cpp b/rainbow/WinGl/DrawText.cpp new file mode 100644 index 000000000..a15060695 --- /dev/null +++ b/rainbow/WinGl/DrawText.cpp @@ -0,0 +1,273 @@ +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +void OpenGLFont::Load(const String& fileName) +{ + String filePath = GetDataFile(fileName); + String xml = LoadFile(filePath); + XmlParser p(xml); + float scale = 1.0f / 1.f; + + while(!p.IsTag()) + p.Skip(); + + p.PassTag("font"); + + while(!p.End()) + { + if(p.TagE("common")) + { + scaleW = (float) p.Double("scaleW"); + scaleH = (float) p.Double("scaleH"); + lineHeight = (float) p.Double("lineHeight"); + base = (float) p.Double("base"); + } + else if(p.Tag("pages")) + { + while(!p.End()) + { + if(p.TagE("page")) + { + String fileName = p["file"]; + files.Add(fileName); + //Image img = StreamRaster::LoadFileAny(GetDataFile(fileName)); + //int serialId = Resources::Bind(img); + pages.Add(-1); + } + else + p.Skip(); + } + + } + else if(p.Tag("chars")) + { + while(!p.End()) + { + if(p.TagE("char")) + { + CharInfo& ci = chars.Add(); + + int page = p.Int("page"); + + ci.id = p.Int("id"); + ci.x = (float) p.Double("x"); + ci.y = (float) p.Double("y"); + ci.width = (float) p.Double("width"); + ci.height = (float) p.Double("height"); + ci.xoffset = (float) p.Double("xoffset"); + ci.yoffset = (float) p.Double("yoffset"); + ci.xadvance = (float) p.Double("xadvance"); + ci.page = page; + + ci.x *= scale; + ci.y *= scale; + ci.width *= scale; + ci.height *= scale; + ci.xoffset *= scale; + ci.yoffset *= scale; + ci.xadvance *= scale; + } + else + p.Skip(); + } + } + else if(p.Tag("kernings")) + { + while(!p.End()) + { + if(p.TagE("kerning")) + { + int first = p.Int("first"); + int second = p.Int("second"); + float amount = (float) p.Double("amount"); + + VectorMap& vm = kerns.GetAdd(first); + vm.Add(second, amount * scale); + } + else + p.Skip(); + } + } + else + p.Skip(); + } +} + +void OpenGLFont::UpdateTextures() +{ + if(texturesUpdated) + return; + + for(int i = 0; i < files.GetCount(); i++) + { + Image img = StreamRaster::LoadFileAny(GetDataFile(files[i])); + int64 serialId = Resources::Bind(img, true); + pages[i] = serialId; + } + + texturesUpdated = true; +} + +//extern int gpuProgram; + +void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) +{ + if(!text) + return; + + const wchar* s = text; + OpenGLFont& fi = Resources::StdFont(font.IsBold()); + + glColor4ub(ink.GetR(), ink.GetG(), ink.GetB(), (int) alpha); + glEnable(GL_TEXTURE_2D); + + #if CLIP_MODE == 3 + float cl = (float) clip.left; + float ct = (float) clip.top; + float cr = (float) clip.right; + float cb = (float) clip.bottom; + #endif + fi.UpdateTextures(); + + glEnableClientState(GL_TEXTURE_COORD_ARRAY); +// glUseProgram(gpuProgram); + + float xp = (float) x; + float yp = (float) y; + + while(*s && n > 0) + { + int ch = *s; + int cn = ch - 32; + + if(cn >= 0 && cn < fi.chars.GetCount()) + { + const OpenGLFont::CharInfo& ci = fi.chars[cn]; + + cn <<= 3; + + Resources::Bind(fi.pages[ci.page], true); + //int my_sampler_uniform_location = glGetUniformLocation(gpuProgram, "textMap"); + //glActiveTexture(GL_TEXTURE0); + //glUniform1i(my_sampler_uniform_location, 0); + + float sx = (float) ci.xoffset + xp + drawing_offset.x; + float sy = (float) ci.yoffset + yp + drawing_offset.y; + float dx = sx + ci.width; + float dy = sy + ci.height; + + #if CLIP_MODE == 3 + if(sx <= clip.right && sy <= clip.bottom && dx >= clip.left && dy >= clip.top) + #endif + { + float tl = (float) ci.x; + float tt = (float) ci.y; + float tr = (float) ci.x + ci.width; + float tb = (float) ci.y + ci.height; + + float sw = (float) fi.scaleW; + float sh = (float) fi.scaleH; + + #if CLIP_MODE == 3 + if(sx < cl) + { + tl += (cl - sx); + sx = cl; + } + + if(sy < ct) + { + tt += (ct - sy); + sy = ct; + } + + if(dx > cr) + { + tr -= dx - cr; + dx = cr; + } + + if(dy > cb) + { + tb -= dy - cb; + dy = cb; + } + #endif + + float tw = 1.f / sw; + float th = 1.f / sh; + + tl *= tw; + tt *= th; + tr *= tw; + tb *= th; + + float vtx[] = { + sx, dy, + sx, sy, + dx, dy, + dx, sy + }; + + float crd[] = { + tl, tb, + tl, tt, + tr, tb, + tr, tt + }; + //SetVec(vtx, sx, sy, dx, dy); + //SetVec(crd, tl, tt, tr, tb); + + glTexCoordPointer(2, GL_FLOAT, 0, crd); + glVertexPointer(2, GL_FLOAT, 0, vtx); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + + xp += ci.xadvance; + + int k = fi.kerns.Find(*s); + if(k >= 0) + xp += fi.kerns[k].Get(*(s + 1), 0); + } + + ++s; + --n; + } + + glUseProgram(0); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable(GL_TEXTURE_2D); + glColor4ub(255, 255, 255, (int) alpha); +} + +Size GetTextSize(const wchar *text, const OpenGLFont& fi, int n) +{ + if(n < 0) + n = wstrlen(text); + Sizef sz; + sz.cx = 0; + const wchar *wtext = (const wchar *)text; + while(n > 0) { + int ch = *wtext++; + int cn = ch - 32; + + if(cn >= 0 && cn < fi.chars.GetCount()) + { + const OpenGLFont::CharInfo& ci = fi.chars[cn]; + sz.cx += ci.xadvance; + int k = fi.kerns.Find(ch); + if(k >= 0) + sz.cx += fi.kerns[k].Get(*wtext, 0); + } + n--; + } + sz.cy = fi.lineHeight; + return sz; +} + +END_UPP_NAMESPACE + +#endif \ No newline at end of file diff --git a/rainbow/WinGl/Event.cpp b/rainbow/WinGl/Event.cpp index af6488608..5e9dde98a 100644 --- a/rainbow/WinGl/Event.cpp +++ b/rainbow/WinGl/Event.cpp @@ -6,15 +6,15 @@ NAMESPACE_UPP #define LLOG(x) LOG(x) -static Point fbmousepos; +static Point glmousepos; Point GetMousePos() { - return fbmousepos; + return glmousepos; } void Ctrl::DoMouseGl(int event, Point p, int zdelta) { - fbmousepos = p; + glmousepos = p; int a = event & Ctrl::ACTION; if(a == Ctrl::UP && Ctrl::ignoreclick) { EndIgnore(); @@ -51,19 +51,6 @@ Rect fbCaretRect; Image fbCaretBak; int fbCaretTm; -Image Ctrl::GetBak(Rect& tr) -{ - Image bak; - tr.Intersect(framebuffer.GetSize()); - if(!tr.IsEmpty()) { - Image h = framebuffer; - bak = CreateImage(tr.GetSize(), Black); - Copy(bak, Point(0, 0), h, tr); - framebuffer = h; - } - return bak; -} - void Ctrl::RemoveCursor() { } diff --git a/rainbow/WinGl/Image.cpp b/rainbow/WinGl/Image.cpp new file mode 100644 index 000000000..176cfa38b --- /dev/null +++ b/rainbow/WinGl/Image.cpp @@ -0,0 +1,125 @@ +#include + +#ifdef GUI_WINGL + +//#include + +NAMESPACE_UPP + +#define LTIMING(x) // RTIMING(x) + +void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels) +{ + GuiLock __; +} + +void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff) +{ + GuiLock __; +} + +struct Image::Data::SystemData { +}; + +void Image::Data::SysInitImp() +{ + SystemData& sd = Sys(); +} + +void Image::Data::SysReleaseImp() +{ + SystemData& sd = Sys(); +} + +Image::Data::SystemData& Image::Data::Sys() const +{ + ASSERT(sizeof(system_buffer) >= sizeof(SystemData)); + return *(SystemData *)system_buffer; +} + +int Image::Data::GetResCountImp() const +{ + SystemData& sd = Sys(); + return 0; +} + +void Image::Data::PaintImp(SystemDraw& w, int x, int y, const Rect& src, Color c) +{ + GuiLock __; + SystemData& sd = Sys(); +} + +Image ImageDraw::Get(bool pm) const +{ + ImageBuffer result(image.GetSize()); + const RGBA *e = image.End(); + const RGBA *p = ~image; + RGBA *t = ~result; + if(has_alpha) { + const RGBA *a = ~alpha; + while(p < e) { + *t = *p++; + (t++)->a = (a++)->r; + } + if(pm) + Premultiply(result); + result.SetKind(IMAGE_ALPHA); + } + else { + while(p < e) { + *t = *p++; + (t++)->a = 255; + } + } + return result; +} + +Draw& ImageDraw::Alpha() +{ + has_alpha = true; + return alpha_painter; +} + + +ImageDraw::ImageDraw(Size sz) +: ImageDraw__(sz.cx, sz.cy), + BufferPainter(image), + alpha_painter(alpha) +{ + has_alpha = false; +} + +ImageDraw::ImageDraw(int cx, int cy) +: ImageDraw__(cx, cy), + BufferPainter(image), + alpha_painter(alpha) +{ + has_alpha = false; +} + +#define IMAGECLASS FBImg +#define IMAGEFILE +#include +#define IMAGECLASS FBImg +#define IMAGEFILE +#include + +Image Image::Arrow() { return FBImg::arrow(); } +Image Image::Wait() { return FBImg::wait(); } +Image Image::IBeam() { return FBImg::ibeam(); } +Image Image::No() { return FBImg::no(); } +Image Image::SizeAll() { return FBImg::sizeall(); } +Image Image::SizeHorz() { return FBImg::sizehorz(); } +Image Image::SizeVert() { return FBImg::sizevert(); } +Image Image::SizeTopLeft() { return FBImg::sizetopleft(); } +Image Image::SizeTop() { return FBImg::sizetop(); } +Image Image::SizeTopRight() { return FBImg::sizetopright(); } +Image Image::SizeLeft() { return FBImg::sizeleft(); } +Image Image::SizeRight() { return FBImg::sizeright(); } +Image Image::SizeBottomLeft() { return FBImg::sizebottomleft(); } +Image Image::SizeBottom() { return FBImg::sizebottom(); } +Image Image::SizeBottomRight() { return FBImg::sizebottomright(); } + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/Proc.cpp b/rainbow/WinGl/Proc.cpp index 9e41e652a..d438b3893 100644 --- a/rainbow/WinGl/Proc.cpp +++ b/rainbow/WinGl/Proc.cpp @@ -63,40 +63,40 @@ LRESULT CALLBACK glWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa } return 0L; case WM_LBUTTONDOWN: - Ctrl::DoMouseFB(Ctrl::LEFTDOWN, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::LEFTDOWN, Point((dword)lParam)); return 0L; case WM_LBUTTONUP: - Ctrl::DoMouseFB(Ctrl::LEFTUP, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::LEFTUP, Point((dword)lParam)); return 0L; case WM_LBUTTONDBLCLK: - Ctrl::DoMouseFB(Ctrl::LEFTDOUBLE, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::LEFTDOUBLE, Point((dword)lParam)); return 0L; case WM_RBUTTONDOWN: - Ctrl::DoMouseFB(Ctrl::RIGHTDOWN, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::RIGHTDOWN, Point((dword)lParam)); return 0L; case WM_RBUTTONUP: - Ctrl::DoMouseFB(Ctrl::RIGHTUP, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::RIGHTUP, Point((dword)lParam)); return 0L; case WM_RBUTTONDBLCLK: - Ctrl::DoMouseFB(Ctrl::RIGHTDOUBLE, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::RIGHTDOUBLE, Point((dword)lParam)); return 0L; case WM_MBUTTONDOWN: - Ctrl::DoMouseFB(Ctrl::MIDDLEDOWN, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::MIDDLEDOWN, Point((dword)lParam)); return 0L; case WM_MBUTTONUP: - Ctrl::DoMouseFB(Ctrl::MIDDLEUP, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::MIDDLEUP, Point((dword)lParam)); return 0L; case WM_MBUTTONDBLCLK: - Ctrl::DoMouseFB(Ctrl::MIDDLEDOUBLE, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::MIDDLEDOUBLE, Point((dword)lParam)); return 0L; case WM_MOUSEMOVE: - Ctrl::DoMouseFB(Ctrl::MOUSEMOVE, Point((dword)lParam)); + Ctrl::DoMouseGl(Ctrl::MOUSEMOVE, Point((dword)lParam)); return 0L; case 0x20a: // WM_MOUSEWHEEL: { Point p(0, 0); ::ClientToScreen(hwnd, p); - Ctrl::DoMouseFB(Ctrl::MOUSEWHEEL, Point((dword)lParam) - p, (short)HIWORD(wParam)); + Ctrl::DoMouseGl(Ctrl::MOUSEWHEEL, Point((dword)lParam) - p, (short)HIWORD(wParam)); } return 0L; case WM_SETCURSOR: @@ -146,7 +146,7 @@ LRESULT CALLBACK glWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa keycode = (dword)wParam; bool b = false; if(keycode) - b = Ctrl::DoKeyFB(keycode, LOWORD(lParam)); + b = Ctrl::DoKeyGl(keycode, LOWORD(lParam)); // LOG("key processed = " << b); // if(b || (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP) // && wParam != VK_F4 && !PassWindowsKey((dword)wParam)) // 17.11.2003 Mirek -> invoke system menu @@ -164,7 +164,7 @@ LRESULT CALLBACK glWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case WM_HELP: return TRUE; case WM_CLOSE: - fbEndSession = true; + glEndSession = true; } return DefWindowProc(hwnd, message, wParam, lParam); } diff --git a/rainbow/WinGl/Top.cpp b/rainbow/WinGl/Top.cpp new file mode 100644 index 000000000..33d38f265 --- /dev/null +++ b/rainbow/WinGl/Top.cpp @@ -0,0 +1,82 @@ +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +#define LLOG(x) // LOG(x) + +void TopWindow::SyncSizeHints() {} + +void TopWindow::SyncTitle0() +{ + GuiLock __; +} + +void TopWindow::SyncCaption0() +{ + GuiLock __; +} + +void TopWindow::Open(Ctrl *owner) +{ + GuiLock __; +} + +void TopWindow::Open() +{ + painting = false; +} + +void TopWindow::OpenMain() +{ +} + +void TopWindow::Minimize(bool effect) +{ + state = MINIMIZED; +} + +TopWindow& TopWindow::FullScreen(bool b) +{ + return *this; +} + +void TopWindow::Maximize(bool effect) +{ + state = MAXIMIZED; +} + +void TopWindow::Overlap(bool effect) +{ + GuiLock __; + state = OVERLAPPED; +} + +TopWindow& TopWindow::TopMost(bool b, bool stay_top) +{ + GuiLock __; + return *this; +} + +bool TopWindow::IsTopMost() const +{ + return true; +} + +void TopWindow::GuiPlatformConstruct() +{ +} + +void TopWindow::GuiPlatformDestruct() +{ +} + +void TopWindow::SerializePlacement(Stream& s, bool reminimize) +{ + GuiLock __; +} + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/Top.h b/rainbow/WinGl/Top.h index bdd5b8bab..64ae70937 100644 --- a/rainbow/WinGl/Top.h +++ b/rainbow/WinGl/Top.h @@ -1,3 +1,3 @@ //$ class TopWindow { - +bool painting; //$ }; \ No newline at end of file diff --git a/rainbow/WinGl/Util.cpp b/rainbow/WinGl/Util.cpp new file mode 100644 index 000000000..afd19a1c8 --- /dev/null +++ b/rainbow/WinGl/Util.cpp @@ -0,0 +1,20 @@ +#include + +#ifdef GUI_WINGL + +NAMESPACE_UPP + +void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n, Color color, uint64 pattern) +{ +} + +/* +Size GetScreenSize() +{ + return ScreenInfo().GetPageSize(); +} +*/ + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/Win.cpp b/rainbow/WinGl/Win.cpp index 871a17689..3a0959f7c 100644 --- a/rainbow/WinGl/Win.cpp +++ b/rainbow/WinGl/Win.cpp @@ -8,7 +8,7 @@ HWND glHWND; HDC hDC; HGLRC hRC; -bool glEndSession; +bool glEndSession = false; bool GlEndSession() { @@ -59,7 +59,7 @@ void DestroyGL() ReleaseDC(glHWND, hDC); } -void GlInit(HINSTANCE hInstance) +int GlInit(HINSTANCE hInstance) { GuiLock __; @@ -67,21 +67,25 @@ void GlInit(HINSTANCE hInstance) WNDCLASSW wc; Zero(wc); - wc.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW|CS_OWNDC; + wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC)glWindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"UPP-FB-CLASS"; RegisterClassW(&wc); - glHWND = CreateWindowW(L"UPP-FB-CLASS", L"", WS_OVERLAPPED|WS_VISIBLE|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - NULL, NULL, hInstance, NULL); + glHWND = CreateWindowW( + L"UPP-FB-CLASS", L"", + WS_OVERLAPPED | WS_VISIBLE | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, hInstance, NULL); + + if(!glHWND) + return -1; - - HDC hDC = ::GetDC(glHWND); + hDC = ::GetDC(glHWND); if(!hDC) - return; + return -2; PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); @@ -94,15 +98,14 @@ void GlInit(HINSTANCE hInstance) pfd.iLayerType = PFD_MAIN_PLANE; int pf = ChoosePixelFormat(hDC, &pfd); if(!pf) { - RLOG("OpenGL: ChoosePixelFormat error"); DestroyGL(); - return; + return -3; } if(!SetPixelFormat(hDC, pf, &pfd)) { RLOG("OpenGL: SetPixelFormat error"); DestroyGL(); - return; + return -4; } DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); hRC = wglCreateContext(hDC); @@ -110,13 +113,13 @@ void GlInit(HINSTANCE hInstance) { RLOG("OpenGL: wglCreateContext error"); DestroyGL(); - return; + return -5; } if(!wglMakeCurrent(hDC, hRC)) { RLOG("OpenGL: wglMakeCurrent error"); DestroyGL(); - return; + return -6; } //ActivateGLContext(); GLenum err = glewInit(); @@ -124,15 +127,15 @@ void GlInit(HINSTANCE hInstance) { RLOG("OpenGL: Glew library initialization error: " + String((const char*) glewGetErrorString(err))); DestroyGL(); - return; + return -7; } //InitializeShaders(); //wglSwapIntervalEXT(0); //SetTimeCallback(-10, THISBACK(Repaint), 1); - //SetTimer(fbHWND, 1, 10, NULL); - + SetTimer(glHWND, 1, 10, NULL); + return 1; } END_UPP_NAMESPACE diff --git a/rainbow/WinGl/WinGl.h b/rainbow/WinGl/WinGl.h index ef34fdfee..5ec6a1075 100644 --- a/rainbow/WinGl/WinGl.h +++ b/rainbow/WinGl/WinGl.h @@ -8,12 +8,18 @@ #include #include +#include + #define GUI_WINGL NAMESPACE_UPP extern bool glEndSession; +extern HWND glHWND; +extern HDC hDC; +extern HGLRC hRC; +void ActivateGLContext(); LRESULT CALLBACK glWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); #define GUI_FB @@ -93,6 +99,7 @@ class SystemDraw : public Draw { public: virtual dword GetInfo() const; virtual Size GetPageSize() const; + bool CanSetSurface() { return false; } void PlaneEquation(double eq[4], float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3); void SetClipRect(const Rect& r); @@ -225,7 +232,8 @@ struct ImageDraw__ { ImageDraw__(int cx, int cy) : image(cx, cy), alpha(cx, cy) {} }; -class ImageDraw : private ImageDraw__ { +class ImageDraw : private ImageDraw__, public BufferPainter { + BufferPainter alpha_painter; bool has_alpha; Image Get(bool pm) const; diff --git a/rainbow/WinGl/WinGl.upp b/rainbow/WinGl/WinGl.upp index 7dfb94c7f..a5ad81363 100644 --- a/rainbow/WinGl/WinGl.upp +++ b/rainbow/WinGl/WinGl.upp @@ -1,14 +1,26 @@ +options + "-D_WIN32 -DGLEW_STATIC"; + file WinGl.h, Keys.h, Draw.cpp, + DrawOp.cpp, + DrawText.cpp, Win.cpp, + Wnd.cpp, Proc.cpp, After.h, Event.cpp, Top.h, + Top.cpp, Ctrl.h, Ctrl.cpp, + Clip.cpp, + Dnd.cpp, + Image.cpp, + ChSysInit.cpp, + Util.cpp, Glew readonly separator, glew.h, glxew.h, diff --git a/rainbow/WinGl/Wnd.cpp b/rainbow/WinGl/Wnd.cpp new file mode 100644 index 000000000..432e1901c --- /dev/null +++ b/rainbow/WinGl/Wnd.cpp @@ -0,0 +1,418 @@ +#include + +#ifdef GUI_FB + +NAMESPACE_UPP + +#define LLOG(x) + +Ptr Ctrl::desktop; +Vector Ctrl::topctrl; + +Point Ctrl::fbCursorPos = Null; +Image Ctrl::fbCursorImage; +Point Ctrl::fbCursorBakPos = Null; +Image Ctrl::fbCursorBak; +Rect Ctrl::fbCaretRect; +Image Ctrl::fbCaretBak; +int Ctrl::fbCaretTm; + +void Ctrl::SetDesktop(Ctrl& q) +{ + desktop = &q; +// desktop->SetRect(framebuffer.GetSize()); + desktop->SetOpen(true); + desktop->SetTop(); +} + +void Ctrl::InitGl() +{ + Ctrl::InitTimer(); +} + +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::GetTopCtrls() +{ + Vector ctrl; + if(desktop) + ctrl.Add(desktop); + for(int i = 0; i < topctrl.GetCount(); i++) + ctrl.Add(topctrl[i]); + return ctrl; +} + +Ctrl *Ctrl::GetOwner() +{ + GuiLock __; + return NULL; +} + +Ctrl *Ctrl::GetActiveCtrl() +{ + GuiLock __; + return desktop; +} + +// Vector Ctrl::hotkey; + +int Ctrl::RegisterSystemHotKey(dword key, Callback 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 GlIsWaitingEvent(); +} + +bool Ctrl::ProcessEvent(bool *quit) +{ + ASSERT(IsMainThread()); + if(DoCall()) + return false; + if(GlEndSession()) { + if(quit) *quit = true; + return false; + } + if(!GetMouseLeft() && !GetMouseRight() && !GetMouseMiddle()) + ReleaseCtrlCapture(); + if(GlProcessEvent(quit)) { + DefferedFocusSync(); + SyncCaret(); + return true; + } + return false; +} + +bool Ctrl::ProcessEvents(bool *quit) +{ + if(!ProcessEvent(quit)) + return false; + while(ProcessEvent(quit) && (!LoopCtrl || LoopCtrl->InLoop()) && !GlEndSession()); // LoopCtrl-MF 071008 + TimerProc(GetTickCount()); + SweepMkImageCache(); + if(desktop && !painting) { + painting = true; + RemoveCursor(); + RemoveCaret(); + + ActivateGLContext(); + //SyncLayout(1); + //InitInfoPanel(); + Rect rect; + Size csz = rect.GetSize(); + Rect clip(csz); + SystemDraw draw(hDC, csz); + //draw.alpha = alpha; + //draw.angle = angle; + draw.FlatView(); + draw.Clear(); + //ApplyTransform(TS_BEFORE_PAINT); + desktop->CtrlPaint(draw, clip);//, &infoPanel); + //AnimateCaret(); + //ApplyTransform(TS_AFTER_PAINT); + SwapBuffers(hDC); + painting = false; + } + CursorSync(); + return false; +} + +void Ctrl::EventLoop0(Ctrl *ctrl) +{ + GuiLock __; + ASSERT(IsMainThread()); + ASSERT(LoopLevel == 0 || ctrl); + LoopLevel++; + LLOG("Entering event loop at level " << LoopLevel << BeginIndent); + Ptr ploop; + if(ctrl) { + ploop = LoopCtrl; + LoopCtrl = ctrl; + ctrl->inloop = true; + } + + bool quit = false; + ProcessEvents(&quit); + while(!GlEndSession() && !quit && ctrl ? ctrl->IsOpen() && ctrl->InLoop() : GetTopCtrls().GetCount()) + { +// LLOG(GetSysTime() << " % " << (unsigned)msecs() % 10000 << ": EventLoop / GuiSleep"); + SyncCaret(); + GuiSleep(20); + if(GlEndSession()) break; +// LLOG(GetSysTime() << " % " << (unsigned)msecs() % 10000 << ": EventLoop / ProcessEvents"); + ProcessEvents(&quit); +// LLOG(GetSysTime() << " % " << (unsigned)msecs() % 10000 << ": EventLoop / after ProcessEvents"); + } + + if(ctrl) + LoopCtrl = ploop; + LoopLevel--; + LLOG(EndIndent << "Leaving event loop "); +} + +void Ctrl::GuiSleep0(int ms) +{ + GuiLock __; + ASSERT(IsMainThread()); + LLOG("GuiSleep"); + if(GlEndSession()) + return; + LLOG("GuiSleep 2"); + int level = LeaveGMutexAll(); + GlSleep(ms); + EnterGMutex(level); +} + +Rect Ctrl::GetWndUpdateRect() const +{ + GuiLock __; + Rect r; + return Rect(0, 0, 1000, 600); +} + +Rect Ctrl::GetWndScreenRect() const +{ + GuiLock __; + return GetRect(); +} + +void Ctrl::WndShow0(bool b) +{ + GuiLock __; +} + +void Ctrl::WndUpdate0() +{ + GuiLock __; +} + +bool Ctrl::IsWndOpen() const { + GuiLock __; + return FindTopCtrl() >= 0 || this == desktop; +} + +void Ctrl::SetAlpha(byte alpha) +{ + GuiLock __; +} + +Rect Ctrl::GetWorkArea() const +{ + GuiLock __; + return Rect(); +} + +void Ctrl::GetWorkArea(Array& rc) +{ + GuiLock __; +} + +Rect Ctrl::GetVirtualWorkArea() +{ + return Rect(); +} + +Rect Ctrl::GetWorkArea(Point pt) +{ + return Rect(); +} + +Rect Ctrl::GetVirtualScreenArea() +{ + GuiLock __; + return Rect(); +} + +Rect Ctrl::GetPrimaryWorkArea() +{ + Rect r; + return Rect(); +} + +Rect Ctrl::GetPrimaryScreenArea() +{ + return Rect(); +} + +int Ctrl::GetKbdDelay() +{ + GuiLock __; + return 500; +} + +int Ctrl::GetKbdSpeed() +{ + GuiLock __; + return 1000 / 32; +} + +void Ctrl::WndDestroy0() +{ + int q = FindTopCtrl(); + if(q >= 0) { + topctrl.Remove(q); + } + if(top) { + delete top; + top = NULL; + } + isopen = false; +} + +void Ctrl::SetWndForeground0() +{ + GuiLock __; + int q = FindTopCtrl(); + if(q >= 0) { + topctrl.Remove(q); + topctrl.Add(this); + } +} + +bool Ctrl::IsWndForeground() const +{ + GuiLock __; + return false; +} + +void Ctrl::WndEnable0(bool *b) +{ + GuiLock __; +} + +void Ctrl::SetWndFocus0(bool *b) +{ + GuiLock __; + *b = 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::WndInvalidateRect0(const Rect& r) +{ + GuiLock __; + ::InvalidateRect(glHWND, NULL, false); +} + +void Ctrl::WndSetPos0(const Rect& rect) +{ + GuiLock __; + SetWndRect(rect); +} + +void Ctrl::WndUpdate0r(const Rect& r) +{ + GuiLock __; +} + +void Ctrl::WndScrollView0(const Rect& r, int dx, int dy) +{ + GuiLock __; + Refresh(r); +} + +void Ctrl::PopUp(Ctrl *owner, bool savebits, bool activate, bool dropshadow, bool topmost) +{ + _DBG_ // Add owner management!!!! + ASSERT(!IsChild() && !IsOpen() && FindTopCtrl() < 0); + topctrl.Add(this); + popup = isopen = true; + SetTop(); + if(activate) SetFocus(); +} + +Rect Ctrl::GetDefaultWindowRect() { + return Rect(0, 0, 100, 100); +} + +Vector SplitCmdLine__(const char *cmd) +{ + Vector 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; +} + +END_UPP_NAMESPACE + +#endif diff --git a/rainbow/WinGl/tahoma14.fnt b/rainbow/WinGl/tahoma14.fnt new file mode 100644 index 000000000..69414a0e2 --- /dev/null +++ b/rainbow/WinGl/tahoma14.fnt @@ -0,0 +1,643 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rainbow/WinGl/tahoma14.png b/rainbow/WinGl/tahoma14.png new file mode 100644 index 000000000..11f6d8188 Binary files /dev/null and b/rainbow/WinGl/tahoma14.png differ diff --git a/rainbow/WinGl/tahoma14b.fnt b/rainbow/WinGl/tahoma14b.fnt new file mode 100644 index 000000000..2293afd05 --- /dev/null +++ b/rainbow/WinGl/tahoma14b.fnt @@ -0,0 +1,537 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rainbow/WinGl/tahoma14b.png b/rainbow/WinGl/tahoma14b.png new file mode 100644 index 000000000..e04d63593 Binary files /dev/null and b/rainbow/WinGl/tahoma14b.png differ