diff --git a/ofxaddons_thumbnail.png b/ofxaddons_thumbnail.png new file mode 100644 index 0000000..1b8f519 Binary files /dev/null and b/ofxaddons_thumbnail.png differ diff --git a/screenshot/ofxScrollingText.png b/screenshot/ofxScrollingText.png new file mode 100644 index 0000000..40de8ba Binary files /dev/null and b/screenshot/ofxScrollingText.png differ diff --git a/src/ofxScrollingText.cpp b/src/ofxScrollingText.cpp new file mode 100644 index 0000000..8c94887 --- /dev/null +++ b/src/ofxScrollingText.cpp @@ -0,0 +1,136 @@ +// +// ofxScrollingText.cpp +// +// Created by Teruaki Tsubokura on 2014/03/13. +// +// + +#include "ofxScrollingText.h" + +//-------------------------------------------------------------- +ofxScrollingText *ofxScrollingText::mIns = 0; // inctance()内の条件式のために初期化 +ofxScrollingText* ofxScrollingText::instance(){ + if(!mIns){ + mIns = new ofxScrollingText(); + } + return mIns; +} + +//-------------------------------------------------------------- +ofxScrollingText::ofxScrollingText(){ + isVisible = false; + isPlaying = false; + isScroll = true; + fontColor = ofColor(255,255,255,255); + bgColor = ofColor(30, 30, 30, 180); + speed = 17.0; + alpha = 0; + textString = ""; + textPosition.y = ofGetHeight() * 0.8; + width = ofGetWidth(); + height = ofGetHeight()/10; +} + +//-------------------------------------------------------------- +ofxScrollingText::~ofxScrollingText(){ + +} + +//-------------------------------------------------------------- +void ofxScrollingText::setup(string _fontPath, int _fontSize){ + font.loadFont(_fontPath, _fontSize, true, true); + height = _fontSize * 2; +} + +//-------------------------------------------------------------- +void ofxScrollingText::update(){ + width = ofGetWidth(); + textPosition.y = ofGetHeight() - height; + if(isVisible && textString != ""){ + if( alpha < 1) alpha += (1 - alpha) * 0.1; + if(isScroll){ + if(0 < textPosition.x + font.stringWidth(textString)){ + textPosition.x -= speed; + }else{ + isVisible = false; + } + }else{ + textPosition.x = ofGetWidth() / 2 - font.stringWidth(textString) / 2; + } + }else{ + if( alpha > 0.01){ + alpha += (0 - alpha) * 0.1; + }else{ + alpha = 0; + if(isPlaying){ + isPlaying = false; + cout << "[ofxScrollingText] completeEvent." << endl; + ofNotifyEvent(ofxScrollingText::completeEvent); + } + } + } +} + +//-------------------------------------------------------------- +void ofxScrollingText::draw(){ + ofPushStyle(); + ofSetColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a * alpha); + ofRect(0, textPosition.y, width, height); + ofSetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * alpha); + font.drawString(textString, textPosition.x, textPosition.y + height - (height - font.stringHeight(textString))/2); + ofPopStyle(); +} + +//-------------------------------------------------------------- +void ofxScrollingText::showText(string _message){ + if(_message != ""){ + textString = _message; + isVisible = true; + isPlaying = true; + textPosition.x = ofGetWidth(); + } +} + +//-------------------------------------------------------------- +void ofxScrollingText::hideText(){ + isVisible = false; +} + +//-------------------------------------------------------------- +bool ofxScrollingText::getVisible(){ + return isVisible; +} + +//-------------------------------------------------------------- +void ofxScrollingText::setFontColor(ofColor _color){ + fontColor = _color; +} + +//-------------------------------------------------------------- +ofColor ofxScrollingText::getFontColor(){ + return fontColor; +} + +//-------------------------------------------------------------- +void ofxScrollingText::setBackgroundColor(ofColor _color){ + bgColor = _color; +} + +//-------------------------------------------------------------- +ofColor ofxScrollingText::getBackgroundColor(){ + return bgColor; +} + +//-------------------------------------------------------------- +void ofxScrollingText::setSpeed(float _speed){ + speed = _speed; +} + +//-------------------------------------------------------------- +float ofxScrollingText::getSpeed(){ + return speed; +} + +ofEvent ofxScrollingText::completeEvent; + + diff --git a/src/ofxScrollingText.h b/src/ofxScrollingText.h new file mode 100644 index 0000000..6d54dd9 --- /dev/null +++ b/src/ofxScrollingText.h @@ -0,0 +1,55 @@ +// +// ofxScrollingText.h +// +// Created by Teruaki Tsubokura on 2014/03/13. +// +// + +#pragma once + +#include "ofMain.h" +#include "ofxTrueTypeFontUC.h" + +class ofxScrollingText{ +public: + static ofxScrollingText* instance(); + void setup(string _fontPath, int _fontSize = 48); + void update(); + void draw(); + + void showText(string _message); + void hideText(); + bool getVisible(); + + void setFontColor(ofColor _color); + ofColor getFontColor(); + + void setBackgroundColor(ofColor _color); + ofColor getBackgroundColor(); + + void setSpeed(float _speed); + float getSpeed(); + + //テロップ再生完了イベント + static ofEvent completeEvent; + +private: + //シングルトン用にコンストラクタをprivateにして呼べなくする。 + ofxScrollingText(); + ~ofxScrollingText(); + //シングルトン用インスタンス + static ofxScrollingText* mIns; + + ofxTrueTypeFontUC font; + bool isVisible; + bool isPlaying; + bool isScroll; + float speed; + float alpha; + ofColor fontColor; + ofColor bgColor; + string textString; + ofPoint textPosition; + int width; + int height; +};