From 7dda33ee1cd1bd6359dd2dfa93d038890aebc077 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 7 Oct 2025 14:20:45 +0000 Subject: [PATCH] things git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@204 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 2 +- include/MwOO/Base.h | 24 +++++++- include/MwOO/Widget/Button.h | 6 +- include/MwOO/Widget/Frame.h | 6 +- include/MwOO/Widget/Image.h | 6 +- include/MwOO/Widget/Menu.h | 6 +- include/MwOO/Widget/OpenGL.h | 6 +- include/MwOO/Widget/ScrollBar.h | 6 +- include/MwOO/Widget/SubMenu.h | 6 +- include/MwOO/Widget/Vulkan.h | 6 +- include/MwOO/Widget/Window.h | 6 +- oosrc/base.cc | 39 +++++++++++- oosrc/widget/button.cc | 2 +- oosrc/widget/frame.cc | 2 +- oosrc/widget/image.cc | 2 +- oosrc/widget/menu.cc | 2 +- oosrc/widget/opengl.cc | 2 +- oosrc/widget/scrollbar.cc | 2 +- oosrc/widget/submenu.cc | 2 +- oosrc/widget/vulkan.cc | 2 +- oosrc/widget/window.cc | 2 +- tools/genoo.pl | 106 ++++++++++++++++++++++++++++++-- 22 files changed, 204 insertions(+), 39 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index e8e0e3c..0d71300 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -161,7 +161,7 @@ format: src/$(LIB)Mw$(SO): $(L_OBJS) $(CC) $(L_LDFLAGS) $(SHARED) -o $@ $^ $(L_LIBS) -src/$(LIB)MwOO$(SO): $(OOL_OBJS) lib +src/$(LIB)MwOO$(SO): $(OOL_OBJS) src/$(LIB)Mw$(SO) $(CC) $(OOL_LDFLAGS) $(SHARED) -o $@ $(OOL_OBJS) $(OOL_LIBS) examples/gl%$(EXEC): examples/gl%.o src/$(LIB)Mw$(SO) diff --git a/include/MwOO/Base.h b/include/MwOO/Base.h index 33d21a2..90f3a44 100644 --- a/include/MwOO/Base.h +++ b/include/MwOO/Base.h @@ -4,13 +4,31 @@ #include -class MwOOWidget { +#define MwOODeclare(name, parent_class) \ + public: \ + name(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : parent_class(widget_name, parent, x, y, w, h) {} + +namespace MwOO { +class Base { protected: MwWidget widget; + private: + void SetHandler(void); + public: - MwOOWidget(MwClass widget_class, const char* name, MwOOWidget* parent, int x, int y, int w, int h); - ~MwOOWidget(void); + void Loop(void); + /* BEGIN AUTOGENERATE */ + virtual void OnActivate(void*) {}; + virtual void OnResize(void*) {}; + virtual void OnTick(void*) {}; + virtual void OnMenu(void*) {}; + + /* END AUTOGENERATE */ + + Base(MwClass widget_class, const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + ~Base(void); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/Button.h b/include/MwOO/Widget/Button.h index 3408d21..b75653e 100644 --- a/include/MwOO/Widget/Button.h +++ b/include/MwOO/Widget/Button.h @@ -4,9 +4,11 @@ #include -class MwOOButtonWidget : public MwOOWidget { +namespace MwOO { +class Button : public MwOO::Base { public: - MwOOButtonWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + Button(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/Frame.h b/include/MwOO/Widget/Frame.h index a28c027..f5d7057 100644 --- a/include/MwOO/Widget/Frame.h +++ b/include/MwOO/Widget/Frame.h @@ -4,9 +4,11 @@ #include -class MwOOFrameWidget : public MwOOWidget { +namespace MwOO { +class Frame : public MwOO::Base { public: - MwOOFrameWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + Frame(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/Image.h b/include/MwOO/Widget/Image.h index dd8c4db..8bf33f3 100644 --- a/include/MwOO/Widget/Image.h +++ b/include/MwOO/Widget/Image.h @@ -4,9 +4,11 @@ #include -class MwOOImageWidget : public MwOOWidget { +namespace MwOO { +class Image : public MwOO::Base { public: - MwOOImageWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + Image(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/Menu.h b/include/MwOO/Widget/Menu.h index 9cb8855..5496526 100644 --- a/include/MwOO/Widget/Menu.h +++ b/include/MwOO/Widget/Menu.h @@ -4,9 +4,11 @@ #include -class MwOOMenuWidget : public MwOOWidget { +namespace MwOO { +class Menu : public MwOO::Base { public: - MwOOMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + Menu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/OpenGL.h b/include/MwOO/Widget/OpenGL.h index c82d6fe..dfa1641 100644 --- a/include/MwOO/Widget/OpenGL.h +++ b/include/MwOO/Widget/OpenGL.h @@ -4,9 +4,11 @@ #include -class MwOOOpenGLWidget : public MwOOWidget { +namespace MwOO { +class OpenGL : public MwOO::Base { public: - MwOOOpenGLWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + OpenGL(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/ScrollBar.h b/include/MwOO/Widget/ScrollBar.h index c443d68..842f645 100644 --- a/include/MwOO/Widget/ScrollBar.h +++ b/include/MwOO/Widget/ScrollBar.h @@ -4,9 +4,11 @@ #include -class MwOOScrollBarWidget : public MwOOWidget { +namespace MwOO { +class ScrollBar : public MwOO::Base { public: - MwOOScrollBarWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + ScrollBar(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/SubMenu.h b/include/MwOO/Widget/SubMenu.h index 7aa2e4b..8574f00 100644 --- a/include/MwOO/Widget/SubMenu.h +++ b/include/MwOO/Widget/SubMenu.h @@ -4,9 +4,11 @@ #include -class MwOOSubMenuWidget : public MwOOWidget { +namespace MwOO { +class SubMenu : public MwOO::Base { public: - MwOOSubMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + SubMenu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/Vulkan.h b/include/MwOO/Widget/Vulkan.h index 7ae31c2..f86869c 100644 --- a/include/MwOO/Widget/Vulkan.h +++ b/include/MwOO/Widget/Vulkan.h @@ -4,9 +4,11 @@ #include -class MwOOVulkanWidget : public MwOOWidget { +namespace MwOO { +class Vulkan : public MwOO::Base { public: - MwOOVulkanWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + Vulkan(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/include/MwOO/Widget/Window.h b/include/MwOO/Widget/Window.h index 02da074..0d07a21 100644 --- a/include/MwOO/Widget/Window.h +++ b/include/MwOO/Widget/Window.h @@ -4,9 +4,11 @@ #include -class MwOOWindowWidget : public MwOOWidget { +namespace MwOO { +class Window : public MwOO::Base { public: - MwOOWindowWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h); + Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); }; +} // namespace MwOO #endif diff --git a/oosrc/base.cc b/oosrc/base.cc index 17a46e2..e446883 100644 --- a/oosrc/base.cc +++ b/oosrc/base.cc @@ -1,10 +1,43 @@ /* $Id$ */ #include -MwOOWidget::MwOOWidget(MwClass widget_class, const char* name, MwOOWidget* parent, int x, int y, int w, int h){ - this->widget = MwCreateWidget(widget_class, name, parent->widget, x, y, w, h); +MwOO::Base::Base(MwClass widget_class, const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h){ + this->widget = MwCreateWidget(widget_class, widget_name, parent == NULL ? NULL : parent->widget, x, y, w, h); + if(this->widget != NULL){ + this->SetHandler(); + } } -MwOOWidget::~MwOOWidget(void){ +MwOO::Base::~Base(void){ MwDestroyWidget(this->widget); } + +void MwOO::Base::Loop(void){ + MwLoop(this->widget); +} + +/* BEGIN AUTOGENERATE */ +static void __OnActivate(MwWidget widget, void* user, void* call){ + MwOO::Base* c = (MwOO::Base*)user; + c->OnActivate(call); +} +static void __OnResize(MwWidget widget, void* user, void* call){ + MwOO::Base* c = (MwOO::Base*)user; + c->OnResize(call); +} +static void __OnTick(MwWidget widget, void* user, void* call){ + MwOO::Base* c = (MwOO::Base*)user; + c->OnTick(call); +} +static void __OnMenu(MwWidget widget, void* user, void* call){ + MwOO::Base* c = (MwOO::Base*)user; + c->OnMenu(call); +} + +void MwOO::Base::SetHandler(void){ + MwAddUserHandler(this->widget, MwNactivateHandler, __OnActivate, this); + MwAddUserHandler(this->widget, MwNresizeHandler, __OnResize, this); + MwAddUserHandler(this->widget, MwNtickHandler, __OnTick, this); + MwAddUserHandler(this->widget, MwNmenuHandler, __OnMenu, this); +} +/* END AUTOGENERATE */ diff --git a/oosrc/widget/button.cc b/oosrc/widget/button.cc index 620bdb6..f408b05 100644 --- a/oosrc/widget/button.cc +++ b/oosrc/widget/button.cc @@ -2,5 +2,5 @@ #include #include -MwOOButtonWidget::MwOOButtonWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwButtonClass, name, parent, x, y, w, h){ +MwOO::Button::Button(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwButtonClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/frame.cc b/oosrc/widget/frame.cc index 59011f4..7124f6d 100644 --- a/oosrc/widget/frame.cc +++ b/oosrc/widget/frame.cc @@ -2,5 +2,5 @@ #include #include -MwOOFrameWidget::MwOOFrameWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwFrameClass, name, parent, x, y, w, h){ +MwOO::Frame::Frame(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwFrameClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/image.cc b/oosrc/widget/image.cc index d8769dc..54806b9 100644 --- a/oosrc/widget/image.cc +++ b/oosrc/widget/image.cc @@ -2,5 +2,5 @@ #include #include -MwOOImageWidget::MwOOImageWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwImageClass, name, parent, x, y, w, h){ +MwOO::Image::Image(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwImageClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/menu.cc b/oosrc/widget/menu.cc index 79383ba..61f8d1c 100644 --- a/oosrc/widget/menu.cc +++ b/oosrc/widget/menu.cc @@ -2,5 +2,5 @@ #include #include -MwOOMenuWidget::MwOOMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwMenuClass, name, parent, x, y, w, h){ +MwOO::Menu::Menu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwMenuClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/opengl.cc b/oosrc/widget/opengl.cc index cfc72b4..af7f100 100644 --- a/oosrc/widget/opengl.cc +++ b/oosrc/widget/opengl.cc @@ -2,5 +2,5 @@ #include #include -MwOOOpenGLWidget::MwOOOpenGLWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwOpenGLClass, name, parent, x, y, w, h){ +MwOO::OpenGL::OpenGL(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwOpenGLClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/scrollbar.cc b/oosrc/widget/scrollbar.cc index 26ec47c..993d2b3 100644 --- a/oosrc/widget/scrollbar.cc +++ b/oosrc/widget/scrollbar.cc @@ -2,5 +2,5 @@ #include #include -MwOOScrollBarWidget::MwOOScrollBarWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwScrollBarClass, name, parent, x, y, w, h){ +MwOO::ScrollBar::ScrollBar(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwScrollBarClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/submenu.cc b/oosrc/widget/submenu.cc index 3afa3c7..38def23 100644 --- a/oosrc/widget/submenu.cc +++ b/oosrc/widget/submenu.cc @@ -2,5 +2,5 @@ #include #include -MwOOSubMenuWidget::MwOOSubMenuWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwSubMenuClass, name, parent, x, y, w, h){ +MwOO::SubMenu::SubMenu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwSubMenuClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/vulkan.cc b/oosrc/widget/vulkan.cc index b1801e7..a9d5055 100644 --- a/oosrc/widget/vulkan.cc +++ b/oosrc/widget/vulkan.cc @@ -2,5 +2,5 @@ #include #include -MwOOVulkanWidget::MwOOVulkanWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwVulkanClass, name, parent, x, y, w, h){ +MwOO::Vulkan::Vulkan(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwVulkanClass, widget_name, parent, x, y, w, h){ } diff --git a/oosrc/widget/window.cc b/oosrc/widget/window.cc index 08e996b..b283d70 100644 --- a/oosrc/widget/window.cc +++ b/oosrc/widget/window.cc @@ -2,5 +2,5 @@ #include #include -MwOOWindowWidget::MwOOWindowWidget(const char* name, MwOOWidget* parent, int x, int y, int w, int h) : MwOOWidget(MwWindowClass, name, parent, x, y, w, h){ +MwOO::Window::Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwWindowClass, widget_name, parent, x, y, w, h){ } diff --git a/tools/genoo.pl b/tools/genoo.pl index 60d610c..2bedbf7 100755 --- a/tools/genoo.pl +++ b/tools/genoo.pl @@ -1,8 +1,28 @@ #!/usr/bin/env perl # $Id$ +use Config::Tiny; + +my $conf = Config::Tiny->read("resource/widget.ini"); + my $objs = ""; +my $decl = ""; +my @calls = (); +open(IN, "<", "include/Mw/StringDefs.h"); +while (my $hl = ) { + $hl =~ s/\r?\n$//; + if ($hl =~ /^#define[ \t]+([^ ]+)[ \t]+"C(.+)"$/) { + my $name = "On" . uc(substr($2, 0, 1)) . substr($2, 1); + my @c = ($1, $name); + + $decl = $decl . " virtual void " . $name . "(void*){};\n"; + + push(@calls, [@c]); + } +} +close(HIN); + opendir(DIR, "include/Mw/Widget"); my @files = readdir(DIR); foreach my $f (@files) { @@ -21,12 +41,14 @@ foreach my $f (@files) { 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 "namespace MwOO {\n"); + print(OUT " class ${name} : public MwOO::Base {\n"); + print(OUT " public:\n"); print(OUT -" MwOO${name}Widget(const char* name, MwOOWidget* parent, int x, int y, int w, int h);\n" +" ${name}(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h);\n" ); - print(OUT "};\n"); + print(OUT " };\n"); + print(OUT "}\n"); print(OUT "\n"); print(OUT "#endif\n"); close(OUT); @@ -37,7 +59,7 @@ foreach my $f (@files) { 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(Mw${name}Class, name, parent, x, y, w, h){\n" +"MwOO::${name}::${name}(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(Mw${name}Class, widget_name, parent, x, y, w, h){\n" ); print(OUT "}\n"); close(OUT); @@ -52,3 +74,77 @@ open(OUT, ">", "oosrc/deps.mk"); print(OUT "# \$Id\$\n"); print(OUT "OOL_OBJS +=$objs\n"); close(OUT); + +my $base_h = ""; +my $skip = 0; + +open(IN, "<", "include/MwOO/Base.h"); +while (my $l = ) { + $l =~ s/\r?\n$//; + if ($l =~ /BEGIN AUTOGENERATE/) { + $base_h = $base_h . "/* BEGIN AUTOGENERATE */\n"; + $skip = 1; + $base_h = $base_h . $decl . "\n"; + } + elsif ($l =~ /END AUTOGENERATE/) { + $base_h = $base_h . "/* END AUTOGENERATE */\n"; + $skip = 0; + } + elsif (!$skip) { + $base_h = $base_h . $l . "\n"; + } +} +close(IN); + +open(OUT, ">", "include/MwOO/Base.h"); +print(OUT "$base_h"); +close(OUT); + +my $base_c = ""; +my $skip = 0; + +open(IN, "<", "oosrc/base.cc"); +while (my $l = ) { + $l =~ s/\r?\n$//; + if ($l =~ /BEGIN AUTOGENERATE/) { + $base_c = $base_c . "/* BEGIN AUTOGENERATE */\n"; + $skip = 1; + + foreach my $call (@calls) { + my @c = @{$call}; + $base_c = + $base_c + . "static void __" + . $c[1] + . "(MwWidget widget, void* user, void* call){\n"; + $base_c = $base_c . " MwOO::Base* c = (MwOO::Base*)user;\n"; + $base_c = $base_c . " c->" . $c[1] . "(call);\n"; + $base_c = $base_c . "}\n"; + } + $base_c = $base_c . "\n"; + + $base_c = $base_c . "void MwOO::Base::SetHandler(void){\n"; + foreach my $call (@calls) { + my @c = @{$call}; + $base_c = + $base_c + . " MwAddUserHandler(this->widget, " + . $c[0] . ", __" + . $c[1] + . ", this);\n"; + } + $base_c = $base_c . "}\n"; + } + elsif ($l =~ /END AUTOGENERATE/) { + $base_c = $base_c . "/* END AUTOGENERATE */\n"; + $skip = 0; + } + elsif (!$skip) { + $base_c = $base_c . $l . "\n"; + } +} +close(IN); + +open(OUT, ">", "oosrc/base.cc"); +print(OUT "$base_c"); +close(OUT);