First think of the interface ==> bad...

This commit is contained in:
Edouard Dupin 2011-10-20 18:24:43 +02:00
parent 57d1d2ec74
commit 733c5a5483
11 changed files with 389 additions and 38 deletions

View File

@ -35,23 +35,13 @@
*/
int main(int argc, char *argv[])
{
printf("==================================================\n");
printf("== ewol:: Init()\n");
printf("==================================================\n");
ewol::Init(argc, argv);
// create the windows
//ewol::Windows myWindows(ewol::WINDOWS_MAIN);
printf("==================================================\n");
printf("== ewol:: Run()\n");
printf("==================================================\n");
ewol::Run();
printf("==================================================\n");
printf("== ewol:: UnInit()\n");
printf("==================================================\n");
ewol::UnInit();
return 0;

View File

@ -24,25 +24,239 @@
#include <ewolDebug.h>
#include <etkString.h>
#include <guiX11.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glx.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
namespace guiAbstraction {
#undef __class__
#define __class__ "guiAbstraction::X11display"
class X11display
{
public:
X11display( etk::String name ) {
m_display = XOpenDisplay( name.c_str() );
if(NULL == m_display) {
EWOL_CRITICAL("Could not open display named='" << name << "'.");
} else {
EWOL_INFO("Display opened named='" << name << "'.");
}
}
~X11display() {
if( NULL != m_display ) {
XCloseDisplay ( m_display );
m_display = 0;
}
}
operator Display*() { return m_display; }
private:
Display* m_display;
};
#undef __class__
#define __class__ "guiAbstraction::X11eventMng"
class X11eventMng
{
private:
ewol::Windows* m_uniqueWindows;
X11display& m_display;
bool m_run;
public:
X11eventMng(X11display& d) : m_run(true), m_display(d)
{
m_uniqueWindows = NULL;
}
~X11eventMng()
{
}
void Setwindow(ewol::Windows* newWindows)
{
m_uniqueWindows = newWindows;
}
void Run()
{
m_run = true;
XEvent report;
while (m_run) {
XNextEvent(m_display, &report);
HasEvent(report);
}
}
void Stop()
{
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)
{
return m_display;
}
};
};
#undef __class__
#define __class__ "guiAbstraction"
static bool guiAbstractionIsInit = false;
static X11display * myDisplay = NULL;
static X11eventMng * myEventManager = NULL;
void guiAbstraction::Init(int32_t argc, char *argv[])
{
EWOL_INFO("INIT for X11 environement");
if (false == guiAbstractionIsInit) {
// set the gui is init :
guiAbstractionIsInit = true;
EWOL_INFO("INIT for X11 environement");
myDisplay = new X11display("");
myEventManager = X11eventMng(myDisplay);
} else {
EWOL_CRITICAL("Can not INIT X11 ==> already init before");
}
}
void guiAbstraction::Run(void)
{
EWOL_INFO("Start Running");
EWOL_INFO("Stop Running");
if (true == guiAbstractionIsInit) {
EWOL_INFO("Start Running");
myEventManager.Run();
EWOL_INFO("Stop Running");
} else {
EWOL_CRITICAL("Can not Run X11 ==> not init ... ");
}
}
void guiAbstraction::Stop(void)
{
if (true == guiAbstractionIsInit) {
myEventManager.Stop();
} else {
EWOL_CRITICAL("Can not Stop X11 ==> not init ... ");
}
}
void guiAbstraction::SetDisplayOnWindows(ewol::Windows & newOne)
{
if (true == guiAbstractionIsInit) {
myEventManager.Setwindow(&newOne);
} else {
EWOL_CRITICAL("Can not set Windows X11 ==> not init ... ");
}
}
void guiAbstraction::UnInit(void)
{
EWOL_INFO("UN-INIT for X11 environement");
if (true == guiAbstractionIsInit) {
EWOL_INFO("UN-INIT for X11 environement");
if (NULL != myEventManager) {
delete(myEventManager);
}
if (NULL != myDisplay) {
delete(myDisplay);
}
guiAbstractionIsInit = false;
} else {
EWOL_CRITICAL("Can not Un-Init X11 ==> not init ... ");
}
}

View File

@ -27,12 +27,15 @@
#define __GUI_ABSTRACTION_H__
#include <etkTypes.h>
#include <ewolWindows.h>
namespace guiAbstraction
{
void Init(int32_t argc, char *argv[]);
void Run(void);
void Stop(void);
void UnInit(void);
void SetDisplayOnWindows(ewol::Windows & newOne);
};

View File

@ -0,0 +1,70 @@
/**
*******************************************************************************
* @file etkSingleton.h
* @brief ewol : singleton system class
* @author Edouard DUPIN
* @date 04/12/2010
* @par Project
* ewol TK
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __ETK_SINGLETON_H__
#define __ETK_SINGLETON_H__
namespace etk {
template <typename T>
class Singleton
{
protected:
// Constructeur/destructeur
Singleton() { }
~Singleton() { /*std::cout << "destroying singleton." << std::endl;*/ }
public:
// Interface publique
static T *Get()
{
if (NULL == _singleton)
{
_singleton = new T;
}
return (static_cast<T*> (_singleton));
}
static void Kill()
{
if (NULL != _singleton)
{
delete _singleton;
_singleton = NULL;
}
}
private:
// Unique instance
static T *_singleton;
};
template <typename T>
T *Singleton<T>::_singleton = NULL;
}
#endif

