2019-06-10 19:29:33 +02:00
# include "PaintableWidget.h"
2019-06-10 19:54:09 +02:00
# include "PaletteWidget.h"
2019-06-12 05:58:31 +02:00
# include "ToolboxWidget.h"
2019-10-01 00:18:20 -05:00
# include <LibDraw/PNGLoader.h>
# include <LibGUI/GAboutDialog.h>
2019-06-10 21:05:20 +02:00
# include <LibGUI/GAction.h>
2019-06-10 19:29:33 +02:00
# include <LibGUI/GApplication.h>
2019-06-10 19:54:09 +02:00
# include <LibGUI/GBoxLayout.h>
2019-06-25 20:27:32 +02:00
# include <LibGUI/GFilePicker.h>
2019-06-10 21:05:20 +02:00
# include <LibGUI/GMenu.h>
# include <LibGUI/GMenuBar.h>
2019-06-25 20:27:32 +02:00
# include <LibGUI/GMessageBox.h>
2019-06-10 19:29:33 +02:00
# include <LibGUI/GWindow.h>
2020-01-13 12:22:49 +01:00
# include <stdio.h>
2019-06-10 19:29:33 +02:00
int main ( int argc , char * * argv )
{
2020-01-17 11:12:06 +01:00
if ( pledge ( " stdio shared_buffer accept rpath unix wpath cpath fattr " , nullptr ) < 0 ) {
2020-01-13 12:22:49 +01:00
perror ( " pledge " ) ;
return 1 ;
}
2019-06-10 19:29:33 +02:00
GApplication app ( argc , argv ) ;
2020-01-17 11:12:06 +01:00
if ( pledge ( " stdio shared_buffer accept rpath wpath cpath " , nullptr ) < 0 ) {
2020-01-13 12:22:49 +01:00
perror ( " pledge " ) ;
return 1 ;
}
2019-09-21 18:34:06 +02:00
auto window = GWindow : : construct ( ) ;
2019-06-10 19:29:33 +02:00
window - > set_title ( " PaintBrush " ) ;
2019-06-12 05:58:31 +02:00
window - > set_rect ( 100 , 100 , 640 , 480 ) ;
2019-10-01 00:18:20 -05:00
window - > set_icon ( load_png ( " /res/icons/16x16/app-paintbrush.png " ) ) ;
2019-06-10 19:29:33 +02:00
2019-09-22 00:17:53 +02:00
auto horizontal_container = GWidget : : construct ( ) ;
2019-06-12 05:58:31 +02:00
window - > set_main_widget ( horizontal_container ) ;
horizontal_container - > set_layout ( make < GBoxLayout > ( Orientation : : Horizontal ) ) ;
horizontal_container - > layout ( ) - > set_spacing ( 0 ) ;
2019-06-10 19:54:09 +02:00
2019-06-22 16:26:04 +02:00
new ToolboxWidget ( horizontal_container ) ;
2019-06-12 05:58:31 +02:00
2019-09-22 00:17:53 +02:00
auto vertical_container = GWidget : : construct ( horizontal_container . ptr ( ) ) ;
2019-06-12 05:58:31 +02:00
vertical_container - > set_layout ( make < GBoxLayout > ( Orientation : : Vertical ) ) ;
vertical_container - > layout ( ) - > set_spacing ( 0 ) ;
2019-09-21 20:04:00 +02:00
auto paintable_widget = PaintableWidget : : construct ( vertical_container ) ;
2019-11-29 22:39:23 +01:00
paintable_widget - > set_focus ( true ) ;
2019-09-21 20:04:00 +02:00
PaletteWidget : : construct ( * paintable_widget , vertical_container ) ;
2019-06-10 19:29:33 +02:00
window - > show ( ) ;
2019-06-10 21:05:20 +02:00
auto menubar = make < GMenuBar > ( ) ;
2019-12-09 21:05:28 +01:00
auto app_menu = GMenu : : construct ( " PaintBrush " ) ;
2019-10-01 00:18:20 -05:00
app_menu - > add_action ( GCommonActions : : make_open_action ( [ & ] ( auto & ) {
Optional < String > open_path = GFilePicker : : get_open_filepath ( ) ;
if ( ! open_path . has_value ( ) )
return ;
auto bitmap = load_png ( open_path . value ( ) ) ;
if ( ! bitmap ) {
GMessageBox : : show ( String : : format ( " Failed to load '%s' " , open_path . value ( ) . characters ( ) ) , " Open failed " , GMessageBox : : Type : : Error , GMessageBox : : InputType : : OK , window ) ;
return ;
}
paintable_widget - > set_bitmap ( * bitmap ) ;
} ) ) ;
app_menu - > add_separator ( ) ;
2019-09-14 22:10:44 +02:00
app_menu - > add_action ( GCommonActions : : make_quit_action ( [ ] ( auto & ) {
2019-06-10 21:05:20 +02:00
GApplication : : the ( ) . quit ( 0 ) ;
return ;
} ) ) ;
2019-10-01 00:18:20 -05:00
menubar - > add_menu ( move ( app_menu ) ) ;
2019-06-10 21:05:20 +02:00
2019-12-09 21:05:28 +01:00
auto edit_menu = GMenu : : construct ( " Edit " ) ;
2019-06-10 21:05:20 +02:00
menubar - > add_menu ( move ( edit_menu ) ) ;
2019-12-09 21:05:28 +01:00
auto help_menu = GMenu : : construct ( " Help " ) ;
2019-10-01 00:18:20 -05:00
help_menu - > add_action ( GAction : : create ( " About " , [ & ] ( auto & ) {
GAboutDialog : : show ( " PaintBrush " , load_png ( " /res/icons/32x32/app-paintbrush.png " ) , window ) ;
2019-06-10 21:05:20 +02:00
} ) ) ;
menubar - > add_menu ( move ( help_menu ) ) ;
app . set_menubar ( move ( menubar ) ) ;
2019-06-10 19:29:33 +02:00
return app . exec ( ) ;
}