Cinder applications can respond to files dropped onto the application window through the callback, fileDrop
. This method takes a ci::app::FileDropEvent
object as a parameter with information about the event.
Your application must implement a fileDrop
method which takes a ci::app::FileDropEvent
object as a parameter.
Add the following method to the application's class declaration:
void fileDrop( FileDropEvent event );
We will learn how to work with the ci::app::FileDropEvent
object to work with file drop events. Perform the following steps to do so:
ci::app::FileDropEvent
parameter to access the list of files dropped onto the application by calling the getFiles
method. This method returns a conststd::vector
container with fs::path
objects:const vector<fs::path >& files = event.getFiles();
ci::Vec2i
object with the position of the files dropped, type in the following line of code:Vec2i dropPosition = event.getPos();
getX
and getY
methods, for example:int pOS X = event.getX(); int posY = event.getY();
getNumFiles
method:int numFiles = event.getNumFiles();
getFile
method and pass the index as a parameter.For example, to access the file with an index of 2
, you can use the following line of code:
const fs::path& file = event.getFile( 2 );
A Cinder application will respond to the system's native event for file drops. It will then create a ci::app::FileDropEvent
object with information about the event and call the fileDrop
callback in our application. This way Cinder creates a uniform way of responding to file drop events across the Windows and OS X platforms.
Cinder uses ci::fs::path
objects to define paths. These are typedef
instances of boost::filesystem::path
objects and allow for much greater flexibility when working with paths. To learn more about the fs::path
objects, please refer to the boost::filesystem
library reference, available at http://www.boost.org/doc/libs/1_50_0/libs/filesystem/doc/index.htm.
3.138.204.186