Skip to content

Commit

Permalink
Update hover on tool change
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Sep 4, 2023
1 parent 3314f08 commit 89daec3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
31 changes: 17 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ static void resetToolState() {
g_drawVerts.clear();
}

static void setTool(Tool tool) {
g_tool = tool;
resetToolState();
if (!(TOOL_FLAGS[tool] & (1 << g_state.selMode)))
g_state.selMode = SEL_ELEMENTS; // TODO
if ((TOOL_FLAGS[tool] & TOOLF_DRAW) && (TOOL_FLAGS[tool] & TOOLF_HOVFACE))
if (auto face = g_hoverFace.find(g_state.surf))
g_state.workPlane = facePlane(g_state.surf, *face);
POINT pt = cursorPos();
HWND overWnd = WindowFromPoint(pt);
if (GetWindowThreadProcessId(overWnd, nullptr) == GetCurrentThreadId())
setCursorHitTest(overWnd, pt);
}

static std::vector<edge_id> sortEdgeLoop(const Surface &surf, immer::set<edge_id> edges) {
std::vector<edge_id> loop;
auto edgesTrans = edges.transient();
Expand Down Expand Up @@ -340,9 +326,26 @@ void MainWindow::showStdException(std::exception e) {
MessageBoxA(wnd, e.what(), "Unexpected Error", MB_ICONERROR);
}

void MainWindow::setTool(Tool tool) {
g_tool = tool;
resetToolState();
if (!(TOOL_FLAGS[tool] & (1 << g_state.selMode)))
g_state.selMode = SEL_ELEMENTS; // TODO
if ((TOOL_FLAGS[tool] & TOOLF_DRAW) && (TOOL_FLAGS[tool] & TOOLF_HOVFACE))
if (auto face = g_hoverFace.find(g_state.surf))
g_state.workPlane = facePlane(g_state.surf, *face);
POINT pt = cursorPos();
if (hoveredViewport && WindowFromPoint(pt) == hoveredViewport->wnd) {
hoveredViewport->updateHover(screenToClient(hoveredViewport->wnd, pt));
setCursorHitTest(hoveredViewport->wnd, pt);
}
}

bool MainWindow::removeViewport(ViewportWindow *viewport) {
if (activeViewport == viewport)
activeViewport = &mainViewport;
if (hoveredViewport == viewport)
hoveredViewport = NULL;
// hack https://stackoverflow.com/a/60220391/11525734
std::unique_ptr<ViewportWindow> stalePtr(viewport);
auto ret = extraViewports.erase(stalePtr);
Expand Down
3 changes: 2 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MainWindow : public chroma::WindowImpl {
const TCHAR * className() const override { return APP_NAME; }

public:
ViewportWindow *activeViewport;
ViewportWindow *activeViewport, *hoveredViewport;

void pushUndo();
void pushUndo(EditorState newState);
Expand Down Expand Up @@ -73,6 +73,7 @@ class MainWindow : public chroma::WindowImpl {
ViewportWindow mainViewport;
std::unordered_set<std::unique_ptr<ViewportWindow>> extraViewports;

void setTool(Tool tool);
void closeExtraViewports();
void resetModel();
bool save();
Expand Down
11 changes: 7 additions & 4 deletions src/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,13 +872,14 @@ void ViewportWindow::onButtonUp(HWND, int, int, UINT) {
}

void ViewportWindow::onMouseMove(HWND, int x, int y, UINT keyFlags) {
g_mainWindow.hoveredViewport = this;
if (!trackMouse) {
TrackMouseEvent(tempPtr(TRACKMOUSEEVENT{sizeof(TRACKMOUSEEVENT), TME_LEAVE, wnd}));
trackMouse = true;
}
POINT curPos = {x, y};
if (mouseMode == MOUSE_NONE) {
updateHover(curPos);
if (!trackMouse) {
TrackMouseEvent(tempPtr(TRACKMOUSEEVENT{sizeof(TRACKMOUSEEVENT), TME_LEAVE, wnd}));
trackMouse = true;
}
} else if (curPos != lastCurPos) {
SIZE delta = {curPos.x - lastCurPos.x, curPos.y - lastCurPos.y};
switch (mouseMode) {
Expand Down Expand Up @@ -921,6 +922,8 @@ void ViewportWindow::onMouseMove(HWND, int x, int y, UINT keyFlags) {

void ViewportWindow::onMouseLeave(HWND) {
trackMouse = false;
if (g_mainWindow.hoveredViewport == this)
g_mainWindow.hoveredViewport = NULL;
if (mouseMode == MOUSE_NONE && g_hover.type != PICK_NONE) {
g_hover = {};
g_mainWindow.refreshAll();
Expand Down
2 changes: 1 addition & 1 deletion src/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ViewportWindow : public chroma::WindowImpl {
void refreshImmediate();
void clearTextureCache();
void updateProjMat();
void updateHover(POINT pos);
glm::vec3 forwardAxis();
bool onCommand(HWND, int, HWND, UINT);

Expand All @@ -79,7 +80,6 @@ class ViewportWindow : public chroma::WindowImpl {

void lockMouse(POINT clientPos, MouseMode mode);
void setViewMode(ViewMode mode);
void updateHover(POINT pos);
void startToolAdjust(POINT pos);
void toolAdjust(POINT pos, SIZE delta, UINT keyFlags);
void drawMesh(const RenderMesh &mesh);
Expand Down

0 comments on commit 89daec3

Please sign in to comment.