载入中...
搜索中...
未找到
EditorDock.cpp
浏览该文件的文档.
1#include "editor/EditorDock.h"
2
3#include "common/Exception.h"
4
5namespace eve::editor {
6
8 sizes_["left"] = 200.f;
9 sizes_["right"] = 280.f;
10 sizes_["top"] = 40.f;
11 sizes_["bottom"] = 24.f;
12}
13
14void EditorDock::setRegionSize(const std::string &region, float pixels) {
15 if (region != "left" && region != "right" && region != "top" && region != "bottom") {
16 throw Exception("EditorDock::setRegionSize: expected left|right|top|bottom");
17 }
18 if (pixels < 0.f) throw Exception("EditorDock::setRegionSize: size must be >= 0");
19 sizes_[region] = pixels;
20}
21
22float EditorDock::getRegionSize(const std::string &region) const { return sizeOf(region); }
23
24float EditorDock::sizeOf(const std::string &region) const {
25 auto it = sizes_.find(region);
26 return it == sizes_.end() ? 0.f : it->second;
27}
28
29void EditorDock::layout(float screenW, float screenH) {
30 if (screenW <= 0.f || screenH <= 0.f) {
31 throw Exception("EditorDock::layout: screen size must be > 0");
32 }
33 float left = sizeOf("left");
34 float right = sizeOf("right");
35 float top = sizeOf("top");
36 float bottom = sizeOf("bottom");
37 // Clamp so center remains non-negative
38 if (left + right > screenW) {
39 float s = screenW / (left + right);
40 left *= s;
41 right *= s;
42 }
43 if (top + bottom > screenH) {
44 float s = screenH / (top + bottom);
45 top *= s;
46 bottom *= s;
47 }
48
49 rects_["top"] = {0.f, 0.f, screenW, top};
50 rects_["bottom"] = {0.f, screenH - bottom, screenW, bottom};
51 rects_["left"] = {0.f, top, left, screenH - top - bottom};
52 rects_["right"] = {screenW - right, top, right, screenH - top - bottom};
53 rects_["center"] = {left, top, screenW - left - right, screenH - top - bottom};
54}
55
56const EditorDock::Rect *EditorDock::rectOf(const std::string &region) const {
57 auto it = rects_.find(region);
58 return it == rects_.end() ? nullptr : &it->second;
59}
60
61float EditorDock::getRegionX(const std::string &region) const {
62 const Rect *r = rectOf(region);
63 if (!r) throw Exception("EditorDock::getRegionX: call layout() first / unknown region");
64 return r->x;
65}
66float EditorDock::getRegionY(const std::string &region) const {
67 const Rect *r = rectOf(region);
68 if (!r) throw Exception("EditorDock::getRegionY: call layout() first / unknown region");
69 return r->y;
70}
71float EditorDock::getRegionW(const std::string &region) const {
72 const Rect *r = rectOf(region);
73 if (!r) throw Exception("EditorDock::getRegionW: call layout() first / unknown region");
74 return r->w;
75}
76float EditorDock::getRegionH(const std::string &region) const {
77 const Rect *r = rectOf(region);
78 if (!r) throw Exception("EditorDock::getRegionH: call layout() first / unknown region");
79 return r->h;
80}
81
82} // namespace eve::editor
uint32_t s
Definition Weather.cpp:28
float getRegionX(const std::string &region) const
void setRegionSize(const std::string &region, float pixels)
float getRegionY(const std::string &region) const
void layout(float screenW, float screenH)
float getRegionW(const std::string &region) const
float getRegionH(const std::string &region) const
float getRegionSize(const std::string &region) const