Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cinder Creative Coding Cookbook

You're reading from   Cinder Creative Coding Cookbook If you know C++ this book takes your creative potential to a whole other level. The practical recipes show you how to create interactive and visually dynamic applications using Cinder which will excite and delight your audience.

Arrow left icon
Product type Paperback
Published in May 2013
Publisher Packt
ISBN-13 9781849518703
Length 352 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Toc

Table of Contents (19) Chapters Close

Cinder Creative Coding Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started 2. Preparing for Development FREE CHAPTER 3. Using Image Processing Techniques 4. Using Multimedia Content 5. Building Particle Systems 6. Rendering and Texturing Particle Systems 7. Using 2D Graphics 8. Using 3D Graphics 9. Adding Animation 10. Interacting with the User 11. Sensing and Tracking Input from the Camera 12. Using Audio Input and Output Index

Accessing files dropped onto the application window


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.

Getting ready

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 );

How to do it…

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:

  1. In the method implementation you can use the 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();
  2. The position where the files were dropped onto the window can be accessed through the following callback methods:

    • To get a ci::Vec2i object with the position of the files dropped, type in the following line of code:

      Vec2i dropPosition = event.getPos();
    • To get the x and y coordinates separately, you can use the getX and getY methods, for example:

      int pOS X = event.getX();
      int posY = event.getY();
  3. You can find the number of dropped files by using the getNumFiles method:

    int numFiles = event.getNumFiles();
  4. To access a specific file, if you already know its index, you can use the 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 );

How it works…

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.

There's more…

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image