Browse Source

Add ScaleSurfaceFromToCmd and integrate it

master
Krisjanis Rijnieks 9 years ago
parent
commit
ac32484445
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 2
      src/Application/GuiBaseWidget.h
  3. 20
      src/Application/ProjectionMappingState.cpp
  4. 5
      src/Application/ProjectionMappingState.h
  5. 2
      src/Application/ScaleWidget.cpp
  6. 4
      src/Application/ScaleWidget.h
  7. 24
      src/Commands/ScaleSurfaceFromToCmd.cpp
  8. 26
      src/Commands/ScaleSurfaceFromToCmd.h

6
example/example.xcodeproj/project.pbxproj

@ -40,6 +40,7 @@
0130C9831CE65AA600911E17 /* snappy-stubs-internal.cc in Sources */ = {isa = PBXBuildFile; fileRef = 0130C94B1CE65AA600911E17 /* snappy-stubs-internal.cc */; };
0130C9841CE65AA600911E17 /* snappy.cc in Sources */ = {isa = PBXBuildFile; fileRef = 0130C94E1CE65AA600911E17 /* snappy.cc */; };
0177D5511D0B05230096A920 /* ToggleAnimatedSourceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0177D5501D0B05230096A920 /* ToggleAnimatedSourceCmd.cpp */; };
01CD67871D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01CD67861D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp */; };
01F9EB1D1D624702009CA5E8 /* MvLayerDnCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01F9EB1B1D624702009CA5E8 /* MvLayerDnCmd.cpp */; };
01F9EB1E1D624702009CA5E8 /* MvLayerUpCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01F9EB1C1D624702009CA5E8 /* MvLayerUpCmd.cpp */; };
391717EF1B08FFDA00F9A484 /* SetApplicationStateCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717ED1B08FFDA00F9A484 /* SetApplicationStateCmd.cpp */; };
@ -240,6 +241,8 @@
0130C95B1CE65AA600911E17 /* ofxIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxIO.h; sourceTree = "<group>"; };
0177D54F1D0B05230096A920 /* ToggleAnimatedSourceCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToggleAnimatedSourceCmd.h; path = Commands/ToggleAnimatedSourceCmd.h; sourceTree = "<group>"; };
0177D5501D0B05230096A920 /* ToggleAnimatedSourceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ToggleAnimatedSourceCmd.cpp; path = Commands/ToggleAnimatedSourceCmd.cpp; sourceTree = "<group>"; };
01CD67851D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScaleSurfaceFromToCmd.h; path = Commands/ScaleSurfaceFromToCmd.h; sourceTree = "<group>"; };
01CD67861D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScaleSurfaceFromToCmd.cpp; path = Commands/ScaleSurfaceFromToCmd.cpp; sourceTree = "<group>"; };
01F9EB191D624702009CA5E8 /* MvLayerDnCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MvLayerDnCmd.h; path = Commands/MvLayerDnCmd.h; sourceTree = "<group>"; };
01F9EB1A1D624702009CA5E8 /* MvLayerUpCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MvLayerUpCmd.h; path = Commands/MvLayerUpCmd.h; sourceTree = "<group>"; };
01F9EB1B1D624702009CA5E8 /* MvLayerDnCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MvLayerDnCmd.cpp; path = Commands/MvLayerDnCmd.cpp; sourceTree = "<group>"; };
@ -928,6 +931,8 @@
0117D7091D64EBB4008FECEB /* ScaleSurfaceUpCmd.cpp */,
0117D7061D64EBB4008FECEB /* ScaleSurfaceDnCmd.h */,
0117D7081D64EBB4008FECEB /* ScaleSurfaceDnCmd.cpp */,
01CD67851D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.h */,
01CD67861D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp */,
);
name = Commands;
sourceTree = "<group>";
@ -1216,6 +1221,7 @@
392651711C5429C600C54844 /* HomographyHelper.cpp in Sources */,
39C1247D19F187D5005DF557 /* CircleJoint.cpp in Sources */,
39264842192224F90008A7F5 /* tinyxmlerror.cpp in Sources */,
01CD67871D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp in Sources */,
3926483B192224DA0008A7F5 /* ofxXmlSettings.cpp in Sources */,
0130C9681CE65AA600911E17 /* README.md in Sources */,
39C1245119EE95DD005DF557 /* DirectoryWatcher.cpp in Sources */,

2
src/Application/GuiBaseWidget.h

