void sageRect::scale(float r) { int oldHalfWidth = halfWidth(); int oldHalfHeight = halfHeight(); width = (int)floor(width*r + 0.5); height = (int)floor(height*r + 0.5); x = x + oldHalfWidth - halfWidth(); y = y + oldHalfHeight - halfHeight(); }
void GUISUMOAbstractView::drawDecals() { glTranslated(0, 0, .99); myDecalsLock.lock(); for (std::vector<GUISUMOAbstractView::Decal>::iterator l = myDecals.begin(); l != myDecals.end();) { GUISUMOAbstractView::Decal& d = *l; if (!d.initialised) { try { FXImage* i = MFXImageHelper::loadImage(getApp(), d.filename); if (MFXImageHelper::scalePower2(i)) { WRITE_WARNING("Scaling '" + d.filename + "'."); } d.glID = GUITexturesHelper::add(i); d.initialised = true; } catch (InvalidArgument& e) { WRITE_ERROR("Could not load '" + d.filename + "'.\n" + e.what()); l = myDecals.erase(l); continue; } } glPushMatrix(); glTranslated(d.centerX, d.centerY, 0); glRotated(d.rot, 0, 0, 1); glColor3d(1, 1, 1); SUMOReal halfWidth((d.width / 2.)); SUMOReal halfHeight((d.height / 2.)); GUITexturesHelper::drawTexturedBox(d.glID, -halfWidth, -halfHeight, halfWidth, halfHeight); glPopMatrix(); ++l; } myDecalsLock.unlock(); glTranslated(0, 0, -.99); }
void sageRect::rotate(sageRotation rot) { int halfW = halfWidth(); int halfH = halfHeight(); int centerX = x + halfW; int centerY = y + halfH; orientation = orientation + rot; if (rot == CCW_90 || rot == CCW_270) { x = centerX - halfH; y = centerY - halfW; int oldWidth = width; width = height; height = oldWidth; } }
void virtualDesktop::locateApp(appInExec *app, displayConnection *connection, int idx) { // a single table display, multiple vertical displays sageRect newLayout = *(sageRect *)app; if (connection) { sageRect neighbor = *(sageRect *)connection->displays[1-idx]; int offset = connection->offset; if (table) { // vertical to table switch(connection->edges[idx]) { case LEFT_EDGE: newLayout.rotate(CCW_90); newLayout.x = 0; offset = connection->offset*(1-idx*2); newLayout.y = app->x - neighbor.halfWidth() + halfHeight() + offset; break; case RIGHT_EDGE: newLayout.rotate(CCW_270); newLayout.x = width - newLayout.width; newLayout.y = halfHeight() + offset - (app->x - neighbor.halfWidth()) - newLayout.height; break; case BOTTOM_EDGE: newLayout.rotate(CCW_180); newLayout.x = halfWidth() + offset - (app->x - neighbor.halfWidth()) - newLayout.width; newLayout.y = 0; break; case TOP_EDGE: offset = connection->offset*(1-idx*2); newLayout.x = halfWidth() + offset + (app->x - neighbor.halfWidth()); newLayout.y = width - newLayout.height; break; } } else { // table to vertical if (connection->displays[1-idx]->table) { newLayout.resetOrientation(); switch(connection->edges[1-idx]) { case LEFT_EDGE: offset = connection->offset*(1-idx*2); newLayout.x = halfWidth() + offset - newLayout.halfWidth() + app->centerY() - neighbor.halfHeight(); break; case RIGHT_EDGE: newLayout.x = halfWidth() + offset - newLayout.halfWidth() - (app->centerY() - neighbor.halfHeight()); break; case BOTTOM_EDGE: newLayout.x = halfWidth() + offset - newLayout.halfWidth() - (app->centerX() - neighbor.halfWidth()); break; case TOP_EDGE: offset = connection->offset*(1-idx*2); newLayout.x = halfWidth() + offset - newLayout.halfWidth() + (app->centerX() - neighbor.halfWidth()); break; } newLayout.y = 0; } else { // vertical to vertical switch(connection->edges[idx]) { case LEFT_EDGE: newLayout.x = 0; break; case RIGHT_EDGE: newLayout.x = width - newLayout.width; break; } offset = connection->offset*(1-idx*2); newLayout.y = halfHeight() + offset + app->y - neighbor.halfHeight(); } } } if (newLayout.centerX() < 0) newLayout.x = 1 - newLayout.halfWidth(); else if (newLayout.centerX() > width) newLayout.x = width - newLayout.halfWidth() - 1; if (newLayout.x < 0 && newLayout.x + newLayout.width > width) { float leftScale = (float)newLayout.centerX()/(newLayout.halfWidth()+1); float rightScale = (float)(width-newLayout.centerX())/(newLayout.halfWidth()+1); float scaleRatio = MAX(leftScale, rightScale); newLayout.scale(scaleRatio); } if (newLayout.centerY() < 0) newLayout.y = 1 - newLayout.halfHeight(); else if (newLayout.centerY() > height) newLayout.y = height - newLayout.halfHeight() - 1; if (newLayout.y < 0 && newLayout.y + newLayout.height > height) { float bottomScale = (float)newLayout.centerY()/(newLayout.halfHeight()+1); float topScale = (float)(height-newLayout.centerY())/(newLayout.halfHeight()+1); float scaleRatio = MAX(bottomScale, topScale); newLayout.scale(scaleRatio); } if (connection) { switch(connection->edges[idx]) { case LEFT_EDGE: newLayout.x = 0; break; case RIGHT_EDGE: newLayout.x = width - newLayout.width; break; case BOTTOM_EDGE: newLayout.y = 0; break; case TOP_EDGE: newLayout.y = width - newLayout.height; break; } } *(sageRect *)app = newLayout; }