bindings/c,cpp,python: More support
authorJerome St-Louis <jerome@ecere.com>
Wed, 22 Jun 2016 07:25:11 +0000 (03:25 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 21 Nov 2016 14:18:58 +0000 (09:18 -0500)
- python: Support for callbacks, FontResource
- Added parameter to eC_init to specify whether loading Ecere
- This prevents two copies being loaded, which was breaking OpenGL fonts on GL driver class equality

bindings/c/eC.c
bindings/c/eC.h
bindings/c/ecere.c
bindings/c/ecere.h
bindings/cpp/ecere.hpp
bindings/cpp/samples/sample4.cpp
bindings/python/cffi-ecere.h
bindings/python/pyEcere.epj
bindings/python/pyEcere.py
bindings/python/samples/sample.py

index 6ee1cf9..0a4df94 100644 (file)
@@ -107,12 +107,12 @@ Method * method_Application_main;
 
 GlobalFunction * function_PrintLn;
 
-Application eC_init(bool guiApp, int argc, char * argv[])
+Application eC_init(bool loadEcere, bool guiApp, int argc, char * argv[])
 {
    Application app = eC_initApp(guiApp, argc, argv);
    if(app)
    {
-      Module module = Module_load(app, "ecereCOM", publicAccess);
+      Module module = Module_load(app, loadEcere ? "ecere" : "ecereCOM", publicAccess);
       app->_refCount++;
       if(module)
       {
index ae527cb..1f94a9a 100644 (file)
@@ -51,20 +51,20 @@ extern "C"
    typedef void * HINSTANCE;
    #define WINAPI __stdcall
    #define MAIN_DECLARATION int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, char * cmdLine, int show)
-   #define eC_init_CALL eC_init(true, 0, null)
+   #define eC_init_CALL eC_init(true, true, 0, null)
 #else
    #define MAIN_DECLARATION int main(int argc, char * argv[])
    #ifdef __cplusplus
       #if defined(__CONSOLE_APP__)
-         #define eC_init_CALL eC_init(false, null, null)
+         #define eC_init_CALL eC_init(true, false, null, null)
       #else
-         #define eC_init_CALL eC_init(true, null, null)
+         #define eC_init_CALL eC_init(true, true, null, null)
       #endif
    #else
       #if defined(__CONSOLE_APP__)
-         #define eC_init_CALL eC_init(false, argc, argv)
+         #define eC_init_CALL eC_init(true, false, argc, argv)
       #else
-         #define eC_init_CALL eC_init(true, argc, argv)
+         #define eC_init_CALL eC_init(true, true, argc, argv)
       #endif
    #endif
 #endif
@@ -644,6 +644,11 @@ struct ClassTemplateParameter
    ClassTemplateParameter * next;
    const char *name;
    TemplateParameterType type;
+   union
+   {
+      const char * dataTypeString;     // For expression
+      TemplateMemberType memberType;   // For identifier
+   };
    ClassTemplateArgument defaultArg;
    void *param;
 };
@@ -1082,7 +1087,7 @@ extern Method * method_Application_main;
 
 extern int Application_main_vTblID;
 
-Module eC_init(bool guiApp, int argc, char * argv[]);
+Module eC_init(bool loadEcere, bool guiApp, int argc, char * argv[]);
 
 #if defined(__cplusplus)
    #undef bool
index fe1b8b1..439edea 100644 (file)
@@ -12,6 +12,8 @@ Property * property_FontResource_faceName;
 Property * property_FontResource_size;
 Property * property_FontResource_bold;
 Property * property_FontResource_italic;
+Property * property_FontResource_outlineSize;
+Property * property_FontResource_outlineFade;
 
 void (* FontResource_set_faceName)(FontResource f, constString v);
 constString (* FontResource_get_faceName)(FontResource f);
@@ -19,6 +21,12 @@ constString (* FontResource_get_faceName)(FontResource f);
 void (* FontResource_set_size)(FontResource f, float v);
 float (* FontResource_get_size)(FontResource f);
 
+void (* FontResource_set_outlineSize)(FontResource f, float v);
+float (* FontResource_get_outlineSize)(FontResource f);
+
+void (* FontResource_set_outlineFade)(FontResource f, float v);
+float (* FontResource_get_outlineFade)(FontResource f);
+
 void (* FontResource_set_bold)(FontResource f, bool v);
 bool (* FontResource_get_bold)(FontResource f);
 
@@ -38,9 +46,11 @@ Property * property_Window_hasMinimize;
 Property * property_Window_hasMaximize;
 Property * property_Window_borderStyle;
 Property * property_Window_background;
+Property * property_Window_foreground;
 Property * property_Window_parent;
 Property * property_Window_position;
 Property * property_Window_font;
+Property * property_Window_displayDriver;
 
 Method * method_Window_modal;
 Method * method_Window_create;
@@ -72,6 +82,9 @@ Window (* Window_get_parent)(Window w);
 void (* Window_set_background)(Window w, Color v);
 Color (* Window_get_background)(Window w);
 
+void (* Window_set_foreground)(Window w, Color v);
+Color (* Window_get_foreground)(Window w);
+
 void (* Window_set_position)(Window w, const Point * v);
 void (* Window_get_position)(Window w, Point * v);
 
@@ -81,6 +94,9 @@ FontResource (* Window_get_font)(Window w);
 void (* Window_set_caption)(Window w, constString v);
 constString (* Window_get_caption)(Window w);
 
+void (* Window_set_displayDriver)(Window w, constString v);
+constString (* Window_get_displayDriver)(Window w);
+
 DialogResult (* Window_modal)(Window);
 
 bool (* Window_create)(Window);
@@ -148,6 +164,20 @@ Module ecere_init(Module fromModule)
             FontResource_set_italic = (void *)property_FontResource_italic->Set;
             FontResource_get_italic = (void *)property_FontResource_italic->Get;
          }
+
+         property_FontResource_outlineSize = Class_findProperty(class_FontResource, "outlineSize", module);
+         if(property_FontResource_outlineSize)
+         {
+            FontResource_set_outlineSize = (void *)property_FontResource_outlineSize->Set;
+            FontResource_get_outlineSize = (void *)property_FontResource_outlineSize->Get;
+         }
+
+         property_FontResource_outlineFade = Class_findProperty(class_FontResource, "outlineFade", module);
+         if(property_FontResource_outlineFade)
+         {
+            FontResource_set_outlineFade = (void *)property_FontResource_outlineFade->Set;
+            FontResource_get_outlineFade = (void *)property_FontResource_outlineFade->Get;
+         }
       }
 
       class_Window = eC_findClass(module, "Window");
@@ -168,6 +198,13 @@ Module ecere_init(Module fromModule)
          if(method_Window_onRedraw)
             Window_onRedraw_vTblID = method_Window_onRedraw->vid;
 
+         property_Window_displayDriver = Class_findProperty(class_Window, "displayDriver", module);
+         if(property_Window_displayDriver)
+         {
+            Window_set_displayDriver = (void *)property_Window_displayDriver->Set;
+            Window_get_displayDriver = (void *)property_Window_displayDriver->Get;
+         }
+
          property_Window_caption = Class_findProperty(class_Window, "caption", module);
          if(property_Window_caption)
          {
@@ -203,6 +240,13 @@ Module ecere_init(Module fromModule)
             Window_get_background = (void *)property_Window_background->Get;
          }
 
+         property_Window_foreground = Class_findProperty(class_Window, "foreground", module);
+         if(property_Window_foreground)
+         {
+            Window_set_foreground = (void *)property_Window_foreground->Set;
+            Window_get_foreground = (void *)property_Window_foreground->Get;
+         }
+
          property_Window_hasClose = Class_findProperty(class_Window, "hasClose", module);
          if(property_Window_hasClose)
          {
index ba85b74..92a493b 100644 (file)
@@ -72,18 +72,18 @@ extern "C"
 #define COLOR_SET_g(x, g)  (x) = ((Color)(x) & ~((Color)COLOR_g_MASK)) | (((Color)(g)) << COLOR_g_SHIFT)
 #define COLOR_SET_b(x, b)  (x) = ((Color)(x) & ~((Color)COLOR_b_MASK)) | (((Color)(b)) << COLOR_b_SHIFT)
 
-#define BORDERBITS_contour_mask  0x00000001
-#define BORDERBITS_contour_shift 0
-#define BORDERBITS_fixed_mask    0x00000002
-#define BORDERBITS_fixed_shift   1
-#define BORDERBITS_sizable_mask  0x00000004
-#define BORDERBITS_sizable_shift 2
-#define BORDERBITS_deep_mask     0x00000008
-#define BORDERBITS_deep__shift   3
-#define BORDERBITS_bevel_mask    0x00000010
-#define BORDERBITS_bevel_shift   4
-#define BORDERBITS_thin_mask     0x00000020
-#define BORDERBITS_thin_shift    5
+#define BORDERBITS_contour_MASK  0x00000001
+#define BORDERBITS_contour_SHIFT 0
+#define BORDERBITS_fixed_MASK    0x00000002
+#define BORDERBITS_fixed_SHIFT   1
+#define BORDERBITS_sizable_MASK  0x00000004
+#define BORDERBITS_sizable_SHIFT 2
+#define BORDERBITS_deep_MASK     0x00000008
+#define BORDERBITS_deep_SHIFT    3
+#define BORDERBITS_bevel_MASK    0x00000010
+#define BORDERBITS_bevel_SHIFT   4
+#define BORDERBITS_thin_MASK     0x00000020
+#define BORDERBITS_thin_SHIFT    5
 
 #define BORDERBITS_contour(x)    ((((BorderBits)(x)) & BORDERBITS_contour_MASK) >> BORDERBITS_contours_SHIFT)
 #define BORDERBITS_fixed(x)      ((((BorderBits)(x)) & BORDERBITS_fixed_MASK) >> BORDERBITS_fixed_SHIFT)
@@ -140,6 +140,8 @@ typedef Instance FontResource;
 // Properties
 extern Property * property_FontResource_faceName;
 extern Property * property_FontResource_size;
+extern Property * property_FontResource_outlineSize;
+extern Property * property_FontResource_outlineFade;
 
 extern void (* FontResource_set_faceName)(FontResource f, constString v);
 extern constString (* FontResource_get_faceName)(FontResource f);
@@ -147,6 +149,12 @@ extern constString (* FontResource_get_faceName)(FontResource f);
 extern void (* FontResource_set_size)(FontResource f, float v);
 extern float (* FontResource_get_size)(FontResource f);
 
+extern void (* FontResource_set_outlineSize)(FontResource f, float v);
+extern float (* FontResource_get_outlineSize)(FontResource f);
+
+extern void (* FontResource_set_outlineFade)(FontResource f, float v);
+extern float (* FontResource_get_outlineFade)(FontResource f);
+
 extern void (* FontResource_set_bold)(FontResource f, bool v);
 extern bool (* FontResource_get_bold)(FontResource f);
 
@@ -191,13 +199,13 @@ enum enum_BorderStyle
 #endif
 {
    none,
-   contour      = BORDERBITS_contour_mask,
-   fixed        = BORDERBITS_fixed_mask | contour,
-   sizable      = BORDERBITS_sizable_mask | fixed,
-   thin         = BORDERBITS_thin_mask | fixed,
-   sizableThin  = BORDERBITS_sizable_mask | thin,
-   deep         = BORDERBITS_deep_mask,
-   bevel        = BORDERBITS_bevel_mask,
+   contour      = BORDERBITS_contour_MASK,
+   fixed        = BORDERBITS_fixed_MASK | contour,
+   sizable      = BORDERBITS_sizable_MASK | fixed,
+   thin         = BORDERBITS_thin_MASK | fixed,
+   sizableThin  = BORDERBITS_sizable_MASK | thin,
+   deep         = BORDERBITS_deep_MASK,
+   bevel        = BORDERBITS_bevel_MASK,
    sizableDeep  = sizable|deep,
    sizableBevel = sizable|bevel,
    fixedDeep    = fixed|deep,
@@ -248,6 +256,9 @@ extern Window (* Window_get_parent)(Window w);
 extern void (* Window_set_background)(Window w, Color v);
 extern Color (* Window_get_background)(Window w);
 
+extern void (* Window_set_foreground)(Window w, Color v);
+extern Color (* Window_get_foreground)(Window w);
+
 extern void (* Window_set_position)(Window w, const Point * v);
 extern void (* Window_get_position)(Window w, Point * v);
 
@@ -257,6 +268,9 @@ extern FontResource (* Window_get_font)(Window w);
 extern void (* Window_set_caption)(Window w, constString v);
 extern constString (* Window_get_caption)(Window w);
 
+extern void (* Window_set_displayDriver)(Window w, constString v);
+extern constString (* Window_get_displayDriver)(Window w);
+
 // Methods
 extern DialogResult (* Window_modal)(Window);
 
index 9612533..09b88b4 100644 (file)
@@ -125,6 +125,10 @@ public:
       set(constString, caption, Window, Window_set_caption(self ? self->impl : null, v))
       get(constString, caption, Window, return Window_get_caption(self ? self->impl : null))
    );
+   property(displayDriver,
+      set(constString, displayDriver, Window, Window_set_displayDriver(self ? self->impl : null, v))
+      get(constString, displayDriver, Window, return Window_get_displayDriver(self ? self->impl : null))
+   );
    property(font,
       set(const FontResource &, font, Window, Window_set_font(self ? self->impl : null, v.impl))
       get(FontResource &, font, Window,
index cd5993e..e9e5d00 100644 (file)
@@ -11,6 +11,7 @@ public:
    {
       caption = $("Sample App using Ecere Toolkit/C++ Bindings");
       borderStyle = sizable;
+      displayDriver = "OpenGL";
       clientSize = { 640, 480 };
       hasClose = true;
       hasMaximize = true;
index c9f19e3..b99fe6a 100644 (file)
-typedef struct class_members_Instance * Instance;
-typedef Instance Module;
-typedef Module Application;
 typedef struct Class Class;
 typedef uint32_t bool;
+typedef uint32_t uint32;
 typedef uint32_t Color;
+typedef uint32 BorderBits;
+
+enum enum_BorderStyle
+{
+   none,
+   contour      = 0x00000001,
+   fixed        = 0x00000003,
+   sizable      = 0x00000007,
+   thin         = 0x00000023,
+   sizableThin  = 0x00000027,
+   deep         = 0x00000008,
+   bevel        = 0x00000010,
+   sizableDeep  = 0x0000000F,
+   sizableBevel = 0x00000017,
+   fixedDeep    = 0x0000000B,
+   fixedBevel   = 0x00000013,
+   deepContour  = 0x00000009
+};
+typedef BorderBits BorderStyle;
+
+struct class_members_Instance
+{
+   void **_vTbl;
+   Class * _class;
+   int _refCount;
+};
+
+typedef struct class_members_Instance * Instance;
+
+typedef Instance Module;
+typedef Module Application;
+
+enum AccessMode
+{
+   defaultAccess,
+   publicAccess,
+   privateAccess,
+   staticAccess,
+   baseSystemAccess
+};
+typedef enum AccessMode AccessMode;
+
+enum ClassType
+{
+   normalClass,
+   structClass,
+   bitClass,
+   unitClass,
+   enumClass,
+   noHeadClass
+};
+typedef enum ClassType ClassType;
 
 typedef char * String;
 typedef const char * constString;
 
-//struct Class { ...; };
+struct Class
+{
+   Class * prev;
+   Class * next;
+   const char *name;
+   int offset;
+   int structSize;
+   void **_vTbl;
+   int vTblSize;
+   bool (*Constructor)(void *);
+   void (*Destructor)(void *);
+
+   int offsetClass;
+   int sizeClass;
+   Class * base;
+   ...;
+   /*BinaryTree methods;
+   BinaryTree members;
+   BinaryTree prop;
+   OldList membersAndProperties;
+   BinaryTree classProperties;
+   OldList derivatives;
+   */
+   int memberID;
+   int startMemberID;
+   //ClassType type;
+   Module module;
+   //NameSpace * nameSpace;
+   const char *dataTypeString;
+   //Type dataType;
+   int typeSize;
+   int defaultAlignment;
+   //void (*Initialize)();
+   int memberOffset;
+   //OldList selfWatchers;
+   const char *designerClass;
+   bool noExpansion;
+   const char *defaultProperty;
+   bool comRedefinition;
+   int count;
+   int isRemote;
+   bool internalDecl;
+   void *data;
+   bool computeSize;
+   short structAlignment;
+   short pointerAlignment;
+   int destructionWatchOffset;
+   bool fixed;
+   //OldList delayedCPValues;
+   //AccessMode inheritanceAccess;
+   const char *fullName;
+   void *symbol;
+   /*OldList conversions;
+   OldList templateParams;
+   ClassTemplateArgument * templateArgs;*/
+   Class * templateClass;
+   //OldList templatized;
+   int numParams;
+   bool isInstanceClass;
+   bool byValueSystemClass;
+   void * bindingsClass;
+};
+
+constString getTranslatedString(constString name, constString string, constString stringAndContext);
+
+Class * eC_registerClass(ClassType type, const char *name, const char *baseName, int size, int sizeClass,
+   bool (*Constructor)(void *), void (*Destructor)(void *), Module module, AccessMode declMode, AccessMode inheritanceAccess);
 
 Instance Instance_new(Class * _class);
 Instance Instance_newEx(Class * _class, bool bindingsAlloc);
+void Instance_setMethod(Instance instance, constString name, void *function);
 
 void Instance_evolve(Instance *instancePtr, Class * _class);
 
-Application eC_init(bool guiApp, int argc, char * argv[]);
+Application eC_init(bool loadEcere, bool guiApp, int argc, char * argv[]);
 Module ecere_init(Module fromModule);
 
 void Application_main(Application app);
@@ -27,37 +144,108 @@ extern Class * class_int;
 extern Class * class_double;
 extern Class * class_String;
 extern Class * class_Window;
+extern Class * class_Button;
 extern Class * class_GuiApplication;
 
+extern Class * class_FontResource;
+
 #define false 0
 #define true 1
 
 typedef struct Size Size;
 struct Size { int w, h; };
 
+typedef struct Point Point;
+struct Point { int x, y; };
+
+typedef Instance Surface;
+
+extern void (* Surface_writeTextf)(Surface s, int x, int y, const char * format, ...);
+
 typedef Instance FontResource;
 
+extern void (* FontResource_set_faceName)(FontResource f, constString v);
+extern constString (* FontResource_get_faceName)(FontResource f);
+
+extern void (* FontResource_set_size)(FontResource f, float v);
+extern float (* FontResource_get_size)(FontResource f);
+
+extern void (* FontResource_set_bold)(FontResource f, bool v);
+extern bool (* FontResource_get_bold)(FontResource f);
+
+extern void (* FontResource_set_italic)(FontResource f, bool v);
+extern bool (* FontResource_get_italic)(FontResource f);
+
+extern void (* FontResource_set_outlineSize)(FontResource f, float v);
+extern float (* FontResource_get_outlineSize)(FontResource f);
+
+extern void (* FontResource_set_outlineFade)(FontResource f, float v);
+extern float (* FontResource_get_outlineFade)(FontResource f);
+
 typedef Instance Window;
+typedef Window Button;
+typedef Window MessageBox;
 typedef int64_t DialogResult;
+typedef uint32 Modifiers;
 
 extern DialogResult (* Window_modal)(Window);
 extern bool (* Window_create)(Window);
-extern void (* FontResource_set_size)(FontResource f, float v);
+
+extern void (* Window_set_parent)(Window w, Window v);
+extern Window (* Window_get_parent)(Window w);
+
+extern void (* Window_set_displayDriver)(Window w, constString v);
+extern constString (* Window_get_displayDriver)(Window w);
 
 extern void (* Window_set_size)(Window w, const Size * v);
+extern void (* Window_get_size)(Window w, Size * v);
+
+extern void (* Window_set_font)(Window w, const FontResource font);
+extern FontResource (* Window_get_font)(Window w);
+
+extern void (* Window_set_position)(Window w, const Point * v);
+extern void (* Window_get_position)(Window w, Point * v);
 
 extern void (* Window_set_hasClose)(Window w, bool hasClose);
 extern bool (* Window_get_hasClose)(Window w);
 
+extern void (* Window_set_hasMaximize)(Window w, bool hasMaximize);
+extern bool (* Window_get_hasMaximize)(Window w);
+
+extern void (* Window_set_hasMinimize)(Window w, bool hasMinimize);
+extern bool (* Window_get_hasMinimize)(Window w);
+
 extern void (* Window_set_caption)(Window w, constString caption);
 extern constString (* Window_get_caption)(Window w);
 
+extern void (* Window_set_borderStyle)(Window w, BorderStyle borderStyle);
+extern BorderStyle (* Window_get_borderStyle)(Window w);
+
 extern void (* Window_set_background)(Window w, Color background);
 extern Color (* Window_get_background)(Window w);
 
+extern void (* Window_set_foreground)(Window w, Color v);
+extern Color (* Window_get_foreground)(Window w);
+
+extern void (* MessageBox_set_contents)(MessageBox m, constString contents);
+extern constString (* MessageBox_get_contents)(MessageBox m);
+
 #define COLOR_r_MASK       0x00FF0000
 #define COLOR_r_SHIFT      16
 #define COLOR_g_MASK       0x0000FF00
 #define COLOR_g_SHIFT      8
 #define COLOR_b_MASK       0x000000FF
 #define COLOR_b_SHIFT      0
+
+#define BORDERBITS_contour_MASK  0x00000001
+#define BORDERBITS_contour_SHIFT 0
+#define BORDERBITS_fixed_MASK    0x00000002
+#define BORDERBITS_fixed_SHIFT   1
+#define BORDERBITS_sizable_MASK  0x00000004
+#define BORDERBITS_sizable_SHIFT 2
+#define BORDERBITS_deep_MASK     0x00000008
+#define BORDERBITS_deep_SHIFT    3
+#define BORDERBITS_bevel_MASK    0x00000010
+#define BORDERBITS_bevel_SHIFT   4
+#define BORDERBITS_thin_MASK     0x00000020
+#define BORDERBITS_thin_SHIFT    5
index 2bc3bb6..3f52603 100644 (file)
@@ -10,7 +10,7 @@
       "TargetFileName" : "_pyEcere",
       "Libraries" : [
          "ecere",
-         "python3"
+         "python34"
       ]
    },
    "Configurations" : [
index e1d04f4..08895c0 100644 (file)
@@ -1,5 +1,14 @@
-import sys
 from _pyEcere import *
+import sys
+import inspect
+import os
+
+app = ffi.NULL
+
+def I18N(s):
+   return ffi.string(lib.getTranslatedString(os.path.splitext(os.path.basename(inspect.getfile(sys._getframe(1))))[0].encode('utf8'), s.encode('utf8'), ffi.NULL        )).decode('utf8')
+def I18NC(s, c):
+   return ffi.string(lib.getTranslatedString(os.path.splitext(os.path.basename(inspect.getfile(sys._getframe(1))))[0].encode('utf8'), s.encode('utf8'), c.encode('utf8'))).decode('utf8')
 
 def convertTypedArgs(args):
    cargs = ()
@@ -11,9 +20,67 @@ def convertTypedArgs(args):
 
 def printLn(*args): lib.PrintLn(*convertTypedArgs(args))
 
+class BorderBits:
+   def __init__(self, this = None, contour = False, fixed = False, sizable = False, deep = False, bevel = False, thin = False):
+      if this is not None:
+         self.this = this
+      else:
+         self.this = (
+            (contour << lib.BORDERBITS_contour_SHIFT) |
+            (fixed   << lib.BORDERBITS_fixed_SHIFT)   |
+            (sizable << lib.BORDERBITS_sizable_SHIFT) |
+            (deep    << lib.BORDERBITS_deep_SHIFT)    |
+            (bevel   << lib.BORDERBITS_bevel_SHIFT)   |
+            (thin    << lib.BORDERBITS_thin_SHIFT) )
+
+   @property
+   def contour(self): return ((((self.value)) & lib.BORDERBITS_contour_MASK) >> lib.BORDERBITS_contour_SHIFT)
+   @contour.setter
+   def contour(self, value): self.value = ((self.value) & ~(lib.BORDERBITS_contour_MASK)) | (((value)) << lib.BORDERBITS_contour_SHIFT)
+
+   @property
+   def fixed(self): return ((((self.value)) & lib.BORDERBITS_fixed_MASK) >> lib.BORDERBITS_fixed_SHIFT)
+   @fixed.setter
+   def fixed(self, value): self.value = ((self.value) & ~(lib.BORDERBITS_fixed_MASK)) | (((value)) << lib.BORDERBITS_fixed_SHIFT)
+
+   @property
+   def sizable(self): return ((((self.value)) & lib.BORDERBITS_sizable_MASK) >> lib.BORDERBITS_sizable_SHIFT)
+   @sizable.setter
+   def sizable(self, value): self.value = ((self.value) & ~(lib.BORDERBITS_sizable_MASK)) | (((value)) << lib.BORDERBITS_sizable_SHIFT)
+
+   @property
+   def deep(self): return ((((self.value)) & lib.BORDERBITS_deep_MASK) >> lib.BORDERBITS_deep_SHIFT)
+   @deep.setter
+   def deep(self, value): self.value = ((self.value) & ~(lib.BORDERBITS_deep_MASK)) | (((value)) << lib.BORDERBITS_deep_SHIFT)
+
+   @property
+   def bevel(self): return ((((self.value)) & lib.BORDERBITS_bevel_MASK) >> lib.BORDERBITS_bevel_SHIFT)
+   @bevel.setter
+   def bevel(self, value): self.value = ((self.value) & ~(lib.BORDERBITS_bevel_MASK)) | (((value)) << lib.BORDERBITS_bevel_SHIFT)
+
+   @property
+   def thin(self): return ((((self.value)) & lib.BORDERBITS_thin_MASK) >> lib.BORDERBITS_thin_SHIFT)
+   @thin.setter
+   def thin(self, value): self.value = ((self.value) & ~(lib.BORDERBITS_thin_MASK)) | (((value)) << lib.BORDERBITS_thin_SHIFT)
+
+class BorderStyle(BorderBits):
+   none         = BorderBits(this = lib.none)
+   contour      = BorderBits(this = lib.contour)
+   fixed        = BorderBits(this = lib.fixed)
+   sizable      = BorderBits(this = lib.sizable)
+   thin         = BorderBits(this = lib.thin)
+   sizableThin  = BorderBits(this = lib.sizableThin)
+   deep         = BorderBits(this = lib.deep)
+   bevel        = BorderBits(this = lib.bevel)
+   sizableDeep  = BorderBits(this = lib.sizableDeep)
+   sizableBevel = BorderBits(this = lib.sizableBevel)
+   fixedDeep    = BorderBits(this = lib.fixedDeep)
+   fixedBevel   = BorderBits(this = lib.fixedBevel)
+   deepContour  = BorderBits(this = lib.deepContour)
+
 class Color:
    def __init__(self, r = 0, g = 0, b = 0):
-      self.value = ((((r)) << lib.COLOR_r_SHIFT) | ((g) << lib.COLOR_g_SHIFT) | ((b)) << lib.COLOR_b_SHIFT)
+      self.value = (r << lib.COLOR_r_SHIFT) | (g << lib.COLOR_g_SHIFT) | (b << lib.COLOR_b_SHIFT)
 
    @property
    def r(self): return ((((self.value)) & lib.COLOR_r_MASK) >> lib.COLOR_r_SHIFT)
@@ -30,19 +97,75 @@ class Color:
    @b.setter
    def b(self, value): self.value = ((self.value) & ~(lib.COLOR_b_MASK)) | (((value)) << lib.COLOR_b_SHIFT)
 
+class FontResource:
+   def __init__(self, faceName = None, size = None, outlineSize = None, outlineFade = None):
+      self.this = lib.Instance_new(lib.class_FontResource)
+      if faceName is not None:      self.faceName = faceName
+      if size is not None:          self.size = size
+      if outlineSize is not None:   self.outlineSize = outlineSize
+      if outlineFade is not None:   self.outlineFade = outlineFade
+
+   @property
+   def faceName(self): return ffi.string(lib.FontResource_get_faceName(self.this)).decode('utf8')
+   @faceName.setter
+   def faceName(self, value): lib.FontResource_set_faceName(self.this, value.encode('utf8'))
+
+   @property
+   def size(self): return lib.FontResource_get_size(self.this)
+   @size.setter
+   def size(self, value): lib.FontResource_set_size(self.this, value)
+
+   @property
+   def outlineSize(self): return lib.FontResource_get_outlineSize(self.this)
+   @outlineSize.setter
+   def outlineSize(self, value): lib.FontResource_set_outlineSize(self.this, value)
+
+   @property
+   def outlineFade(self): return lib.FontResource_get_outlineFade(self.this)
+   @outlineFade.setter
+   def outlineFade(self, value): lib.FontResource_set_outlineFade(self.this, value)
+
+   @property
+   def size(self): return lib.FontResource_get_size(self.this)
+   @size.setter
+   def size(self, value): lib.FontResource_set_size(self.this, value)
+
 class Size:
    def __init__(self, w = 0, h = 0):
       self.this = ffi.new("Size *")
       self.this.w = w
       self.this.h = h
 
-class Instance(object):
+class Point:
+   def __init__(self, x = 0, y = 0):
+      self.this = ffi.new("Point *")
+      self.this.x = x
+      self.this.y = y
+
+class Instance:
    def __init__(self): self.this = ffi.NULL
 
+@ffi.callback("void(Instance)")
+def cb_Instance_destructor(w):
+   instance = ffi.from_handle(ffi.cast("void **", ffi.cast("char *", w) + w._class.offset)[0])
+   #print("Instance destroyed now!")
+   instance.handle = 0
+
+class Surface(Instance):
+   def __init__(self, this = None):
+      if this is not None:
+         self.this = this
+
+   def writeTextf(self, x, y, format):
+      lib.Surface_writeTextf(self.this, x, y, format.encode('utf8'))
+
 class Application(Instance):
    def __init__(self):
-      self.this = lib.eC_init(True, len(sys.argv), [ffi.new("char[]", i.encode('utf8')) for i in sys.argv])
+      self.this = lib.eC_init(True, True, len(sys.argv), [ffi.new("char[]", i.encode('utf8')) for i in sys.argv])
       lib.ecere_init(self.this)
+      Window.pyClass_Window         = lib.eC_registerClass(lib.normalClass, "PyWindow"    .encode('utf8'), "Window"     .encode('utf8'), 8, 0, ffi.NULL, ffi.cast("void(*)(void *)", cb_Instance_destructor), self.this, lib.publicAccess, lib.publicAccess);
+      Button.pyClass_Button         = lib.eC_registerClass(lib.normalClass, "PyButton"    .encode('utf8'), "Button"     .encode('utf8'), 8, 0, ffi.NULL, ffi.cast("void(*)(void *)", cb_Instance_destructor), self.this, lib.publicAccess, lib.publicAccess);
+      MessageBox.pyClass_MessageBox = lib.eC_registerClass(lib.normalClass, "PyMessageBox".encode('utf8'), "MessageBox" .encode('utf8'), 8, 0, ffi.NULL, ffi.cast("void(*)(void *)", cb_Instance_destructor), self.this, lib.publicAccess, lib.publicAccess);
 
    def main(self):
       lib.Application_main(self.this)
@@ -50,35 +173,148 @@ class Application(Instance):
 class GuiApplication(Application):
    def __init__(self):
       Application.__init__(self)
-      rApp = ffi.new("Instance *"); rApp[0] = self.this; lib.Instance_evolve(rApp, lib.class_GuiApplication); self.this = rApp[0]
+      rApp = ffi.new("Instance *", self.this); lib.Instance_evolve(rApp, lib.class_GuiApplication); self.this = rApp[0]
+
+@ffi.callback("void(Window, Surface)")
+def cb_Window_onRedraw(w, s):
+   window = ffi.from_handle(ffi.cast("void **", ffi.cast("char *", w) + w._class.offset)[0])
+   surface = Surface(this = s)
+   window.fn_onRedraw(window, surface)
 
 class Window(Instance):
-   def __init__(self, caption = None, hasClose = None, clientSize = None, background = None):
-      self.this = lib.Instance_new(lib.class_Window)
-      if caption != None:      self.caption = caption
-      if hasClose != None:     self.hasClose = hasClose
-      if clientSize != None:   self.clientSize = clientSize
-      if background != None:   self.background = background
+   def __init__(self,
+      parent = None, caption = None, displayDriver = None,
+      hasClose = None, hasMinimize = None, hasMaximize = None,
+      borderStyle = None, clientSize = None, font = None, background = None, foreground = None, position = None):
+
+      self.this = lib.Instance_new(Window.pyClass_Window)
+      self.handle = ffi.new_handle(self)
+      ffi.cast("void **", ffi.cast("char *", self.this) + self.this._class.offset)[0] = self.handle
+
+      if parent is not None:        self.parent = parent
+      if caption is not None:       self.caption = caption
+      if displayDriver is not None: self.displayDriver = displayDriver
+      if hasClose is not None:      self.hasClose = hasClose
+      if hasMinimize is not None:   self.hasMinimize = hasMinimize
+      if hasMaximize is not None:   self.hasMaximize = hasMaximize
+      if borderStyle is not None:   self.borderStyle = borderStyle
+      if clientSize is not None:    self.clientSize = clientSize
+      if font is not None:          self.font = font
+      if position is not None:      self.position = position
+      if background is not None:    self.background = background
+      if foreground is not None:    self.foreground = foreground
+
+   #def __del__(self):
+      #print("Window object is gone!")
 
    def create(self): lib.Window_create(self.this)
    def modal(self): lib.Window_modal(self.this)
 
    @property
+   def parent(self): value = lib.Window_get_parent(self.this); return Window(this = value)
+   @parent.setter
+   def parent(self, value): lib.Window_set_parent(self.this, value.this)
+
+   @property
+   def position(self): value = Point(); lib.Window_get_position(self.this, value.this); return value
+   @position.setter
+   def position(self, value): lib.Window_set_position(self.this, value.this)
+
+   @property
    def clientSize(self): value = Size(); lib.Window_get_size(self.this, value.this); return value
    @clientSize.setter
    def clientSize(self, value): lib.Window_set_size(self.this, value.this)
 
    @property
-   def hasClose(self): value = ffi.new("bool *"); lib.Window_get_hasClose(self.this, value); return value
+   def hasClose(self): value = lib.Window_get_hasClose(self.this); return value
    @hasClose.setter
    def hasClose(self, value): lib.Window_set_hasClose(self.this, value)
 
    @property
+   def hasMaximize(self): value = lib.Window_get_hasMaximize(self.this); return value
+   @hasMaximize.setter
+   def hasMaximize(self, value): lib.Window_set_hasMaximize(self.this, value)
+
+   @property
+   def hasMinimize(self): value = lib.Window_get_hasMinimize(self.this); return value
+   @hasMinimize.setter
+   def hasMinimize(self, value): lib.Window_set_hasMinimize(self.this, value)
+
+   @property
+   def borderStyle(self): value = lib.Window_get_borderStyle(self.this); return BorderStyle(this = value)
+   @borderStyle.setter
+   def borderStyle(self, value): lib.Window_set_borderStyle(self.this, value.this)
+
+   @property
    def caption(self): value = lib.Window_get_caption(self.this); return ffi.string(value).decode('utf8')
    @caption.setter
    def caption(self, value): lib.Window_set_caption(self.this, value.encode('utf8'))
 
    @property
+   def displayDriver(self): value = lib.Window_get_displayDriver(self.this); return ffi.string(value).decode('utf8')
+   @displayDriver.setter
+   def displayDriver(self, value): lib.Window_set_displayDriver(self.this, value.encode('utf8'))
+
+   @property
+   def foreground(self): value = Color(); lib.Window_get_foreground(self.this, value.this); return value
+   @foreground.setter
+   def foreground(self, value): lib.Window_set_foreground(self.this, value.value)
+
+   @property
    def background(self): value = Color(); lib.Window_get_background(self.this, value.this); return value
    @background.setter
    def background(self, value): lib.Window_set_background(self.this, value.value)
+
+   @property
+   def font(self): value = lib.Window_get_font(self.this); return FontResource(this = value)
+   @font.setter
+   def font(self, value): lib.Window_set_font(self.this, value.this)
+
+   @property
+   def onRedraw(self): return self.fn_onRedraw
+   @onRedraw.setter
+   def onRedraw(self, value):
+      self.fn_onRedraw = value
+      lib.Instance_setMethod(self.this, "OnRedraw".encode('utf8'), cb_Window_onRedraw);
+
+@ffi.callback("bool(Window, Button, int, int, Modifiers)")
+def cb_Button_notifyClicked(m, b, x, y, mods):
+   button = ffi.from_handle(ffi.cast("void **", ffi.cast("char *", b) + b._class.offset)[0])
+   master = ffi.from_handle(ffi.cast("void **", ffi.cast("char *", m) + m._class.offset)[0])
+   button.fn_notifyClicked(master, button, x, y, mods)
+   return True
+
+class Button(Window):
+   def __init__(self, parent = None, caption = None, position = None, font = None, notifyClicked = None):
+      self.this = lib.Instance_new(Button.pyClass_Button)
+      self.handle = ffi.new_handle(self)
+      ffi.cast("void **", ffi.cast("char *", self.this) + self.this._class.offset)[0] = self.handle
+
+      if parent is not None:        self.parent = parent
+      if caption is not None:       self.caption = caption
+      if position is not None:      self.position = position
+      if font is not None:          self.font = font
+      if notifyClicked is not None: self.notifyClicked = notifyClicked
+
+   @property
+   def notifyClicked(self): return self.fn_notifyClicked
+   @notifyClicked.setter
+   def notifyClicked(self, value):
+      self.fn_notifyClicked = value
+      lib.Instance_setMethod(self.this, "NotifyClicked".encode('utf8'), cb_Button_notifyClicked);
+
+class MessageBox(Window):
+   def __init__(self, parent = None, caption = None, contents = None, position = None):
+      self.this = lib.Instance_new(MessageBox.pyClass_MessageBox)
+      self.handle = ffi.new_handle(self)
+      ffi.cast("void **", ffi.cast("char *", self.this) + self.this._class.offset)[0] = self.handle
+
+      if parent is not None:       self.parent = parent
+      if caption is not None:      self.caption = caption
+      if contents is not None:     self.contents = contents
+      if position is not None:     self.position = position
+
+   @property
+   def contents(self): value = lib.MessageBox_get_contents(self.this); return ffi.string(value).decode('utf8')
+   @contents.setter
+   def contents(self, value): lib.MessageBox_set_contents(self.this, value.encode('utf8'))
index d6249a2..a9bba60 100644 (file)
@@ -4,15 +4,43 @@ app = GuiApplication()
 printLn("Testing Variadic Functions!\n", 1, " + ", 2, " = ", 1+2)
 printLn("Pi = ", 3.141592653589)
 
-Window(
-   caption = "Hello, Python!!",
-   hasClose = True,
-   clientSize = Size(640, 480),
-   background = Color(b = 255))
+class MyForm(Window):
+   def __init__(self):
+      Window.__init__(self,
+         displayDriver = "OpenGL",
+         caption = I18N("Hello, Python!!"),
+         hasClose = True,
+         hasMaximize = True,
+         hasMinimize = True,
+         borderStyle = BorderStyle.sizable,
+         clientSize = Size(640, 480),
+         background = Color(b = 255),
+         foreground = Color(r = 235, b = 115, g = 200),
+         font = FontResource("Merriweather", 30, outlineSize = 4.0, outlineFade = 0.2) )
+
+      def myOnRedraw(self, surface):
+         surface.writeTextf(20, 20, I18N("Writing Stuff on the wall!!"))
+      self.onRedraw = myOnRedraw
+
+      def button1Clicked(self, button, x, y, mods):
+         printLn("I got pushed! (master is ", self.caption, ")")
+         self.background = Color(b = 255, g = 192, r = 64)
+         MessageBox(caption = I18N("Hello, Python!"), contents = I18N("Python is pretty nifty.")).modal()
+         return True
+
+      self.button1 = Button(
+            parent = self,
+            caption = "Push It!",
+            position = Point(80,80),
+            font = FontResource("Merriweather", 30),
+            notifyClicked = button1Clicked )
+
+MyForm()
+
 Window(
    caption = "Bindings are cool, 詠春 too!",
    hasClose = True,
    clientSize = Size(320, 200),
-   background = Color(255))
+   background = Color(255) )
 
 app.main()