BVB Source Codes

Gource Show action.cpp Source code

Return Download Gource: download action.cpp Source code - Download Gource Source code - Type:.cpp
  1. /*
  2.     Copyright (C) 2009 Andrew Caudwell (acaudwell@gmail.com)
  3.  
  4.     This program is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU General Public License
  6.     as published by the Free Software Foundation; either version
  7.     3 of the License, or (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. */
  17.  
  18. #include "action.h"
  19.  
  20. RAction::RAction(RUser* source, RFile* target, float addedtime) {
  21.     this->source    = source;
  22.     this->target    = target;
  23.     this->addedtime = addedtime;
  24.  
  25.     progress = 0.0;
  26.  
  27.     rate = 0.5;
  28. }
  29.  
  30. void RAction::apply() {
  31.     target->touch(colour);
  32. }
  33.  
  34. void RAction::logic(float dt) {
  35.     if(progress >= 1.0) return;
  36.  
  37.     if(progress == 0.0) {
  38.         apply();
  39.     }
  40.  
  41.     float action_rate = std::min(10.0f, rate * std::max(1.0f, ((float)source->getPendingActionCount())));
  42.  
  43.     progress = std::min(progress + action_rate * dt, 1.0f);
  44. }
  45.  
  46. void RAction::drawToVBO(quadbuf& buffer) const {
  47.     if(isFinished()) return;
  48.  
  49.     vec2 src  = source->getPos();
  50.     vec2 dest = target->getAbsolutePos();
  51.  
  52.     //TODO: could use glm::perp
  53.  
  54.     vec2 n    = normalise(dest - src);
  55.     vec2 perp = vec2(-n.y, n.x);
  56.  
  57.     vec2 offset     = perp * target->getSize() * 0.5f;
  58.     vec2 offset_src = offset * 0.3f;
  59.  
  60.     float alpha = 1.0 - progress;
  61.     float alpha2 = alpha * 0.1;
  62.  
  63.     vec4 col1 = vec4(colour, alpha);
  64.     vec4 col2 = vec4(colour, alpha2);
  65.  
  66.     quadbuf_vertex v1(src  - offset_src,  col2, vec2(0.0f, 0.0f));
  67.     quadbuf_vertex v2(src  + offset_src,  col2, vec2(0.0f, 1.0f));
  68.     quadbuf_vertex v3(dest + offset,      col1, vec2(1.0f, 1.0f));
  69.     quadbuf_vertex v4(dest - offset,      col1, vec2(1.0f, 0.0f));
  70.  
  71.     buffer.add(0, v1, v2, v3, v4);
  72. }
  73.  
  74. void RAction::draw(float dt) {
  75.     if(isFinished()) return;
  76.  
  77.     vec2 src  = source->getPos();
  78.     vec2 dest = target->getAbsolutePos();
  79.  
  80.     vec2 n    = normalise(dest - src);
  81.     vec2 perp = vec2(-n.y, n.x);
  82.  
  83.     vec2 offset     = perp * target->getSize() * 0.5f;
  84.     vec2 offset_src = offset * 0.3f;
  85.  
  86.     float alpha = 1.0 - progress;
  87.     float alpha2 = alpha * 0.1;
  88.  
  89.     vec4 col1 = vec4(colour, alpha);
  90.     vec4 col2 = vec4(colour, alpha2);
  91.  
  92.     glBegin(GL_QUADS);
  93.         glColor4fv(glm::value_ptr(col2));
  94.         glTexCoord2f(0.0,0.0);
  95.         glVertex2f(src.x - offset_src.x, src.y - offset_src.y);
  96.         glTexCoord2f(0.0,1.0);
  97.         glVertex2f(src.x + offset_src.x, src.y + offset_src.y);
  98.  
  99.         glColor4fv(glm::value_ptr(col1));
  100.         glTexCoord2f(1.0,1.0);
  101.         glVertex2f(dest.x + offset.x, dest.y + offset.y);
  102.         glTexCoord2f(1.0,0.0);
  103.        glVertex2f(dest.x - offset.x, dest.y - offset.y);
  104.     glEnd();
  105. }
  106.  
  107. CreateAction::CreateAction(RUser* source, RFile* target, float addedtime) : RAction(source, target, addedtime) {
  108.     colour = vec3(0.0, 1.0, 0.0);
  109. }
  110.  
  111. RemoveAction::RemoveAction(RUser* source, RFile* target, float addedtime): RAction(source, target, addedtime) {
  112.     colour = vec3(1.0, 0.0, 0.0);
  113. }
  114.  
  115. void RemoveAction::logic(float dt) {
  116.     float old_progress = progress;
  117.  
  118.     RAction::logic(dt);
  119.  
  120.     if(old_progress < 1.0 && progress >= 1.0) {
  121.         target->remove();
  122.     }
  123. }
  124.  
  125. ModifyAction::ModifyAction(RUser* source, RFile* target, float addedtime, const vec3& modify_colour)
  126.     : modify_colour(modify_colour), RAction(source, target, addedtime) {
  127.     colour = vec3(1.0, 0.7, 0.3);
  128. }
  129.  
  130. void ModifyAction::apply() {
  131.     RAction::apply();
  132.     target->setFileColour(modify_colour);
  133. }
  134.  
downloadaction.cpp Source code - Download Gource Source code
Related Source Codes/Software:
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
ImageOptim - GUI image optimizer for Mac htt... 2017-01-09
falcon - Falcon is a low-level, high-performance Python fra... 2017-01-09
prerender - Node server that uses phantomjs to render a javasc... 2017-01-09
che - Eclipse Che: Next-generation Eclipse IDE. Open sou... 2017-01-10
notepad-plus-plus - Notepad++ official repository h... 2017-01-10
waterline - An adapter-based ORM for Node.js with support for ... 2017-01-10
Workerman - An asynchronous event driven PHP framework for eas... 2017-01-10
structor - An advanced visual editor for React components ... 2017-01-10
GroundControl - Remote configuration for iOS 2017-04-30
browser-diet - 2017-04-30
react-music - Make beats with React! http... 2017-04-30
java-code-styles - IntelliJ IDEA code style settings for Square's Jav... 2017-04-30
swing - A swipeable cards interface. The swipe-left/swipe-... 2017-04-30
qTip2 - qTip2 - Pretty powerful tooltips ... 2017-04-30
jo - JSON output from a shell 2017-04-30
Fluidbox - Replicating and improving the lightbox module seen... 2017-04-30
boto3 - AWS SDK for Python http://a... 2017-04-30
PreloadJS - PreloadJS makes preloading assets & getting ag... 2017-04-29

 Back to top