Browse Source

Move vertex on `moveSelectionBy`

master
Krisjanis Rijnieks 9 years ago
parent
commit
0a3c6ff8a2
  1. 21
      src/Surfaces/SurfaceManager.cpp
  2. 4
      src/Surfaces/SurfaceManager.h

21
src/Surfaces/SurfaceManager.cpp

@ -8,7 +8,7 @@ SurfaceManager::SurfaceManager(){
selectedSurface = 0; selectedSurface = 0;
ofAddListener(_surfaces.vertexChangedEvent, this, &SurfaceManager::onVertexChanged); ofAddListener(_surfaces.vertexChangedEvent, this, &SurfaceManager::onVertexChanged);
ofAddListener(_surfaces.verticesChangedEvent, this, &SurfaceManager::onVerticesChanged); ofAddListener(_surfaces.verticesChangedEvent, this, &SurfaceManager::onVerticesChanged);
_selectedVertexIndex = 0; _selectedVertexIndex = -1;
} }
void SurfaceManager::draw(){ void SurfaceManager::draw(){
@ -28,6 +28,7 @@ void SurfaceManager::removeSelectedSurface(){
if(_surfaces[i] == selectedSurface){ if(_surfaces[i] == selectedSurface){
_surfaces.erase(i); _surfaces.erase(i);
selectedSurface = 0; selectedSurface = 0;
_selectedVertexIndex = -1;
break; break;
} }
} }
@ -76,6 +77,7 @@ BaseSurface * SurfaceManager::selectSurface(int index){
} }
selectedSurface = _surfaces[index]; selectedSurface = _surfaces[index];
_selectedVertexIndex = -1;
ofSendMessage("surfaceSelected"); ofSendMessage("surfaceSelected");
return selectedSurface; return selectedSurface;
} }
@ -84,6 +86,7 @@ BaseSurface * SurfaceManager::selectSurface(BaseSurface * surface){
for(int i = 0; i < _surfaces.size(); i++){ for(int i = 0; i < _surfaces.size(); i++){
if(_surfaces[i] == surface){ if(_surfaces[i] == surface){
selectedSurface = surface; selectedSurface = surface;
_selectedVertexIndex = -1;
ofSendMessage("surfaceSelected"); ofSendMessage("surfaceSelected");
ofNotifyEvent(surfaceSelectedEvent, i, this); ofNotifyEvent(surfaceSelectedEvent, i, this);
return selectedSurface; return selectedSurface;
@ -96,6 +99,7 @@ BaseSurface * SurfaceManager::selectSurface(BaseSurface * surface){
BaseSurface * SurfaceManager::selectNextSurface(){ BaseSurface * SurfaceManager::selectNextSurface(){
int next; int next;
_selectedVertexIndex = -1;
if(selectedSurface == 0){ if(selectedSurface == 0){
next = 0; next = 0;
@ -123,6 +127,7 @@ BaseSurface * SurfaceManager::selectNextSurface(){
BaseSurface * SurfaceManager::selectPrevSurface(){ BaseSurface * SurfaceManager::selectPrevSurface(){
int prev; int prev;
_selectedVertexIndex = -1;
if(selectedSurface == 0){ if(selectedSurface == 0){
prev = _surfaces.size() - 1; prev = _surfaces.size() - 1;
@ -160,7 +165,9 @@ void SurfaceManager::selectNextVertex(){
int numVertices = selectedSurface->getVertices().size(); int numVertices = selectedSurface->getVertices().size();
if(_selectedVertexIndex < numVertices - 1){ if(_selectedVertexIndex == -1){
_selectedVertexIndex = 0;
}else if(_selectedVertexIndex < numVertices - 1){
_selectedVertexIndex += 1; _selectedVertexIndex += 1;
}else{ }else{
_selectedVertexIndex = 0; _selectedVertexIndex = 0;
@ -191,13 +198,19 @@ void SurfaceManager::moveSelectionBy(ofVec2f v){
return; return;
} }
if(_selectedVertexIndex != -1){
selectedSurface->getVertices()[_selectedVertexIndex] += v;
ofNotifyEvent(vertexChangedEvent, _selectedVertexIndex, this);
}else{
selectedSurface->moveBy(v); selectedSurface->moveBy(v);
}
// TODO: use member variable for this in the future // TODO: use member variable for this in the future
} }
void SurfaceManager::deselectSurface(){ void SurfaceManager::deselectSurface(){
selectedSurface = 0; selectedSurface = 0;
_selectedVertexIndex = -1;
} }
BaseSurface * SurfaceManager::getSurface(int index){ BaseSurface * SurfaceManager::getSurface(int index){
@ -213,8 +226,8 @@ int SurfaceManager::size(){
return _surfaces.size(); return _surfaces.size();
} }
void SurfaceManager::onVertexChanged(ofVec3f & vertex){ void SurfaceManager::onVertexChanged(int & i){
ofNotifyEvent(vertexChangedEvent, vertex, this); ofNotifyEvent(vertexChangedEvent, i, this);
} }
void SurfaceManager::onVerticesChanged(vector<ofVec3f> & vertices){ void SurfaceManager::onVerticesChanged(vector<ofVec3f> & vertices){

4
src/Surfaces/SurfaceManager.h

@ -51,12 +51,12 @@ class SurfaceManager {
int size(); int size();
ofEvent <ofVec3f> vertexChangedEvent; ofEvent <int> vertexChangedEvent;
ofEvent <vector<ofVec3f>> verticesChangedEvent; ofEvent <vector<ofVec3f>> verticesChangedEvent;
ofEvent <int> surfaceSelectedEvent; ofEvent <int> surfaceSelectedEvent;
ofEvent <int> vertexSelectedEvent; ofEvent <int> vertexSelectedEvent;
void onVertexChanged(ofVec3f & vertex); void onVertexChanged(int & i);
void onVerticesChanged(vector<ofVec3f> & vertices); void onVerticesChanged(vector<ofVec3f> & vertices);
private: private:

Loading…
Cancel
Save