From 9f2efd4771cfcfb1537e7d262e9538eef6518522 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 7 Oct 2025 11:02:38 +0000 Subject: [PATCH] oo binding git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@202 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 17 +++++----- include/MwOO/Base.h | 17 ++++++++++ include/MwOO/Widget/Button.h | 12 +++++++ include/MwOO/Widget/Frame.h | 12 +++++++ include/MwOO/Widget/Image.h | 12 +++++++ include/MwOO/Widget/Menu.h | 12 +++++++ include/MwOO/Widget/OpenGL.h | 12 +++++++ include/MwOO/Widget/ScrollBar.h | 12 +++++++ include/MwOO/Widget/SubMenu.h | 12 +++++++ include/MwOO/Widget/Vulkan.h | 12 +++++++ include/MwOO/Widget/Window.h | 12 +++++++ oosrc/base.cc | 10 ++++++ oosrc/deps.mk | 2 ++ oosrc/widget/button.cc | 7 +++++ oosrc/widget/frame.cc | 7 +++++ oosrc/widget/image.cc | 7 +++++ oosrc/widget/menu.cc | 7 +++++ oosrc/widget/opengl.cc | 7 +++++ oosrc/widget/scrollbar.cc | 7 +++++ oosrc/widget/submenu.cc | 7 +++++ oosrc/widget/vulkan.cc | 7 +++++ oosrc/widget/window.cc | 7 +++++ src/widget/scrollbar.c | 4 +-- tools/doc.pl | 2 +- tools/genoo.pl | 55 +++++++++++++++++++++++++++++++++ 25 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 include/MwOO/Base.h create mode 100644 include/MwOO/Widget/Button.h create mode 100644 include/MwOO/Widget/Frame.h create mode 100644 include/MwOO/Widget/Image.h create mode 100644 include/MwOO/Widget/Menu.h create mode 100644 include/MwOO/Widget/OpenGL.h create mode 100644 include/MwOO/Widget/ScrollBar.h create mode 100644 include/MwOO/Widget/SubMenu.h create mode 100644 include/MwOO/Widget/Vulkan.h create mode 100644 include/MwOO/Widget/Window.h create mode 100644 oosrc/base.cc create mode 100644 oosrc/deps.mk create mode 100644 oosrc/widget/button.cc create mode 100644 oosrc/widget/frame.cc create mode 100644 oosrc/widget/image.cc create mode 100644 oosrc/widget/menu.cc create mode 100644 oosrc/widget/opengl.cc create mode 100644 oosrc/widget/scrollbar.cc create mode 100644 oosrc/widget/submenu.cc create mode 100644 oosrc/widget/vulkan.cc create mode 100644 oosrc/widget/window.cc create mode 100755 tools/genoo.pl diff --git a/GNUmakefile b/GNUmakefile index c7e9ace..e8e0e3c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -31,11 +31,12 @@ L_OBJS += src/external/ds.o src/external/image.o L_OBJS += src/widget/window.o src/widget/button.o src/widget/frame.o src/widget/menu.o src/widget/submenu.o src/widget/image.o src/widget/scrollbar.o L_OBJS += src/cursor/default.o src/cursor/cross.o -OOL_CFLAGS = $(CFLAGS) -fPIC -OOL_LDFLAGS = $(LDFLAGS) -OOL_LIBS = $(LIBS) +OOL_CFLAGS = $(DEPINC) $(CFLAGS) -std=c++98 -fPIC -D_MILSKO +OOL_LDFLAGS = $(LDFLAGS) -L src +OOL_LIBS = $(LIBS) -lMw -OOL_OBJS = src/core.o +OOL_OBJS = oosrc/base.o +include oosrc/deps.mk E_CFLAGS = $(CFLAGS) E_LDFLAGS = $(LDFLAGS) -Lsrc @@ -136,11 +137,13 @@ EXAMPLES = examples/example$(EXEC) examples/rotate$(EXEC) examples/image$(EXEC) ifeq ($(OPENGL),1) L_OBJS += src/widget/opengl.o +OOL_OBJS += oosrc/widget/opengl.o EXAMPLES += examples/gltriangle$(EXEC) examples/glgears$(EXEC) examples/glboing$(EXEC) examples/glcube$(EXEC) endif ifeq ($(VULKAN),1) L_OBJS += src/widget/vulkan.o +OOL_OBJS += oosrc/widget/vulkan.o EXAMPLES += examples/vulkan$(EXEC) endif @@ -152,14 +155,14 @@ oolib: src/$(LIB)MwOO$(SO) examples: $(EXAMPLES) format: - clang-format --verbose -i `find src include examples tools "(" -name "*.c" -or -name "*.h" ")" -and -not -name "stb_*.h"` + clang-format --verbose -i `find oosrc src include examples tools "(" -name "*.c" -or -name "*.h" ")" -and -not -name "stb_*.h"` perltidy -b -bext='/' --paren-tightness=2 `find tools -name "*.pl"` src/$(LIB)Mw$(SO): $(L_OBJS) $(CC) $(L_LDFLAGS) $(SHARED) -o $@ $^ $(L_LIBS) -src/$(LIB)MwOO$(SO): $(OOL_OBJS) src/$(LIB)Mw$(SO) - $(CC) $(OOL_LDFLAGS) $(SHARED) -o $@ $^ $(OOL_LIBS) +src/$(LIB)MwOO$(SO): $(OOL_OBJS) lib + $(CC) $(OOL_LDFLAGS) $(SHARED) -o $@ $(OOL_OBJS) $(OOL_LIBS) examples/gl%$(EXEC): examples/gl%.o src/$(LIB)Mw$(SO) $(CC) $(E_LDFLAGS) -o $@ $< $(E_LIBS) $(GL) diff --git a/include/MwOO/Base.h b/include/MwOO/Base.h new file mode 100644 index 0000000..9ea8f86 --- /dev/null +++ b/include/MwOO/Base.h @@ -0,0 +1,17 @@ +/* $Id$ */ +#ifndef __MWOO_BASE_H__ +#define __MWOO_BASE_H__ + +#include + +class MwOOWidget { + protected: + MwClass widget_class = NULL; + MwWidget widget; + + public: + MwOOWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + ~MwOOWidget(void); +}; + +#endif diff --git a/include/MwOO/Widget/Button.h b/include/MwOO/Widget/Button.h new file mode 100644 index 0000000..3408d21 --- /dev/null +++ b/include/MwOO/Widget/Button.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_BUTTON_H__ +#define __MWOO_WIDGET_BUTTON_H__ + +#include + +class MwOOButtonWidget : public MwOOWidget { + public: + MwOOButtonWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/Frame.h b/include/MwOO/Widget/Frame.h new file mode 100644 index 0000000..a28c027 --- /dev/null +++ b/include/MwOO/Widget/Frame.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_FRAME_H__ +#define __MWOO_WIDGET_FRAME_H__ + +#include + +class MwOOFrameWidget : public MwOOWidget { + public: + MwOOFrameWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/Image.h b/include/MwOO/Widget/Image.h new file mode 100644 index 0000000..dd8c4db --- /dev/null +++ b/include/MwOO/Widget/Image.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_IMAGE_H__ +#define __MWOO_WIDGET_IMAGE_H__ + +#include + +class MwOOImageWidget : public MwOOWidget { + public: + MwOOImageWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/Menu.h b/include/MwOO/Widget/Menu.h new file mode 100644 index 0000000..9cb8855 --- /dev/null +++ b/include/MwOO/Widget/Menu.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_MENU_H__ +#define __MWOO_WIDGET_MENU_H__ + +#include + +class MwOOMenuWidget : public MwOOWidget { + public: + MwOOMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/OpenGL.h b/include/MwOO/Widget/OpenGL.h new file mode 100644 index 0000000..c82d6fe --- /dev/null +++ b/include/MwOO/Widget/OpenGL.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_OPENGL_H__ +#define __MWOO_WIDGET_OPENGL_H__ + +#include + +class MwOOOpenGLWidget : public MwOOWidget { + public: + MwOOOpenGLWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/ScrollBar.h b/include/MwOO/Widget/ScrollBar.h new file mode 100644 index 0000000..c443d68 --- /dev/null +++ b/include/MwOO/Widget/ScrollBar.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_SCROLLBAR_H__ +#define __MWOO_WIDGET_SCROLLBAR_H__ + +#include + +class MwOOScrollBarWidget : public MwOOWidget { + public: + MwOOScrollBarWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/SubMenu.h b/include/MwOO/Widget/SubMenu.h new file mode 100644 index 0000000..7aa2e4b --- /dev/null +++ b/include/MwOO/Widget/SubMenu.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_SUBMENU_H__ +#define __MWOO_WIDGET_SUBMENU_H__ + +#include + +class MwOOSubMenuWidget : public MwOOWidget { + public: + MwOOSubMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/Vulkan.h b/include/MwOO/Widget/Vulkan.h new file mode 100644 index 0000000..7ae31c2 --- /dev/null +++ b/include/MwOO/Widget/Vulkan.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_VULKAN_H__ +#define __MWOO_WIDGET_VULKAN_H__ + +#include + +class MwOOVulkanWidget : public MwOOWidget { + public: + MwOOVulkanWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/include/MwOO/Widget/Window.h b/include/MwOO/Widget/Window.h new file mode 100644 index 0000000..02da074 --- /dev/null +++ b/include/MwOO/Widget/Window.h @@ -0,0 +1,12 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_WINDOW_H__ +#define __MWOO_WIDGET_WINDOW_H__ + +#include + +class MwOOWindowWidget : public MwOOWidget { + public: + MwOOWindowWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); +}; + +#endif diff --git a/oosrc/base.cc b/oosrc/base.cc new file mode 100644 index 0000000..d7a8e19 --- /dev/null +++ b/oosrc/base.cc @@ -0,0 +1,10 @@ +/* $Id$ */ +#include + +MwOOWidget::MwOOWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h){ + this->widget = MwCreateWidget(this->widget_class, name, parent->widget, x, y, w, h); +} + +MwOOWidget::~MwOOWidget(void){ + MwDestroyWidget(this->widget); +} diff --git a/oosrc/deps.mk b/oosrc/deps.mk new file mode 100644 index 0000000..1c7af34 --- /dev/null +++ b/oosrc/deps.mk @@ -0,0 +1,2 @@ +# $Id$ +OOL_OBJS += oosrc/widget/button.o oosrc/widget/frame.o oosrc/widget/image.o oosrc/widget/menu.o oosrc/widget/scrollbar.o oosrc/widget/submenu.o oosrc/widget/window.o diff --git a/oosrc/widget/button.cc b/oosrc/widget/button.cc new file mode 100644 index 0000000..522e568 --- /dev/null +++ b/oosrc/widget/button.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOButtonWidget::MwOOButtonWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwButtonClass; +} diff --git a/oosrc/widget/frame.cc b/oosrc/widget/frame.cc new file mode 100644 index 0000000..e16d084 --- /dev/null +++ b/oosrc/widget/frame.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOFrameWidget::MwOOFrameWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwFrameClass; +} diff --git a/oosrc/widget/image.cc b/oosrc/widget/image.cc new file mode 100644 index 0000000..f27754c --- /dev/null +++ b/oosrc/widget/image.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOImageWidget::MwOOImageWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwImageClass; +} diff --git a/oosrc/widget/menu.cc b/oosrc/widget/menu.cc new file mode 100644 index 0000000..6545c10 --- /dev/null +++ b/oosrc/widget/menu.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOMenuWidget::MwOOMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwMenuClass; +} diff --git a/oosrc/widget/opengl.cc b/oosrc/widget/opengl.cc new file mode 100644 index 0000000..6c9e46c --- /dev/null +++ b/oosrc/widget/opengl.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOOpenGLWidget::MwOOOpenGLWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwOpenGLClass; +} diff --git a/oosrc/widget/scrollbar.cc b/oosrc/widget/scrollbar.cc new file mode 100644 index 0000000..850bf3a --- /dev/null +++ b/oosrc/widget/scrollbar.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOScrollBarWidget::MwOOScrollBarWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwScrollBarClass; +} diff --git a/oosrc/widget/submenu.cc b/oosrc/widget/submenu.cc new file mode 100644 index 0000000..e47875e --- /dev/null +++ b/oosrc/widget/submenu.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOSubMenuWidget::MwOOSubMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwSubMenuClass; +} diff --git a/oosrc/widget/vulkan.cc b/oosrc/widget/vulkan.cc new file mode 100644 index 0000000..089b57a --- /dev/null +++ b/oosrc/widget/vulkan.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOVulkanWidget::MwOOVulkanWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwVulkanClass; +} diff --git a/oosrc/widget/window.cc b/oosrc/widget/window.cc new file mode 100644 index 0000000..64d78db --- /dev/null +++ b/oosrc/widget/window.cc @@ -0,0 +1,7 @@ +/* $Id$ */ +#include +#include + +MwOOWindowWidget::MwOOWindowWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){ + this->widget_class = MwWindowClass; +} diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index b749c83..224e787 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -142,9 +142,9 @@ static void mouse_move(MwWidget handle) { int max = MwGetInteger(handle, MwNmaxValue); if(or == MwVERTICAL) { - l = handle->mouse_point.y + scr->pos; + l = handle->mouse_point.y + scr->pos; } else if(or == MwHORIZONTAL) { - l = handle->mouse_point.x + scr->pos; + l = handle->mouse_point.x + scr->pos; } len = l / len; diff --git a/tools/doc.pl b/tools/doc.pl index bd4c766..f4341b4 100755 --- a/tools/doc.pl +++ b/tools/doc.pl @@ -89,7 +89,7 @@ sub scan_dir { print(STDERR "Scanning $path\n"); my @paths = sort(readdir($dh)); foreach my $p (@paths) { - if ($p eq '.' || $p eq '..') { + if ($p eq '.' || $p eq '..' || $p eq 'MwOO') { next; } scan_dir($first, $path . "/" . $p); diff --git a/tools/genoo.pl b/tools/genoo.pl new file mode 100755 index 0000000..a491cae --- /dev/null +++ b/tools/genoo.pl @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +# $Id$ + +my $objs = ""; + +opendir(DIR, "include/Mw/Widget"); +my @files = readdir(DIR); +foreach my $f (@files) { + if ($f eq '.' || $f eq '..') { + next; + } + + $f =~ /^(.+)\.h$/; + + my $name = $1; + + open(OUT, ">", "include/MwOO/Widget/$f"); + print(OUT "/* \$Id\$ */\n"); + print(OUT "#ifndef __MWOO_WIDGET_" . uc($name) . "_H__\n"); + print(OUT "#define __MWOO_WIDGET_" . uc($name) . "_H__\n"); + print(OUT "\n"); + print(OUT "#include \n"); + print(OUT "\n"); + print(OUT "class MwOO${name}Widget : public MwOOWidget {\n"); + print(OUT "public:\n"); + print(OUT +" MwOO${name}Widget(const char* name, MwOOWidget* parent, int x, int y, int w, int h);\n" + ); + print(OUT "};\n"); + print(OUT "\n"); + print(OUT "#endif\n"); + close(OUT); + + open(OUT, ">", "oosrc/widget/" . lc($name) . ".cc"); + print(OUT "/* \$Id\$ */\n"); + print(OUT "#include \n"); + print(OUT "#include \n"); + print(OUT "\n"); + print(OUT +"MwOO${name}Widget::MwOO${name}Widget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(name, parent, x, y, w, h){\n" + ); + print(OUT " this->widget_class = Mw${name}Class;\n"); + print(OUT "}\n"); + close(OUT); + + if (!($name eq 'Vulkan' || $name eq 'OpenGL')) { + $objs = $objs . " oosrc/widget/" . lc($name) . ".o"; + } +} +closedir(DIR); + +open(OUT, ">", "oosrc/deps.mk"); +print(OUT "# \$Id\$\n"); +print(OUT "OOL_OBJS +=$objs\n"); +close(OUT);