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-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>
2019-07-18 10:15:00 +02:00
# include <LibDraw/PNGLoader.h>
2019-06-10 19:29:33 +02:00
int main ( int argc , char * * argv )
{
GApplication app ( argc , argv ) ;
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-06-10 19:29:33 +02:00
2019-09-21 17:05:35 +02:00
auto horizontal_container = GWidget : : construct ( nullptr ) ;
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-21 17:05:35 +02:00
auto vertical_container = GWidget : : construct ( horizontal_container ) ;
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 ) ;
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 > ( ) ;
auto app_menu = make < GMenu > ( " PaintBrush " ) ;
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 ;
} ) ) ;
menubar - > add_menu ( move ( app_menu ) ) ;
auto file_menu = make < GMenu > ( " File " ) ;
2019-09-20 19:36:39 +02:00
file_menu - > add_action ( GCommonActions : : make_open_action ( [ & ] ( auto & ) {
2019-06-25 20:27:32 +02:00
GFilePicker picker ;
if ( picker . exec ( ) = = GFilePicker : : ExecOK ) {
auto filename = picker . selected_file ( ) . string ( ) ;
auto bitmap = load_png ( filename ) ;
if ( ! bitmap ) {
2019-07-16 21:32:10 +02:00
GMessageBox msgbox ( String : : format ( " Failed to load '%s' " , filename . characters ( ) ) , " Open failed " , GMessageBox : : Type : : Error , GMessageBox : : InputType : : OK , window ) ;
2019-06-25 20:27:32 +02:00
msgbox . exec ( ) ;
return ;
}
paintable_widget - > set_bitmap ( * bitmap ) ;
}
} ) ) ;
2019-06-10 21:05:20 +02:00
menubar - > add_menu ( move ( file_menu ) ) ;
auto edit_menu = make < GMenu > ( " Edit " ) ;
menubar - > add_menu ( move ( edit_menu ) ) ;
auto help_menu = make < GMenu > ( " Help " ) ;
help_menu - > add_action ( GAction : : create ( " About " , [ ] ( const GAction & ) {
dbgprintf ( " FIXME: Implement Help/About \n " ) ;
} ) ) ;
menubar - > add_menu ( move ( help_menu ) ) ;
app . set_menubar ( move ( menubar ) ) ;
2019-06-10 19:29:33 +02:00
return app . exec ( ) ;
}