summaryrefslogtreecommitdiff
path: root/FESgui/src/selectpanel.h
blob: a6811bc8f6994605214bdc7cc1ef0f56149641ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include "ofMain.h"
#include "ofxGui.h"

/* a gui panel that receives key and drag events. */

class selectPanel : public ofxPanel {
	public:
	selectPanel(string _name=""){
		name=_name;
		ofRegisterKeyEvents(this, defaultEventsPriority);
		ofRegisterDragEvents(this, defaultEventsPriority);
	}
	bool mouseMoved(ofMouseEventArgs & args){
		if (args.x>getPosition().x&&
			args.x-getPosition().x<getWidth()&&
			args.y>getPosition().y&&
			args.y-getPosition().y<getHeight()){
			isSelected=true;	
			setHeaderBackgroundColor(ofColor(255,128,0));
		}
		else {
			isSelected=false;
			setHeaderBackgroundColor(ofColor(80,80,80));
		}
	}
	bool keyPressed(ofKeyEventArgs & args){
		if (isSelected){
			ofLog()<<name<<" KEY> "<<args.key;
			switch(args.key){
				default:
					break;
			}
		}
	}
	bool keyReleased(ofKeyEventArgs & args){
		//required in order to call ofRegisterKeyEvents
	}
	virtual void loadfile(const string & f){};
	bool dragEvent(ofDragInfo & dragInfo){
		if (dragInfo.position.x>getPosition().x&&
			dragInfo.position.x-getPosition().x<getWidth()&&
			dragInfo.position.y>getPosition().y&&
			dragInfo.position.y-getPosition().y<getHeight()){
			ofLog()<<name<<" DRAG> "<<dragInfo.files[0];
			loadfile(dragInfo.files[0]);
		}
	}
private:
	bool isSelected;
	string name;
};