Esempio n. 1
1
void textureDrawExt(Game* g, Texture* t, 
                    float x, float y, float w, float h,
                    float tX, float tY, float tW, float tH,
                    float originX, float originY,
                    float scaleX, float scaleY, float angle, float alpha,
                    bool additiveBlend, Color color)
{
    #ifdef OPENGL
    
        renderBatchDrawTextureExt(&g->renderBatch, t, x, y, w, h, tX, tY, tW, tH,
                                  originX, originY, angle, scaleX, scaleY, g);
        
    #else
        
        // TODO: Change the rotation implementation to match the OpenGL implementation.
        //       (Scale affects the rotation origin in this function)
        
        float scaleOffsetX = fabs(scaleX) * w * (originX / w);
        float scaleOffsetY = fabs(scaleY) * h * (originY / h);
        
        SDL_Rect dest = { 
            x - scaleOffsetX - roundf(g->camera.x) + originX, 
            y - scaleOffsetY - roundf(g->camera.y) + originY, 
            w *= fabs(scaleX), 
            h *= fabs(scaleY) 
        };
        
        int flip = 0;
        if(scaleX < 0)
            flip = flip | SDL_FLIP_HORIZONTAL;
        if(scaleY < 0)
            flip = flip | SDL_FLIP_VERTICAL;
        
        if(alpha > 1)
            alpha = 1;
        if(alpha < 0)
            alpha = 0;
        
        SDL_SetTextureColorMod(t->data, 
                               clampi((color.r * 255), 0, 255), 
                               clampi((color.g * 255), 0, 255), 
                               clampi((color.b * 255), 0, 255));
        SDL_SetTextureAlphaMod(t->data, alpha * color.a * 255);
        
        if(additiveBlend)
            SDL_SetTextureBlendMode(t->data, SDL_BLENDMODE_ADD);
        else
            SDL_SetTextureBlendMode(t->data, SDL_BLENDMODE_BLEND);
        
        SDL_Rect source = { tX, tY, tW, tH };
        SDL_Point center = { originX * scaleX, originY * scaleY };
        SDL_RenderCopyEx(g->renderer, t->data, &source, &dest, 
                         angle * 180 / PI, &center, flip);
                         
    #endif
} 
Esempio n. 2
0
Vec2i Vec2i::clamp(const Vec2i &vec, int a, int b)
{
	Vec2i C;
	C.x() = clampi(vec.x(), a,b);
	C.y() = clampi(vec.y(), a,b);
	return C;
}
Esempio n. 3
0
void WSpacePlot::mousePressEvent(QMouseEvent *e) {
  
  if (e->button()==LeftButton) {
    
    QPoint pos=frame()->mapFrom(this,e->pos())-
      frame()->contentsRect().topLeft();
    
    currCursorPos=pos;
    
    float x,y;
    mapFromViewCoords(pos,x,y);
    QPoint cell=QPoint(clampi(int(rint(x)),0,viewSize.width()),
		       clampi(int(rint(y)),0,viewSize.height()));
    
    int index=cell.x()+cell.y()*viewSize.width();

    if (multiSelect)
      if (e->state() & ShiftButton) {
	clearTmpSelected();
	selectRectTmp(QRect(startCell,cell),selecting);
      } else if (e->state() & ControlButton) {
	startCell=cell;
	acceptTmpSelected();
	selecting=!(cellData[index].attr & selected);
	selectRectTmp(QRect(startCell,cell),selecting);
      } else {
	startCell=cell;
	if ((cellData[index].attr & selected) &&
	    (cellData[index].attr & normal))
	  dragEnabled=true;
	else {
	  clearSelection();
	  selecting=true;
	  selectRectTmp(QRect(startCell,cell),selecting);
	}
	e->ignore();
      }
    else {
      clearSelection();
      selectRectTmp(QRect(cell,cell),true);
      emit selectionChanged();
      e->ignore();
    }

    setCellLabel(pos,cell);
    updateGraph();

    currCell=cell;

  } else e->ignore();
}
Esempio n. 4
0
void WSpacePlot::mouseMoveEvent(QMouseEvent *e) {
  
  if (e->state() & LeftButton) {

    QPoint pos=frame()->mapFrom(this,e->pos())-
      frame()->contentsRect().topLeft();
   
    currCursorPos=pos;
    
    float x,y;
    mapFromViewCoords(pos,x,y);
    QPoint cell=QPoint(clampi(int(rint(x)),0,viewSize.width()),
		       clampi(int(rint(y)),0,viewSize.height()));
    
    if (dragEnabled) {
      dragEnabled=false;
      clearCellLabel();
      emit wouldDrag();
    } else {
      if (!QRect(QPoint(0,0),getFrameSize()).contains(pos)) {
	if (!autoPanTimer->isActive()) autoPanTimer->start(1);
      } else {
	autoPanTimer->stop();
	if (cell!=currCell) {
	  if (multiSelect) {
	    clearTmpSelected();
	    selectRectTmp(QRect(startCell,cell),selecting);
	  } else {
	    clearSelection();
	    selectRectTmp(QRect(cell,cell),true);
	    emit selectionChanged();
	  }
	}
	setCellLabel(pos,cell);
      }
    }
    
    currCell=cell;

    updateGraph();
    
  } else e->ignore(); 
}
Esempio n. 5
0
void lineDraw(Game* g, float ax, float ay, float bx, float by,
              float cr, float cg, float cb, float ca)
{
    #ifdef OPENGL
    
        
    
    #else
        SDL_SetRenderDrawBlendMode(g->renderer,
                                   SDL_BLENDMODE_BLEND);
        SDL_SetRenderDrawColor(g->renderer, 
                               clampi((cr * 255), 0, 255), 
                               clampi((cg * 255), 0, 255), 
                               clampi((cb * 255), 0, 255), 
                               clampi((ca * 255), 0, 255));
        SDL_RenderDrawLine(g->renderer, ax, ay, bx, by);
    
    #endif
}
Esempio n. 6
0
void rectangleDraw(Game* g, float x, float y, float w, float h, 
                   float cr, float cg, float cb, float ca)
{
    #ifdef OPENGL
    
        
    
    #else
    
        SDL_Rect rect = { (int)x, (int)y, (int)w, (int)h };
        SDL_SetRenderDrawBlendMode(g->renderer,
                                   SDL_BLENDMODE_BLEND);
        SDL_SetRenderDrawColor(g->renderer, 
                               clampi((cr * 255), 0, 255), 
                               clampi((cg * 255), 0, 255), 
                               clampi((cb * 255), 0, 255), 
                               clampi((ca * 255), 0, 255));
        SDL_RenderFillRect(g->renderer, &rect);
    
    #endif
}
Esempio n. 7
0
void WSpacePlot::autoPan() {

  float x,y;
  mapFromViewCoords(currCursorPos,x,y);

  QPoint cell=QPoint(clampi(int(rint(x)),0,viewSize.width()),
		     clampi(int(rint(y)),0,viewSize.height()));
  
  setCellLabel(currCursorPos,cell);

  float dx=getXVisRange()>x?getXVisRange().min()-x:
    (getXVisRange()<x?getXVisRange().max()-x:0);
  float dy=getYVisRange()>y?getYVisRange().min()-y:
    (getYVisRange()<y?getYVisRange().max()-y:0);

  if (dx) {
    WRange vrx=getXVisRange()-dx*0.05;
    vrx.adjustToFit(getXDataRange());
    setXVisRange(vrx);
  }

  if (dy) {
    WRange vry=getYVisRange()-dy*0.05;
    vry.adjustToFit(getYDataRange());
    setYVisRange(vry);
  }

  if (multiSelect) {
    clearTmpSelected();
    selectRectTmp(QRect(startCell,cell),selecting);
  } else {
    clearSelection();
    selectRectTmp(QRect(cell,cell),true);
    emit selectionChanged();
  }
}
Esempio n. 8
0
/* Set up all data. */
static void init(struct bs2b *bs2b)
{
    float Fc_lo, Fc_hi;
    float G_lo,  G_hi;
    float x, g;

    bs2b->srate = clampi(bs2b->srate, 2000, 192000);

    switch(bs2b->level)
    {
    case BS2B_LOW_CLEVEL: /* Low crossfeed level */
        Fc_lo = 360.0f;
        Fc_hi = 501.0f;
        G_lo  = 0.398107170553497f;
        G_hi  = 0.205671765275719f;
        break;

    case BS2B_MIDDLE_CLEVEL: /* Middle crossfeed level */
        Fc_lo = 500.0f;
        Fc_hi = 711.0f;
        G_lo  = 0.459726988530872f;
        G_hi  = 0.228208484414988f;
        break;

    case BS2B_HIGH_CLEVEL: /* High crossfeed level (virtual speakers are closer to itself) */
        Fc_lo = 700.0f;
        Fc_hi = 1021.0f;
        G_lo  = 0.530884444230988f;
        G_hi  = 0.250105790667544f;
        break;

    case BS2B_LOW_ECLEVEL: /* Low easy crossfeed level */
        Fc_lo = 360.0f;
        Fc_hi = 494.0f;
        G_lo  = 0.316227766016838f;
        G_hi  = 0.168236228897329f;
        break;

    case BS2B_MIDDLE_ECLEVEL: /* Middle easy crossfeed level */
        Fc_lo = 500.0f;
        Fc_hi = 689.0f;
        G_lo  = 0.354813389233575f;
        G_hi  = 0.187169483835901f;
        break;

    default: /* High easy crossfeed level */
        bs2b->level = BS2B_HIGH_ECLEVEL;

        Fc_lo = 700.0f;
        Fc_hi = 975.0f;
        G_lo  = 0.398107170553497f;
        G_hi  = 0.205671765275719f;
        break;
    } /* switch */

    g = 1.0f / (1.0f - G_hi + G_lo);

    /* $fc = $Fc / $s;
     * $d  = 1 / 2 / pi / $fc;
     * $x  = exp(-1 / $d);
     */
    x           = expf(-2.0f * F_PI * Fc_lo / bs2b->srate);
    bs2b->b1_lo = x;
    bs2b->a0_lo = G_lo * (1.0f - x) * g;

    x           = expf(-2.0f * F_PI * Fc_hi / bs2b->srate);
    bs2b->b1_hi = x;
    bs2b->a0_hi = (1.0f - G_hi * (1.0f - x)) * g;
    bs2b->a1_hi = -x * g;
} /* init */
Esempio n. 9
0
Vec2i Vec2i::clamp(int a, int b)
{
	x_ = clampi(x_,a,b);
	y_ = clampi(y_,a,b);
	return *this;
}