-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowLessMenu.cpp
More file actions
132 lines (104 loc) · 2.66 KB
/
WindowLessMenu.cpp
File metadata and controls
132 lines (104 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "mouseEvent.h"
#include "WindowLessAction.h"
#include "WindowLessMenu.h"
namespace
{
const int MENU_WIDTH = 250;
const int MENU_HEIGHT = 400;
const int ACTION_HEIGHT = 50;
}
WindowLessMenu::WindowLessMenu(ShowObject* parent) : WindowLessWidget(parent)
{
resize(MENU_WIDTH, MENU_HEIGHT);
}
WindowLessMenu::~WindowLessMenu()
{
}
void WindowLessMenu::move(Point loc)
{
updateActionLoc(getLoc(), loc);
WindowLessWidget::move(loc.x(), loc.y());
}
void WindowLessMenu::move(int x, int y)
{
Point newPoint = { x, y };
updateActionLoc(getLoc(), newPoint);
WindowLessWidget::move(x, y);
}
void WindowLessMenu::addAction(WindowLessAction* action)
{
Point& menuLoc = getLoc();
action->move(menuLoc.x(), menuLoc.y() + m_nMenuLine * ACTION_HEIGHT);
action->resize(MENU_WIDTH, ACTION_HEIGHT);
m_nActionNum++;
m_nMenuLine++;
m_vecAction.push_back(action);
resize(MENU_WIDTH, m_nMenuLine * ACTION_HEIGHT);
}
void WindowLessMenu::addActions(std::vector<WindowLessAction*> actions)
{
if (actions.empty())
return;
Point& menuLoc = getLoc();
int actionX = menuLoc.x();
int actionY = menuLoc.y() + m_nMenuLine * ACTION_HEIGHT;
int signleActionWidth = MENU_WIDTH / actions.size();
for (int i = 0; i < actions.size(); ++i)
{
actions[i]->move(actionX + i * signleActionWidth, actionY);
actions[i]->resize(signleActionWidth, ACTION_HEIGHT);
m_nActionNum++;
m_vecAction.push_back(actions[i]);
}
m_nMenuLine++;
resize(MENU_WIDTH, m_nMenuLine * ACTION_HEIGHT);
}
void WindowLessMenu::show()
{
WindowLessWidget::show();
for (auto x : m_vecAction)
{
if (!x->isShow())
continue;
x->show();
}
}
int WindowLessMenu::chooseAction(MouseEvent* event)
{
int count = 0;
Point* mousePressPoint = event->getPos();
int x = mousePressPoint->x();
int y = mousePressPoint->y();
RECT menuRect = getRect();
if (!isShow() || x < menuRect.left || x > menuRect.right || y < menuRect.top || y > menuRect.bottom)
return -1;
for (auto action : m_vecAction)
{
RECT actionRect = action->getRect();
if (x > actionRect.left && x < actionRect.right && y > actionRect.top && y < actionRect.bottom)
return count;
count++;
}
return -1;
}
void WindowLessMenu::updateActionLoc(Point& oldLoc, Point& newLoc)
{
Point diffPoint = newLoc.minusPoint(oldLoc);
for (auto action : m_vecAction)
{
Point actionNewLoc = action->getLoc().addPoint(diffPoint);
action->move(actionNewLoc.x(), actionNewLoc.y());
}
}
void WindowLessMenu::mousePressEvent(MouseEvent* event)
{
if (isShow())
{
hide();
return;
}
if (event->getButtonType() == MouseEvent::ButtonType::RIGHTBUTTON)
show();
if (event->getButtonType() == MouseEvent::ButtonType::LEFTBUTTON)
chooseAction(event);
}