Permalink
Browse files

Re-added caption class (lost in rebasing accident).

  • Loading branch information...
1 parent 5966380 commit e0bf342facc533f4697301704ef6e6b365b782dc @acaudwell committed Feb 25, 2013
Showing with 100 additions and 0 deletions.
  1. +49 −0 src/caption.cpp
  2. +51 −0 src/caption.h
View
49 src/caption.cpp
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com)
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 3 of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "caption.h"
+
+RCaption::RCaption(const std::string& caption, time_t timestamp, const FXFont& font) {
+ this->caption = caption;
+ this->timestamp = timestamp;
+ this->font = font;
+
+ alpha = 1.0f;
+ colour = gGourceSettings.caption_colour;
+ decay = 1.0f / gGourceSettings.caption_duration;
+}
+
+const vec2& RCaption::getPos() {
+ return pos;
+}
+
+void RCaption::setPos(const vec2& pos) {
+ this->pos = pos;
+}
+
+bool RCaption::isFinished() {
+ return alpha <= 0.0f;
+}
+
+void RCaption::logic(float dt) {
+ alpha = std::max(0.0f, alpha - dt * decay);
+}
+
+void RCaption::draw() {
+ font.setColour(vec4(colour.x, colour.y, colour.z, 1.0f - fabs(alpha - 0.5) * 2.0f));
+ font.draw(pos.x, pos.y, caption);
+}
View
51 src/caption.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (C) 2010 Andrew Caudwell (acaudwell@gmail.com)
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 3 of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef RCAPTION_H
+#define RCAPTION_H
+
+#include "core/display.h"
+#include "core/fxfont.h"
+#include "gource_settings.h"
+
+class RCaption {
+ float alpha;
+ float decay;
+
+ vec2 pos;
+
+ vec3 colour;
+
+ FXFont font;
+
+public:
+ std::string caption;
+ time_t timestamp;
+
+ RCaption(const std::string& caption, time_t timestamp, const FXFont& font);
+
+ void setPos(const vec2& pos);
+ const vec2& getPos();
+
+ bool isFinished();
+
+ void logic(float dt);
+
+ void draw();
+};
+
+#endif

0 comments on commit e0bf342

Please sign in to comment.