2020-01-18 09:38:21 +01:00
/*
* Copyright ( c ) 2018 - 2020 , Andreas Kling < kling @ serenityos . org >
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
*
* 1. Redistributions of source code must retain the above copyright notice , this
* list of conditions and the following disclaimer .
*
* 2. Redistributions in binary form must reproduce the above copyright notice ,
* this list of conditions and the following disclaimer in the documentation
* and / or other materials provided with the distribution .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS "
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL
* DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY ,
* OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2019-09-16 00:41:03 +10:00
# include <AK/String.h>
# include <AK/Vector.h>
2020-02-06 20:33:02 +01:00
# include <LibGUI/Application.h>
# include <LibGUI/BoxLayout.h>
# include <LibGUI/Button.h>
# include <LibGUI/Desktop.h>
# include <LibGUI/Label.h>
# include <LibGUI/StackWidget.h>
# include <LibGUI/Window.h>
2020-02-14 23:53:11 +01:00
# include <LibGfx/Font.h>
2019-09-16 00:41:03 +10:00
2020-02-13 23:47:49 -05:00
# include "BackgroundWidget.h"
2019-09-16 00:41:03 +10:00
# include "TextWidget.h"
struct ContentPage {
String menu_name ;
String title ;
Vector < String > content ;
} ;
int main ( int argc , char * * argv )
{
Vector < ContentPage > pages = {
{
" Welcome " ,
" Welcome " ,
{
" Welcome to the exciting new world of Serenity, where the year is 1998 and the leading OS vendor has decided to merge their flagship product with a Unix-like kernel. " ,
" Sit back and relax as you take a brief tour of the options available on this screen. " ,
" If you want to explore an option, just click it. " ,
} ,
} ,
{
" Register Now " ,
" Register Now! " ,
{
" Registering your copy of Serenity opens the doors to full integration of Serenity into your life, your being, and your soul. " ,
" By registering Serenity, you enter into the draw to win a lifetime supply of milk, delivered fresh each day by a mystical horse wearing a full tuxedo. " ,
" To register, simply write your contact details on a piece of paper and hold it up to your monitor. " ,
} ,
} ,
{
" Connect to the Internet " ,
" Connect to the Internet " ,
{
" On the Internet, you can correspond through electronic mail (e-mail), get the latest news and financial information, and visit Web sites around the world, most of which will make you really angry. " ,
" Serenity includes several internet applications, such as an IRC (Internet relay chat) client, 4chan browser, telnet server, and basic utilities like ping. " ,
" Come chat with us today! How bad can it be? " ,
} ,
} ,
{
" Have fun " ,
" Play Some Games! " ,
{
" Serenity includes several games built right into the base system. These include the classic game Snake and the anti-productivity mainstay Minesweeper. " ,
" With a little extra effort, you can even play the original id Software hit DOOM, albeit without sound. No sound just means you won't alert your boss, so it's more of a feature than a limitation. " ,
} ,
} ,
} ;
2020-02-02 15:07:41 +01:00
GUI : : Application app ( argc , argv ) ;
2019-09-16 00:41:03 +10:00
2020-02-02 15:07:41 +01:00
auto window = GUI : : Window : : construct ( ) ;
2019-09-16 00:41:03 +10:00
window - > set_title ( " Welcome to Serenity " ) ;
2020-02-06 13:02:38 +01:00
Gfx : : Rect window_rect { 0 , 0 , 640 , 360 } ;
2020-02-02 15:07:41 +01:00
window_rect . center_within ( GUI : : Desktop : : the ( ) . rect ( ) ) ;
2019-09-16 00:41:03 +10:00
window - > set_resizable ( true ) ;
window - > set_rect ( window_rect ) ;
2020-02-13 23:47:49 -05:00
auto background = BackgroundWidget : : construct ( ) ;
2019-09-16 00:41:03 +10:00
window - > set_main_widget ( background ) ;
2020-02-13 23:47:49 -05:00
background - > set_fill_with_background_color ( false ) ;
2020-02-06 14:44:13 +01:00
background - > set_layout ( make < GUI : : VerticalBoxLayout > ( ) ) ;
2020-02-13 23:47:49 -05:00
background - > layout ( ) - > set_margins ( { 16 , 8 , 16 , 8 } ) ;
2019-09-16 00:41:03 +10:00
background - > layout ( ) - > set_spacing ( 8 ) ;
2020-02-02 15:07:41 +01:00
background - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fill ) ;
2019-09-16 00:41:03 +10:00
//
// header
//
2020-02-02 15:07:41 +01:00
auto header = GUI : : Label : : construct ( background . ptr ( ) ) ;
2020-02-06 11:56:38 +01:00
header - > set_font ( Gfx : : Font : : default_bold_font ( ) ) ;
2019-09-16 00:41:03 +10:00
header - > set_text ( " Welcome to Serenity " ) ;
2020-02-06 11:56:38 +01:00
header - > set_text_alignment ( Gfx : : TextAlignment : : CenterLeft ) ;
2020-02-02 15:07:41 +01:00
header - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fixed ) ;
2019-09-16 00:41:03 +10:00
header - > set_preferred_size ( 0 , 30 ) ;
//
// main section
//
2020-02-02 15:07:41 +01:00
auto main_section = GUI : : Widget : : construct ( background . ptr ( ) ) ;
2020-02-06 14:44:13 +01:00
main_section - > set_layout ( make < GUI : : HorizontalBoxLayout > ( ) ) ;
2019-09-16 00:41:03 +10:00
main_section - > layout ( ) - > set_margins ( { 0 , 0 , 0 , 0 } ) ;
main_section - > layout ( ) - > set_spacing ( 8 ) ;
2020-02-02 15:07:41 +01:00
main_section - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fill ) ;
2019-09-16 00:41:03 +10:00
2020-02-02 15:07:41 +01:00
auto menu = GUI : : Widget : : construct ( main_section . ptr ( ) ) ;
2020-02-06 14:44:13 +01:00
menu - > set_layout ( make < GUI : : VerticalBoxLayout > ( ) ) ;
2019-09-16 00:41:03 +10:00
menu - > layout ( ) - > set_margins ( { 0 , 0 , 0 , 0 } ) ;
menu - > layout ( ) - > set_spacing ( 8 ) ;
2020-02-02 15:07:41 +01:00
menu - > set_size_policy ( GUI : : SizePolicy : : Fixed , GUI : : SizePolicy : : Fill ) ;
2019-09-16 00:41:03 +10:00
menu - > set_preferred_size ( 200 , 0 ) ;
2020-02-02 15:07:41 +01:00
auto stack = GUI : : StackWidget : : construct ( main_section ) ;
stack - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fill ) ;
2019-09-16 00:41:03 +10:00
for ( auto & page : pages ) {
2020-02-02 15:07:41 +01:00
auto content = GUI : : Widget : : construct ( stack . ptr ( ) ) ;
2020-02-06 14:44:13 +01:00
content - > set_layout ( make < GUI : : VerticalBoxLayout > ( ) ) ;
2019-09-16 00:41:03 +10:00
content - > layout ( ) - > set_margins ( { 0 , 0 , 0 , 0 } ) ;
content - > layout ( ) - > set_spacing ( 8 ) ;
2020-02-02 15:07:41 +01:00
content - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fill ) ;
2019-09-16 00:41:03 +10:00
2020-02-02 15:07:41 +01:00
auto content_title = GUI : : Label : : construct ( content ) ;
2020-02-06 11:56:38 +01:00
content_title - > set_font ( Gfx : : Font : : default_bold_font ( ) ) ;
2019-09-16 00:41:03 +10:00
content_title - > set_text ( page . title ) ;
2020-02-06 11:56:38 +01:00
content_title - > set_text_alignment ( Gfx : : TextAlignment : : CenterLeft ) ;
2020-02-02 15:07:41 +01:00
content_title - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fixed ) ;
2019-09-16 00:41:03 +10:00
content_title - > set_preferred_size ( 0 , 10 ) ;
for ( auto & paragraph : page . content ) {
2019-09-21 20:04:00 +02:00
auto content_text = TextWidget : : construct ( content ) ;
2020-02-06 11:56:38 +01:00
content_text - > set_font ( Gfx : : Font : : default_font ( ) ) ;
2019-09-16 00:41:03 +10:00
content_text - > set_text ( paragraph ) ;
2020-02-06 11:56:38 +01:00
content_text - > set_text_alignment ( Gfx : : TextAlignment : : TopLeft ) ;
2019-09-16 00:41:03 +10:00
content_text - > set_line_height ( 12 ) ;
content_text - > wrap_and_set_height ( ) ;
}
2020-02-02 15:07:41 +01:00
auto menu_option = GUI : : Button : : construct ( menu ) ;
2020-02-06 11:56:38 +01:00
menu_option - > set_font ( Gfx : : Font : : default_font ( ) ) ;
2019-09-16 00:41:03 +10:00
menu_option - > set_text ( page . menu_name ) ;
2020-02-06 11:56:38 +01:00
menu_option - > set_text_alignment ( Gfx : : TextAlignment : : CenterLeft ) ;
2020-02-02 15:07:41 +01:00
menu_option - > set_size_policy ( GUI : : SizePolicy : : Fill , GUI : : SizePolicy : : Fixed ) ;
2019-09-16 00:41:03 +10:00
menu_option - > set_preferred_size ( 0 , 20 ) ;
2019-09-21 19:42:16 +02:00
menu_option - > on_click = [ content = content . ptr ( ) , & stack ] ( auto & ) {
2019-09-16 00:41:03 +10:00
stack - > set_active_widget ( content ) ;
content - > invalidate_layout ( ) ;
} ;
}
window - > show ( ) ;
return app . exec ( ) ;
}