summaryrefslogtreecommitdiff
path: root/Applications/VisualBuilder
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-11 00:05:47 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-11 00:05:47 +0200
commit8268ece1bd66260fda13aa151680a797bf530755 (patch)
tree073e501930f4ff2a61fa470acbe1d5a741de4b03 /Applications/VisualBuilder
parent0bc72551f4d25823ceb49af24055bbdd8c0d4657 (diff)
downloadserenity-8268ece1bd66260fda13aa151680a797bf530755.zip
VisualBuilder: Start working on an interface builder application.
It's tedious making interfaces programmatically. Let's make a program to help us with this. :^)
Diffstat (limited to 'Applications/VisualBuilder')
-rw-r--r--Applications/VisualBuilder/.gitignore3
-rw-r--r--Applications/VisualBuilder/Makefile33
-rw-r--r--Applications/VisualBuilder/VBForm.cpp25
-rw-r--r--Applications/VisualBuilder/VBForm.h20
-rw-r--r--Applications/VisualBuilder/VBWidget.cpp0
-rw-r--r--Applications/VisualBuilder/VBWidget.h15
-rwxr-xr-xApplications/VisualBuilder/VisualBuilderbin0 -> 245268 bytes
-rw-r--r--Applications/VisualBuilder/main.cpp56
8 files changed, 152 insertions, 0 deletions
diff --git a/Applications/VisualBuilder/.gitignore b/Applications/VisualBuilder/.gitignore
new file mode 100644
index 0000000000..bc36e52322
--- /dev/null
+++ b/Applications/VisualBuilder/.gitignore
@@ -0,0 +1,3 @@
+*.o
+*.d
+InterfaceEditor
diff --git a/Applications/VisualBuilder/Makefile b/Applications/VisualBuilder/Makefile
new file mode 100644
index 0000000000..cacbff9524
--- /dev/null
+++ b/Applications/VisualBuilder/Makefile
@@ -0,0 +1,33 @@
+OBJS = \
+ VBForm.o \
+ VBWidget.o \
+ main.o
+
+APP = VisualBuilder
+
+STANDARD_FLAGS = -std=c++17 -Wno-sized-deallocation
+WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough
+FLAVOR_FLAGS = -fno-exceptions -fno-rtti
+OPTIMIZATION_FLAGS = -Os
+INCLUDE_FLAGS = -I../.. -I. -I../../LibC
+
+DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
+
+CXXFLAGS = -MMD -MP $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(FLAVOR_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
+CXX = i686-pc-serenity-g++
+LD = i686-pc-serenity-g++
+LDFLAGS = -L../../LibC -L../../LibCore -L../../LibGUI
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -lcore -lc
+
+.cpp.o:
+ @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+-include $(OBJS:%.o=%.d)
+
+clean:
+ @echo "CLEAN"; rm -f $(APPS) $(OBJS) *.d
+
diff --git a/Applications/VisualBuilder/VBForm.cpp b/Applications/VisualBuilder/VBForm.cpp
new file mode 100644
index 0000000000..5f40d8263e
--- /dev/null
+++ b/Applications/VisualBuilder/VBForm.cpp
@@ -0,0 +1,25 @@
+#include "VBForm.h"
+#include <LibGUI/GPainter.h>
+
+VBForm::VBForm(const String& name, GWidget* parent)
+ : GWidget(parent)
+{
+ set_fill_with_background_color(true);
+ set_background_color(Color::LightGray);
+}
+
+VBForm::~VBForm()
+{
+}
+
+void VBForm::paint_event(GPaintEvent& event)
+{
+ GPainter painter(*this);
+ painter.add_clip_rect(event.rect());
+
+ for (int y = 0; y < height(); y += m_grid_size) {
+ for (int x = 0; x < width(); x += m_grid_size) {
+ painter.set_pixel({ x, y }, Color::Black);
+ }
+ }
+}
diff --git a/Applications/VisualBuilder/VBForm.h b/Applications/VisualBuilder/VBForm.h
new file mode 100644
index 0000000000..64bc69dd9e
--- /dev/null
+++ b/Applications/VisualBuilder/VBForm.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <LibGUI/GWidget.h>
+#include <AK/Vector.h>
+#include "VBWidget.h"
+
+class VBForm : public GWidget {
+public:
+ explicit VBForm(const String& name, GWidget* parent = nullptr);
+ virtual ~VBForm() override;
+
+protected:
+ virtual void paint_event(GPaintEvent&) override;
+
+private:
+ String m_name;
+ int m_grid_size { 5 };
+
+ Vector<VBWidget*> m_widgets;
+};
diff --git a/Applications/VisualBuilder/VBWidget.cpp b/Applications/VisualBuilder/VBWidget.cpp
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/Applications/VisualBuilder/VBWidget.cpp
diff --git a/Applications/VisualBuilder/VBWidget.h b/Applications/VisualBuilder/VBWidget.h
new file mode 100644
index 0000000000..231336621c
--- /dev/null
+++ b/Applications/VisualBuilder/VBWidget.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <SharedGraphics/Rect.h>
+
+class VBWidget {
+public:
+ VBWidget();
+ virtual ~VBWidget();
+
+ Rect rect() const { return m_rect; }
+ void set_rect(const Rect& rect) { m_rect = rect; }
+
+private:
+ Rect m_rect;
+};
diff --git a/Applications/VisualBuilder/VisualBuilder b/Applications/VisualBuilder/VisualBuilder
new file mode 100755
index 0000000000..4381e1052a
--- /dev/null
+++ b/Applications/VisualBuilder/VisualBuilder
Binary files differ
diff --git a/Applications/VisualBuilder/main.cpp b/Applications/VisualBuilder/main.cpp
new file mode 100644
index 0000000000..0602b39ea6
--- /dev/null
+++ b/Applications/VisualBuilder/main.cpp
@@ -0,0 +1,56 @@
+#include <LibGUI/GWindow.h>
+#include <LibGUI/GWidget.h>
+#include <LibGUI/GBoxLayout.h>
+#include <LibGUI/GApplication.h>
+#include <LibGUI/GStatusBar.h>
+#include <LibGUI/GToolBar.h>
+#include <LibGUI/GMenuBar.h>
+#include <LibGUI/GTextEditor.h>
+#include <LibGUI/GAction.h>
+#include <LibGUI/GFontDatabase.h>
+#include <LibCore/CFile.h>
+#include <AK/StringBuilder.h>
+#include "VBForm.h"
+#include "VBWidget.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <signal.h>
+#include <fcntl.h>
+
+int main(int argc, char** argv)
+{
+ GApplication app(argc, argv);
+
+ auto* form1 = new VBForm("Form1");
+
+ auto menubar = make<GMenuBar>();
+ auto app_menu = make<GMenu>("Visual Builder");
+ app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) {
+ GApplication::the().quit(0);
+ return;
+ }));
+ menubar->add_menu(move(app_menu));
+
+ auto file_menu = make<GMenu>("File");
+ menubar->add_menu(move(file_menu));
+
+ auto edit_menu = make<GMenu>("Edit");
+ menubar->add_menu(move(edit_menu));
+
+ auto help_menu = make<GMenu>("Help");
+ help_menu->add_action(GAction::create("About", [] (const GAction&) {
+ dbgprintf("FIXME: Implement Help/About\n");
+ }));
+ menubar->add_menu(move(help_menu));
+
+ app.set_menubar(move(menubar));
+
+ auto* window = new GWindow;
+ window->set_title("Form1");
+ window->set_rect(20, 200, 640, 400);
+ window->set_main_widget(form1);
+ window->set_should_exit_event_loop_on_close(true);
+ window->show();
+
+ return app.exec();
+}