Search code examples
imagedrag-and-dropcinder

Dynamical drawing images in Cinder (Windows)


I have used Cinder about few weeks and i have some problem. I am using method "drag-and-drop" in my program :

void TutorialApp::fileDrop(FileDropEvent drop){               ///        drop are images
for(size_t i=0; i<drop.getNumFiles();++i){
     Vertex imageVertex = Vertex((Vec2i(drop.getPos().x, drop.getPos().y+200)));
     imageVertex.path = drop.getFiles()[i];

and next my step is draw Vertex with associeted image. So that is question: how to add resources in this case, or maybe there is more easy solution? Thank


Solution

  • Straight to the point: First of all,you want to keep images (i.e gl::Texture) in your objects, that you want to draw. So in your class Vertex, add this gl::Texture as member. And then I suggest to use this function to load image and edit constructor, to take gl::Texture as parameter.

    So you end up with something like this:

    class testVertex
    {
    public:
    testVertex(Vec2i _pos, gl::Texture image);
    
    void draw(){
    
        gl::draw(texture, pos);
    }
    private:
        gl::Texture texture;
        Vec2i pos;
    };
    ///constructor
    testVertex::testVertex(Vec2i _pos, gl::Texture image)
    {
        pos = _pos;
        texture = image;
    }
    
    
    class BasicApp : public AppNative {
    public:
        void setup();
        void mouseMove( MouseEvent event ); 
        void mouseUp( MouseEvent event );   
        void keyUp(KeyEvent event);
    void fileDrop(FileDropEvent event);
    void update();
    void draw();
    
    //// create container for testVertex
    vector <testVertex> mVertices;
    }
    
    
    /// To load images via drop...
    void BasicApp::fileDrop(FileDropEvent event){
        gl::Texture fileTexture = loadImage(event.getFile(0));
        mVertices.push_back(testVertex(Vec2i(event.getX(), event.getY()), fileTexture));
    }
    /// To draw images...
    void BasicApp::draw(){
        for (int i = 0; i < mVertices.size(); i++)
        {
            mVertices[i].draw();
        }
    }
    ///