forked from lenLRX/win32gl1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.cpp
163 lines (142 loc) · 2.28 KB
/
scene.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "stdafx.h"
#include "scene.h"
#include <stdlib.h>
#include <cassert>
using namespace std;
Scene::Scene(string name) :_name(name), id(0)
{
}
Scene::~Scene()
{
}
void Scene::init()
{
;
}
void Scene::clean()
{
}
void Scene::update(float dt)
{
throw 0;
}
bool Scene::sceneMouseEvent(mouseEvent _event)
{
return false;
}
void Scene::setname(string name)
{
_name = name;
}
string Scene::getname()
{
return _name;
}
int Scene::addchild(Sprite* child)
{
id++;
child->setid(id);
_sprites.push_back(child);
return id;
}
void Scene::removeChildByID(int id)
{
if (_sprites.size())
{
vector<Sprite*>::iterator it = _sprites.begin();
while (it != _sprites.end())
{
if ((*it)->getid() == id)
{
it= _sprites.erase(it);
}
else
{
it++;
}
}
}
if (_keyBoardEventList.size())
{
vector<Sprite*>::iterator it = _keyBoardEventList.begin();
while (it != _keyBoardEventList.end())
{
if ((*it)->getid() == id)
{
it = _keyBoardEventList.erase(it);
}
else
{
it++;
}
}
}
//throw 0;
if (_mouseEventList.size())
{
vector<Sprite*>::iterator it = _mouseEventList.begin();
while (it != _mouseEventList.end())
{
if ((*it)->getid() == id)
{
it = _mouseEventList.erase(it);
}
else
{
it++;
}
}
}
id = 0;
}
Sprite* Scene::getChildByID(int id)
{
if (_sprites.size())
{
for (vector<Sprite*>::iterator it = _sprites.begin(); it != _sprites.end(); it++)
{
if (id == (*it)->getid())//我们找到了对应ID的精灵
return (*it);
}
}
throw 0;//没找到或者向量为空,抛出异常
}
void Scene::handleMouseEvent(Point pt)
{
;
}
vector<Sprite*>& Scene::getSpriteList()
{
return _sprites;
}
void Scene::registerMouseEvent(Sprite* _sprite)
{
_mouseEventList.push_back(_sprite);
}
void Scene::processMouseEvent(mouseEvent _event)
{
if (sceneMouseEvent(_event))
{
return;
}
if (_mouseEventList.size())
{
for (vector<Sprite*>::iterator it = _mouseEventList.begin(); it != _mouseEventList.end(); it++)
{
if ((*it)->mouseEventCallBack(_event))
return; //当mouseEventCallBack返回值为真时,判断消息已经被处理完毕
}
}
}
void Scene::onKeyPressedCallback(int key)
{
assert(key < 256);
_keys[key]=1;
}
void Scene::clearKeys()
{
for (int i = 0; i < 256; i++)
{
_keys[i] = 0;
}
}