From 733c5a54834ee08699ed3b8909dca23403f7cef1 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Thu, 20 Oct 2011 18:24:43 +0200 Subject: [PATCH] First think of the interface ==> bad... --- Sources/Main.cpp | 10 -- Sources/base/guiX11.cpp | 222 ++++++++++++++++++++++++++++++++++++- Sources/base/guiX11.h | 3 + Sources/etk/etkSingleton.h | 70 ++++++++++++ Sources/etk/etkTypes.h | 14 +-- Sources/ewol.cpp | 12 +- Sources/ewol.h | 1 + Sources/ewolDebug.h | 4 +- Sources/ewolWidget.h | 10 +- Sources/ewolWindows.cpp | 26 +++++ Sources/ewolWindows.h | 55 +++++++++ 11 files changed, 389 insertions(+), 38 deletions(-) create mode 100644 Sources/etk/etkSingleton.h create mode 100644 Sources/ewolWindows.cpp create mode 100644 Sources/ewolWindows.h diff --git a/Sources/Main.cpp b/Sources/Main.cpp index 59a4f60c..4d24672d 100644 --- a/Sources/Main.cpp +++ b/Sources/Main.cpp @@ -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; diff --git a/Sources/base/guiX11.cpp b/Sources/base/guiX11.cpp index 56bf08fc..9fd3089c 100644 --- a/Sources/base/guiX11.cpp +++ b/Sources/base/guiX11.cpp @@ -24,25 +24,239 @@ #include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +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 ... "); + } } diff --git a/Sources/base/guiX11.h b/Sources/base/guiX11.h index 13cfd212..7f0ce0d0 100644 --- a/Sources/base/guiX11.h +++ b/Sources/base/guiX11.h @@ -27,12 +27,15 @@ #define __GUI_ABSTRACTION_H__ #include +#include namespace guiAbstraction { void Init(int32_t argc, char *argv[]); void Run(void); + void Stop(void); void UnInit(void); + void SetDisplayOnWindows(ewol::Windows & newOne); }; diff --git a/Sources/etk/etkSingleton.h b/Sources/etk/etkSingleton.h new file mode 100644 index 00000000..0c525049 --- /dev/null +++ b/Sources/etk/etkSingleton.h @@ -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 + 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 (_singleton)); + } + + static void Kill() + { + if (NULL != _singleton) + { + delete _singleton; + _singleton = NULL; + } + } + + private: + // Unique instance + static T *_singleton; + }; + + template + T *Singleton::_singleton = NULL; +} + +#endif + + diff --git a/Sources/etk/etkTypes.h b/Sources/etk/etkTypes.h index 4a49855e..8ebb2a29 100644 --- a/Sources/etk/etkTypes.h +++ b/Sources/etk/etkTypes.h @@ -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; } diff --git a/Sources/ewol.cpp b/Sources/ewol.cpp index 111b9a4e..db56fef3 100644 --- a/Sources/ewol.cpp +++ b/Sources/ewol.cpp @@ -22,17 +22,7 @@ ******************************************************************************* */ -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include -*/ + #include "ewol.h" // need to run xcompmgr to have transparency diff --git a/Sources/ewol.h b/Sources/ewol.h index 2a204fe7..5523b7b6 100644 --- a/Sources/ewol.h +++ b/Sources/ewol.h @@ -27,6 +27,7 @@ #define __EWOL_H__ #include +#include namespace ewol { void Init(int32_t argc, char *argv[]); diff --git a/Sources/ewolDebug.h b/Sources/ewolDebug.h index aaaaabc5..ffd053d7 100644 --- a/Sources/ewolDebug.h +++ b/Sources/ewolDebug.h @@ -22,8 +22,8 @@ ******************************************************************************* */ -#ifndef __ETK_DEBUG_INTERNAL_H__ -#define __ETK_DEBUG_INTERNAL_H__ +#ifndef __EWOL_DEBUG_H__ +#define __EWOL_DEBUG_H__ #include #include diff --git a/Sources/ewolWidget.h b/Sources/ewolWidget.h index bdcf0a0c..86f2e22f 100644 --- a/Sources/ewolWidget.h +++ b/Sources/ewolWidget.h @@ -22,13 +22,13 @@ ******************************************************************************* */ -#include -#include -#include - #ifndef __EWOL_WIDGET_H__ #define __EWOL_WIDGET_H__ +#include +#include +#include + 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 { diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp new file mode 100644 index 00000000..d69f309a --- /dev/null +++ b/Sources/ewolWindows.cpp @@ -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. + * + ******************************************************************************* + */ + + + diff --git a/Sources/ewolWindows.h b/Sources/ewolWindows.h new file mode 100644 index 00000000..278598e2 --- /dev/null +++ b/Sources/ewolWindows.h @@ -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 +#include +#include +#include +#include + +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 +