mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:57:46 +00:00
Move apps into a top-level Applications/ directory.
This commit is contained in:
parent
29f2a22d34
commit
2cf1dd5b6f
27 changed files with 30 additions and 26 deletions
3
Applications/FontEditor/.gitignore
vendored
Normal file
3
Applications/FontEditor/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.o
|
||||
*.d
|
||||
FontEditor
|
247
Applications/FontEditor/FontEditor.cpp
Normal file
247
Applications/FontEditor/FontEditor.cpp
Normal file
|
@ -0,0 +1,247 @@
|
|||
#include "FontEditor.h"
|
||||
#include <SharedGraphics/Painter.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GTextBox.h>
|
||||
|
||||
FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_font, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_edited_font(move(edited_font))
|
||||
{
|
||||
if (path.is_empty())
|
||||
m_path = "/saved.font";
|
||||
else
|
||||
m_path = path;
|
||||
|
||||
m_glyph_map_widget = new GlyphMapWidget(*m_edited_font, this);
|
||||
m_glyph_map_widget->move_to({ 90, 5 });
|
||||
|
||||
m_glyph_editor_widget = new GlyphEditorWidget(*m_edited_font, this);
|
||||
m_glyph_editor_widget->move_to({ 5, 5 });
|
||||
|
||||
m_name_textbox = new GTextBox(this);
|
||||
m_name_textbox->set_relative_rect({ 5, 135, 100, 20 });
|
||||
m_name_textbox->set_text(m_edited_font->name());
|
||||
m_name_textbox->on_change = [this] (GTextBox&) {
|
||||
m_edited_font->set_name(m_name_textbox->text());
|
||||
};
|
||||
|
||||
auto* save_button = new GButton(this);
|
||||
save_button->set_caption("Save");
|
||||
save_button->set_relative_rect({ 5, 170, 100, 20 });
|
||||
save_button->on_click = [this] (GButton&) {
|
||||
dbgprintf("write to file: '%s'\n", m_path.characters());
|
||||
m_edited_font->write_to_file(m_path);
|
||||
};
|
||||
|
||||
auto* quit_button = new GButton(this);
|
||||
quit_button->set_caption("Quit");
|
||||
quit_button->set_relative_rect({ 110, 170, 100, 20 });
|
||||
quit_button->on_click = [] (GButton&) {
|
||||
exit(0);
|
||||
};
|
||||
|
||||
auto* info_label = new GLabel(this);
|
||||
info_label->set_relative_rect({ 5, 110, 100, 20 });
|
||||
|
||||
auto* demo_label_1 = new GLabel(this);
|
||||
demo_label_1->set_font(m_edited_font.copy_ref());
|
||||
demo_label_1->set_text("quick fox jumps nightly above wizard.");
|
||||
demo_label_1->set_relative_rect({ 110, 120, 300, 20 });
|
||||
|
||||
auto* demo_label_2 = new GLabel(this);
|
||||
demo_label_2->set_font(m_edited_font.copy_ref());
|
||||
demo_label_2->set_text("QUICK FOX JUMPS NIGHTLY ABOVE WIZARD!");
|
||||
demo_label_2->set_relative_rect({ 110, 140, 300, 20 });
|
||||
|
||||
m_glyph_editor_widget->on_glyph_altered = [this, demo_label_1, demo_label_2] {
|
||||
m_glyph_map_widget->update();
|
||||
demo_label_1->update();
|
||||
demo_label_2->update();
|
||||
};
|
||||
|
||||
m_glyph_map_widget->on_glyph_selected = [this, info_label] (byte glyph) {
|
||||
m_glyph_editor_widget->set_glyph(glyph);
|
||||
info_label->set_text(String::format("0x%b (%c)", glyph, glyph));
|
||||
};
|
||||
|
||||
m_glyph_map_widget->set_selected_glyph('A');
|
||||
}
|
||||
|
||||
FontEditorWidget::~FontEditorWidget()
|
||||
{
|
||||
}
|
||||
|
||||
GlyphMapWidget::GlyphMapWidget(Font& mutable_font, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_font(mutable_font)
|
||||
{
|
||||
set_relative_rect({ 0, 0, preferred_width(), preferred_height() });
|
||||
}
|
||||
|
||||
GlyphMapWidget::~GlyphMapWidget()
|
||||
{
|
||||
}
|
||||
|
||||
int GlyphMapWidget::preferred_width() const
|
||||
{
|
||||
return columns() * (font().glyph_width() + m_horizontal_spacing) + 2;
|
||||
}
|
||||
|
||||
int GlyphMapWidget::preferred_height() const
|
||||
{
|
||||
return rows() * (font().glyph_height() + m_vertical_spacing) + 2;
|
||||
}
|
||||
|
||||
void GlyphMapWidget::set_selected_glyph(byte glyph)
|
||||
{
|
||||
if (m_selected_glyph == glyph)
|
||||
return;
|
||||
m_selected_glyph = glyph;
|
||||
if (on_glyph_selected)
|
||||
on_glyph_selected(glyph);
|
||||
update();
|
||||
}
|
||||
|
||||
Rect GlyphMapWidget::get_outer_rect(byte glyph) const
|
||||
{
|
||||
int row = glyph / columns();
|
||||
int column = glyph % columns();
|
||||
return {
|
||||
column * (font().glyph_width() + m_horizontal_spacing) + 1,
|
||||
row * (font().glyph_height() + m_vertical_spacing) + 1,
|
||||
font().glyph_width() + m_horizontal_spacing,
|
||||
font().glyph_height() + m_horizontal_spacing
|
||||
};
|
||||
}
|
||||
|
||||
void GlyphMapWidget::paint_event(GPaintEvent&)
|
||||
{
|
||||
Painter painter(*this);
|
||||
painter.set_font(font());
|
||||
painter.fill_rect(rect(), Color::White);
|
||||
painter.draw_rect(rect(), Color::Black);
|
||||
|
||||
byte glyph = 0;
|
||||
|
||||
for (int row = 0; row < rows(); ++row) {
|
||||
for (int column = 0; column < columns(); ++column, ++glyph) {
|
||||
Rect outer_rect = get_outer_rect(glyph);
|
||||
Rect inner_rect(
|
||||
outer_rect.x() + m_horizontal_spacing / 2,
|
||||
outer_rect.y() + m_vertical_spacing / 2,
|
||||
font().glyph_width(),
|
||||
font().glyph_height()
|
||||
);
|
||||
if (glyph == m_selected_glyph) {
|
||||
painter.fill_rect(outer_rect, Color::Red);
|
||||
painter.draw_glyph(inner_rect.location(), glyph, Color::White);
|
||||
} else {
|
||||
painter.draw_glyph(inner_rect.location(), glyph, Color::Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_focused())
|
||||
painter.draw_focus_rect(rect());
|
||||
}
|
||||
|
||||
void GlyphMapWidget::mousedown_event(GMouseEvent& event)
|
||||
{
|
||||
// FIXME: This is a silly loop.
|
||||
for (unsigned glyph = 0; glyph < 256; ++glyph) {
|
||||
if (get_outer_rect(glyph).contains(event.position())) {
|
||||
set_selected_glyph(glyph);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlyphEditorWidget::GlyphEditorWidget(Font& mutable_font, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_font(mutable_font)
|
||||
{
|
||||
set_relative_rect({ 0, 0, preferred_width(), preferred_height() });
|
||||
}
|
||||
|
||||
GlyphEditorWidget::~GlyphEditorWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::set_glyph(byte glyph)
|
||||
{
|
||||
if (m_glyph == glyph)
|
||||
return;
|
||||
m_glyph = glyph;
|
||||
update();
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::paint_event(GPaintEvent&)
|
||||
{
|
||||
Painter painter(*this);
|
||||
painter.fill_rect(rect(), Color::White);
|
||||
painter.draw_rect(rect(), Color::Black);
|
||||
|
||||
for (int y = 0; y < font().glyph_height(); ++y)
|
||||
painter.draw_line({ 0, y * m_scale }, { font().glyph_width() * m_scale, y * m_scale }, Color::Black);
|
||||
|
||||
for (int x = 0; x < font().glyph_width(); ++x)
|
||||
painter.draw_line({ x * m_scale, 0 }, { x * m_scale, font().glyph_height() * m_scale }, Color::Black);
|
||||
|
||||
painter.translate(1, 1);
|
||||
|
||||
auto bitmap = font().glyph_bitmap(m_glyph);
|
||||
|
||||
for (int y = 0; y < font().glyph_height(); ++y) {
|
||||
for (int x = 0; x < font().glyph_width(); ++x) {
|
||||
Rect rect { x * m_scale, y * m_scale, m_scale, m_scale };
|
||||
if (bitmap.bit_at(x, y))
|
||||
painter.fill_rect(rect, Color::Black);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_focused()) {
|
||||
painter.translate(-1, -1);
|
||||
painter.draw_focus_rect(rect());
|
||||
}
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::mousedown_event(GMouseEvent& event)
|
||||
{
|
||||
draw_at_mouse(event);
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::mousemove_event(GMouseEvent& event)
|
||||
{
|
||||
if (event.buttons() & (GMouseButton::Left | GMouseButton::Right))
|
||||
draw_at_mouse(event);
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::draw_at_mouse(const GMouseEvent& event)
|
||||
{
|
||||
bool set = event.buttons() & GMouseButton::Left;
|
||||
bool unset = event.buttons() & GMouseButton::Right;
|
||||
if (!(set ^ unset))
|
||||
return;
|
||||
int x = (event.x() - 1) / m_scale;
|
||||
int y = (event.y() - 1) / m_scale;
|
||||
auto bitmap = font().glyph_bitmap(m_glyph);
|
||||
ASSERT((unsigned)x < bitmap.width());
|
||||
ASSERT((unsigned)y < bitmap.height());
|
||||
if (bitmap.bit_at(x, y) == set)
|
||||
return;
|
||||
bitmap.set_bit_at(x, y, set);
|
||||
if (on_glyph_altered)
|
||||
on_glyph_altered();
|
||||
update();
|
||||
}
|
||||
|
||||
int GlyphEditorWidget::preferred_width() const
|
||||
{
|
||||
return font().glyph_width() * m_scale + 1;
|
||||
}
|
||||
|
||||
int GlyphEditorWidget::preferred_height() const
|
||||
{
|
||||
return font().glyph_height() * m_scale + 1;
|
||||
}
|
85
Applications/FontEditor/FontEditor.h
Normal file
85
Applications/FontEditor/FontEditor.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <AK/Function.h>
|
||||
|
||||
class GlyphEditorWidget;
|
||||
class GlyphMapWidget;
|
||||
class GTextBox;
|
||||
|
||||
class FontEditorWidget final : public GWidget {
|
||||
public:
|
||||
FontEditorWidget(const String& path, RetainPtr<Font>&&, GWidget* parent = nullptr);
|
||||
virtual ~FontEditorWidget() override;
|
||||
|
||||
private:
|
||||
RetainPtr<Font> m_edited_font;
|
||||
|
||||
GlyphMapWidget* m_glyph_map_widget { nullptr };
|
||||
GlyphEditorWidget* m_glyph_editor_widget { nullptr };
|
||||
GTextBox* m_name_textbox { nullptr };
|
||||
|
||||
String m_path;
|
||||
};
|
||||
|
||||
class GlyphMapWidget final : public GWidget {
|
||||
public:
|
||||
GlyphMapWidget(Font&, GWidget* parent);
|
||||
virtual ~GlyphMapWidget() override;
|
||||
|
||||
byte selected_glyph() const { return m_selected_glyph; }
|
||||
void set_selected_glyph(byte);
|
||||
|
||||
int rows() const { return m_rows; }
|
||||
int columns() const { return 256 / m_rows; }
|
||||
|
||||
int preferred_width() const;
|
||||
int preferred_height() const;
|
||||
|
||||
Font& font() { return *m_font; }
|
||||
const Font& font() const { return *m_font; }
|
||||
|
||||
Function<void(byte)> on_glyph_selected;
|
||||
|
||||
private:
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual bool accepts_focus() const override { return true; }
|
||||
|
||||
Rect get_outer_rect(byte glyph) const;
|
||||
|
||||
RetainPtr<Font> m_font;
|
||||
int m_rows { 8 };
|
||||
int m_horizontal_spacing { 2 };
|
||||
int m_vertical_spacing { 2 };
|
||||
byte m_selected_glyph { 0 };
|
||||
};
|
||||
|
||||
class GlyphEditorWidget final : public GWidget {
|
||||
public:
|
||||
GlyphEditorWidget(Font&, GWidget* parent);
|
||||
virtual ~GlyphEditorWidget() override;
|
||||
|
||||
byte glyph() const { return m_glyph; }
|
||||
void set_glyph(byte);
|
||||
|
||||
int preferred_width() const;
|
||||
int preferred_height() const;
|
||||
|
||||
Font& font() { return *m_font; }
|
||||
const Font& font() const { return *m_font; }
|
||||
|
||||
Function<void()> on_glyph_altered;
|
||||
|
||||
private:
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void mousemove_event(GMouseEvent&) override;
|
||||
virtual bool accepts_focus() const override { return true; }
|
||||
|
||||
void draw_at_mouse(const GMouseEvent&);
|
||||
|
||||
RetainPtr<Font> m_font;
|
||||
byte m_glyph { 0 };
|
||||
int m_scale { 10 };
|
||||
};
|
35
Applications/FontEditor/Makefile
Normal file
35
Applications/FontEditor/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
OBJS = \
|
||||
FontEditor.o \
|
||||
main.o
|
||||
|
||||
APP = FontEditor
|
||||
|
||||
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 -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
|
||||
|
35
Applications/FontEditor/main.cpp
Normal file
35
Applications/FontEditor/main.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "FontEditor.h"
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
RetainPtr<Font> edited_font;
|
||||
String path;
|
||||
|
||||
if (argc == 2) {
|
||||
path = argv[1];
|
||||
edited_font = Font::load_from_file(path);
|
||||
if (!edited_font) {
|
||||
fprintf(stderr, "Couldn't load font: %s\n", path.characters());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (edited_font)
|
||||
edited_font = edited_font->clone();
|
||||
else
|
||||
edited_font = Font::default_font().clone();
|
||||
|
||||
GEventLoop loop;
|
||||
auto* window = new GWindow;
|
||||
window->set_title("FontEditor");
|
||||
window->set_rect({ 50, 50, 420, 200 });
|
||||
auto* font_editor = new FontEditorWidget(path, move(edited_font));
|
||||
font_editor->set_relative_rect({ 0, 0, 420, 200 });
|
||||
window->set_main_widget(font_editor);
|
||||
window->set_should_exit_app_on_close(true);
|
||||
window->show();
|
||||
return loop.exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue