first windows seams work, but in the main principe, I need to remove decoration...

This commit is contained in:
Edouard Dupin 2011-10-21 15:07:56 +02:00
parent 733c5a5483
commit da1c15efe9
8 changed files with 640 additions and 348 deletions

View File

@ -43,7 +43,7 @@ VERSION_BUILD_TIME=$(shell date)
###############################################################################
### Platform specificity : ###
###############################################################################
SUPPORTED_PLATFORM=X11 DoubleBuffer IPhone Android
SUPPORTED_PLATFORM=X11 DoubleBuffer IPhone IPad Android AndroidTablet
DEFAULT_PLATFORM=X11
# default platform can be overridden
@ -55,8 +55,12 @@ else ifeq ($(PLATFORM), DoubleBuffer)
CXXFILES += base/guiDoubleBuffer.cpp
else ifeq ($(PLATFORM), IPhone)
CXXFILES += base/guiIPhone.cpp
else ifeq ($(PLATFORM), IPad)
CXXFILES += base/guiIPad.cpp
else ifeq ($(PLATFORM), Android)
CXXFILES += base/guiAndroid.cpp
else ifeq ($(PLATFORM), AndroidTablet)
CXXFILES += base/guiAndroidTablet.cpp
else
$(error you must specify a corect platform : make PLATFORM=$(SUPPORTED_PLATFORM))
endif
@ -160,7 +164,8 @@ CXXFILES += etk/etkDebug.cpp \
# Ewol Sources :
CXXFILES += ewol.cpp \
ewolDebug.cpp \
ewolWidget.cpp
ewolWidget.cpp \
ewolWindows.cpp
# Ewol Test Software :

View File

@ -23,26 +23,49 @@
*/
#include "ewol.h"
#include <ewol.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// need to run xcompmgr to have transparency
class Plop :public ewol::Windows
{
public:
Plop(void)
{
};
~Plop(void)
{
};
};
/**
* @brief main input fonction
*/
int main(int argc, char *argv[])
{
Plop * myWindowsExample = new Plop();
ewol::Init(argc, argv);
// create the windows
//ewol::Windows myWindows(ewol::WINDOWS_MAIN);
// create the specific windows
ewol::DisplayWindows(myWindowsExample);
ewol::Run();
ewol::DisplayWindows(NULL);
delete(myWindowsExample);
ewol::UnInit();
return 0;
}

View File

