Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Teruaki Tsubokura
committed
Mar 14, 2014
0 parents
commit ffcce9e
Showing
4 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <void> ofxScrollingText::completeEvent; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> 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; | ||
}; |