add dialog things

This commit is contained in:
Nishi 2026-04-18 02:31:46 +09:00
commit 90e572aad8
Signed by: nishi
GPG key ID: 27EF69B208EB9343
56 changed files with 658 additions and 193 deletions

View file

@ -47,9 +47,9 @@ static std::string get_ctype(typeinfo type, int name = 1, int do_ptr = 1) {
} else if(type.type == "struct") {
ret += type.struct_name;
} else if(type.type == "widget") {
if(type.widget_type == ""){
if(type.widget_type == "") {
ret += "MwCXX::Base*";
}else{
} else {
ret += "MwCXX::" + type.widget_type + "*";
}
}
@ -198,20 +198,35 @@ static std::string scan_widget_property_source(xl_node_t* node, std::string widg
return widget_property_source(widget, xl_get_attribute(node, "name"));
}
static std::string widget_handler_header(std::string name, std::string indent = "") {
static std::string widget_handler_header(std::string widget, std::string name, std::string indent = "", int func = 1) {
std::stringstream strm;
std::string pre = "";
strm << indent + "virtual void On" + upperfirst(name) + "(" + (handlers[name].has_arg ? (get_ctype(handlers[name].arg_type, 0, 0) + " value") : "") + ") {};" << std::endl;
strm << indent;
if(func) {
strm << "virtual void On" + upperfirst(name);
} else {
strm << "void (*" + upperfirst(name) + "Handler)";
pre += "MwCXX::" + widget + "* widget";
if(handlers[name].has_arg) pre += ", ";
}
strm << "(" + pre + (handlers[name].has_arg ? (get_ctype(handlers[name].arg_type, 0, 0) + " value") : "") + ")";
if(func) strm << " {}";
strm << ";" << std::endl;
return strm.str();
}
static std::string scan_widget_handler_header(xl_node_t* node, std::string indent) {
static std::string scan_widget_handler_header(xl_node_t* node, std::string widget, std::string indent, int func = 1) {
xl_node_t* child = node->first_child;
if(node->type != XL_NODE_NODE) return "";
return widget_handler_header(xl_get_attribute(node, "name"), indent);
return widget_handler_header(widget, xl_get_attribute(node, "name"), indent, func);
}
static std::string widget_handler_source(std::string widget, std::string name) {
@ -230,6 +245,7 @@ static std::string widget_handler_source(std::string widget, std::string name) {
strm << "static void __On" + upperfirst(name) + "(MwWidget handle, void* user, void* call) {" << std::endl;
strm << " ((MwCXX::" + widget + "*)user)->On" + upperfirst(name) + "(" + cast + ");" << std::endl;
strm << " if(((MwCXX::" + widget + "*)user)->" + upperfirst(name) + "Handler != NULL) ((MwCXX::" + widget + "*)user)->" + upperfirst(name) + "Handler((MwCXX::" + widget + "*)user" + (handlers[name].has_arg ? (", " + cast) : "") + ");" << std::endl;
strm << "}" << std::endl;
strm << std::endl;
@ -279,31 +295,42 @@ static void scan_widget(xl_node_t* node) {
OFS << " " + name + "(MwCXX::String name, MwCXX::Base* parent, int x, int y, unsigned int width, unsigned int height);" << std::endl;
if(p_nodes != NULL) {
std::string r = "";
std::string r;
r = "";
for(int i = 0; p_nodes[i] != NULL; i++) {
for(xl_node_t* child = p_nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = p_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
r += scan_widget_property_header(child, "\t\t");
}
}
if(r != "") OFS << std::endl
<< r;
}
if(h_nodes != NULL) {
std::string r = "";
std::string r;
r = "";
for(int i = 0; h_nodes[i] != NULL; i++) {
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
r += scan_widget_handler_header(child, "\t\t");
r += scan_widget_handler_header(child, name, "\t\t");
}
}
if(r != "") OFS << std::endl
<< r;
r = "";
for(int i = 0; h_nodes[i] != NULL; i++) {
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
r += scan_widget_handler_header(child, name, "\t\t", 0);
}
}
if(r != "") OFS << std::endl
<< r;
}
@ -337,7 +364,7 @@ static void scan_widget(xl_node_t* node) {
if(p_nodes != NULL) {
for(int i = 0; p_nodes[i] != NULL; i++) {
for(xl_node_t* child = p_nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = p_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
OFS << scan_widget_property_source(child, name);
@ -347,7 +374,7 @@ static void scan_widget(xl_node_t* node) {
if(h_nodes != NULL) {
for(int i = 0; h_nodes[i] != NULL; i++) {
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
OFS << scan_widget_handler_source(child, name);
@ -357,6 +384,9 @@ static void scan_widget(xl_node_t* node) {
OFS << "void MwCXX::" + name + "::RegisterHandlers() {" << std::endl;
if(h_nodes != NULL) {
int f;
f = 0;
for(int i = 0; h_nodes[i] != NULL; i++) {
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next) {
std::string hname;
@ -366,6 +396,21 @@ static void scan_widget(xl_node_t* node) {
hname = xl_get_attribute(child, "name");
OFS << " MwAddUserHandler(this->widget, MwN" + hname + "Handler, __On" + upperfirst(hname) + ", (void*)this);" << std::endl;
f = 1;
}
}
if(f) OFS << std::endl;
for(int i = 0; h_nodes[i] != NULL; i++) {
for(xl_node_t* child = h_nodes[i]->first_child; child != NULL; child = child->next) {
std::string hname;
if(child->type != XL_NODE_NODE) continue;
hname = xl_get_attribute(child, "name");
OFS << " this->" + upperfirst(hname) + "Handler = NULL;" << std::endl;
}
}
}
@ -379,49 +424,139 @@ static void scan_widget(xl_node_t* node) {
files["objs"] << " src/widget/" + lowercase(name) + ".o";
}
static std::string function_decl(xl_node_t* node, std::string prefix = ""){
xl_node_t* ret = NULL;
static std::string function_decl(xl_node_t* node, std::string prefix = "") {
xl_node_t* ret = NULL;
xl_node_t** nodes;
std::string r = "";
if((nodes = xl_get_path(node, "return")) != NULL){
for(int i = 0; nodes[i] != NULL; i++){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
if((nodes = xl_get_path(node, "return")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type == XL_NODE_NODE) ret = child;
}
}
free(nodes);
}
if(ret == NULL){
if(ret == NULL) {
r += "void ";
}else{
} else {
r += get_ctype(xml_to_type(ret), 0, 0) + " ";
}
r += prefix + std::string(xl_get_attribute(node, "name")).substr(2);
r += "(";
if((nodes = xl_get_path(node, "arguments")) != NULL){
for(int i = 0; nodes[i] != NULL; i++){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
if((nodes = xl_get_path(node, "arguments")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
if(r.substr(r.size() - 1, 1) != "(") r += ", ";
r += get_ctype(xml_to_type(child), 1, 1);
r += get_ctype(xml_to_type(child), 1, 0);
}
}
free(nodes);
}
r += ")";
return r;
}
static std::string function_source(xl_node_t* node){
return "";
static std::string function_source(xl_node_t* node) {
std::stringstream strm;
xl_node_t** nodes;
xl_node_t* ret = NULL;
xl_node_t* widget = NULL;
typeinfo type;
int first = 1;
if((nodes = xl_get_path(node, "return")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type == XL_NODE_NODE) ret = child;
}
}
free(nodes);
}
strm << function_decl(node, "MwCXX::") << " {" << std::endl;
strm << " ";
if(ret != NULL) {
type = xml_to_type(ret);
if(type.type == "widget") {
std::string str = get_ctype(type, 0);
strm << "return new " + str.substr(0, str.size() - 1) + "(";
} else if(type.type == "string") {
strm << "const char* _ret = ";
} else {
strm << "return (" + get_ctype(type, 0) + ")";
}
}
strm << std::string(xl_get_attribute(node, "name")) + "(";
first = 1;
if((nodes = xl_get_path(node, "arguments")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
typeinfo type2;
if(child->type != XL_NODE_NODE) continue;
if(std::string(child->name) == "widget" && widget == NULL) widget = child;
type2 = xml_to_type(child);
if(first) {
first = 0;
} else {
strm << ", ";
}
if(type2.type == "widget") {
strm << type2.name + "->GetWidget()";
} else {
if(type2.type == "string") {
strm << std::endl;
strm << "#ifdef MWCXX_USE_C_STRING" << std::endl;
strm << type2.name << std::endl;
strm << "#else" << std::endl;
strm << type2.name + ".c_str()" << std::endl;
strm << "#endif" << std::endl;
strm << " ";
} else {
strm << "(" + get_ctype(type2, 0) + ")" + type2.name;
}
}
}
}
free(nodes);
}
if(ret != NULL && type.type == "widget") {
strm << ")";
if(widget != NULL) strm << ", " + std::string(xl_get_attribute(widget, "name"));
}
strm << ");" << std::endl;
if(ret != NULL && type.type == "string") {
strm << "#ifdef MWCXX_USE_C_STRING" << std::endl;
strm << " return _ret;" << std::endl;
strm << "#else" << std::endl;
strm << " return MwCXX::String(_ret);" << std::endl;
strm << "#endif" << std::endl;
}
strm << "}" << std::endl;
return strm.str();
}
static std::string function_header(xl_node_t* node){
static std::string function_header(xl_node_t* node) {
return function_decl(node) + ";";
}
@ -432,7 +567,7 @@ static void scan_header(xl_node_t* node) {
name = xl_get_attribute(node, "name");
if(name.size() >= 7 && name.substr(0, 7) == "Dialog/"){
if(name.size() >= 7 && name.substr(0, 7) == "Dialog/") {
xl_node_t** nodes;
#define OFS files["D" + name.substr(7) + ".h"]
@ -443,10 +578,13 @@ static void scan_header(xl_node_t* node) {
OFS << "#define __MWCXX_DIALOG_" + uppercase(name.substr(7)) + "_H__" << std::endl;
OFS << std::endl;
OFS << "#include <MwCXX/Widget/All.h>" << std::endl;
OFS << std::endl;
OFS << "namespace MwCXX {" << std::endl;
if((nodes = xl_get_path(node, "functions")) != NULL){
for(int i = 0; nodes[i] != NULL; i++){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
if((nodes = xl_get_path(node, "functions")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
OFS << " " + function_header(child) << std::endl;
@ -463,6 +601,26 @@ static void scan_header(xl_node_t* node) {
#undef OFS
#define OFS files["D" + name.substr(7) + ".cc"]
OFS = std::ofstream("src/dialog/" + lowercase(name.substr(7)) + ".cc");
OFS << "#include <MwCXX/" + name + ".h>" << std::endl;
OFS << std::endl;
if((nodes = xl_get_path(node, "functions")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
OFS << function_source(child);
}
}
free(nodes);
}
files["objs"] << " src/dialog/" + lowercase(name.substr(7)) + ".o";
#undef OFS
}
}
@ -481,13 +639,21 @@ static void base_widget() {
OFS << widget_property_header(p->first);
f = 1;
}
if(f) OFS << std::endl;
f = 0;
for(auto p = handlers.begin(); p != handlers.end(); p++) {
if(!p->second.common) continue;
OFS << widget_handler_header("Base", p->first);
f = 1;
}
if(f) OFS << std::endl;
for(auto p = handlers.begin(); p != handlers.end(); p++) {
if(!p->second.common) continue;
OFS << widget_handler_header(p->first);
OFS << widget_handler_header("Base", p->first, "", 0);
}
#undef OFS
@ -516,6 +682,12 @@ static void base_widget() {
OFS << " MwAddUserHandler(this->widget, MwN" + h->first + "Handler, __On" + upperfirst(h->first) + ", (void*)this);" << std::endl;
}
OFS << std::endl;
for(auto h = handlers.begin(); h != handlers.end(); h++) {
if(!h->second.common) continue;
OFS << " this->" + upperfirst(h->first) + "Handler = NULL;" << std::endl;
}
OFS << "}" << std::endl;
#undef OFS
@ -548,7 +720,7 @@ int main(int argc, char** argv) {
if((nodes = xl_get_path(h->root, "properties")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
scan_property(child);
@ -560,7 +732,7 @@ int main(int argc, char** argv) {
if((nodes = xl_get_path(h->root, "handlers")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
scan_handler(child);
@ -572,7 +744,7 @@ int main(int argc, char** argv) {
if((nodes = xl_get_path(h->root, "headers")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
if(child->type != XL_NODE_NODE) continue;
scan_header(child);
@ -584,16 +756,38 @@ int main(int argc, char** argv) {
base_widget();
#define OFS files["AllWidgets.h"]
OFS = std::ofstream("include/MwCXX/Widget/All.h");
OFS << "#ifndef __MWCXX_WIDGET_ALL_H__" << std::endl;
OFS << "#define __MWCXX_WIDGET_ALL_H__" << std::endl;
OFS << std::endl;
if((nodes = xl_get_path(h->root, "widgets")) != NULL) {
for(int i = 0; nodes[i] != NULL; i++) {
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next){
for(xl_node_t* child = nodes[i]->first_child; child != NULL; child = child->next) {
std::string name;
if(child->type != XL_NODE_NODE) continue;
scan_widget(child);
name = xl_get_attribute(child, "name");
if(name == "OpenGL" || name == "Vulkan") continue;
OFS << "#include <MwCXX/Widget/" + name + ".h>" << std::endl;
}
}
free(nodes);
}
OFS << std::endl;
OFS << "#endif" << std::endl;
#undef OFS
files["objs"] << std::endl;
for(auto f = files.begin(); f != files.end(); f++) {