@ -37,10 +37,18 @@
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
//#define TEST_MODE_1
/*
bool guiAbstraction(Display *d, XEvent *e, char *arg)
{
return (e->type == MapNotify) && (e->xmap.window == *(Window*)arg);
}
*/
namespace guiAbstraction {
#ifdef TEST_MODE_1
#undef __class__
#define __class__ "guiAbstraction::X11display"
class X11display
@ -60,7 +68,10 @@ namespace guiAbstraction {
m_display = 0;
}
}
operator Display*() { return m_display; }
Display * GetDisplay(void)
{
return m_display;
}
private:
Display* m_display;
};
@ -71,10 +82,10 @@ namespace guiAbstraction {
{
private:
ewol::Windows* m_uniqueWindows;
X11display& m_display;
Display * m_display;
bool m_run;
public:
X11eventMng(X11display& d) : m_run(true), m_display(d)
X11eventMng(X11display& d) : m_run(true), m_display(d.GetDisplay() )
{
m_uniqueWindows = NULL;
}
@ -92,10 +103,15 @@ namespace guiAbstraction {
void Run()
{
m_run = true;
XEvent report;
XEvent event;
while (m_run) {
XNextEvent(m_display, &report);
HasEvent(report);
while (XPending(m_display)) {
//...
// draw the current windows in every case ...
m_uniqueWindows->SysDraw();
// For test, otherwithe the display leach all the CPU
usleep( 100000 );
}//end if m_uniqueWindows
}
}
@ -103,89 +119,487 @@ namespace guiAbstraction {
{
m_run = false;
}
private:
bool HasEvent(XEvent& report)
{
if(NULL != m_uniqueWindows) {
switch ( report.type )
{
case Expose:
m_uniqueWindows->SysOnExpose();
break;
case ButtonPress:
if ( report.xbutton.button & Button2 ) {
m_uniqueWindows->GenEventInput(2, EVENT_INPUT_TYPE_DOWN, (double)report.xbutton.x, (double)report.xbutton.y);
} else if (report.xbutton.button & Button1) {
m_uniqueWindows->GenEventInput(1, EVENT_INPUT_TYPE_DOWN, (double)report.xbutton.x, (double)report.xbutton.y);
}
break;
case ButtonRelease:
if(report.xbutton.button & Button2) {
m_uniqueWindows->GenEventInput(2, EVENT_INPUT_TYPE_UP, (double)report.xbutton.x, (double)report.xbutton.y);
} else if (report.xbutton.button & Button1) {
m_uniqueWindows->GenEventInput(1, EVENT_INPUT_TYPE_UP, (double)report.xbutton.x, (double)report.xbutton.y);
}
break;
case EnterNotify:
m_uniqueWindows->GenEventInput(0, EVENT_INPUT_TYPE_ENTER, (double)report.xcrossing.x, (double)report.xcrossing.y);
break;
case MotionNotify:
m_uniqueWindows->GenEventInput(0, EVENT_INPUT_TYPE_MOVE, (double)report.xmotion.x, (double)report.xmotion.y);
break;
case LeaveNotify:
m_uniqueWindows->GenEventInput(0, EVENT_INPUT_TYPE_LEAVE, (double)report.xcrossing.x, (double)report.xcrossing.y);
break;
case FocusIn:
m_uniqueWindows->SetFocus();
break;
case FocusOut:
m_uniqueWindows->RmFocus();
break;
case KeyPress:
case KeyRelease:
{
char buf[11];
KeySym keysym;
XComposeStatus status;
int count = XLookupString(&report.xkey, buf, 10, &keysym, &status);
buf[count] = '\0';
if(report.type == KeyPress) {
// TODO : set the char here...
} else {
// TODO : set the char here...
}
break;
}
//case DestroyNotify:
// break;
case MapNotify:
m_uniqueWindows->SysOnShow();
break;
case UnmapNotify:
m_uniqueWindows->SysOnHide();
break;
case ClientMessage:
{
Atom atom = XInternAtom(m_display, "WM_DELETE_WINDOW", false);
if(atom == report.xclient.data.l[0]) {
m_uniqueWindows->SysOnKill();
}
break;
}
}
return true;
} else {
return false;
}
}
X11display& get_display(void)
Display * GetDisplay(void)
{
return m_display;
}
};
const int event_mask = ExposureMask
| ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
| FocusChangeMask
| KeyPressMask
| KeyReleaseMask
| SubstructureNotifyMask
| StructureNotifyMask
| SubstructureRedirectMask;
#undef __class__
#define __class__ "guiAbstraction::X11Windows"
class X11Windows
{
private:
Display * m_display;
Window m_window;
X11eventMng& m_event_dispatcher;
Atom m_atom[1];
size_ts m_size;
position_ts m_position;
private:
// Not copyable
X11Windows(const X11Windows&);
void operator=(X11Windows&);
public:
X11Windows(X11eventMng& e)
: m_display(e.GetDisplay()),
m_event_dispatcher(e)
{
m_window = 0;
m_atom[0] = 0;
if(!m_window) {
int Xscreen = DefaultScreen((void*)m_display);
Window Xroot = RootWindow((void*)m_display, Xscreen);
//RootWindow((void*)m_display,0)
m_window = XCreateSimpleWindow(m_display,
Xroot,
20, // origin X
20, // origin Y
300, // Width
200, //Height
0,
WhitePixel((void*)m_display,0),
WhitePixel((void*)m_display,0));
//set_background ( m_background );
if(0==m_window) {
EWOL_CRITICAL("Could not create the basic window");
}
}
//m_event_dispatcher.Setwindow(this);
Show();
}
~X11Windows(void)
{
Hide();
if(m_window) {
XDestroyWindow(m_display, m_window);
m_window = 0;
}
m_event_dispatcher.Setwindow(NULL);
}
private:
//
// From window_base:
//
virtual void Show(void)
{
XSelectInput(m_display, m_window, guiAbstraction::event_mask);
XMapWindow(m_display, m_window);
XFlush(m_display);
}
virtual void Hide(void)
{
XUnmapWindow(m_display, m_window);
XFlush(m_display);
}
/*
virtual void set_background(color& c)
{
// hold a ref to the alloc'ed color
m_background.set(c);
XSetWindowBackground(m_display, m_window, c.pixel());
refresh();
}
virtual void set_focus(void)
{
XSetInputFocus(m_display, id(), RevertToParent, CurrentTime );
refresh();
}
virtual void refresh(void)
{
XClearWindow(m_display, m_window);
XFlush(m_display);
on_expose();
}
virtual rectangle get_rect(void)
{
Window root;
int x = 0, y = 0;
unsigned int width = 0, height = 0, border_width = 0, depth = 0;
XGetGeometry(m_display,
m_window,
&root,
&x,
&y,
&width,
&height,
&border_width,
&depth);
return rectangle(point(x,y), width, height );
}
*/
virtual long Id(void)
{
return m_window;
}
Display * GetDisplay(void)
{
return m_display;
}
virtual X11eventMng& get_event_dispatcher(void)
{
return m_event_dispatcher;
}
};
#else
class X11systemInterface
{
private:
Atom del_atom;
Display *m_display;
GLXFBConfig fbconfig;
Window WindowHandle, GLXWindowHandle;
int width, height;
bool m_run;
ewol::Windows* m_uniqueWindows;
bool CreateX11Context(void)
{
XEvent event;
int x,y, attr_mask;
XSizeHints hints;
XWMHints *StartupState;
XTextProperty textprop;
XSetWindowAttributes attr;
static char *title = (char*)"FTB's little OpenGL example";
// Connect to the X server
m_display = XOpenDisplay(NULL);
if(NULL == m_display) {
EWOL_CRITICAL("Could not open display X.");
exit(-1);
} else {
EWOL_INFO("Display opened.");
}
int Xscreen = DefaultScreen(m_display);
Window Xroot = RootWindow(m_display, Xscreen);
int numfbconfigs;
int VisualData[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_ALPHA_SIZE, 1,
GLX_DEPTH_SIZE, 1,
None
};
XVisualInfo *visual;
GLXFBConfig *fbconfigs = glXChooseFBConfig(m_display, Xscreen, VisualData, &numfbconfigs);
for(int i = 0; i<numfbconfigs; i++) {
visual = glXGetVisualFromFBConfig(m_display, fbconfigs[i]);
if(!visual) {
continue;
}
XRenderPictFormat * pictFormat = XRenderFindVisualFormat(m_display, visual->visual);
if(!pictFormat) {
continue;
}
if(pictFormat->direct.alphaMask > 0) {
fbconfig = fbconfigs[i];
break;
}
}
// Create a colormap - only needed on some X clients, eg. IRIX
attr.colormap = XCreateColormap(m_display, Xroot, visual->visual, AllocNone);
attr.border_pixel = 0;
attr.event_mask = StructureNotifyMask
| EnterWindowMask
| LeaveWindowMask
| ExposureMask
| ButtonPressMask
| ButtonReleaseMask
| OwnerGrabButtonMask
| KeyPressMask
| KeyReleaseMask;
// set no background at the gui
attr.background_pixmap = None;
// select internal attribute
attr_mask = CWBackPixmap | CWColormap | CWBorderPixel | CWEventMask;
// Create the window
width = DisplayWidth(m_display, DefaultScreen(m_display))/2;
height = DisplayHeight(m_display, DefaultScreen(m_display))/2;
x=width/2;
y=height/4;
// Real create of the window
WindowHandle = XCreateWindow(m_display,
Xroot,
x, y, width, height,
1,
visual->depth,
InputOutput,
visual->visual,
attr_mask, &attr);
if( !WindowHandle ) {
EWOL_CRITICAL("Couldn't create the window");
exit(-1);
}
/* Configure it... (ok, ok, this next bit isn't "minimal") */
textprop.value = (unsigned char*)title;
textprop.encoding = XA_STRING;
textprop.format = 8;
textprop.nitems = strlen(title);
hints.x = x;
hints.y = y;
hints.width = width;
hints.height = height;
hints.flags = USPosition|USSize;
StartupState = XAllocWMHints();
StartupState->initial_state = NormalState;
StartupState->flags = StateHint;
XSetWMProperties(m_display, WindowHandle,&textprop, &textprop,/* Window title/icon title*/
NULL, 0,/* Argv[], argc for program*/
&hints, /* Start position/size*/
StartupState,/* Iconised/not flag */
NULL);
XFree(StartupState);
/* Open it, wait for it to appear */
XMapWindow(m_display, WindowHandle);
//XIfEvent(m_display, &event, WaitForMapNotify, (char*)&WindowHandle);
// Set the kill atom so we get a message when the user tries to close the window
if ((del_atom = XInternAtom(m_display, "WM_DELETE_WINDOW", 0)) != None) {
XSetWMProtocols(m_display, WindowHandle, &del_atom, 1);
}
return true;
}
bool CreateOGlContext(void)
{
/* See if we can do OpenGL on this visual */
int dummy;
if (!glXQueryExtension(m_display, &dummy, &dummy)) {
EWOL_CRITICAL("OpenGL not supported by X server");
exit(-1);
}
/* Create the OpenGL rendering context */
GLXContext RenderContext = glXCreateNewContext(m_display, fbconfig, GLX_RGBA_TYPE, 0, True);
if (!RenderContext) {
EWOL_CRITICAL("Failed to create a GL context");
exit(-1);
}
GLXWindowHandle = glXCreateWindow(m_display, fbconfig, WindowHandle, NULL);
/* Make it current */
if (!glXMakeContextCurrent(m_display, GLXWindowHandle, GLXWindowHandle, RenderContext)) {
EWOL_CRITICAL("glXMakeCurrent failed for window");
exit(-1);
}
return true;
}
void Draw(void)
{
EWOL_DEBUG("redraw (" << width << "," << height << ")");
if(NULL == m_uniqueWindows) {
//EWOL_DEBUG("Has No Windows set...");
// set the size of the open GL system
glViewport(0,0,width,height);
// Clear the screen with transparency ...
glClearColor(0.750, 0.750, 0.750, 0.5);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0., (float)width, 0., (float)height, 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
glBegin(GL_QUADS);
glColor3f(1., 0., 0.); glVertex3f( .25*(float)width, .25*(float)height, 0.);
glColor3f(0., 1., 0.); glVertex3f( .75*(float)width, .25*(float)height, 0.);
glColor3f(0., 0., 1.); glVertex3f( .75*(float)width, .75*(float)height, 0.);
glColor3f(1., 1., 0.); glVertex3f( .25*(float)width, .75*(float)height, 0.);
glEnd();
} else {
m_uniqueWindows->SysDraw();
}
/* Swapbuffers */
glXSwapBuffers(m_display, GLXWindowHandle);
}
public:
X11systemInterface(void)
{
CreateX11Context();
CreateOGlContext();
m_run = true;
}
~X11systemInterface(void)
{
Stop();
}
void Setwindow(ewol::Windows* newWindows)
{
m_uniqueWindows = newWindows;
if (NULL != m_uniqueWindows) {
m_uniqueWindows->CalculateSize((double)width, (double)height);
}
}
void Run(void)
{
// main cycle
while(true == m_run) {
XEvent event;
XConfigureEvent *xc;
// main X boucle :
while (XPending(m_display)) {
XNextEvent(m_display, &event);
switch (event.type)
{
case ClientMessage:
{
Atom atom = XInternAtom(m_display, "WM_DELETE_WINDOW", false);
if(atom == event.xclient.data.l[0]) {
if (NULL != m_uniqueWindows) {
m_uniqueWindows->SysOnKill();
}
Stop();
}
}
break;
case ConfigureNotify:
width = event.xconfigure.width;
height = event.xconfigure.height;
break;
}
// parse event
if(NULL == m_uniqueWindows) {
EWOL_DEBUG("Has No Windows set...");
} else {
switch (event.type)
{
case ConfigureNotify:
EWOL_DEBUG("Change Windows Size : (" << event.xconfigure.width << "," << event.xconfigure.height << ")");
m_uniqueWindows->CalculateSize((double)event.xconfigure.width, (double)event.xconfigure.height);
break;
case Expose:
m_uniqueWindows->SysOnExpose();
break;
case ButtonPress:
if ( event.xbutton.button & Button2 ) {
m_uniqueWindows->GenEventInput(2, ewol::EVENT_INPUT_TYPE_DOWN, (double)event.xbutton.x, (double)event.xbutton.y);
} else if (event.xbutton.button & Button1) {
m_uniqueWindows->GenEventInput(1, ewol::EVENT_INPUT_TYPE_DOWN, (double)event.xbutton.x, (double)event.xbutton.y);
}
break;
case ButtonRelease:
if(event.xbutton.button & Button2) {
m_uniqueWindows->GenEventInput(2, ewol::EVENT_INPUT_TYPE_UP, (double)event.xbutton.x, (double)event.xbutton.y);
} else if (event.xbutton.button & Button1) {
m_uniqueWindows->GenEventInput(1, ewol::EVENT_INPUT_TYPE_UP, (double)event.xbutton.x, (double)event.xbutton.y);
}
break;
case EnterNotify:
m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_ENTER, (double)event.xcrossing.x, (double)event.xcrossing.y);
break;
case MotionNotify:
m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_MOVE, (double)event.xmotion.x, (double)event.xmotion.y);
break;
case LeaveNotify:
m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_LEAVE, (double)event.xcrossing.x, (double)event.xcrossing.y);
break;
case FocusIn:
m_uniqueWindows->SetFocus();
break;
case FocusOut:
m_uniqueWindows->RmFocus();
break;
case KeyPress:
case KeyRelease:
{
char buf[11];
KeySym keysym;
XComposeStatus status;
int count = XLookupString(&event.xkey, buf, 10, &keysym, &status);
buf[count] = '\0';
if(event.type == KeyPress) {
// TODO : set the char here...
} else {
// TODO : set the char here...
}
break;
}
//case DestroyNotify:
// break;
case MapNotify:
m_uniqueWindows->SysOnShow();
break;
case UnmapNotify:
m_uniqueWindows->SysOnHide();
break;
}
}
}
Draw();
usleep( 100000 );
}
}
void Stop(void)
{
m_run = false;
}
};
#endif
@ -197,17 +611,24 @@ namespace guiAbstraction {
#define __class__ "guiAbstraction"
static bool guiAbstractionIsInit = false;
static X11display * myDisplay = NULL;
static X11eventMng * myEventManager = NULL;
#ifdef TEST_MODE_1
static guiAbstraction::X11display * myDisplay = NULL;
static guiAbstraction::X11eventMng * myEventManager = NULL;
#else
static guiAbstraction::X11systemInterface * myX11Access = NULL;
#endif
void guiAbstraction::Init(int32_t argc, char *argv[])
{
if (false == guiAbstractionIsInit) {
// set the gui is init :
guiAbstractionIsInit = true;
EWOL_INFO("INIT for X11 environement");
myDisplay = new X11display("");
myEventManager = X11eventMng(myDisplay);
#ifdef TEST_MODE_1
myDisplay = new guiAbstraction::X11display("");
myEventManager = new guiAbstraction::X11eventMng(*myDisplay);
#else
myX11Access = new guiAbstraction::X11systemInterface();
#endif
} else {
EWOL_CRITICAL("Can not INIT X11 ==> already init before");
}
@ -218,7 +639,11 @@ void guiAbstraction::Run(void)
{
if (true == guiAbstractionIsInit) {
EWOL_INFO("Start Running");
myEventManager.Run();
#ifdef TEST_MODE_1
myEventManager->Run();
#else
myX11Access->Run();
#endif
EWOL_INFO("Stop Running");
} else {
EWOL_CRITICAL("Can not Run X11 ==> not init ... ");
@ -228,16 +653,24 @@ void guiAbstraction::Run(void)
void guiAbstraction::Stop(void)
{
if (true == guiAbstractionIsInit) {
myEventManager.Stop();
#ifdef TEST_MODE_1
myEventManager->Stop();
#else
myX11Access->Stop();
#endif
} else {
EWOL_CRITICAL("Can not Stop X11 ==> not init ... ");
}
}
void guiAbstraction::SetDisplayOnWindows(ewol::Windows & newOne)
void guiAbstraction::SetDisplayOnWindows(ewol::Windows * newOne)
{
if (true == guiAbstractionIsInit) {
myEventManager.Setwindow(&newOne);
#ifdef TEST_MODE_1
myEventManager->Setwindow(newOne);
#else
myX11Access->Setwindow(newOne);
#endif
} else {
EWOL_CRITICAL("Can not set Windows X11 ==> not init ... ");
}
@ -247,12 +680,18 @@ void guiAbstraction::UnInit(void)
{
if (true == guiAbstractionIsInit) {
EWOL_INFO("UN-INIT for X11 environement");
if (NULL != myEventManager) {
delete(myEventManager);
}
if (NULL != myDisplay) {
delete(myDisplay);
}
#ifdef TEST_MODE_1
if (NULL != myEventManager) {
delete(myEventManager);
}
if (NULL != myDisplay) {
delete(myDisplay);
}
#else
if (NULL != myX11Access) {
delete(myX11Access);
}
#endif
guiAbstractionIsInit = false;
} else {
EWOL_CRITICAL("Can not Un-Init X11 ==> not init ... ");

View File

@ -35,7 +35,7 @@ namespace guiAbstraction
void Run(void);
void Stop(void);
void UnInit(void);
void SetDisplayOnWindows(ewol::Windows & newOne);
void SetDisplayOnWindows(ewol::Windows * newOne);
};

View File

@ -25,223 +25,18 @@
#include "ewol.h"
// need to run xcompmgr to have transparency
#if 0
static Atom del_atom;
static Display *Xdisplay;
static GLXFBConfig fbconfig;
static Window WindowHandle, GLXWindowHandle;
static int width, height;
/**
* @brief
*/
static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
{
return (e->type == MapNotify) && (e->xmap.window == *(Window*)arg);
}
/**
* @brief Create the X11 windows
*/
static void createX11Window()
{
XEvent event;
int x,y, attr_mask;
XSizeHints hints;
XWMHints *StartupState;
XTextProperty textprop;
XSetWindowAttributes attr;
static char *title = (char*)"FTB's little OpenGL example";
// Connect to the X server
Xdisplay = XOpenDisplay(NULL);
if (NULL == Xdisplay) {
fprintf(stderr, "Couldn't connect to X server\n");
exit(-1);
}
int Xscreen = DefaultScreen(Xdisplay);
Window Xroot = RootWindow(Xdisplay, Xscreen);
int numfbconfigs;
int VisualData[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_ALPHA_SIZE, 1,
GLX_DEPTH_SIZE, 1,
None
};
XVisualInfo *visual;
GLXFBConfig *fbconfigs = glXChooseFBConfig(Xdisplay, Xscreen, VisualData, &numfbconfigs);
for(int i = 0; i<numfbconfigs; i++) {
visual = glXGetVisualFromFBConfig(Xdisplay, fbconfigs[i]);
if(!visual) {
continue;
}
XRenderPictFormat * pictFormat = XRenderFindVisualFormat(Xdisplay, visual->visual);
if(!pictFormat) {
continue;
}
if(pictFormat->direct.alphaMask > 0) {
fbconfig = fbconfigs[i];
break;
}
}
// Create a colormap - only needed on some X clients, eg. IRIX
attr.colormap = XCreateColormap(Xdisplay, Xroot, visual->visual, AllocNone);;
attr.border_pixel = 0;
attr.event_mask = StructureNotifyMask
| EnterWindowMask
| LeaveWindowMask
| ExposureMask
| ButtonPressMask
| ButtonReleaseMask
| OwnerGrabButtonMask
| KeyPressMask
| KeyReleaseMask;
// set no background at the gui
attr.background_pixmap = None;
// select internal attribute
attr_mask = CWBackPixmap | CWColormap | CWBorderPixel | CWEventMask;
// Create the window
width = DisplayWidth(Xdisplay, DefaultScreen(Xdisplay))/2;
height = DisplayHeight(Xdisplay, DefaultScreen(Xdisplay))/2;
x=width/2;
y=height/4;
// Real create of the window
WindowHandle = XCreateWindow(Xdisplay,
Xroot,
x, y, width, height,
1,
visual->depth,
InputOutput,
visual->visual,
attr_mask, &attr);
if( !WindowHandle ) {
fprintf(stderr, "Couldn't create the window\n");
exit(-1);
}
/* Configure it... (ok, ok, this next bit isn't "minimal") */
textprop.value = (unsigned char*)title;
textprop.encoding = XA_STRING;
textprop.format = 8;
textprop.nitems = strlen(title);
hints.x = x;
hints.y = y;
hints.width = width;
hints.height = height;
hints.flags = USPosition|USSize;
StartupState = XAllocWMHints();
StartupState->initial_state = NormalState;
StartupState->flags = StateHint;
XSetWMProperties(Xdisplay, WindowHandle,&textprop, &textprop,/* Window title/icon title*/
NULL, 0,/* Argv[], argc for program*/
&hints, /* Start position/size*/
StartupState,/* Iconised/not flag */
NULL);
XFree(StartupState);
/* Open it, wait for it to appear */
XMapWindow(Xdisplay, WindowHandle);
XIfEvent(Xdisplay, &event, WaitForMapNotify, (char*)&WindowHandle);
// Set the kill atom so we get a message when the user tries to close the window
if ((del_atom = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", 0)) != None) {
XSetWMProtocols(Xdisplay, WindowHandle, &del_atom, 1);
}
}
/**
* @brief Create a special context to manage transparency of the windows inside X11 system :
*/
static void createTheRenderContext()
{
/* See if we can do OpenGL on this visual */
int dummy;
if (!glXQueryExtension(Xdisplay, &dummy, &dummy)) {
fprintf(stderr, "OpenGL not supported by X server\n");
exit(-1);
}
/* Create the OpenGL rendering context */
GLXContext RenderContext = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True);
if (!RenderContext) {
fprintf(stderr, "Failed to create a GL context\n");
exit(-1);
}
GLXWindowHandle = glXCreateWindow(Xdisplay, fbconfig, WindowHandle, NULL);
/* Make it current */
if (!glXMakeContextCurrent(Xdisplay, GLXWindowHandle, GLXWindowHandle, RenderContext)) {
fprintf(stderr, "glXMakeCurrent failed for window\n");
exit(-1);
}
}
/**
* @brief draw the current diplay of the screen
*/
static void Draw(void)
{
// set the size of the open GL system
glViewport(0,0,width,height);
// Clear the screen with transparency ...
glClearColor(0.750, 0.750, 0.750, 0.5);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0., (float)width, 0., (float)height, 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
glBegin(GL_QUADS);
glColor3f(1., 0., 0.); glVertex3f( .25*(float)width, .25*(float)height, 0.);
glColor3f(0., 1., 0.); glVertex3f( .75*(float)width, .25*(float)height, 0.);
glColor3f(0., 0., 1.); glVertex3f( .75*(float)width, .75*(float)height, 0.);
glColor3f(1., 1., 0.); glVertex3f( .25*(float)width, .75*(float)height, 0.);
glEnd();
printf("redraw (%d,%d)\n", width, height);
/* Swapbuffers */
glXSwapBuffers(Xdisplay, GLXWindowHandle);
}
#endif
#if __PLATFORM__ == X11
#include "guiX11.h"
#elif __PLATFORM__ == DoubleBuffer
#include "guiDoubleBuffer.h"
#elif __PLATFORM__ == Android
#include "guiAndroid.h"
#elif __PLATFORM__ == AndroidTablet
#include "guiAndroidTablet.h"
#elif __PLATFORM__ == IPhone
#include "guiIPhone.h"
#elif __PLATFORM__ == IPad
#include "guiIPad.h"
#else
#error you need to specify a platform ...
#endif
@ -250,41 +45,11 @@ static void Draw(void)
void ewol::Init(int argc, char *argv[])
{
guiAbstraction::Init(argc, argv);
//createX11Window();
//createTheRenderContext();
}
void ewol::Run(void)
{
guiAbstraction::Run();
/*
// main cycle
while(1) {
XEvent event;
XConfigureEvent *xc;
// main X boucle :
while (XPending(Xdisplay)) {
XNextEvent(Xdisplay, &event);
switch (event.type)
{
case ClientMessage:
// Request close of the current client :
if (event.xclient.data.l[0] == del_atom) {
// TODO : Clear all internal elements ...
exit(0);
}
break;
case ConfigureNotify:
xc = &(event.xconfigure);
width = xc->width;
height = xc->height;
break;
}
}
Draw();
usleep( 100000 );
}
*/
}
void ewol::UnInit(void)
@ -293,6 +58,10 @@ void ewol::UnInit(void)
}
void ewol::DisplayWindows(ewol::Windows * windows)
{
guiAbstraction::SetDisplayOnWindows(windows);
}

View File

@ -27,12 +27,16 @@
#define __EWOL_H__
#include <etkTypes.h>
#include <etkString.h>
#include <ewolWidget.h>
#include <ewolWindows.h>
namespace ewol {
void Init(int32_t argc, char *argv[]);
void Run(void);
void Stop(void);
void UnInit(void);
void DisplayWindows(ewol::Windows * windows);
};

View File

@ -22,5 +22,53 @@
*******************************************************************************
*/
#include <etkTypes.h>
#include <etkString.h>
#include <ewolWidget.h>
#include <ewolWindows.h>
#include <ewolWindows.h>
#include <GL/gl.h>
bool ewol::Windows::CalculateSize(double availlableX, double availlableY)
{
m_size.x = availlableX;
m_size.y = availlableY;
return true;
}
void ewol::Windows::SysDraw(void)
{
static double ploppp = 0.1;
EWOL_DEBUG("Drow on (" << m_size.x << "," << m_size.y << ")");
// set the size of the open GL system
glViewport(0,0,m_size.x,m_size.y);
// Clear the screen with transparency ...
glClearColor(0.750, 0.750, 0.750, 0.5);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0., m_size.x, 0., m_size.y, 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
//EWOL_DEBUG("plop is " << ploppp << " devient " << (1.0-ploppp) );
glBegin(GL_QUADS);
glColor3f(1., 0., 0.); glVertex3f( ploppp*m_size.x, ploppp*m_size.y, 0.);
glColor3f(0., 1., 0.); glVertex3f( (1.0-ploppp)*m_size.x, ploppp*m_size.y, 0.);
glColor3f(0., 0., 1.); glVertex3f( (1.0-ploppp)*m_size.x, (1.0-ploppp)*m_size.y, 0.);
glColor3f(1., 1., 0.); glVertex3f( ploppp*m_size.x, (1.0-ploppp)*m_size.y, 0.);
glEnd();
ploppp += 0.05;
if (ploppp>0.5) {
ploppp = 0;
}
}

View File

@ -35,19 +35,23 @@ namespace ewol {
class Windows :public ewol::Widget
{
public:
Windows(void);
virtual ~Windows(void);
Windows(void) {};
virtual ~Windows(void) {};
// internal event at ewol system :
public:
void SysOnShow(void);
void SysOnHide(void);
void SysOnKill(void);
void SysDraw(void);
void SysOnShow(void) {};
void SysOnHide(void) {};
void SysOnKill(void) {};
void SysOnExpose(void) {};
public:
virtual void OnShow(void) { };
virtual void OnHide(void) { };
virtual bool OnKill(void) { return true; };
virtual void OnReduce(void) { };
virtual void On(void) { };
// from Widget management :
virtual bool CalculateSize(double availlableX, double availlableY);
};
};