@ -20,7 +20,7 @@ class GuiBaseWidget {
virtual void onMouseDragged(ofMouseEventArgs & e) = 0;
virtual bool inside(float x, float y) = 0;
virtual float getScale(){}
ofEvent <GuiWidgetEvent> guiWidgetEvent;

20
src/Application/ProjectionMappingState.cpp

@ -3,6 +3,10 @@
namespace ofx {
namespace piMapper {
ProjectionMappingState::ProjectionMappingState(){
_surfaceScaleBeforeTransform = 1.0f;
}
ProjectionMappingState * ProjectionMappingState::_instance = 0;
ProjectionMappingState * ProjectionMappingState::instance(){
@ -337,14 +341,22 @@ void ProjectionMappingState::onBackgroundPressed(Application * app, GuiBackgroun
}
void ProjectionMappingState::onGuiEvent(Application * app, GuiEvent & e){
// Scale widget now. More later.
if(e.widget == &Gui::instance()->getScaleWidget()){
if(e.args.type == e.args.Pressed){
cout << "Scale Pressed" << endl;
_surfaceScaleBeforeTransform =
app->getSurfaceManager()->getSelectedSurface()->getScale();
}else if(e.args.type == e.args.Released){
cout << "Scale Released" << endl;
if(_surfaceScaleBeforeTransform !=
app->getSurfaceManager()->getSelectedSurface()->getScale()){
app->getCmdManager()->exec(new ScaleSurfaceFromToCmd(
app->getSurfaceManager()->getSelectedSurface(),
_surfaceScaleBeforeTransform,
app->getSurfaceManager()->getSelectedSurface()->getScale()));
}
}else if(e.args.type == e.args.Dragged){
cout << "Scale Dragged" << endl;
cout << "Scale: " << e.widget->getScale() << endl;
app->getSurfaceManager()->getSelectedSurface()->scaleTo(e.widget->getScale());
}
}

5
src/Application/ProjectionMappingState.h

@ -27,6 +27,7 @@
#include "MvLayerDnCmd.h"
#include "ScaleSurfaceUpCmd.h"
#include "ScaleSurfaceDnCmd.h"
#include "ScaleSurfaceFromToCmd.h"
#include "SurfaceType.h"
#include "Gui.h"
@ -52,8 +53,12 @@ class ProjectionMappingState : public ApplicationBaseState {
void onGuiEvent(Application * app, GuiEvent & e);
private:
ProjectionMappingState();
static ProjectionMappingState * _instance;
float _surfaceScaleBeforeTransform;
};
} // namespace piMapper

2
src/Application/ScaleWidget.cpp

@ -9,7 +9,7 @@ ScaleWidget::ScaleWidget(){
_handle.width = 20;
_handle.height = 20;
_scale = 1.0f;
_surface = 0;
}

4
src/Application/ScaleWidget.h

@ -25,7 +25,7 @@ class ScaleWidget : public GuiBaseWidget {
// This should be the size of the objet's bounding box
void setSurface(BaseSurface * s);
float getScale(){
return _scale;
}
@ -34,7 +34,7 @@ class ScaleWidget : public GuiBaseWidget {
ofRectangle _handle;
ofPolyline _line;
float _scale;
bool _dragging;

24
src/Commands/ScaleSurfaceFromToCmd.cpp

@ -0,0 +1,24 @@
#include "ScaleSurfaceFromToCmd.h"
namespace ofx {
namespace piMapper {
ScaleSurfaceFromToCmd::ScaleSurfaceFromToCmd(BaseSurface * selectedSurface, float from, float to){
_selectedSurface = selectedSurface;
_scaleFrom = from;
_scaleTo = to;
}
void ScaleSurfaceFromToCmd::exec(){
ofLogNotice("ScaleSurfaceFromToCmd", "exec");
_selectedSurface->scaleTo(_scaleTo);
}
void ScaleSurfaceFromToCmd::undo(){
ofLogNotice("ScaleSurfaceFromToCmd", "undo");
_selectedSurface->scaleTo(_scaleFrom);
}
} // namespace piMapper
} // namespace ofx

26
src/Commands/ScaleSurfaceFromToCmd.h

@ -0,0 +1,26 @@
#pragma once
#include "BaseCmd.h"
#include "BaseSurface.h"
namespace ofx {
namespace piMapper {
class ScaleSurfaceFromToCmd : public BaseUndoCmd {
public:
ScaleSurfaceFromToCmd(BaseSurface * selectedSurface, float from, float to);
void exec();
void undo();
private:
BaseSurface * _selectedSurface;
float _scaleFrom;
float _scaleTo;
};
} // namespace piMapper
} // namespace ofx
Loading…
Cancel
Save