Rainbow: WinGL..

git-svn-id: svn://ultimatepp.org/upp/trunk@3635 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
unodgs 2011-07-10 21:11:03 +00:00
parent a1c08763d0
commit 712e69b6a5
21 changed files with 638 additions and 154 deletions

View file

@ -12,20 +12,21 @@ struct App : public Ctrl {
void Paint(Draw& w)
{
LOG("Paint");
Size sz = GetSize();
DDUMP(sz);
w.DrawRect(0, 0, sz.cx, sz.cy, SWhite);
w.DrawRect(0, 0, sz.cx, sz.cy, SRed);
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();
//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)
@ -63,16 +64,12 @@ struct App : public Ctrl {
GUI_APP_MAIN
{
#if EDITOR
RichEditWithToolBar app;
#else
App app;
#endif
ChStdSkin();
Ctrl::SetDesktop(app);
app.SetFocus();
#if !EDITOR
app.popup.PopUp();
#endif
/*TopWindow top;
top.Add(app.SizePos());
top.Open();*/
Ctrl::EventLoop();
}

View file

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

View file

@ -1,4 +1,4 @@
#include <CtrlCore/CtrlCore.h>
#include "TopFrame.h"
#ifdef GUI_WINGL
@ -52,6 +52,7 @@ bool GuiPlatformHasSizeGrip()
void GuiPlatformGripResize(TopWindow *q)
{
q->GripResize();
}
Color GuiPlatformGetScreenPixel(int x, int y)

View file

@ -1,6 +1,5 @@
//$ class Ctrl {
static Ptr<Ctrl> desktop;
static Rect screenRect;
static Vector<Ctrl *> topctrl;
static Point fbCursorPos;
@ -14,7 +13,16 @@
static int fbCaretTm;
int FindTopCtrl() const;
static void SyncTopWindows();
void NewTop() { top = new Top; top->owner_window = NULL; }
void PutForeground();
static void MouseEventGl(Ptr<Ctrl> t, int event, Point p, int zdelta);
friend class TopWindowFrame;
friend class SystemDraw;
public:
static Rect screenRect;
static void InitGl();
static void DoMouseGl(int event, Point p, int zdelta = 0);

View file

@ -1,4 +1,4 @@
#include <CtrlCore/CtrlCore.h>
#include "TopFrame.h"
#ifdef GUI_WINGL

View file

@ -1,5 +1,5 @@
#include <CtrlCore/CtrlCore.h>
#include <WinGl/Fonts.brc>
//#include <WinGl/Fonts.brc>
#ifdef GUI_WINGL
@ -115,10 +115,10 @@ OpenGLFont& Resources::GetFontBrc(const char* fontName, const byte* fontDef, con
OpenGLFont& Resources::StdFont(bool bold)
{
return GetFont(bold ? "tahoma14b.fnt" : "tahoma14.fnt");
return GetFontBrc(
/* return GetFontBrc(
bold ? "tahoma14b.fnt" : "tahoma14.fnt",
bold ? resTahoma14Fnt : resTahoma14BoldFnt,
bold ? resTahoma14Img : resTahoma14BoldImg);
bold ? resTahoma14Img : resTahoma14BoldImg);*/
}
dword SystemDraw::GetInfo() const

View file

@ -105,8 +105,6 @@ void OpenGLFont::Parse(const char* xml, bool parsePages)
p.Skip();
}
}
extern "C" byte* resTahoma14Img;
extern "C" int resTahoma14Img_length;
void OpenGLFont::UpdateTextures()
{
if(texturesUpdated)
@ -121,14 +119,11 @@ void OpenGLFont::UpdateTextures()
for(int i = 0; i < compiledFiles.GetCount(); i++)
{
DUMP(compiledFiles[i]);
//String imgData((const char*) compiledFiles[i]);
/* DUMP(compiledFiles[i]);
MemStream ms((void*) resTahoma14Img, resTahoma14Img_length);
//String imgData((const char*) resTahoma14Img);
//Image img = StreamRaster::LoadStringAny(imgData);
Image img = StreamRaster::LoadAny(ms);
int64 serialId = Resources::Bind(img, true);
pages[i] = serialId;
pages[i] = serialId;*/
}
texturesUpdated = true;

View file

@ -1,4 +1,5 @@
#include <CtrlCore/CtrlCore.h>
//#include <CtrlCore/CtrlCore.h>
#include "TopFrame.h"
#ifdef GUI_WINGL
@ -12,6 +13,19 @@ Point GetMousePos() {
return glmousepos;
}
void Ctrl::MouseEventGl(Ptr<Ctrl> t, int event, Point p, int zdelta)
{
Rect rr = t->GetRect();
if((event & Ctrl::ACTION) == DOWN && !dynamic_cast<TopWindowFrame *>(~t)) {
t->SetFocusWnd();
if(t) t->SetForeground();
}
if(t)
t->DispatchMouse(event, p - rr.TopLeft(), zdelta);
if(t)
t->PostInput();
}
void Ctrl::DoMouseGl(int event, Point p, int zdelta)
{
glmousepos = p;
@ -23,7 +37,18 @@ void Ctrl::DoMouseGl(int event, Point p, int zdelta)
else
if(a == Ctrl::DOWN && ignoreclick)
return;
LLOG("Mouse event: " << event << " position " << p << " zdelta " << zdelta);
LLOG("Mouse event: " << event << " position " << p << " zdelta " << zdelta << ", capture " << Upp::Name(captureCtrl));
if(captureCtrl)
MouseEventGl(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)) {
MouseEventGl(t, event, p, zdelta);
return;
}
}
Ctrl *desktop = GetDesktop();
if(desktop) {
desktop->DispatchMouse(event, p, zdelta);

View file

@ -346,9 +346,6 @@ Image Image::Cross() WCURSOR_(IDC_CROSS)
Image Image::Hand() WCURSOR_(IDC_HAND)*/
#define IMAGECLASS WinGlImg
#define IMAGEFILE <WinGl/WinGl.iml>
#include <Draw/iml_header.h>
#define IMAGECLASS WinGlImg
#define IMAGEFILE <WinGl/WinGl.iml>
#include <Draw/iml_source.h>

View file

@ -1,3 +1,5 @@
#ifndef _WinGl_Keys_h_
#define _WinGl_Keys_h_
K_BACK = VK_BACK + K_DELTA,
K_BACKSPACE = VK_BACK + K_DELTA,
@ -107,3 +109,5 @@ K_CTRL_EQUAL = K_CTRL|0xbb|K_DELTA,
K_CTRL_APOSTROPHE= K_CTRL|0xde|K_DELTA,
K_BREAK = VK_CANCEL + K_DELTA,
#endif

View file

@ -54,6 +54,10 @@ LRESULT CALLBACK glWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
#endif
// LLOG("Ctrl::WindowProc(" << message << ") in " << ::Name(this) << ", focus " << (void *)::GetFocus());
switch(message) {
case WM_DESTROY:
DestroyGl();
::PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
Ctrl::DoMouseGl(Ctrl::LEFTDOWN, Point((dword)lParam));
return 0L;
@ -154,8 +158,6 @@ LRESULT CALLBACK glWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
//ActivateGlContext();
Ctrl::SetWindowSize(Size(LOWORD(lParam), HIWORD(lParam)));
return 0L;
case WM_MOVE:
return 0L;
case WM_HELP:
return TRUE;
case WM_CLOSE:
@ -166,4 +168,4 @@ LRESULT CALLBACK glWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
END_UPP_NAMESPACE
#endif
#endif

View file

@ -1,4 +1,4 @@
#include <CtrlCore/CtrlCore.h>
#include "TopFrame.h"
#ifdef GUI_WINGL
@ -6,35 +6,92 @@ NAMESPACE_UPP
#define LLOG(x) // LOG(x)
void TopWindow::SyncSizeHints() {}
void TopWindow::SyncFrameRect(const Rect& r)
{
frame->SetClient(r);
}
void TopWindow::DestroyFrame()
{
if(frame->IsOpen())
frame->Close();
}
void TopWindow::GripResize()
{
frame->GripResize();
}
void TopWindow::SyncSizeHints()
{
SyncCaption0();
}
void TopWindow::SyncTitle0()
{
GuiLock __;
SyncCaption0();
}
void TopWindow::SyncCaption0()
{
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 <<= Proxy(WhenClose);
frame->icon = icon;
}
void TopWindow::SyncRect()
{
frame->SyncRect();
Rect r = frame->GetClient();
if(r != GetRect()) {
SetRect(r);
}
}
void TopWindow::Open(Ctrl *owner)
{
GuiLock __;
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->PopUp(owner, false, true);
PopUp(frame, false, true);
popup = false;
SetRect(frame->GetClient());
SyncCaption0();
if(state == MAXIMIZED)
frame->Maximize();
}
void TopWindow::Open()
{
Open(GetActiveCtrl());
painting = false;
}
void TopWindow::OpenMain()
{
Open(NULL);
}
void TopWindow::Minimize(bool effect)
{
state = MINIMIZED;
// state = MINIMIZED;
}
TopWindow& TopWindow::FullScreen(bool b)
@ -45,12 +102,14 @@ TopWindow& TopWindow::FullScreen(bool b)
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)
@ -66,10 +125,12 @@ bool TopWindow::IsTopMost() const
void TopWindow::GuiPlatformConstruct()
{
frame = new TopWindowFrame;
}
void TopWindow::GuiPlatformDestruct()
{
delete frame;
}
void TopWindow::SerializePlacement(Stream& s, bool reminimize)

View file

@ -1,3 +1,14 @@
//$ class TopWindow {
bool painting;
private:
TopWindowFrame *frame;
void SyncRect();
void SyncFrameRect(const Rect& r);
void DestroyFrame();
friend class Ctrl;
bool painting;
public:
void GripResize();
//$ };

200
rainbow/WinGl/TopFrame.cpp Normal file
View file

@ -0,0 +1,200 @@
#include "TopFrame.h"
#ifdef GUI_WINGL
NAMESPACE_UPP
#define LLOG(x) // LOG(x)
TopWindowFrame::TopWindowFrame()
{
close.SetImage(WinGlImg::close());
close.EdgeStyle();
Add(close);
maximize.SetImage(WinGlImg::maximize());
maximize.EdgeStyle();
Add(maximize);
maximize <<= THISBACK(ToggleMaximize);
maximized = false;
sizeable = false;
}
void TopWindowFrame::SyncRect()
{
if(maximized) {
Size sz = screenRect.GetSize();
if(GetRect().GetSize() != sz)
SetRect(sz);
}
}
void TopWindowFrame::Maximize()
{
if(!maximized && maximize.IsShown()) {
maximized = true;
overlapped = GetRect();
SetRect(screenRect);
maximize.SetImage(WinGlImg::overlap());
}
}
void TopWindowFrame::Overlap()
{
if(maximized && maximize.IsShown()) {
maximized = false;
SetRect(overlapped);
maximize.SetImage(WinGlImg::maximize());
}
}
void TopWindowFrame::ToggleMaximize()
{
if(maximized)
Overlap();
else
Maximize();
}
Rect TopWindowFrame::Margins() const
{
return maximized ? Rect(0, 0, 0, 0) : ChMargins(WinGlImg::border());
}
void TopWindowFrame::Paint(Draw& w)
{
Size sz = GetSize();
Rect m = Margins();
int c = GetStdFontCy() + 4;
ChPaintEdge(w, sz, WinGlImg::border());
ChPaint(w, m.left, m.top, sz.cx - m.left - m.right, GetStdFontCy() + 4, WinGlImg::title());
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(WinGlImg::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();
DLOG("START DRAG ---------------");
}
void TopWindowFrame::GripResize()
{
dir = Point(1, 1);
StartDrag();
}
void TopWindowFrame::LeftDown(Point p, dword keyflags)
{
dir = GetDragMode(p);
StartDrag();
}
void TopWindowFrame::LeftDouble(Point p, dword keyflags)
{
ToggleMaximize();
IgnoreMouseUp();
}
void TopWindowFrame::MouseMove(Point, dword)
{
//DDUMP(HasWndCapture());
DDUMP(HasCapture());
if(!HasCapture())
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::CursorImage(Point p, dword)
{
if(!sizeable)
return Image::Arrow();
p = HasCapture() ? dir : GetDragMode(p);
static Image (*im[9])() = {
Image::SizeTopLeft, Image::SizeLeft, Image::SizeBottomLeft,
Image::SizeTop, Image::Arrow, Image::SizeBottom,
Image::SizeTopRight, Image::SizeRight, Image::SizeBottomRight,
};
return (*im[(p.x + 1) * 3 + (p.y + 1)])();
}
END_UPP_NAMESPACE
#endif

55
rainbow/WinGl/TopFrame.h Normal file
View file

@ -0,0 +1,55 @@
#ifndef _WinGl_TopFrame_h_
#define _WinGl_TopFrame_h_
#include <CtrlLib/CtrlLib.h>
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 LeftDouble(Point p, dword keyflags);
virtual void MouseMove(Point p, dword keyflags);
private:
Point dir;
Point startpos;
Rect startrect;
bool maximized;
Rect overlapped;
Point GetDragMode(Point p);
void StartDrag();
Rect Margins() const;
Rect ComputeClient(Rect r);
typedef TopWindowFrame CLASSNAME;
public:
String title;
Button close, maximize;
Image icon;
Size minsize;
bool sizeable;
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();
};
END_UPP_NAMESPACE
#endif

View file

@ -6,10 +6,10 @@ extern void GuiMainFn_();
NAMESPACE_UPP
HWND hWnd;
HWND glHwnd;
HDC hDC;
HGLRC hRC;
HWND hWnd = NULL;
HWND glHwnd = NULL;
HDC hDC = NULL;
HGLRC hRC = NULL;
bool glEndSession = false;
@ -50,23 +50,23 @@ void ActivateGlContext()
void DestroyGl(bool destroyWindow)
{
wglMakeCurrent(NULL, NULL);
if(hDC != NULL && hRC != NULL)
wglMakeCurrent(NULL, NULL);
if(hRC)
wglDeleteContext(hRC);
if(hRC)
{
wglDeleteContext(hRC);
hRC = NULL;
}
if(hDC)
::ReleaseDC(glHwnd, hDC);
if(destroyWindow)
::DestroyWindow(glHwnd);
{
::ReleaseDC(glHwnd, hDC);
hDC = NULL;
}
}
int GlInit(HINSTANCE hInstance)
int CreateGlWindow(HINSTANCE hInstance)
{
GuiLock __;
Ctrl::InitGl();
WNDCLASSW wc;
Zero(wc);
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
@ -85,15 +85,27 @@ int GlInit(HINSTANCE hInstance)
if(!glHwnd)
return -1;
return 1;
}
int CreateGlContext()
{
hDC = ::GetDC(glHwnd);
if(!hDC)
return -2;
return -1;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_SUPPORT_COMPOSITION | PFD_GENERIC_ACCELERATED;
pfd.dwFlags =
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER |
PFD_SUPPORT_OPENGL |
PFD_SUPPORT_COMPOSITION |
//0x00008000 |
PFD_GENERIC_ACCELERATED;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
@ -102,42 +114,40 @@ int GlInit(HINSTANCE hInstance)
int pf = ChoosePixelFormat(hDC, &pfd);
if(!pf) {
RLOG("OpenGL: ChoosePixelFormat error");
DestroyGl();
return -3;
return -2;
}
RLOG("OpenGL: ChoosePixelFormat ok..");
if(!SetPixelFormat(hDC, pf, &pfd)) {
RLOG("OpenGL: SetPixelFormat error");
DestroyGl();
return -4;
return -3;
}
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
hRC = wglCreateContext(hDC);
if(!hRC)
{
RLOG("OpenGL: wglCreateContext error");
DestroyGl();
return -5;
return -4;
}
RLOG("OpenGL: wglCreateContext ok..");
if(!wglMakeCurrent(hDC, hRC))
{
RLOG("OpenGL: wglMakeCurrent error");
DestroyGl();
return -6;
return -5;
}
//ActivateGLContext();
RLOG("OpenGL: wglMakeCurrent ok..");
GLenum err = glewInit();
if(err != GLEW_OK)
{
RLOG("OpenGL: Glew library initialization error: " + String((const char*) glewGetErrorString(err)));
DestroyGl();
return -7;
return -6;
}
RLOG("OpenGL: glewInit ok..");
//InitializeShaders();
wglSwapIntervalEXT(0);
//SetTimeCallback(-10, THISBACK(Repaint), 1);
SetTimer(glHwnd, 1, 10, NULL);
RLOG("OpenGL: SetTimer ok..");
return 1;
}
@ -148,7 +158,17 @@ int AppMain(HINSTANCE hInstance, LPSTR lpCmdLine)
{
UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine));
UPP::AppInitEnvironment__();
int r = UPP::GlInit(hInstance);
// Ctrl::InitTimer();
Ctrl::InitGl();
//int r = UPP::GlInit(hInstance);
int r = UPP::CreateGlWindow(hInstance);
if(r < 0)
::MessageBox(NULL, Format("OpenGL window could not be created: %r (%s)", r, GetLastErrorMessage()), NULL, MB_ICONEXCLAMATION | MB_OK);
else
r = UPP::CreateGlContext();
if(r < 0)
::MessageBox(NULL, Format("OpenGL context could not be created: %r (%s)", r, GetLastErrorMessage()), NULL, MB_ICONEXCLAMATION | MB_OK);
if(r > 0)
{
GuiMainFn_();
@ -158,7 +178,6 @@ int AppMain(HINSTANCE hInstance, LPSTR lpCmdLine)
UPP::DestroyGl(false);
return UPP::GetExitCode();
} else {
::MessageBox(NULL, Format("OpenGL window could not be initialized: %d", r), NULL, MB_ICONEXCLAMATION | MB_OK);
return r;
}
}

View file

@ -1,25 +1,34 @@
#ifndef _WinGl_WinGl_h_
#define _WinGl_WinGl_h_
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif
#include <WinGl/glew.h>
#include <WinGl/wglew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <Painter/Painter.h>
#define GUI_WINGL
#include <Painter/Painter.h>
NAMESPACE_UPP
#define IMAGECLASS WinGlImg
#define IMAGEFILE <WinGl/WinGl.iml>
#include <Draw/iml_header.h>
extern bool glEndSession;
extern HWND hWnd;
extern HWND glHwnd;
extern HDC hDC;
extern HGLRC hRC;
int CreateGlWindow(HINSTANCE hInstance);
int CreateGlContext();
void ActivateGlContext();
void DestroyGl(bool destroyWindow = true);
LRESULT CALLBACK glWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
@ -286,20 +295,21 @@ public:
~PrinterJob() {}
};
END_UPP_NAMESPACE
class TopWindowFrame;
#define GUIPLATFORM_KEYCODES_INCLUDE <WinGl/Keys.h>
#define GUIPLATFORM_CTRL_TOP_DECLS
#define GUIPLATFORM_CTRL_TOP_DECLS Ctrl *owner_window;
#define GUIPLATFORM_CTRL_DECLS_INCLUDE <WinGl/Ctrl.h>
#define GUIPLATFORM_PASTECLIP_DECLS
#define GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE <WinGl/Top.h>
//#include <CtrlCore/stdids.h>
#ifndef PLATFORM_WIN32
/*#ifndef PLATFORM_WIN32
#include "vkcodes.h" //FIXME
#endif
#endif*/
END_UPP_NAMESPACE
#define GUIPLATFORM_INCLUDE_AFTER <WinGl/After.h>
#endif

View file

@ -14,27 +14,41 @@ IMAGE_ID(sizetopright)
IMAGE_ID(sizebottomleft)
IMAGE_ID(sizebottom)
IMAGE_ID(sizebottomright)
IMAGE_ID(overlap)
IMAGE_ID(maximize)
IMAGE_ID(close)
IMAGE_ID(title)
IMAGE_ID(border)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,87,189,75,28,65,20,31,3,167,1,5,9,146,46,69,26,255,9,155,180,41,83,216,165,180,176,178,75,10)
IMAGE_DATA(73,76,44,36,4,66,56,3,26,36,104,188,228,34,104,66,82,108,35,162,226,89,248,129,224,7,126,128,136,34,136,32)
IMAGE_DATA(34,130,86,218,253,50,220,158,27,179,59,243,246,189,89,93,21,246,55,12,236,205,253,126,111,222,199,188,185,91,85,167)
IMAGE_DATA(30,170,6,61,170,85,149,210,128,146,1,66,13,0,145,6,231,231,143,113,118,214,200,213,224,244,180,9,39,39,79,112)
IMAGE_DATA(124,252,148,163,193,209,209,51,28,30,54,227,224,224,57,246,246,90,226,52,216,223,111,209,188,86,236,238,182,97,103,231)
IMAGE_DATA(5,54,55,95,81,26,108,111,191,196,214,86,187,230,189,197,250,250,59,172,174,126,196,242,114,183,77,131,141,141,46,172)
IMAGE_DATA(173,189,199,202,74,30,75,75,125,88,88,40,98,126,254,7,230,230,6,77,26,205,233,198,226,98,143,230,245,99,118,118)
IMAGE_DATA(4,165,82,169,50,127,99,106,170,24,214,104,91,125,154,215,143,153,153,34,166,167,255,4,124,245,175,150,151,53,154,51)
IMAGE_DATA(160,103,1,147,147,67,152,152,248,133,177,49,143,140,119,124,124,16,163,163,223,2,59,158,55,66,242,61,239,107,196,199)
IMAGE_DATA(225,225,239,214,252,152,114,80,40,124,161,248,198,125,123,123,63,137,206,97,62,255,65,124,214,59,59,223,136,246,232,232)
IMAGE_DATA(120,45,222,67,192,141,34,167,234,213,61,85,83,158,42,84,120,85,110,86,31,161,231,96,243,208,231,59,191,102,137,55)
IMAGE_DATA(146,23,85,167,19,151,211,73,203,253,159,56,238,44,107,30,253,252,76,206,75,220,52,248,164,198,192,181,106,8,110,68)
IMAGE_DATA(195,224,6,26,9,215,197,23,151,88,93,114,121,3,245,149,157,207,7,122,220,175,12,42,113,134,201,5,183,73,56,250)
IMAGE_DATA(36,223,75,252,76,170,143,20,144,97,195,124,251,184,235,109,126,73,245,92,27,146,239,227,246,224,248,72,197,73,33,46)
IMAGE_DATA(199,18,189,201,39,201,89,49,173,185,234,185,118,92,250,206,165,111,227,108,153,81,175,71,77,101,48,140,186,192,37,128)
IMAGE_DATA(176,206,69,127,97,195,21,92,173,173,185,226,214,168,198,52,173,153,26,71,58,147,236,27,199,227,172,153,144,70,141,194)
IMAGE_DATA(154,36,231,42,201,121,188,208,219,225,255,249,245,223,28,216,34,59,79,226,104,26,135,44,110,95,91,28,148,214,71,150)
IMAGE_DATA(56,99,28,148,214,71,150,56,99,28,148,214,71,232,21,223,102,200,230,168,233,30,73,114,183,166,189,22,87,8,123,130)
IMAGE_DATA(107,245,200,85,134,197,136,13,146,203,87,202,53,61,115,112,155,249,215,145,39,105,157,144,117,202,21,117,10,5,73,23)
IMAGE_DATA(81,155,39,225,114,79,158,235,111,139,11,79,210,13,105,228,143,230,103,5,79,204,187,91,5,207,174,198,171,185,26,37)
IMAGE_DATA(221,112,157,85,55,61,115,112,155,249,55,121,187,4,243,47,233,127,209,222,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(672, 15)
IMAGE_DATA(120,156,237,90,205,75,21,81,20,191,101,79,13,148,144,104,231,162,77,155,254,132,8,218,182,108,81,171,150,46,90,181)
IMAGE_DATA(171,69,148,249,22,17,65,132,6,25,18,150,150,5,106,212,226,109,68,84,212,133,31,8,126,224,7,136,40,130,8,34)
IMAGE_DATA(34,232,74,119,167,251,158,239,227,122,230,206,185,231,220,153,121,21,204,25,14,207,153,251,251,157,123,206,239,156,153,121)
IMAGE_DATA(162,170,65,93,83,121,171,85,23,242,31,160,100,6,66,14,0,136,56,112,122,122,29,78,78,110,112,57,112,124,124,11)
IMAGE_DATA(142,142,238,192,225,225,93,14,7,14,14,238,193,254,254,125,216,219,123,8,59,59,45,46,14,236,238,182,104,220,35,216)
IMAGE_DATA(222,126,12,91,91,79,96,125,253,57,197,129,205,205,167,176,177,241,76,227,218,96,117,245,53,44,47,191,131,197,197,142)
IMAGE_DATA(48,14,172,173,189,130,149,149,55,176,180,212,14,11,11,93,48,55,215,7,179,179,223,97,102,166,199,198,209,152,14,152)
IMAGE_DATA(159,255,160,113,221,48,61,61,0,19,19,19,69,255,5,227,227,125,152,163,99,117,105,92,55,76,77,245,193,228,228,239)
IMAGE_DATA(50,94,85,122,105,114,52,230,179,246,94,24,27,251,1,163,163,63,97,120,56,71,214,59,50,210,3,67,67,95,203,113)
IMAGE_DATA(114,185,1,18,159,203,125,9,228,216,223,255,45,84,31,155,6,189,189,159,40,188,117,223,206,206,247,162,57,108,111,127)
IMAGE_DATA(43,158,245,108,246,165,104,143,214,214,23,226,61,4,216,160,101,212,21,117,81,213,21,92,161,198,171,194,205,122,102,232)
IMAGE_DATA(231,242,230,232,252,191,191,22,82,111,64,23,213,160,133,203,104,209,50,231,133,227,122,129,211,60,248,145,116,3,91,13)
IMAGE_DATA(60,201,177,96,67,57,4,54,192,97,96,203,28,9,214,39,23,159,90,125,180,252,11,253,149,205,103,147,62,234,139,7)
IMAGE_DATA(37,156,197,185,198,189,73,56,252,40,235,146,60,163,242,3,13,100,196,176,63,125,252,249,97,121,73,249,220,24,146,117)
IMAGE_DATA(215,30,156,28,169,58,41,115,105,44,225,219,114,146,204,138,237,154,47,159,27,199,231,190,243,185,111,93,177,236,198,124)
IMAGE_DATA(32,157,69,13,190,222,69,102,190,254,163,240,75,46,141,131,249,62,113,192,48,116,234,140,129,113,54,61,168,88,97,120)
IMAGE_DATA(206,53,243,58,206,219,86,11,198,98,190,143,219,226,248,228,17,151,30,113,245,197,22,203,86,139,139,139,247,199,46,137)
IMAGE_DATA(97,139,35,229,227,56,190,124,20,135,182,38,253,181,191,94,213,20,28,147,93,1,40,12,183,136,48,28,53,180,54,83)
IMAGE_DATA(170,250,55,15,39,143,184,244,48,215,189,250,146,54,58,109,180,95,64,102,194,46,92,84,129,205,107,62,110,139,227,147)
IMAGE_DATA(71,92,122,152,235,94,125,169,211,173,174,41,182,218,178,33,59,17,44,172,75,112,155,64,232,220,89,248,191,190,70,213)
IMAGE_DATA(71,233,66,233,201,201,197,88,175,88,163,62,106,139,71,32,19,36,58,17,144,76,202,197,113,225,163,114,176,216,46,14)
IMAGE_DATA(110,22,119,191,176,189,163,242,36,125,144,212,106,242,84,130,189,240,157,17,235,44,166,79,166,228,214,168,250,40,93,40)
IMAGE_DATA(61,57,185,24,235,21,51,159,76,148,5,178,68,13,33,54,171,234,83,136,203,193,226,187,56,84,35,185,120,188,142,99)
IMAGE_DATA(73,114,224,224,77,142,170,178,254,220,220,164,51,149,14,108,58,176,137,112,184,185,137,7,54,125,149,38,183,70,213,71)
IMAGE_DATA(233,66,233,201,201,197,88,175,88,250,37,63,200,193,205,226,238,23,182,119,84,158,164,15,146,90,77,158,74,176,23,190)
IMAGE_DATA(51,98,157,197,6,125,196,100,214,59,205,112,27,158,138,229,139,231,228,129,241,174,61,227,194,115,244,73,74,23,243,154)
IMAGE_DATA(164,79,124,139,97,152,92,201,73,196,178,97,82,124,252,120,73,191,248,22,199,147,233,118,99,99,232,230,120,45,127,94)
IMAGE_DATA(114,27,214,182,102,187,78,197,193,235,46,108,24,135,194,74,241,146,124,36,245,250,234,73,229,73,213,65,218,37,125,228)
IMAGE_DATA(173,166,240,231,148,44,92,190,57,8,87,31,172,65,115,91,254,189,41,60,207,79,102,70,31,197,95,63,185,183,192,185)
IMAGE_DATA(151,181,203,204,127,129,46,157,83,158,205,102,83,124,66,248,210,185,203,125,102,225,15,96,50,114,65,0,0,0,0,0)
IMAGE_END_DATA(960, 20)

View file

@ -17,6 +17,8 @@ file
Event.cpp,
Top.h,
Top.cpp,
TopFrame.h,
TopFrame.cpp,
Ctrl.h,
Ctrl.cpp,
Clip.cpp,
@ -30,6 +32,5 @@ file
wglew.h,
glew.c,
Resources readonly separator,
WinGl.iml,
Fonts.brc;
WinGl.iml;

View file

@ -1,4 +1,4 @@
#include <CtrlCore/CtrlCore.h>
#include "TopFrame.h"
#ifdef GUI_FB
@ -23,14 +23,18 @@ void Ctrl::SetDesktop(Ctrl& q)
desktop = &q;
desktop->SetRect(screenRect);
desktop->SetOpen(true);
desktop->SetTop();
desktop->NewTop();
}
void Ctrl::SetWindowSize(Size sz)
{
screenRect = sz;
DUMP(screenRect);
if(desktop)
{
LOG("SetWindowSize");
desktop->SetRect(screenRect);
}
}
void Ctrl::InitGl()
@ -62,13 +66,19 @@ Vector<Ctrl *> Ctrl::GetTopCtrls()
if(desktop)
ctrl.Add(desktop);
for(int i = 0; i < topctrl.GetCount(); i++)
ctrl.Add(topctrl[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;
return dynamic_cast<TopWindowFrame *>(x) ? x->GetOwner() : x;
}
return NULL;
}
@ -115,11 +125,22 @@ bool Ctrl::IsWaitingEvent()
return GlIsWaitingEvent();
}
void Ctrl::SyncTopWindows()
{
for(int i = 0; i < topctrl.GetCount(); i++) {
TopWindow *w = dynamic_cast<TopWindow *>(topctrl[i]);
if(w)
w->SyncRect();
}
}
bool Ctrl::ProcessEvent(bool *quit)
{
ASSERT(IsMainThread());
if(DoCall())
if(DoCall()) {
SyncTopWindows();
return false;
}
if(GlEndSession()) {
if(quit) *quit = true;
return false;
@ -127,6 +148,7 @@ bool Ctrl::ProcessEvent(bool *quit)
if(!GetMouseLeft() && !GetMouseRight() && !GetMouseMiddle())
ReleaseCtrlCapture();
if(GlProcessEvent(quit)) {
SyncTopWindows();
DefferedFocusSync();
SyncCaret();
return true;
@ -138,14 +160,15 @@ void Ctrl::DrawScreen()
{
if(desktop && !painting) {
painting = true;
RemoveCursor();
RemoveCaret();
//RemoveCursor();
//RemoveCaret();
ActivateGlContext();
//ActivateGlContext();
//SyncLayout(1);
//InitInfoPanel();
Rect rect;
Size csz = desktop->GetSize();
DUMP(csz);
Rect clip(csz);
SystemDraw draw(hDC, csz);
//draw.alpha = alpha;
@ -154,6 +177,12 @@ void Ctrl::DrawScreen()
draw.Clear();
//ApplyTransform(TS_BEFORE_PAINT);
desktop->CtrlPaint(draw, clip);//, &infoPanel);
for(int i = topctrl.GetCount() - 1; i >= 0; i--) {
Rect r = topctrl[i]->GetRect();
draw.Clipoff(r);
topctrl[i]->CtrlPaint(draw, clip);
draw.End();
}
//AnimateCaret();
//ApplyTransform(TS_AFTER_PAINT);
SwapBuffers(hDC);
@ -162,6 +191,11 @@ void Ctrl::DrawScreen()
}
}
void Ctrl::WndUpdate0r(const Rect& r)
{
GuiLock __;
}
bool Ctrl::ProcessEvents(bool *quit)
{
if(!ProcessEvent(quit))
@ -169,9 +203,12 @@ bool Ctrl::ProcessEvents(bool *quit)
while(ProcessEvent(quit) && (!LoopCtrl || LoopCtrl->InLoop()) && !GlEndSession()); // LoopCtrl-MF 071008
TimerProc(GetTickCount());
SweepMkImageCache();
DrawScreen();
CursorSync();
return false;
if(hRC)
{
DrawScreen();
CursorSync();
}
return true;
}
void Ctrl::EventLoop0(Ctrl *ctrl)
@ -223,7 +260,7 @@ void Ctrl::GuiSleep0(int ms)
Rect Ctrl::GetWndScreenRect() const
{
GuiLock __;
return screenRect;
return GetRect();
}
void Ctrl::WndShow0(bool b)
@ -255,6 +292,8 @@ Rect Ctrl::GetWorkArea() const
void Ctrl::GetWorkArea(Array<Rect>& rc)
{
GuiLock __;
Array<Rect> r;
r.Add(screenRect.GetSize());
}
Rect Ctrl::GetVirtualWorkArea()
@ -296,6 +335,9 @@ int Ctrl::GetKbdSpeed()
void Ctrl::WndDestroy0()
{
for(int i = 0; i < topctrl.GetCount(); i++)
if(topctrl[i]->top && topctrl[i]->top->owner_window == this)
topctrl[i]->WndDestroy0();
int q = FindTopCtrl();
if(q >= 0) {
topctrl.Remove(q);
@ -305,27 +347,45 @@ void Ctrl::WndDestroy0()
top = NULL;
}
isopen = false;
TopWindow *win = dynamic_cast<TopWindow *>(this);
if(win)
win->DestroyFrame();
}
void Ctrl::SetWndForeground0()
void Ctrl::PutForeground()
{
GuiLock __;
int q = FindTopCtrl();
if(q >= 0) {
topctrl.Remove(q);
topctrl.Add(this);
}
for(int i = 0; i < topctrl.GetCount(); i++)
if(topctrl[i]->top && topctrl[i]->top->owner_window == this)
topctrl[i]->PutForeground();
}
void Ctrl::SetWndForeground0()
{
GuiLock __;
ASSERT(IsOpen());
if(top && top->owner_window && !IsWndForeground())
top->owner_window->PutForeground();
PutForeground();
}
bool Ctrl::IsWndForeground() const
{
GuiLock __;
return false;
for(int i = 0; i < topctrl.GetCount(); i++)
if(topctrl[i]->top && topctrl[i]->top->owner_window == this && topctrl[i]->IsWndForeground())
return true;
return topctrl.GetCount() ? topctrl.Top() == this : this == desktop;
}
void Ctrl::WndEnable0(bool *b)
{
GuiLock __;
*b = true;
}
void Ctrl::SetWndFocus0(bool *b)
@ -369,14 +429,12 @@ void Ctrl::WndInvalidateRect0(const Rect& r)
void Ctrl::WndSetPos0(const Rect& rect)
{
GuiLock __;
TopWindow *w = dynamic_cast<TopWindow *>(this);
if(w)
w->SyncFrameRect(rect);
SetWndRect(rect);
}
void Ctrl::WndUpdate0r(const Rect& r)
{
GuiLock __;
}
void Ctrl::WndScrollView0(const Rect& r, int dx, int dy)
{
GuiLock __;
@ -385,16 +443,30 @@ void Ctrl::WndScrollView0(const Rect& r, int dx, int dy)
void Ctrl::PopUp(Ctrl *owner, bool savebits, bool activate, bool dropshadow, bool topmost)
{
_DBG_ // Add owner management!!!!
ASSERT(!IsChild() && !IsOpen() && FindTopCtrl() < 0);
NewTop();
if(owner) {
Ctrl *owner_window = owner->GetTopCtrl(); _DBG_ // should perhaps be topwindow;
ASSERT(owner_window->IsOpen());
if(owner_window != desktop) {
owner_window->SetForeground();
top->owner_window = owner_window;
}
}
topctrl.Add(this);
popup = isopen = true;
SetTop();
if(activate) SetFocus();
RefreshLayoutDeep();
if(activate) SetFocusWnd();
}
Rect Ctrl::GetDefaultWindowRect() {
return Rect(0, 0, 100, 100);
GuiLock __;
int ii = 0;
Size sz = screenRect.GetSize();
Rect rect = sz;
rect.Deflate(sz / 8);
rect.Offset(Point(sz) / 16 * (ii % 8));
return rect;
}
Vector<WString> SplitCmdLine__(const char *cmd)

View file

@ -26,5 +26,6 @@
#endif
#ifdef flagWINGL
#define GUIPLATFORM_INCLUDE <WinGl/WinGl.h>
#define GUIPLATFORM_KEYCODES_INCLUDE <WinGl/Keys.h>
#define GUIPLATFORM_INCLUDE <WinGl/WinGl.h>
#endif