c_cpp 简单的触发器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 简单的触发器相关的知识,希望对你有一定的参考价值。

#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{
    
public:
    void setup();
    void update();
    void draw();
    
    void keyPressed(int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    void dragEvent(ofDragInfo dragInfo);
    void gotMessage(ofMessage msg);
    
    
    ofVec2f pos;
    ofVec2f size;
    bool positionIn;
    
    bool mouseInside;
    
    

};
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofRectangle test;
    
    pos = ofVec2f( 300, 300 );
    size = ofVec2f( 200, 200 );
    
    mouseInside = false;
    
}

//--------------------------------------------------------------
void ofApp::update(){
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    
    if (positionIn && !mouseInside) {
        ofSetColor(255,0,0);
        mouseInside = true;
        cout << "bang Remain" << endl;
        
    } else if (!positionIn && mouseInside){
        mouseInside = false;
        ofSetColor(0,0,255);
    }
    
    
    ofRect(pos, size.x, size.y);
    
    
}


//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    
    if (((x>pos.x)&&(x<pos.x+size.x))&&((y>pos.y)&&(y<pos.y+size.y))) {
        positionIn = true;
    } else {
        positionIn = false;
    }
    
    
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
    
}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
    
}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 
    
}

以上是关于c_cpp 简单的触发器的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 天真的代码吃内存来触发MLE的判断。

c_cpp 用于调试信号的自定义插槽,验证它们是否被触发

c_cpp 玩具MC用于VPD触发窗口分辨率

c_cpp c ++的简单模板

c_cpp 简单的ofEvent,ofNotifyEvent

c_cpp C中的简单示例