summaryrefslogtreecommitdiff
path: root/DevTools
diff options
context:
space:
mode:
Diffstat (limited to 'DevTools')
-rw-r--r--DevTools/FormCompiler/Makefile28
-rw-r--r--DevTools/FormCompiler/form.frm1
-rw-r--r--DevTools/FormCompiler/main.cpp48
3 files changed, 77 insertions, 0 deletions
diff --git a/DevTools/FormCompiler/Makefile b/DevTools/FormCompiler/Makefile
new file mode 100644
index 0000000000..497bdacf9a
--- /dev/null
+++ b/DevTools/FormCompiler/Makefile
@@ -0,0 +1,28 @@
+PROGRAM = FormCompiler
+
+SOURCES = \
+ main.cpp \
+ ../../AK/String.cpp \
+ ../../AK/StringImpl.cpp \
+ ../../AK/StringBuilder.cpp \
+ ../../AK/StringView.cpp \
+ ../../AK/JsonObject.cpp \
+ ../../AK/JsonValue.cpp \
+ ../../AK/JsonArray.cpp \
+ ../../AK/JsonParser.cpp \
+ ../../AK/LogStream.cpp \
+ ../../Libraries/LibCore/CIODevice.cpp \
+ ../../Libraries/LibCore/CFile.cpp \
+ ../../Libraries/LibCore/CObject.cpp \
+ ../../Libraries/LibCore/CEvent.cpp \
+ ../../Libraries/LibCore/CEventLoop.cpp
+
+all: $(PROGRAM)
+
+CXXFLAGS = -std=c++17 -Wall -Wextra
+
+$(PROGRAM): $(SOURCES)
+ $(CXX) $(CXXFLAGS) -I../ -I../../ -I../../Libraries/ -o $@ $(SOURCES)
+
+clean:
+ rm -f $(PROGRAM)
diff --git a/DevTools/FormCompiler/form.frm b/DevTools/FormCompiler/form.frm
new file mode 100644
index 0000000000..42e8dfde95
--- /dev/null
+++ b/DevTools/FormCompiler/form.frm
@@ -0,0 +1 @@
+{"name":"Form1","widgets":[{"name":"w1","tooltip":null,"backcolor":"#d4d0c8ff","forecolor":"#000000ff","text":"Hello world!","class":"GLabel","autofill":true,"enabled":true,"visible":true,"x":5,"height":26,"y":5,"width":121},{"name":"w2","tooltip":null,"backcolor":"#d4d0c8ff","forecolor":"#000000ff","text":"Lefty","class":"GButton","autofill":false,"enabled":true,"visible":true,"x":5,"height":26,"y":40,"width":51},{"name":"w3","tooltip":null,"backcolor":"#d4d0c8ff","forecolor":"#000000ff","text":"Righty","class":"GButton","autofill":false,"enabled":true,"visible":true,"x":80,"height":26,"y":40,"width":51},{"name":"w4","enabled":true,"forecolor":"#000000ff","checked":false,"autofill":false,"x":150,"tooltip":null,"height":26,"width":91,"y":5,"class":"GCheckBox","text":"Awesome","backcolor":"#d4d0c8ff","visible":true},{"name":"w5","enabled":true,"forecolor":"#000000ff","checked":false,"autofill":false,"x":150,"tooltip":null,"height":26,"width":51,"y":30,"class":"GCheckBox","text":"Cool","backcolor":"#d4d0c8ff","visible":true}]}
diff --git a/DevTools/FormCompiler/main.cpp b/DevTools/FormCompiler/main.cpp
new file mode 100644
index 0000000000..e3ab18ffa2
--- /dev/null
+++ b/DevTools/FormCompiler/main.cpp
@@ -0,0 +1,48 @@
+#include <AK/JsonArray.h>
+#include <AK/JsonObject.h>
+#include <AK/JsonValue.h>
+#include <AK/LogStream.h>
+#include <LibCore/CFile.h>
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ if (argc != 2) {
+ printf("usage: %s <form-file>\n", argv[0]);
+ return 0;
+ }
+
+ CFile file(argv[1]);
+ if (!file.open(CIODevice::ReadOnly)) {
+ fprintf(stderr, "Error: Cannot open %s: %s\n", argv[1], file.error_string());
+ return 1;
+ }
+
+ auto file_contents = file.read_all();
+ auto json = JsonValue::from_string(file_contents);
+
+ if (!json.is_object()) {
+ fprintf(stderr, "Malformed input\n");
+ return 1;
+ }
+
+ auto name = json.as_object().get("name").to_string();
+ auto widgets = json.as_object().get("widgets");
+
+ if (!widgets.is_array()) {
+ fprintf(stderr, "Malformed input\n");
+ return 1;
+ }
+
+ dbg() << "auto* main_widget = new GWidget(nullptr);";
+
+ widgets.as_array().for_each([&](auto& value) {
+ ASSERT(value.is_object());
+ const JsonObject& widget_object = value.as_object();
+ auto name = widget_object.get("name").to_string();
+ auto class_name = widget_object.get("class").to_string();
+ dbg() << "auto* " << name << " = new " << class_name << "(main_widget);";
+ });
+
+ return 0;
+}