/*!\reimp */ void QSlider::mouseMoveEvent( QMouseEvent *e ) { if ( state != Dragging ) return; if ( style() == WindowsStyle ) { QRect r = rect(); int m = style().maximumSliderDragDistance(); if ( m >= 0 ) { if ( orientation() == Horizontal ) r.setRect( r.x() - m, r.y() - 2*m/3, r.width() + 2*m, r.height() + 3*m ); else r.setRect( r.x() - 2*m/3, r.y() - m, r.width() + 3*m, r.height() + 2*m ); if ( !r.contains( e->pos() ) ) { moveSlider( positionFromValue( sliderStartVal) ); return; } } } int pos = goodPart( e->pos() ); moveSlider( pos - clickOffset ); }
ScrollBar::ScrollBar(double minBase, double maxBase, Qt::Orientation o, QWidget *parent): QScrollBar(o, parent) { init(); setBase(minBase, maxBase); moveSlider(minBase, maxBase); }
void ScrollBar::setInverted(bool inverted) { if ( d_inverted != inverted ) { d_inverted = inverted; moveSlider(minSliderValue(), maxSliderValue()); } }
//------------------------------------------------------------------ void simpleSlider::mousePressed(ofMouseEventArgs & _args) { int sliderLoc=sliderPos.x+pos.x; if(_args.x>sliderLoc&&_args.x<sliderLoc+sliderSize&&_args.y>pos.y&&_args.y<pos.y+sliderSize) { bIsBeingDragged=true; moveSlider(_args.x); } }
ScrollBar::ScrollBar(double minBase, double maxBase, bool logscale, Qt::Orientation o, QWidget *parent): QScrollBar(o, parent), mLogScale(logscale) { init(); setBase(minBase, maxBase); moveSlider(minBase, maxBase); }
void DoubleSlider::mouseMoveEvent(QMouseEvent* e) { e->accept(); float normalizedMousePosTmp = static_cast<float>((e->pos()).x()-leftOffset_) / static_cast<float>(width()-leftOffset_-rightOffset_); if (normalizedMousePosTmp > 1.f) normalizedMousePosTmp = 1.f; else if (normalizedMousePosTmp < 0.f) normalizedMousePosTmp = 0.f; moveSlider(normalizedMousePosTmp); emit valuesChanged(minValue_, maxValue_); }
void ScrollBar::setBase(double min, double max) { if ( min != d_minBase || max != d_maxBase ) { d_minBase = min; d_maxBase = max; moveSlider(minSliderValue(), maxSliderValue()); } }
void ScrollBar::init() { d_inverted = orientation() == Qt::Vertical; d_baseTicks = 1000000; d_minBase = 0.0; d_maxBase = 1.0; moveSlider(d_minBase, d_maxBase); connect(this, SIGNAL(sliderMoved(int)), SLOT(catchSliderMoved(int))); connect(this, SIGNAL(valueChanged(int)), SLOT(catchValueChanged(int))); }
void QvisOpacitySlider::mouseMoveEvent(QMouseEvent *e) { if(state != Dragging) return; QRect r = rect(); int m = maximumSliderDragDistance(); if(m >= 0) { r.setRect(r.x() - m, r.y() - 2*m/3, r.width() + 2*m, r.height() + 3*m); if(!r.contains(e->pos())) { moveSlider( positionFromValue( sliderStartVal) ); return; } } moveSlider(e->pos().x() - clickOffset ); }
void ScrollBar::setBase(double min, double max) { if (mLogScale) { min = log(min); max = log(max); } if (min != d_minBase || max != d_maxBase) { d_minBase = min; d_maxBase = max; moveSlider(minSliderValue(), maxSliderValue()); } }
void QvisOpacitySlider::mousePressEvent(QMouseEvent *e) { resetState(); sliderStartVal = sliderVal; QRect r = sliderRect(); if(e->button() == Qt::RightButton) { return; } else if(r.contains(e->pos())) { state = Dragging; clickOffset = (int)(e->pos().x() - sliderPos); // emit sliderPressed(); } else if(e->button() == Qt::MidButton) { int pos = e->pos().x(); moveSlider(pos - sliderLength() / 2); state = Dragging; clickOffset = sliderLength() / 2; } else if(e->pos().x() < r.left()) { state = TimingDown; subtractPage(); if(!timer) timer = new QTimer(this); connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout())); timer->setSingleShot(true); timer->start(thresholdTime); } else if(e->pos().x() > r.right()) { state = TimingUp; addPage(); if(!timer) timer = new QTimer(this); connect(timer, SIGNAL(timeout()), SLOT(repeatTimeout())); timer->setSingleShot(true); timer->start(thresholdTime); } }
int ScrollBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QScrollBar::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: sliderMoved((*reinterpret_cast< Qt::Orientation(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3]))); break; case 1: valueChanged((*reinterpret_cast< Qt::Orientation(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3]))); break; case 2: setBase((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2]))); break; case 3: moveSlider((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2]))); break; case 4: catchValueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 5: catchSliderMoved((*reinterpret_cast< int(*)>(_a[1]))); break; default: ; } _id -= 6; } return _id; }
void DoubleSlider::mousePressEvent(QMouseEvent* e) { e->accept(); //calculate which marker is nearest to mouse position normalizedMousePos_ = static_cast<float>((e->pos()).x()-leftOffset_) / static_cast<float>(width()-leftOffset_-rightOffset_); mV1_ = minValue_; mV2_ = maxValue_; if (e->button() == Qt::LeftButton) { if (fabs(minValue_ - normalizedMousePos_) < fabs(maxValue_ - normalizedMousePos_)) { leftSliderActive_ = true; rightSliderActive_ = false; } else { leftSliderActive_ = false; rightSliderActive_ = true; } } else if (e->button() == Qt::RightButton) { leftSliderActive_ = true; rightSliderActive_ = true; } moveSlider(normalizedMousePos_); emit toggleInteractionMode(true); }
/*!\reimp */ void QSlider::mousePressEvent( QMouseEvent *e ) { resetState(); sliderStartVal = sliderVal; QRect r = sliderRect(); if ( e->button() == RightButton ) { return; } else if ( r.contains( e->pos() ) ) { state = Dragging; clickOffset = (QCOORD)( goodPart( e->pos() ) - sliderPos ); emit sliderPressed(); } else if ( e->button() == MidButton || (funnyWindowsStyle && style() == WindowsStyle) ) { int pos = goodPart( e->pos() ); moveSlider( pos - slideLength() / 2 ); state = Dragging; clickOffset = slideLength() / 2; } else if ( orient == Horizontal && e->pos().x() < r.left() //### goodPart || orient == Vertical && e->pos().y() < r.top() ) { state = TimingDown; subtractPage(); if ( !timer ) timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout()) ); timer->start( thresholdTime, TRUE ); } else if ( orient == Horizontal && e->pos().x() > r.right() //### goodPart || orient == Vertical && e->pos().y() > r.bottom() ) { state = TimingUp; addPage(); if ( !timer ) timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout()) ); timer->start( thresholdTime, TRUE ); } }
// Draws the interface to the screen void drawInterface() { Sprite *temp; int i = -1; int x, y; TTF_Font *font; SDL_Surface *button; SDL_Rect dest; SDL_Surface icon; // fade HUD in/out if(HUD.menu != 0 && aSlide == false) { if(alpha > 4) alpha -= 5; else alpha = SDL_ALPHA_TRANSPARENT; } else if(alpha < (255*aLevel)) alpha += 5; else { alpha = 255*aLevel; } if(HUD.menu > 0) SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format, 0,0,0)); else { if(players[0].placing > -1) placeStruct2(); } // load font for text font = TTF_OpenFont("fonts/font1.ttf",30); if(font == NULL) { fprintf(stderr,"Font failed to load.\n"); } // unless alpha > 0, don't bother drawing the interface if(alpha > 0) { // minimap temp = LoadSprite("hud/minimap.png",HUD.mapw,HUD.maph); SDL_SetAlpha( temp->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(temp,screen,HUD.mapx,HUD.mapy,0); // info bar temp = LoadSprite("hud/infobar.png",HUD.infow,HUD.infoh); SDL_SetAlpha( temp->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(temp,screen,HUD.infox,HUD.infoy,0); // Draw structure icons while(++i<MAX_STRUCT_TYPES) { if( HUD.aStructs[i].draw == false ) continue; // Draw background temp = LoadSprite("hud/qbutton.png",58,58); SDL_SetAlpha( temp->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(temp, screen, HUD.aStructs[i].x, HUD.aStructs[i].y, 0); // Draw structure icon SDL_SetColorKey(HUD.aStructs[i].img->image, SDL_SRCCOLORKEY , SDL_MapRGB(HUD.aStructs[i].img->image->format, 255,255,255)); SDL_SetAlpha(HUD.aStructs[i].img->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(HUD.aStructs[i].img, screen, HUD.aStructs[i].x+((58-HUD.aStructs[i].img->w)*.5), HUD.aStructs[i].y+((58-HUD.aStructs[i].img->h)*.5), 0); } // Draw unit icons i = -1; while(++i<MAX_UNIT_TYPES) { if( HUD.aUnits[i].draw == false ) continue; // Draw background temp = LoadSprite("hud/qbutton.png",58,58); SDL_SetAlpha(temp->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(temp,screen,HUD.aUnits[i].x,HUD.aUnits[i].y,0); // Draw unit icon SDL_SetColorKey(HUD.aUnits[i].img->image, SDL_SRCCOLORKEY , SDL_MapRGB(HUD.aUnits[i].img->image->format, 255,255,255)); SDL_SetAlpha(HUD.aUnits[i].img->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(HUD.aUnits[i].img, screen, HUD.aUnits[i].x+((58-HUD.aUnits[i].img->w)*.5), HUD.aUnits[i].y+((58-HUD.aUnits[i].img->h)*.5), 0); } // media player bar temp = LoadSprite("hud/mplayerbar.png",HUD.playerw,HUD.playerh); SDL_SetAlpha( temp->image, SDL_SRCALPHA|SDL_RLEACCEL, alpha ); DrawSprite(temp,screen,HUD.playerx,HUD.playery,0); updatePlayer(); // tool tips if(HUD.ttips) showTip(); } // Draw menu if( (HUD.menu > 0) && (HUD.menu != 5) ) { temp = LoadSprite("hud/menu.png",640,480); // center and draw the menu panel and buttons if(screen->w > 640) x = screen->w * .5 - 320; else x = 0; if(screen->h > 480) y = screen->h * .5 - 240; else y = 0; DrawSprite(temp,screen,x,y,0); } // Draw the button text // Main menu if(HUD.menu == 1) { // New Game dest.x = MENU_X+250; dest.y = MENU_Y+55; dest.w = 100; dest.h = 50; if(mouseOver == 1) button = TTF_RenderText_Blended(font,"New Game",oColor); else button = TTF_RenderText_Blended(font,"New Game",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Resume dest.x = MENU_X+260; dest.y = MENU_Y+138; dest.w = 100; dest.h = 50; if(players[0].inGame) { if(mouseOver == 2) button = TTF_RenderText_Blended(font,"Resume",oColor); else button = TTF_RenderText_Blended(font,"Resume",color); } else button = TTF_RenderText_Blended(font,"Resume",bColor); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Save/Load dest.x = MENU_X+245; dest.y = MENU_Y+223; dest.w = 100; dest.h = 50; if(mouseOver == 3) button = TTF_RenderText_Blended(font,"Save/Load",oColor); else button = TTF_RenderText_Blended(font,"Save/Load",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Options dest.x = MENU_X+260; dest.y = MENU_Y+302; dest.w = 100; dest.h = 50; if(mouseOver == 4) button = TTF_RenderText_Blended(font,"Options",oColor); else button = TTF_RenderText_Blended(font,"Options",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Quit dest.x = MENU_X+285; dest.y = MENU_Y+385; dest.w = 100; dest.h = 50; if(mouseOver == 5) button = TTF_RenderText_Blended(font,"Quit",oColor); else button = TTF_RenderText_Blended(font,"Quit",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } // Save/Load submenu else if(HUD.menu == 2) { // Save dest.x = MENU_X+275; dest.y = MENU_Y+55; dest.w = 100; dest.h = 50; if(mouseOver == 1) button = TTF_RenderText_Blended(font,"Save",oColor); else button = TTF_RenderText_Blended(font,"Save",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Load dest.x = MENU_X+275; dest.y = MENU_Y+138; dest.w = 100; dest.h = 50; if(mouseOver == 2) button = TTF_RenderText_Blended(font,"Load",oColor); else button = TTF_RenderText_Blended(font,"Load",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Main Menu dest.x = MENU_X+245; dest.y = MENU_Y+385; dest.w = 100; dest.h = 50; if(mouseOver == 5) button = TTF_RenderText_Blended(font,"Main Menu",oColor); else button = TTF_RenderText_Blended(font,"Main Menu",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } // Options submenu else if(HUD.menu == 3) { // Sound dest.x = MENU_X+275; dest.y = MENU_Y+55; dest.w = 100; dest.h = 50; if(mouseOver == 1) button = TTF_RenderText_Blended(font,"Sound",oColor); else button = TTF_RenderText_Blended(font,"Sound",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Controls dest.x = MENU_X+260; dest.y = MENU_Y+138; dest.w = 100; dest.h = 50; if(mouseOver == 2) button = TTF_RenderText_Blended(font,"Controls",oColor); else button = TTF_RenderText_Blended(font,"Controls",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // HUD dest.x = MENU_X+285; dest.y = MENU_Y+223; dest.w = 100; dest.h = 50; if(mouseOver == 3) button = TTF_RenderText_Blended(font,"HUD",oColor); else button = TTF_RenderText_Blended(font,"HUD",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Game dest.x = MENU_X+270; dest.y = MENU_Y+302; dest.w = 100; dest.h = 50; if(mouseOver == 4) button = TTF_RenderText_Blended(font,"Game",oColor); else button = TTF_RenderText_Blended(font,"Game",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Main Menu dest.x = MENU_X+245; dest.y = MENU_Y+385; dest.w = 100; dest.h = 50; if(mouseOver == 5) button = TTF_RenderText_Blended(font,"Main Menu",oColor); else button = TTF_RenderText_Blended(font,"Main Menu",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } // Sound submenu else if(HUD.menu == 4) { // Sound effects volume dest.x = MENU_X+140; dest.y = MENU_Y+55; dest.w = 100; dest.h = 50; if(mouseOver == 1) button = TTF_RenderText_Blended(font,"Effects Volume",oColor); else button = TTF_RenderText_Blended(font,"Effects Volume",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Draw slots for volume sliders dest.x += 235; dest.y += 15; temp = LoadSprite("hud/menuslots.png",126,13); DrawSprite(temp,screen,dest.x,dest.y,0); dest.y += 85; temp = LoadSprite("hud/menuslots.png",126,13); DrawSprite(temp,screen,dest.x,dest.y,0); // Update info based on slider position dest.x += 10; dest.w = 100; if( (audio.slide == 1) ) { if(SDL_GetMouseState(NULL,NULL)&SDL_BUTTON_LMASK) { audio.eVol = moveSlider(&audio.evSlider,&dest); } else audio.slide = 0; } else if( (audio.slide == 2) ) { if(SDL_GetMouseState(NULL,NULL)&SDL_BUTTON_LMASK) { audio.mVol = moveSlider(&audio.mvSlider,&dest); } else audio.slide = 0; } else { audio.evSlider.x = dest.x + (dest.w*audio.eVol); audio.mvSlider.x = dest.x + (dest.w*audio.mVol); } // Draw sliders temp = LoadSprite("hud/slider.png",50,24); button = IMG_Load("hud/slider.png"); SDL_SetColorKey(button, 0, 0); temp->image = SDL_DisplayFormatAlpha(button); SDL_FreeSurface(button); temp = LoadSprite("hud/slider.png",50,24); DrawSprite(temp,screen,audio.evSlider.x-(audio.evSlider.w*.5),audio.evSlider.y,0); temp = LoadSprite("hud/slider.png",50,24); DrawSprite(temp,screen,audio.mvSlider.x-(audio.mvSlider.w*.5),audio.mvSlider.y,0); // Music volume dest.x = MENU_X+140; dest.y = MENU_Y+138; dest.w = 100; dest.h = 50; if(mouseOver == 2) button = TTF_RenderText_Blended(font,"Music Volume",oColor); else button = TTF_RenderText_Blended(font,"Music Volume",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Mute dest.x = MENU_X+275; dest.y = MENU_Y+223; dest.w = 100; dest.h = 50; if(mouseOver == 3) button = TTF_RenderText_Blended(font,"Mute",oColor); else button = TTF_RenderText_Blended(font,"Mute",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Back dest.x = MENU_X+285; dest.y = MENU_Y+385; dest.w = 100; dest.h = 50; if(mouseOver == 5) button = TTF_RenderText_Blended(font,"Back",oColor); else button = TTF_RenderText_Blended(font,"Back",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } // HUD submenu else if(HUD.menu == 6) { // Alpha level dest.x = MENU_X+175; dest.y = MENU_Y+55; dest.w = 100; dest.h = 50; if(mouseOver == 1) button = TTF_RenderText_Blended(font,"Alpha Level",oColor); else button = TTF_RenderText_Blended(font,"Alpha Level",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Draw slot for alpha slider dest.x += 200; dest.y += 15; temp = LoadSprite("hud/menuslots.png",126,13); DrawSprite(temp,screen,dest.x,dest.y,0); // Update info based on slider position dest.x += 10; dest.w = 100; if( (aSlide == true) ) { if(SDL_GetMouseState(NULL,NULL)&SDL_BUTTON_LMASK) { aLevel = moveSlider(&aSlider,&dest); } else aSlide = false; } else { aSlider.x = dest.x + (dest.w*aLevel); } // Draw sliders temp = LoadSprite("hud/slider.png",50,24); DrawSprite(temp,screen,aSlider.x-(aSlider.w*.5),aSlider.y,0); // Save dest.x = MENU_X+285; dest.y = MENU_Y+138; dest.w = 100; dest.h = 50; if(mouseOver == 2) button = TTF_RenderText_Blended(font,"Save",oColor); else button = TTF_RenderText_Blended(font,"Save",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Load dest.x = MENU_X+285; dest.y = MENU_Y+223; dest.w = 100; dest.h = 50; if(mouseOver == 3) button = TTF_RenderText_Blended(font,"Load",oColor); else button = TTF_RenderText_Blended(font,"Load",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Back dest.x = MENU_X+285; dest.y = MENU_Y+385; dest.w = 100; dest.h = 50; if(mouseOver == 5) button = TTF_RenderText_Blended(font,"Back",oColor); else button = TTF_RenderText_Blended(font,"Back",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } // Game submenu else if(HUD.menu == 7) { // Scroll speed dest.x = MENU_X+175; dest.y = MENU_Y+55; dest.w = 100; dest.h = 50; if(mouseOver == 1) button = TTF_RenderText_Blended(font,"Scroll Speed",oColor); else button = TTF_RenderText_Blended(font,"Scroll Speed",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); // Draw slot for scroll speed slider dest.x += 200; dest.y += 15; temp = LoadSprite("hud/menuslots.png",126,13); DrawSprite(temp,screen,dest.x,dest.y,0); dest.x += 10; dest.w = 100; if( (HUD.sSlide == true) ) { if(SDL_GetMouseState(NULL,NULL)&SDL_BUTTON_LMASK) { sSpeed = moveSlider(&sSlider,&dest); } else HUD.sSlide = false; } else { sSlider.x = dest.x + (dest.w*sSpeed); } // Draw slider temp = LoadSprite("hud/slider.png",50,24); DrawSprite(temp,screen,sSlider.x-(sSlider.w*.5),sSlider.y,0); // Tool tips on/off dest.x = MENU_X+215; dest.y = MENU_Y+138; dest.w = 100; dest.h = 50; if(mouseOver == 2) button = TTF_RenderText_Blended(font,"Tool Tips",oColor); else button = TTF_RenderText_Blended(font,"Tool Tips",color); if(button != NULL) { SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } dest.x += 150; if(HUD.ttips) button = TTF_RenderText_Blended(font,"On",color); else button = TTF_RenderText_Blended(font,"Off",color); if(button != NULL) { SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } // Back dest.x = MENU_X+285; dest.y = MENU_Y+385; dest.w = 100; dest.h = 50; if(mouseOver == 5) button = TTF_RenderText_Blended(font,"Back",oColor); else button = TTF_RenderText_Blended(font,"Back",color); if(button != NULL) SDL_BlitSurface(button,NULL,screen,&dest); SDL_FreeSurface(button); } if(font != NULL) TTF_CloseFont(font); }
//------------------------------------------------------------------ void simpleSlider::mouseDragged(ofMouseEventArgs & _args) { if(bIsBeingDragged) { moveSlider(_args.x); } }
void Slidebar::update(double dt) { static char temp[10]; // ugly hack if(gDInput->mouseButtonDown(LEFTBUTTON)) { if(gDInput->cursorInsideRect(mSlider) || mMovingSlider) { if(gDInput->mouseDX() < 0) { // slider has a valid position if(mSliderPos > 0 + mSliderWidth/2) { moveSlider(gDInput->mouseDX()); // set the value, dx in 0-1 range * value span mValue += (mMaxValue - mMinValue)*((gDInput->mouseDX()) / (mSlideBackground.right - mSlideBackground.left - mSliderWidth)); // - mSliderWidth på vänster sidan?:O callback(getID(), WindowMessage(mValue)); // stop invalid movement if(mSliderPos <= 0 + mSliderWidth/2) { stopSlider(LEFT); } sprintf(temp, "%.2f", mValue); // hack >_> string temp2 = string(temp); mInputBox->setValue(temp2); } else { stopSlider(LEFT); } } else if(gDInput->mouseDX() > 0) { if(mSliderPos < (mSlideBackground.right - mSlideBackground.left - mSliderWidth/2)) { moveSlider(gDInput->mouseDX()); // set the value, dx in 0-1 range * value span mValue += (mMaxValue - mMinValue)*((gDInput->mouseDX()) / (mSlideBackground.right - mSlideBackground.left - mSliderWidth)); callback(getID(), WindowMessage(mValue)); // stop invalid movement if(mSliderPos >= (mSlideBackground.right - mSlideBackground.left - mSliderWidth/2)) { stopSlider(RIGHT); } sprintf(temp, "%.2f", mValue); // hack >_> string temp2 = string(temp); mInputBox->setValue(temp2); } else { stopSlider(RIGHT); } } // dont allow Y movement while sliding gDInput->setCursorY(gDInput->getCursorY() - gDInput->mouseDY()); } } if(gDInput->mouseButtonReleased(LEFTBUTTON)) mMovingSlider = false; }