View File

@ -46,13 +46,13 @@
# define __uint8_t_defined
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned long int uint32_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
#endif
#define etk_min(elemA, elemB) ((elemA)<(elemB)) ? (elemA) : (elemB)
#define etk_max(elemA, elemB) ((elemA)<(elemB)) ? (elemB) : (elemA)
#define etk_average(minimim, elem, maximum) ((minimim)>(elem)) ? (minimim) : ((maximum)<(elem)) ? (maximum) : (elem)
#define etk_min(elemA, elemB) ((elemA)<(elemB)) ? (elemA) : (elemB)
#define etk_max(elemA, elemB) ((elemA)<(elemB)) ? (elemB) : (elemA)
#define etk_avg(minimim, elem, maximum) ((minimim)>(elem)) ? (minimim) : ((maximum)<(elem)) ? (maximum) : (elem)
extern "C"
{
@ -60,9 +60,9 @@ extern "C"
double x;
double y;
};
typedef etkPointAndPosition point_ts;
typedef etkPointAndPosition position_ts;
typedef etkPointAndPosition size_ts;
typedef etkPointAndPosition point_ts;
typedef etkPointAndPosition position_ts;
typedef etkPointAndPosition size_ts;
}

View File

@ -22,17 +22,7 @@
*******************************************************************************
*/
/*
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glx.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
*/
#include "ewol.h"
// need to run xcompmgr to have transparency

View File

@ -27,6 +27,7 @@
#define __EWOL_H__
#include <etkTypes.h>
#include <ewolWidget.h>
namespace ewol {
void Init(int32_t argc, char *argv[]);

View File

@ -22,8 +22,8 @@
*******************************************************************************
*/
#ifndef __ETK_DEBUG_INTERNAL_H__
#define __ETK_DEBUG_INTERNAL_H__
#ifndef __EWOL_DEBUG_H__
#define __EWOL_DEBUG_H__
#include <etkTypes.h>
#include <etkDebug.h>

View File

@ -22,13 +22,13 @@
*******************************************************************************
*/
#include <etkTypes.h>
#include <etkVectorType.h>
#include <ewolDebug.h>
#ifndef __EWOL_WIDGET_H__
#define __EWOL_WIDGET_H__
#include <etkTypes.h>
#include <ewolDebug.h>
#include <etkVectorType.h>
namespace ewol {
extern "C" {
typedef struct {
@ -42,6 +42,8 @@ namespace ewol {
EVENT_INPUT_TYPE_TRIPLE,
EVENT_INPUT_TYPE_MOVE,
EVENT_INPUT_TYPE_UP,
EVENT_INPUT_TYPE_ENTER,
EVENT_INPUT_TYPE_LEAVE,
} eventInputType_te;
typedef enum {

26
Sources/ewolWindows.cpp Normal file
View File

@ -0,0 +1,26 @@
/**
*******************************************************************************
* @file ewolWindows.cpp
* @brief ewol window system (sources)
* @author Edouard DUPIN
* @date 20/10/2011
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/

55
Sources/ewolWindows.h Normal file
View File

@ -0,0 +1,55 @@
/**
*******************************************************************************
* @file ewolWindows.h
* @brief ewol window system (header)
* @author Edouard DUPIN
* @date 20/10/2011
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __EWOL_WINDOWS_H__
#define __EWOL_WINDOWS_H__
#include <etkTypes.h>
#include <ewolDebug.h>
#include <etkVectorType.h>
#include <etkSingleton.h>
#include <ewolWidget.h>
namespace ewol {
class Windows :public ewol::Widget
{
public:
Windows(void);
virtual ~Windows(void);
// internal event at ewol system :
public:
void SysOnShow(void);
void SysOnHide(void);
void SysOnKill(void);
public:
virtual void OnShow(void) { };
virtual void OnHide(void) { };
virtual bool OnKill(void) { return true; };
virtual void OnReduce(void) { };
virtual void On(void) { };
};
};
#endif