Commit 2fc21b19 authored by Lky's avatar Lky

init setup

parent 98bff820
#ifndef MenuItem_h
#define MenuItem_h
#pragma once
#include "ofMain.h"
class MenuItem
{
public:
MenuItem(std::string path, float _x, float _y, std::string _name)
{
name = _name;
if (ofLoadImage(tex, path))
{
if (tex.isAllocated())
{
draw_pos.x = _x;
draw_pos.y = _y;
float rect_x = draw_pos.x - (tex.getWidth() / 2);
float rect_y = draw_pos.y - (tex.getHeight() / 2);
hit_zone = ofRectangle(rect_x, rect_y, tex.getWidth(), tex.getHeight());
tex.setAnchorPercent(0.5, 0.5);
}
}
b_hovered = false;
b_selected = false;
}
~MenuItem()
{
if (tex.isAllocated())
{
tex.clear();
}
}
void draw()
{
if (!tex.isAllocated())
return;
ofPushStyle();
if (b_hovered) ofSetColor(ofColor::lightGrey);
else if (b_selected) ofSetColor(ofColor::orange);
else ofSetColor(ofColor::white);
tex.draw(draw_pos);
ofPopStyle();
}
bool inside(ofVec2f hit)
{
bool _hit = hit_zone.inside(hit);
if (_hit)
{
if (b_selected) return _hit;
else
{
b_hovered = true;
return _hit;
}
}
else
{
b_hovered = false;
return false;
}
}
void select()
{
b_selected = !b_selected;
b_hovered = !b_selected;
}
void unselect()
{
b_selected = false;
b_hovered = false;
}
std::string& getName()
{
return name;
}
private:
ofVec2f draw_pos;
ofTexture tex;
ofRectangle hit_zone;
std::string name;
bool b_hovered;
bool b_selected;
};
#endif /* MenuItem_h */
#ifndef ParamSliderItem_h
#define ParamSliderItem_h
#pragma once
#include "ofMain.h"
class ParamSliderItem
{
public:
ParamSliderItem(float _x, float _y, float _width, float _height, float _min, float _max, std::string _name)
{
name = _name;
draw_pos.x = _x;
draw_pos.y = _y;
float rect_x = draw_pos.x - (_width / 2);
float rect_y = draw_pos.y - (_height / 2);
hit_zone = ofRectangle(rect_x, rect_y, _width, _height);
min_val = _min;
max_val = _max;
b_selected = false;
b_hovered = false;
reset();
}
ParamSliderItem()
{
}
void draw()
{
ofPushStyle();
if (b_hovered) ofSetColor(ofColor::lightGrey);
else ofSetColor(ofColor::white);
float line_x = hit_zone.x;
float line_y = hit_zone.y + (hit_zone.height / 2);
/* Main transport line */
ofDrawLine(line_x, line_y, line_x+hit_zone.width, line_y);
/* Cursor */
ofSetLineWidth(3.0f);
ofDrawLine(line_x+(cur_pos*hit_zone.width), line_y-10, line_x+(cur_pos*hit_zone.width), line_y+10);
ofPopStyle();
}
bool inside(const ofVec2f& hit)
{
if (hit_zone.inside(hit))
{
if (b_selected) return true;
else
{
b_hovered = true;
return true;
}
}
else
{
b_hovered = false;
return false;
}
}
void select()
{
}
void unselect()
{
}
std::string& getName()
{
}
void mouseDown(const ofVec2f& _mouse)
{
cur_pos = (_mouse.x - hit_zone.x) / hit_zone.width;
cur_val = ofMap(cur_pos, 0.0f, 1.0f, min_val, max_val);
}
/*** ADDING THIS TO GET VALUES FROM ARDUINO */
void setValue(float val)
{
cur_val = val;
}
/*******/
float getValue()
{
return cur_val;
}
ofRectangle& getRect()
{
return hit_zone;
}
void reset()
{
cur_val = 1.0f;
cur_pos = ofMap(cur_val, min_val, max_val, 0.0f, 1.0f);
}
private:
ofVec2f draw_pos;
ofRectangle hit_zone;
float cur_pos;
float cur_val;
float min_val;
float max_val;
std::string name;
bool b_hovered;
bool b_selected;
};
#endif /* ParamSlider_h */
#ifndef RangeSliderItem_h
#define RangeSliderItem_h
#pragma once
#include "ofMain.h"
class RangeSliderItem
{
public:
RangeSliderItem(float _x, float _y, float _width, float _height, std::string _name)
{
name = _name;
draw_pos.x = _x;
draw_pos.y = _y;
float rect_x = draw_pos.x - (_width / 2);
float rect_y = draw_pos.y - (_height / 2);
hit_zone = ofRectangle(rect_x, rect_y, _width, _height);
b_selected = false;
b_hovered = false;
range_in = 0.f;
range_out = 1.f;
}
RangeSliderItem()
{
}
void draw()
{
ofPushStyle();
if (b_hovered) ofSetColor(ofColor::lightGrey);
else ofSetColor(ofColor::white);
float line_x = hit_zone.x;
float line_y = hit_zone.y + (hit_zone.height / 2);
/* Main transport line */
ofDrawLine(line_x, line_y, line_x+hit_zone.width, line_y);
/* Cursor */
ofSetLineWidth(3.0f);
ofDrawLine(line_x+cur_pos, line_y-10, line_x+cur_pos, line_y+10);
if (range_in > 0.0f || range_out < 1.0f)
{
/* Loop range */
ofSetColor(255,174,0,100);
float range_start = line_x + (hit_zone.width * range_in);
float range_end = hit_zone.width * (range_out-range_in);
ofDrawRectangle(range_start, line_y-10, range_end, 20);
}
ofPopStyle();
}
bool inside(const ofVec2f& hit)
{
if (hit_zone.inside(hit))
{
if (b_selected) return true;
else
{
b_hovered = true;
return true;
}
}
else
{
b_hovered = false;
return false;
}
}
void select()
{
}
void unselect()
{
}
std::string& getName()
{
}
void setPlayhead(float _cur_pos)
{
cur_pos = _cur_pos*hit_zone.width;
}
void mouseDown(const ofVec2f& _cursor)
{
cur_pos = (_cursor.x - (hit_zone.x + hit_zone.width * range_in)) / ((range_out - range_in) * hit_zone.width);
}
void setRangeIn(float _in)
{
range_in = (_in - hit_zone.x) / hit_zone.width;
if (range_in > range_out)
{
range_in = MAX(0.0f,range_out-0.1f);
}
}
void setRangeOut(float _out)
{
range_out = (_out - hit_zone.x) / hit_zone.width;
if (range_out < range_in)
{
range_out = MIN(1.0f,range_in+0.1f);
}
}
void clearRange()
{
range_in = 0.f;
range_out = 1.f;
}
float getValue()
{
return cur_pos;
}
ofVec2f getSelectedRange()
{
return ofVec2f(range_in, range_out);
}
ofRectangle& getRect()
{
return hit_zone;
}
private:
ofVec2f draw_pos;
ofRectangle hit_zone;
float cur_pos;
float range_in;
float range_out;
std::string name;
bool b_hovered;
bool b_selected;
};
#endif /* RangeSliderItem_h */
#include "ofMain.h"
#include "ofApp.h"
int main( )
{
ofGLWindowSettings settings;
settings.setSize(1024*2, 512*2);
settings.windowMode = OF_WINDOW;
settings.setGLVersion(4, 1);
ofCreateWindow(settings);
ofRunApp(new ofApp());
}
This diff is collapsed.
#pragma once
#include "ofMain.h"
#include "ofxHPVPlayer.h"
#include "ofxTextureRecorder.h"
#include "MenuItem.h"
#include "RangeSliderItem.h"
#include "ParamSliderItem.h"
#include "ofTrueTypeFontExt.h"
class ofApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();
void exit();
void onHPVEvent(const HPVEvent& event);
void setupUI();
void keyPressed(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 windowResized(int w, int h);
ofxHPVPlayer hpvPlayer;
ofxHPVPlayer hpvChannel_2;
std::map<std::string, MenuItem *> ui_items;
RangeSliderItem * range_slider;
ParamSliderItem * speed_slider;
bool b_draw_stats;
bool b_draw_gui;
ofTrueTypeFontExt gui_font;
vector<string> video_names;
float potar_1, potar_2, potar_4, potar_0, potar_10, potar_11;
int opacity_1, opacity_2;
ofTexture videoTexture;
//ofTexture * hpvTexture;
ofxTextureRecorder recorder;
ofFbo fbo;
bool recording;
ofPixels videoPixels;
ofArduino ard;
bool bSetupArduino; // flag variable for setting up arduino once
private:
void setupArduino(const int & version);
void digitalPinChanged(const int & pinNum);
void analogPinChanged(const int & pinNum);
void updateArduino();
string buttonState;
string potValue;
};
#pragma once
#include "ofMain.h"
class ofTrueTypeFontExt : public ofTrueTypeFont
{
public:
// -----------------------------------------------------------------
void drawStringShadowed( string _s, ofVec2f _pos,
ofColor _frontColor = ofColor(255,255,255), ofColor _backColor = ofColor(0,0,0) )
{
drawStringShadowed( _s, _pos.x, _pos.y, _frontColor, _backColor );
}
// -----------------------------------------------------------------
void drawStringShadowed( string _s, float _x, float _y,
ofColor _frontColor = ofColor(255,255,255), ofColor _backColor = ofColor(0,0,0) )
{
ofSetColor( _backColor );
drawString( _s, _x + 1, _y + 1 );
ofSetColor( _frontColor );
drawString( _s, _x, _y );
}
// -----------------------------------------------------------------
void drawTextureAtlas( float _x, float _y, float _w, float _h )
{
if( _w == 0.0f || _h == 0.0f )
{
_w = texAtlas.getWidth();
_h = texAtlas.getHeight();
}
texAtlas.draw( _x, _y, _w, _h );
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment