1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07:34 +00:00

Start working on a simple Launcher app.

Let GButton have an optional icon (GraphicsBitmap) that gets rendered in the
middle of the button if present.

Also add GraphicsBitmap::load_from_file() which allows mmap'ed RGBA32 files.
I wrote a little program to take "raw" files from GIMP and swizzle them into
the correct byte order.
This commit is contained in:
Andreas Kling 2019-02-07 23:13:47 +01:00
parent 71b9ec1ae0
commit 887b4a7a1a
29 changed files with 293 additions and 11 deletions

3
Launcher/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.o
*.d
FontEditor

BIN
Launcher/Launcher Executable file

Binary file not shown.

34
Launcher/Makefile Normal file
View file

@ -0,0 +1,34 @@
OBJS = \
main.o
APP = Launcher
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I. -I../LibC
DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
CXXFLAGS = -MMD -MP $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(USERLAND_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
CXX = clang
LD = ld
AR = ar
LDFLAGS = -static --strip-debug -melf_i386 -e _start --gc-sections
all: $(APP)
$(APP): $(OBJS)
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) ../LibGUI/LibGUI.a ../LibC/LibC.a
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
-include $(OBJS:%.o=%.d)
clean:
@echo "CLEAN"; rm -f $(APPS) $(OBJS) *.d

79
Launcher/main.cpp Normal file
View file

@ -0,0 +1,79 @@
#include <SharedGraphics/GraphicsBitmap.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GEventLoop.h>
#include <signal.h>
#include <unistd.h>
static GWindow* make_launcher_window();
void handle_sigchld(int)
{
dbgprintf("Launcher(%d) Got SIGCHLD\n", getpid());
int pid = waitpid(-1, nullptr, 0);
dbgprintf("Launcher(%d) waitpid() returned %d\n", getpid(), pid);
ASSERT(pid > 0);
}
int main(int, char**)
{
signal(SIGCHLD, handle_sigchld);
GEventLoop loop;
auto* launcher_window = make_launcher_window();
launcher_window->set_should_exit_app_on_close(true);
launcher_window->show();
return loop.exec();
}
GWindow* make_launcher_window()
{
auto* window = new GWindow;
window->set_title("Launcher");
window->set_rect({ 50, 50, 300, 60 });
auto* widget = new GWidget;
window->set_main_widget(widget);
widget->set_relative_rect({ 0, 0, 300, 60 });
auto* terminal_button = new GButton(widget);
terminal_button->set_relative_rect({ 5, 5, 50, 50 });
terminal_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/Terminal.rgb", { 32, 32 }));
terminal_button->on_click = [] (GButton&) {
pid_t child_pid = fork();
if (!child_pid) {
execve("/bin/Terminal", nullptr, nullptr);
ASSERT_NOT_REACHED();
}
};
auto* font_editor_button = new GButton(widget);
font_editor_button->set_relative_rect({ 60, 5, 50, 50 });
font_editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/FontEditor.rgb", { 32, 32 }));
font_editor_button->on_click = [] (GButton&) {
pid_t child_pid = fork();
if (!child_pid) {
execve("/bin/FontEditor", nullptr, nullptr);
ASSERT_NOT_REACHED();
}
};
auto* guitest_editor_button = new GButton(widget);
guitest_editor_button->set_relative_rect({ 115, 5, 50, 50 });
guitest_editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/generic.rgb", { 32, 32 }));
guitest_editor_button->on_click = [] (GButton&) {
pid_t child_pid = fork();
if (!child_pid) {
execve("/bin/guitest", nullptr, nullptr);
ASSERT_NOT_REACHED();
}
};
return window;
}