mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
PaintBrush: Add support for opening files.
Obviously this only supports whatever PNG files that load_png() can decode at the moment.
This commit is contained in:
parent
8adae51b35
commit
b529b4a3e6
3 changed files with 24 additions and 0 deletions
|
@ -90,3 +90,9 @@ void PaintableWidget::set_secondary_color(Color color)
|
||||||
if (on_secondary_color_change)
|
if (on_secondary_color_change)
|
||||||
on_secondary_color_change(color);
|
on_secondary_color_change(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaintableWidget::set_bitmap(const GraphicsBitmap& bitmap)
|
||||||
|
{
|
||||||
|
m_bitmap = bitmap;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ public:
|
||||||
|
|
||||||
Color color_for(const GMouseEvent&);
|
Color color_for(const GMouseEvent&);
|
||||||
|
|
||||||
|
void set_bitmap(const GraphicsBitmap&);
|
||||||
|
|
||||||
GraphicsBitmap& bitmap() { return *m_bitmap; }
|
GraphicsBitmap& bitmap() { return *m_bitmap; }
|
||||||
const GraphicsBitmap& bitmap() const { return *m_bitmap; }
|
const GraphicsBitmap& bitmap() const { return *m_bitmap; }
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
#include <LibGUI/GApplication.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
|
#include <LibGUI/GFilePicker.h>
|
||||||
#include <LibGUI/GMenu.h>
|
#include <LibGUI/GMenu.h>
|
||||||
#include <LibGUI/GMenuBar.h>
|
#include <LibGUI/GMenuBar.h>
|
||||||
|
#include <LibGUI/GMessageBox.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
|
#include <SharedGraphics/PNGLoader.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +44,19 @@ int main(int argc, char** argv)
|
||||||
menubar->add_menu(move(app_menu));
|
menubar->add_menu(move(app_menu));
|
||||||
|
|
||||||
auto file_menu = make<GMenu>("File");
|
auto file_menu = make<GMenu>("File");
|
||||||
|
file_menu->add_action(GAction::create("Open...", { Mod_Ctrl, Key_O }, [&](auto&) {
|
||||||
|
GFilePicker picker;
|
||||||
|
if (picker.exec() == GFilePicker::ExecOK) {
|
||||||
|
auto filename = picker.selected_file().string();
|
||||||
|
auto bitmap = load_png(filename);
|
||||||
|
if (!bitmap) {
|
||||||
|
GMessageBox msgbox(String::format("Failed to load '%s'", filename.characters()), "Open failed", GMessageBox::Type::Error, window);
|
||||||
|
msgbox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
paintable_widget->set_bitmap(*bitmap);
|
||||||
|
}
|
||||||
|
}));
|
||||||
menubar->add_menu(move(file_menu));
|
menubar->add_menu(move(file_menu));
|
||||||
|
|
||||||
auto edit_menu = make<GMenu>("Edit");
|
auto edit_menu = make<GMenu>("Edit");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue