GWindow.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "GWindow.h"
  2. #include "GEvent.h"
  3. #include "GEventLoop.h"
  4. #include <SharedGraphics/GraphicsBitmap.h>
  5. #include <LibC/gui.h>
  6. #include <LibC/stdio.h>
  7. #include <LibC/stdlib.h>
  8. #include <AK/HashMap.h>
  9. static HashMap<int, GWindow*>* s_windows;
  10. static HashMap<int, GWindow*>& windows()
  11. {
  12. if (!s_windows)
  13. s_windows = new HashMap<int, GWindow*>;
  14. return *s_windows;
  15. }
  16. GWindow* GWindow::from_window_id(int window_id)
  17. {
  18. auto it = windows().find(window_id);
  19. if (it != windows().end())
  20. return (*it).value;
  21. return nullptr;
  22. }
  23. GWindow::GWindow(GObject* parent)
  24. : GObject(parent)
  25. {
  26. GUI_CreateWindowParameters wparams;
  27. wparams.rect = { { 100, 400 }, { 140, 140 } };
  28. wparams.background_color = 0xffc0c0;
  29. strcpy(wparams.title, "GWindow");
  30. m_window_id = gui_create_window(&wparams);
  31. if (m_window_id < 0) {
  32. perror("gui_create_window");
  33. exit(1);
  34. }
  35. GUI_WindowBackingStoreInfo backing;
  36. int rc = gui_get_window_backing_store(m_window_id, &backing);
  37. if (rc < 0) {
  38. perror("gui_get_window_backing_store");
  39. exit(1);
  40. }
  41. m_backing = GraphicsBitmap::create_wrapper(backing.size, backing.pixels);
  42. windows().set(m_window_id, this);
  43. }
  44. GWindow::~GWindow()
  45. {
  46. }
  47. void GWindow::set_title(String&& title)
  48. {
  49. if (m_title == title)
  50. return;
  51. m_title = move(title);
  52. }
  53. void GWindow::set_rect(const Rect& rect)
  54. {
  55. if (m_rect == rect)
  56. return;
  57. m_rect = rect;
  58. dbgprintf("GWindow::setRect %d,%d %dx%d\n", m_rect.x(), m_rect.y(), m_rect.width(), m_rect.height());
  59. }
  60. void GWindow::event(GEvent& event)
  61. {
  62. }
  63. bool GWindow::is_visible() const
  64. {
  65. return false;
  66. }
  67. void GWindow::close()
  68. {
  69. }
  70. void GWindow::show()
  71. {
  72. }
  73. void GWindow::update()
  74. {
  75. gui_invalidate_window(m_window_id, nullptr);
  76. }
  77. void GWindow::set_main_widget(GWidget* widget)
  78. {
  79. if (m_main_widget == widget)
  80. return;
  81. m_main_widget = widget;
  82. update();
  83. }