Eigene Dateien/uni/visualisierung/vislu/bsp1/VisLu/VSliceElement.cpp

Go to the documentation of this file.
00001 #include "VSliceElement.h"
00002 #include <iostream>
00003 #include "V2Ddraw.h"
00004 #include "VTexture.h"
00005 #include "corona.h"
00006 
00007 using namespace std;
00008 using namespace corona;
00009 
00010 VSliceElement::VSliceElement(int* width, int* height, unsigned int* fps, int* _sliceNo):
00011         GUIelement(width,height,fps)
00012 {
00013         float * col = new float[3];
00014         col[0] = col[1] = 1.0;
00015         col[2] = 0.0;
00016         this->width = (int)(0.2*(*this->wwidth));
00017         this->height = (int)(0.2*(*this->wheight));
00018         this->x = (int) *(this->wwidth)*0.8;
00019         this->y = (int) *(this->wheight)*0.8;
00020         this->bg = new float[4];
00021         this->bg[0] = 1.0f;
00022         this->bg[1] = 1.0f;
00023         this->bg[2] = 1.0f;
00024         this->bg[3] = 1.0f;
00025         this->exit = new VExitBox(this->x+this->width-15,this->y+5,10,bg,col,&(this->alpha));
00026         this->slider = new VSlider(0.5,this->x+25,this->y+this->height-25,this->x-5,this->y+35,&(this->alpha));
00027 
00028         this->sliceNo = new int();
00029         this->sliceNo = _sliceNo;
00030         this->count = 0;
00031         this->slice = false;
00032 
00033         this->tex = new VTexture("slices.png");
00034         this->dragging = false;
00035 }
00036 
00037 VSliceElement::~VSliceElement(void)
00038 {
00039         delete exit;
00040         delete slider;
00041         delete bg;
00042         delete sliceNo;
00043 }
00044 
00045 void VSliceElement::motion(int xm, int ym) {
00046         exit->inside(xm,ym);
00047 }
00048 
00049 void VSliceElement::render() {
00050         if(!this->active && this->blend) { //einblenden
00051                 float frames = (float)*(this->fps);
00052                 this->alpha+=sin((1.3/frames));
00053                 this->bg[3] = this->alpha;
00054                 this->draw();
00055                 if(this->alpha >= 1) {
00056                         this->alpha = 1;
00057                         this->setActive(true);
00058                 }
00059         }
00060         if(this->active && !this->blend) { //ausblenden
00061                 float frames = (float)*(this->fps);
00062                 this->alpha-=sin((1.3/frames));
00063                 this->bg[3] = this->alpha;
00064                 this->draw();
00065                 if(this->alpha <= 0) {
00066                         this->alpha = 0;
00067                         this->setActive(false);
00068                 }
00069 
00070         }
00071         if(this->active && this->blend) { //aktiv
00072                 this->draw();
00073         }
00074 }
00075 
00076 void VSliceElement::draw() {
00077         glColor4fv(bg);
00078         glEnable(GL_BLEND);
00079         glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
00080         glEnable(GL_TEXTURE_2D);
00081         this->tex->bind();
00082         V2Ddraw::drawBox(this->x,this->y,this->width,this->height, 1);
00083         glDisable(GL_TEXTURE_2D);
00084         exit->draw();
00085 
00086         if (!(count%15)){
00087                 *(this->sliceNo) = this->slice;
00088         }
00089         if (count > 15){
00090                 count = 1;
00091         }
00092         else {
00093                 this->count++;
00094         }
00095         slider->render();
00096 }
00097 
00098 void VSliceElement::released(int xm, int ym) {
00099         this->slider->released(xm,ym);
00100         if(!this->dragging) {
00101                 if(exit->isInside(xm,ym))
00102                         this->setBlend(false);
00103                 else {
00104                         if(((xm-this->x) > 0) && ((xm-this->x) < this->width)){
00105                                 if (((ym-this->y) > 0) && ((ym-this->y) < this->height/2)){
00106                                         float * value = this->slider->getValue();
00107                                         this->slider->setValue(*value + 0.033f);
00108                                         this->slice = -1;
00109                                 }
00110                                 else if (((ym-this->y) > this->height/2) && ((ym-this->y) < this->height)){
00111                                         float * value = this->slider->getValue();
00112                                         this->slider->setValue(*value - 0.033f);
00113                                         this->slice = 1;
00114                                 }
00115                         }
00116                 }
00117         }
00118         this->dragging = false;
00119 }
00120 
00121 void VSliceElement::pressed(int xm, int ym) {
00122         this->slider->pressed(xm,ym);
00123         this->slice = 0;
00124         *(this->sliceNo) = 0;
00125         count = 0;
00126 }
00127 
00128 void VSliceElement::drag(int xm, int ym) {
00129         if(this->slider->isInside(xm,ym))
00130                 this->slider->drag(xm,ym);
00131         this->dragging = true;
00132 }
00133 
00134 bool VSliceElement::isInside(int xm, int ym) {
00135         return xm > this->x-10 && xm < this->x+this->width && ym > this->y && ym < this->y+this->width;
00136 }
00137 
00138 float * VSliceElement::getSliderValue() {
00139         return this->slider->getValue();
00140 }

Generated on Wed Dec 6 11:08:00 2006 for VisLU by  doxygen 1.5.1-p1