mirror of
https://github.com/RGBCube/serenity
synced 2025-06-27 19:22:07 +00:00
PaintBrush: Start working on a simple painting application.
This commit is contained in:
parent
63f029ef9b
commit
d599544890
6 changed files with 114 additions and 0 deletions
3
Applications/PaintBrush/.gitignore
vendored
Normal file
3
Applications/PaintBrush/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
PaintBrush
|
23
Applications/PaintBrush/Makefile
Normal file
23
Applications/PaintBrush/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
include ../../Makefile.common
|
||||||
|
|
||||||
|
OBJS = \
|
||||||
|
PaintableWidget.o \
|
||||||
|
main.o
|
||||||
|
|
||||||
|
APP = PaintBrush
|
||||||
|
|
||||||
|
DEFINES += -DUSERLAND
|
||||||
|
|
||||||
|
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 $(APP) $(OBJS) *.d
|
||||||
|
|
49
Applications/PaintBrush/PaintableWidget.cpp
Normal file
49
Applications/PaintBrush/PaintableWidget.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include "PaintableWidget.h"
|
||||||
|
#include <LibGUI/GPainter.h>
|
||||||
|
#include <SharedGraphics/GraphicsBitmap.h>
|
||||||
|
|
||||||
|
PaintableWidget::PaintableWidget(GWidget* parent)
|
||||||
|
: GWidget(parent)
|
||||||
|
{
|
||||||
|
set_fill_with_background_color(true);
|
||||||
|
set_background_color(Color::LightGray);
|
||||||
|
m_bitmap = GraphicsBitmap::create(GraphicsBitmap::Format::RGB32, { 600, 400 });
|
||||||
|
m_bitmap->fill(Color::White);
|
||||||
|
}
|
||||||
|
|
||||||
|
PaintableWidget::~PaintableWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintableWidget::paint_event(GPaintEvent& event)
|
||||||
|
{
|
||||||
|
GPainter painter(*this);
|
||||||
|
painter.add_clip_rect(event.rect());
|
||||||
|
painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintableWidget::mousedown_event(GMouseEvent& event)
|
||||||
|
{
|
||||||
|
if (event.button() != GMouseButton::Left)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GPainter painter(*m_bitmap);
|
||||||
|
painter.set_pixel(event.position(), Color::Black);
|
||||||
|
update({ event.position(), { 1, 1 } });
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintableWidget::mouseup_event(GMouseEvent&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaintableWidget::mousemove_event(GMouseEvent& event)
|
||||||
|
{
|
||||||
|
if (!rect().contains(event.position()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.buttons() & GMouseButton::Left) {
|
||||||
|
GPainter painter(*m_bitmap);
|
||||||
|
painter.set_pixel(event.position(), Color::Black);
|
||||||
|
update({ event.position(), { 1, 1 } });
|
||||||
|
}
|
||||||
|
}
|
19
Applications/PaintBrush/PaintableWidget.h
Normal file
19
Applications/PaintBrush/PaintableWidget.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/GWidget.h>
|
||||||
|
|
||||||
|
class PaintableWidget final : public GWidget {
|
||||||
|
public:
|
||||||
|
explicit PaintableWidget(GWidget* parent);
|
||||||
|
virtual ~PaintableWidget() override;
|
||||||
|
|
||||||
|
virtual const char* class_name() const override { return "PaintableWidget"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
|
virtual void mouseup_event(GMouseEvent&) override;
|
||||||
|
virtual void mousemove_event(GMouseEvent&) override;
|
||||||
|
|
||||||
|
RetainPtr<GraphicsBitmap> m_bitmap;
|
||||||
|
};
|
18
Applications/PaintBrush/main.cpp
Normal file
18
Applications/PaintBrush/main.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "PaintableWidget.h"
|
||||||
|
#include <LibGUI/GApplication.h>
|
||||||
|
#include <LibGUI/GWindow.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
|
auto* window = new GWindow;
|
||||||
|
window->set_title("PaintBrush");
|
||||||
|
window->set_rect(100, 100, 600, 400);
|
||||||
|
|
||||||
|
auto* paintable_widget = new PaintableWidget(nullptr);
|
||||||
|
window->set_main_widget(paintable_widget);
|
||||||
|
|
||||||
|
window->show();
|
||||||
|
return app.exec();
|
||||||
|
}
|
|
@ -71,6 +71,7 @@ cp ../Applications/ProcessManager/ProcessManager mnt/bin/ProcessManager
|
||||||
cp ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
|
cp ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
|
||||||
cp ../Applications/Terminal/Terminal mnt/bin/Terminal
|
cp ../Applications/Terminal/Terminal mnt/bin/Terminal
|
||||||
cp ../Applications/TextEditor/TextEditor mnt/bin/TextEditor
|
cp ../Applications/TextEditor/TextEditor mnt/bin/TextEditor
|
||||||
|
cp ../Applications/PaintBrush/PaintBrush mnt/bin/PaintBrush
|
||||||
cp ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld
|
cp ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld
|
||||||
cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch
|
cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch
|
||||||
cp ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery
|
cp ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery
|
||||||
|
@ -95,6 +96,7 @@ ln -s Taskbar mnt/bin/tb
|
||||||
ln -s VisualBuilder mnt/bin/vb
|
ln -s VisualBuilder mnt/bin/vb
|
||||||
ln -s WidgetGallery mnt/bin/wg
|
ln -s WidgetGallery mnt/bin/wg
|
||||||
ln -s TextEditor mnt/bin/te
|
ln -s TextEditor mnt/bin/te
|
||||||
|
ln -s PaintBrush mnt/bin/pb
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|
||||||
# Run local sync script, if it exists
|
# Run local sync script, if it exists
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue