git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@204 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-07 14:20:45 +00:00
parent 8c030ba778
commit 7dda33ee1c
22 changed files with 204 additions and 39 deletions

View File

@@ -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)

View File

@@ -4,13 +4,31 @@
#include <Mw/Milsko.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -4,9 +4,11 @@
#include <MwOO/Base.h>
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

View File

@@ -1,10 +1,43 @@
/* $Id$ */
#include <MwOO/Base.h>
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 */

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/Button.h>
#include <Mw/Widget/Button.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/Frame.h>
#include <Mw/Widget/Frame.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/Image.h>
#include <Mw/Widget/Image.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/Menu.h>
#include <Mw/Widget/Menu.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/OpenGL.h>
#include <Mw/Widget/OpenGL.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/ScrollBar.h>
#include <Mw/Widget/ScrollBar.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/SubMenu.h>
#include <Mw/Widget/SubMenu.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/Vulkan.h>
#include <Mw/Widget/Vulkan.h>
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){
}

View File

@@ -2,5 +2,5 @@
#include <MwOO/Widget/Window.h>
#include <Mw/Widget/Window.h>
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){
}

View File

@@ -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 = <IN>) {
$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 <MwOO/Base.h>\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 <Mw/Widget/$name.h>\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 = <IN>) {
$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 = <IN>) {
$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);