WindowComposer.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "WindowComposer.h"
  2. #include "Process.h"
  3. #include <Widgets/Font.h>
  4. #include <Widgets/FrameBuffer.h>
  5. #include <Widgets/WindowManager.h>
  6. #include <Widgets/RootWidget.h>
  7. #include <Widgets/EventLoop.h>
  8. #include <Widgets/MsgBox.h>
  9. #include <Widgets/TextBox.h>
  10. #include <Widgets/Label.h>
  11. #include <Widgets/ListBox.h>
  12. #include <Widgets/Button.h>
  13. #include <Widgets/CheckBox.h>
  14. #include <Widgets/Window.h>
  15. void WindowComposer_main()
  16. {
  17. Font::initialize();
  18. FrameBuffer::initialize();
  19. EventLoop::initialize();
  20. WindowManager::initialize();
  21. AbstractScreen::initialize();
  22. auto info = current->get_display_info();
  23. dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp);
  24. FrameBuffer framebuffer((dword*)info.framebuffer, info.width, info.height);
  25. RootWidget rw;
  26. EventLoop loop;
  27. WindowManager::the().setRootWidget(&rw);
  28. MsgBox(nullptr, "Serenity Operating System");
  29. {
  30. auto* widgetTestWindow = new Window;
  31. widgetTestWindow->setTitle("Widget test");
  32. widgetTestWindow->setRect({ 20, 40, 100, 180 });
  33. auto* widgetTestWindowWidget = new Widget;
  34. widgetTestWindowWidget->setWindowRelativeRect({ 0, 0, 100, 100 });
  35. widgetTestWindow->setMainWidget(widgetTestWindowWidget);
  36. auto* l = new Label(widgetTestWindowWidget);
  37. l->setWindowRelativeRect({ 0, 0, 100, 20 });
  38. l->setText("Label");
  39. auto* b = new Button(widgetTestWindowWidget);
  40. b->setWindowRelativeRect({ 0, 20, 100, 20 });
  41. b->setCaption("Button");
  42. b->onClick = [] (Button& button) {
  43. printf("Button %p clicked!\n", &button);
  44. };
  45. auto* c = new CheckBox(widgetTestWindowWidget);
  46. c->setWindowRelativeRect({ 0, 40, 100, 20 });
  47. c->setCaption("CheckBox");
  48. auto *lb = new ListBox(widgetTestWindowWidget);
  49. lb->setWindowRelativeRect({ 0, 60, 100, 100 });
  50. lb->addItem("This");
  51. lb->addItem("is");
  52. lb->addItem("a");
  53. lb->addItem("ListBox");
  54. auto *tb = new TextBox(widgetTestWindowWidget);
  55. tb->setWindowRelativeRect({ 0, 160, 100, 20 });
  56. tb->setText("Hello!");
  57. tb->setFocus(true);
  58. tb->onReturnPressed = [] (TextBox& textBox) {
  59. printf("TextBox %p return pressed: '%s'\n", &textBox, textBox.text().characters());
  60. MsgBox(nullptr, textBox.text());
  61. };
  62. WindowManager::the().setActiveWindow(widgetTestWindow);
  63. }
  64. dbgprintf("Entering WindowComposer main loop.\n");
  65. loop.exec();
  66. ASSERT_NOT_REACHED();
  67. }