windowing.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "Crown.h"
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <GL/glew.h>
  5. //----------------------------------
  6. // Windows
  7. //----------------------------------
  8. class MainWindow: public Crown::Window
  9. {
  10. public:
  11. MainWindow(Crown::WindowsManager* wm, float x, float y, float width, float height):
  12. Crown::Window(wm, x, y, width, height, "Crown")
  13. {
  14. Crown::StackLayout* sl = new Crown::StackLayout(GetContentWidget());
  15. btnClose = new Crown::Button(sl);
  16. btnClose->SetDesiredSize(-1, -1);
  17. /*Crown::ThemeSpriteWidget* tsw =*/ new Crown::ThemeSpriteWidget(btnClose, Crown::TS_BOOM, 0);
  18. btnClose->OnClickEvent += CreateDelegate(this, &MainWindow::btnClose_OnClick);
  19. }
  20. void btnClose_OnClick(Button* /*obj*/, Crown::EventArgs* /*args*/)
  21. {
  22. Crown::GetDevice()->StopRunning();
  23. }
  24. private:
  25. Crown::Button* btnClose;
  26. };
  27. class MyWindow: public Crown::Window
  28. {
  29. public:
  30. MyWindow(Crown::WindowsManager* wm, float x, float y, float width, float height):
  31. Crown::Window(wm, x, y, width, height, "Test Window")
  32. {
  33. Crown::StackLayout* sl = new Crown::StackLayout(GetContentWidget());
  34. Crown::StackLayout* sl_left = new Crown::StackLayout(sl);
  35. Crown::StackLayout* sl_right = new Crown::StackLayout(sl);
  36. sl->SetOrientationVertical(false);
  37. /*Crown::Button* btn1 =*/ new Crown::Button(sl_left);
  38. Crown::Button* btn2 = new Crown::Button(sl_left);
  39. /*Crown::Button* btn3 =*/ new Crown::Button(sl_left);
  40. Crown::Button* btn4 = new Crown::Button(sl_left);
  41. Crown::Button* btn5 = new Crown::Button(sl_right);
  42. /*Crown::Button* btn6 =*/ new Crown::Button(sl_right);
  43. Crown::Button* btn7 = new Crown::Button(sl_right);
  44. /*Crown::Button* btn8 =*/ new Crown::Button(sl_right);
  45. btn2->SetDesiredSize(-1, -1);
  46. btn4->SetDesiredSize(-1, -1);
  47. btn5->SetDesiredSize(-1, -1);
  48. btn7->SetDesiredSize(-1, -1);
  49. }
  50. private:
  51. };
  52. class ListWindow: public Crown::Window
  53. {
  54. public:
  55. ListWindow(Crown::WindowsManager* wm, float x, float y, float width, float height):
  56. Crown::Window(wm, x, y, width, height, "ListView Window")
  57. {
  58. Crown::StackLayout* sl = new Crown::StackLayout(GetContentWidget());
  59. sl->SetOrientationVertical(false);
  60. Crown::ListView* lw = new Crown::ListView(sl);
  61. // Crown::GenericList gl;
  62. //
  63. // for(int i = 0; i < 15; i++)
  64. // gl.Append(i*3);
  65. // lw->SetItems(gl);
  66. Crown::StackLayout* slRight = new Crown::StackLayout(sl);
  67. Crown::TreeView* treeview = new Crown::TreeView(slRight);
  68. }
  69. private:
  70. };
  71. class MainScene: public Crown::Scene
  72. {
  73. public:
  74. MainScene() {}
  75. virtual ~MainScene()
  76. {
  77. if (tr)
  78. delete tr;
  79. }
  80. virtual void OnLoad()
  81. {
  82. Crown::Renderer* renderer = Crown::GetDevice()->GetRenderer();
  83. renderer->SetClearColor(Crown::Color(0.6f, 0.6f, 0.6f, 1.0f));
  84. Crown::WindowsManager* wm = new Crown::WindowsManager(this);
  85. /*Crown::Window* w1 =*/ new MainWindow(wm, 10.0f, 15.0f, 80.0f, 80.0f);
  86. /*Crown::Window* w2 =*/ new MyWindow(wm, 150.0f, 150.0f, 100.0f, 100.0f);
  87. /*Crown::Window* w3 =*/ new ListWindow(wm, 350.0f, 150.0f, 300.0f, 200.0f);
  88. /*
  89. mFont.SetTrueTypeSize(8);
  90. mImg = mFont.LoadFont("../../res/times.ttf");
  91. Crown::Frame* f = new Crown::Frame();
  92. f->Set(renderer->CreateTexture(mImg), 0, 0, mImg->GetWidth(), mImg->GetHeight());
  93. mSprite.AddFrame(f);
  94. Crown::BMPImageLoader bmp;
  95. bmp.SaveFile(mImg, "../../res/out.bmp");
  96. */
  97. }
  98. virtual void RenderScene()
  99. {
  100. glDisable(GL_LIGHTING);
  101. glColor3f(1, 1, 1);
  102. // Uncomment to gain a huge performance boost
  103. glDisable(GL_DEPTH_TEST);
  104. glDepthMask(GL_FALSE);
  105. Scene::RenderScene();
  106. //glTranslatef(0.0f, 100.0f, 0.0f);
  107. //mSprite.draw(0);
  108. }
  109. //Crown::Image* mImg;
  110. //Crown::Sprite mSprite;
  111. };
  112. int main(int argc, char** argv) {
  113. int wndW, wndH;
  114. wndW = 800;
  115. wndH = 600;
  116. if (argc == 3) {
  117. wndW = atoi(argv[1]);
  118. wndH = atoi(argv[2]);
  119. }
  120. Crown::Device* device = Crown::GetDevice();
  121. if (!device->Init(wndW, wndH, 32, false)) {
  122. return 0;
  123. }
  124. device->GetMainWindow()->SetTitle("Crown Engine v0.1");
  125. MainScene* mainScene = new MainScene();
  126. device->GetSceneManager()->SelectNextScene(mainScene);
  127. device->Run();
  128. device->Shutdown();
  129. return 0;
  130. }