Lagrange
ViewportPanel.h
1/*
2 * Copyright 2021 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/api.h>
15#include <lagrange/ui/Entity.h>
16
17#include <Eigen/Eigen>
18
19namespace lagrange {
20namespace ui {
21
23{
24 Entity viewport;
25
26 int available_width = 0;
27 int available_height = 0;
28
29 //Screen position of the canvas/texture being rendered
30 Eigen::Vector2f canvas_origin = Eigen::Vector2f::Zero();
31
32 // Is mouse over canvas?
33 bool hovered = false;
34
35 // Is any gizmo active in the viewport?
36 bool gizmo_active = false;
37
38 // Mouse position in canvas
39 Eigen::Vector2f mouse_in_canvas = Eigen::Vector2f::Zero();
40
41
42 // Show top toolbar
43 bool show_viewport_toolbar = true;
44
45 /*
46 Helper functions
47 */
48
50 bool is_over_viewport(const Eigen::Vector2f& pos) const;
51
53 Eigen::Vector2f screen_to_viewport(const Eigen::Vector2f& screen_pos) const;
54
56 Eigen::Vector2f viewport_to_screen(const Eigen::Vector2f& viewport_pos) const;
57};
58
59
60// Context variable
61// At any given time, there must be a viewport window that's in focus
62// The actual GUI focus may be a non-viewport window - in that case the focused viewport is the last
63// one that was in focus.
65{
66 Entity viewport_panel = NullEntity;
67};
68
69LA_UI_API Entity add_viewport_panel(Registry& r, const std::string& name, Entity viewport);
70
71
72} // namespace ui
73} // namespace lagrange
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: ViewportPanel.h:65
Definition: ViewportPanel.h:23
Eigen::Vector2f screen_to_viewport(const Eigen::Vector2f &screen_pos) const
Returns position relative to viewport's lower-left corner.
Definition: ViewportPanel.cpp:828
Eigen::Vector2f viewport_to_screen(const Eigen::Vector2f &viewport_pos) const
Returns position relative to the entire screen.
Definition: ViewportPanel.cpp:834
bool is_over_viewport(const Eigen::Vector2f &pos) const
Returns whether pos is over the viewport.
Definition: ViewportPanel.cpp:821