Introduce a weak notion of inheritance
This commit is contained in:
parent
75e3a2dfaf
commit
76e44f261d
@ -31,6 +31,7 @@
|
|||||||
#ifndef GTOOLKIT_GTOOLKIT_H
|
#ifndef GTOOLKIT_GTOOLKIT_H
|
||||||
# define GTOOLKIT_GTOOLKIT_H
|
# define GTOOLKIT_GTOOLKIT_H
|
||||||
|
|
||||||
|
# include "GToolkit/GWidget.h"
|
||||||
# include "GToolkit/GWindow.h"
|
# include "GToolkit/GWindow.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,5 +35,10 @@
|
|||||||
/* GWidget */
|
/* GWidget */
|
||||||
/* types */
|
/* types */
|
||||||
typedef struct _GWidget GWidget;
|
typedef struct _GWidget GWidget;
|
||||||
|
# define GWIDGET(gwidget) (GWidget *)(gwidget)
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
void gwidget_show(GWidget * gwidget);
|
||||||
|
|
||||||
#endif /* !GTOOLKIT_GWIDGET_H */
|
#endif /* !GTOOLKIT_GWIDGET_H */
|
||||||
|
@ -55,6 +55,5 @@ void gwindow_set_title(GWindow * gwindow, char const * title);
|
|||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
void gwindow_resize(GWindow * gwindow, int width, int height);
|
void gwindow_resize(GWindow * gwindow, int width, int height);
|
||||||
void gwindow_show(GWindow * gwindow);
|
|
||||||
|
|
||||||
#endif /* !GTOOLKIT_GWINDOW_H */
|
#endif /* !GTOOLKIT_GWINDOW_H */
|
||||||
|
20
src/common.h
20
src/common.h
@ -34,8 +34,19 @@
|
|||||||
# include <X11/Xlib.h>
|
# include <X11/Xlib.h>
|
||||||
# include <GL/glu.h>
|
# include <GL/glu.h>
|
||||||
# include <GL/glx.h>
|
# include <GL/glx.h>
|
||||||
|
# include <GToolkit.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* types */
|
||||||
|
typedef enum _GWidgetHandler
|
||||||
|
{
|
||||||
|
GWIDGET_HANDLER_SHOW = 0
|
||||||
|
} GWidgetHandler;
|
||||||
|
# define GWIDGET_HANDLER_LAST GWIDGET_HANDLER_SHOW
|
||||||
|
# define GWIDGET_HANDLER_COUNT (GWIDGET_HANDLER_LAST + 1)
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* GToolkit */
|
/* GToolkit */
|
||||||
/* accessors */
|
/* accessors */
|
||||||
Display * gtoolkit_get_display(void);
|
Display * gtoolkit_get_display(void);
|
||||||
@ -47,6 +58,15 @@ void gtoolkit_register_window(GWindow * gwindow);
|
|||||||
void gtoolkit_deregister_window(GWindow * gwindow);
|
void gtoolkit_deregister_window(GWindow * gwindow);
|
||||||
|
|
||||||
|
|
||||||
|
/* GWidget */
|
||||||
|
GWidget * gwidget_new(void);
|
||||||
|
void gwidget_delete(GWidget * gwidget);
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
void gwidget_set_handler(GWidget * gwidget, GWidgetHandler handler, ...);
|
||||||
|
void gwidget_set_self(GWidget * gwidget, void * self);
|
||||||
|
|
||||||
|
|
||||||
/* GWindow */
|
/* GWindow */
|
||||||
/* accessors */
|
/* accessors */
|
||||||
Window gwindow_get_window(GWindow * gwindow);
|
Window gwindow_get_window(GWindow * gwindow);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* Copyright (c) 2006-2020 Pierre Pronchery <khorben@defora.org> */
|
/* Copyright (c) 2020 Pierre Pronchery <khorben@defora.org> */
|
||||||
/* This file is part of DeforaOS Graphics GToolkit */
|
/* This file is part of DeforaOS Graphics GToolkit */
|
||||||
/* All rights reserved.
|
/* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -28,13 +28,81 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef GTOOLKIT_GWIDGET_H
|
#include <stdarg.h>
|
||||||
# define GTOOLKIT_GWIDGET_H
|
#include <stdlib.h>
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
/* GWidget */
|
/* GWidget */
|
||||||
/* public */
|
/* private */
|
||||||
/* types */
|
/* types */
|
||||||
GWidget * widget;
|
typedef void (*GWidgetHandlerSelf)(void * self);
|
||||||
|
|
||||||
#endif /* !GTOOLKIT_GWIDGET_H */
|
struct _GWidget
|
||||||
|
{
|
||||||
|
GWidget * gwidget;
|
||||||
|
|
||||||
|
/* GWidget */
|
||||||
|
void * self;
|
||||||
|
|
||||||
|
/* handlers */
|
||||||
|
GWidgetHandlerSelf handler_show;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* functions */
|
||||||
|
/* gwidget_new */
|
||||||
|
GWidget * gwidget_new(void)
|
||||||
|
{
|
||||||
|
GWidget * gwidget;
|
||||||
|
|
||||||
|
if((gwidget = malloc(sizeof(*gwidget))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
gwidget->gwidget = gwidget;
|
||||||
|
gwidget->self = NULL;
|
||||||
|
gwidget->handler_show = NULL;
|
||||||
|
return gwidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* gwidget_delete */
|
||||||
|
void gwidget_delete(GWidget * gwidget)
|
||||||
|
{
|
||||||
|
free(gwidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* accessors */
|
||||||
|
/* gwidget_set_handler */
|
||||||
|
void gwidget_set_handler(GWidget * gwidget, GWidgetHandler handler, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, handler);
|
||||||
|
switch(handler)
|
||||||
|
{
|
||||||
|
case GWIDGET_HANDLER_SHOW:
|
||||||
|
gwidget->handler_show = va_arg(ap, GWidgetHandlerSelf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* gwidget_set_self */
|
||||||
|
void gwidget_set_self(GWidget * gwidget, void * self)
|
||||||
|
{
|
||||||
|
gwidget->self = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
/* gwidget_show */
|
||||||
|
void gwidget_show(GWidget * gwidget)
|
||||||
|
{
|
||||||
|
if(gwidget->gwidget != gwidget)
|
||||||
|
gwidget = gwidget->gwidget;
|
||||||
|
if(gwidget->handler_show != NULL)
|
||||||
|
gwidget->handler_show(gwidget->self);
|
||||||
|
}
|
@ -32,6 +32,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "GToolkit/GWidget.h"
|
#include "GToolkit/GWidget.h"
|
||||||
#include "GToolkit/GWindow.h"
|
#include "GToolkit/GWindow.h"
|
||||||
|
#include "GToolkit.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +41,7 @@
|
|||||||
/* types */
|
/* types */
|
||||||
struct _GWindow
|
struct _GWindow
|
||||||
{
|
{
|
||||||
#include "gwidget.h"
|
GWidget * gwidget;
|
||||||
|
|
||||||
/* GWindow */
|
/* GWindow */
|
||||||
char * title;
|
char * title;
|
||||||
@ -56,6 +57,10 @@ struct _GWindow
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes */
|
||||||
|
static void _gwindow_show(GWindow * gwindow);
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* public */
|
||||||
/* functions */
|
/* functions */
|
||||||
/* gwindow_new */
|
/* gwindow_new */
|
||||||
@ -69,6 +74,14 @@ GWindow * gwindow_new(void)
|
|||||||
|
|
||||||
if((gwindow = malloc(sizeof(*gwindow))) == NULL)
|
if((gwindow = malloc(sizeof(*gwindow))) == NULL)
|
||||||
return NULL; /* FIXME report */
|
return NULL; /* FIXME report */
|
||||||
|
if((gwindow->gwidget = gwidget_new()) == NULL)
|
||||||
|
{
|
||||||
|
free(gwindow);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
gwidget_set_self(gwindow->gwidget, gwindow);
|
||||||
|
gwidget_set_handler(gwindow->gwidget, GWIDGET_HANDLER_SHOW,
|
||||||
|
_gwindow_show);
|
||||||
gwindow->title = NULL;
|
gwindow->title = NULL;
|
||||||
gwindow->decorated = true;
|
gwindow->decorated = true;
|
||||||
gwindow->fullscreen = false;
|
gwindow->fullscreen = false;
|
||||||
@ -216,8 +229,10 @@ void gwindow_resize(GWindow * gwindow, int width, int height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
/* functions */
|
||||||
/* gwindow_show */
|
/* gwindow_show */
|
||||||
void gwindow_show(GWindow * gwindow)
|
static void _gwindow_show(GWindow * gwindow)
|
||||||
/* FIXME accept flags (focus...) */
|
/* FIXME accept flags (focus...) */
|
||||||
{
|
{
|
||||||
Display * display;
|
Display * display;
|
||||||
|
@ -2,7 +2,7 @@ targets=libGToolkit
|
|||||||
cppflags_force=-I ../include
|
cppflags_force=-I ../include
|
||||||
cflags_force=-W
|
cflags_force=-W
|
||||||
cflags=-Wall -fPIC -g -O2 -pedantic
|
cflags=-Wall -fPIC -g -O2 -pedantic
|
||||||
dist=Makefile,common.h,gwidget.h
|
dist=Makefile,common.h
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
[libGToolkit]
|
[libGToolkit]
|
||||||
@ -10,11 +10,14 @@ type=library
|
|||||||
cflags=`pkg-config --cflags gl`
|
cflags=`pkg-config --cflags gl`
|
||||||
ldflags=`pkg-config --libs gl`
|
ldflags=`pkg-config --libs gl`
|
||||||
install=$(PREFIX)/lib
|
install=$(PREFIX)/lib
|
||||||
sources=gtoolkit.c,gwindow.c
|
sources=gtoolkit.c,gwidget.c,gwindow.c
|
||||||
|
|
||||||
#sources
|
#sources
|
||||||
[gtoolkit.c]
|
[gtoolkit.c]
|
||||||
depends=common.h
|
depends=common.h
|
||||||
|
|
||||||
|
[gwidget.c]
|
||||||
|
depends=common.h
|
||||||
|
|
||||||
[gwindow.c]
|
[gwindow.c]
|
||||||
depends=common.h
|
depends=common.h
|
||||||
|
@ -40,7 +40,7 @@ int main(void)
|
|||||||
return 2;
|
return 2;
|
||||||
window = gwindow_new();
|
window = gwindow_new();
|
||||||
gwindow_set_title(window, "Test window");
|
gwindow_set_title(window, "Test window");
|
||||||
gwindow_show(window);
|
gwidget_show(GWIDGET(window));
|
||||||
gtoolkit_main();
|
gtoolkit_main();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user