void CompositeWindow::damageTransformedRect (float xScale, float yScale, float xTranslate, float yTranslate, const CompRect &rect) { int x1, x2, y1, y2; x1 = (short) (rect.x1 () * xScale) - 1; y1 = (short) (rect.y1 () * yScale) - 1; x2 = (short) (rect.x2 () * xScale + 0.5f) + 1; y2 = (short) (rect.y2 () * yScale + 0.5f) + 1; x1 += (short) xTranslate; y1 += (short) yTranslate; x2 += (short) (xTranslate + 0.5f); y2 += (short) (yTranslate + 0.5f); if (x2 > x1 && y2 > y1) { const CompWindow::Geometry &geom = priv->window->serverGeometry (); x1 += geom.x () + geom.border (); y1 += geom.y () + geom.border (); x2 += geom.x () + geom.border (); y2 += geom.y () + geom.border (); priv->cScreen->damageRegion (CompRegion (CompRect (x1, y1, x2 - x1, y2 - y1))); } }
void WSNamesScreen::drawText (const GLMatrix &matrix) { GLfloat alpha; float x, y, border = 10.0f; CompRect oe = screen->getCurrentOutputExtents (); x = oe.centerX () - textData.getWidth () / 2; /* assign y (for the lower corner!) according to the setting */ switch (optionGetTextPlacement ()) { case WorkspacenamesOptions::TextPlacementCenteredOnScreen: y = oe.centerY () + textData.getHeight () / 2; break; case WorkspacenamesOptions::TextPlacementTopOfScreen: case WorkspacenamesOptions::TextPlacementBottomOfScreen: { CompRect workArea = screen->currentOutputDev ().workArea (); if (optionGetTextPlacement () == WorkspacenamesOptions::TextPlacementTopOfScreen) y = oe.y1 () + workArea.y () + (2 * border) + textData.getHeight (); else y = oe.y1 () + workArea.y () + workArea.height () - (2 * border); } break; default: return; break; } if (timer) alpha = timer / (optionGetFadeTime () * 1000.0f); else alpha = 1.0f; textData.draw (matrix, floor (x), floor (y), alpha); }
void GridAnim::addGeometry (const GLTexture::MatrixList &matrix, const CompRegion ®ion, const CompRegion &clip, unsigned int maxGridWidth, unsigned int maxGridHeight) { if (region.isEmpty ()) // nothing to do return; GLfloat *v, *vMax; bool notUsing3dCoords = !using3D (); CompRect outRect (mAWindow->savedRectsValid () ? mAWindow->savedOutRect () : mWindow->outputRect ()); CompWindowExtents outExtents (mAWindow->savedRectsValid () ? mAWindow->savedOutExtents () : mWindow->output ()); // window output (contents + decorations + shadows) coordinates and size int ox = outRect.x (); int oy = outRect.y (); int owidth = outRect.width (); int oheight = outRect.height (); // to be used if event is shade/unshade float winContentsY = oy + outExtents.top; float winContentsHeight = oheight - outExtents.top - outExtents.bottom; GLWindow *gWindow = GLWindow::get (mWindow); GLVertexBuffer *vertexBuffer = gWindow->vertexBuffer (); int vSize = vertexBuffer->getVertexStride (); // Indentation kept to provide a clean diff with the old code, for now... { int y1 = outRect.y1 (); int x2 = outRect.x2 (); int y2 = outRect.y2 (); float gridW = (float)owidth / (mGridWidth - 1); float gridH; if (mCurWindowEvent == WindowEventShade || mCurWindowEvent == WindowEventUnshade) { if (y1 < winContentsY) // if at top part gridH = mDecorTopHeight; else if (y2 > winContentsY + winContentsHeight) // if at bottom gridH = mDecorBottomHeight; else // in window contents (only in Y coords) { float winContentsHeight = oheight - (mDecorTopHeight + mDecorBottomHeight); gridH = winContentsHeight / (mGridHeight - 3); } } else gridH = (float)oheight / (mGridHeight - 1); int oldCount = vertexBuffer->countVertices (); gWindow->glAddGeometry (matrix, region, clip, gridW, gridH); int newCount = vertexBuffer->countVertices (); v = vertexBuffer->getVertices () + (oldCount * vSize); vMax = vertexBuffer->getVertices () + (newCount * vSize); float x, y, topiyFloat; // For each vertex for (; v < vMax; v += vSize) { x = v[0]; y = v[1]; if (y > y2) y = y2; if (mCurWindowEvent == WindowEventShade || mCurWindowEvent == WindowEventUnshade) { if (y1 < winContentsY) // if at top part { topiyFloat = (y - oy) / mDecorTopHeight; topiyFloat = MIN (topiyFloat, 0.999); // avoid 1.0 } else if (y2 > winContentsY + winContentsHeight) // if at bottom topiyFloat = (mGridHeight - 2) + (mDecorBottomHeight ? (y - winContentsY - winContentsHeight) / mDecorBottomHeight : 0); else // in window contents (only in Y coords) topiyFloat = (mGridHeight - 3) * (y - winContentsY) / winContentsHeight + 1; } else topiyFloat = (mGridHeight - 1) * (y - oy) / oheight; // topiy should be at most (mGridHeight - 2) int topiy = (int)(topiyFloat + 1e-4); if (topiy == mGridHeight - 1) --topiy; int bottomiy = topiy + 1; float iny = topiyFloat - topiy; float inyRest = 1 - iny; // End of calculations for y // Indentation kept to provide a clean diff with the old code... { if (x > x2) x = x2; // find containing grid cell (leftix rightix) x (topiy bottomiy) float leftixFloat = (mGridWidth - 1) * (x - ox) / owidth; int leftix = (int)(leftixFloat + 1e-4); if (leftix == mGridWidth - 1) --leftix; int rightix = leftix + 1; // GridModel::GridObjects that are at top, bottom, left, right corners of quad GridModel::GridObject *objToTopLeft = &(mModel->mObjects[topiy * mGridWidth + leftix]); GridModel::GridObject *objToTopRight = &(mModel->mObjects[topiy * mGridWidth + rightix]); GridModel::GridObject *objToBottomLeft = &(mModel->mObjects[bottomiy * mGridWidth + leftix]); GridModel::GridObject *objToBottomRight = &(mModel->mObjects[bottomiy * mGridWidth + rightix]); Point3d &objToTopLeftPos = objToTopLeft->mPosition; Point3d &objToTopRightPos = objToTopRight->mPosition; Point3d &objToBottomLeftPos = objToBottomLeft->mPosition; Point3d &objToBottomRightPos = objToBottomRight->mPosition; // find position in cell by taking remainder of flooring float inx = leftixFloat - leftix; float inxRest = 1 - inx; // Interpolate to find deformed coordinates float hor1x = (inxRest * objToTopLeftPos.x () + inx * objToTopRightPos.x ()); float hor1y = (inxRest * objToTopLeftPos.y () + inx * objToTopRightPos.y ()); float hor1z = (notUsing3dCoords ? 0 : inxRest * objToTopLeftPos.z () + inx * objToTopRightPos.z ()); float hor2x = (inxRest * objToBottomLeftPos.x () + inx * objToBottomRightPos.x ()); float hor2y = (inxRest * objToBottomLeftPos.y () + inx * objToBottomRightPos.y ()); float hor2z = (notUsing3dCoords ? 0 : inxRest * objToBottomLeftPos.z () + inx * objToBottomRightPos.z ()); float deformedX = inyRest * hor1x + iny * hor2x; float deformedY = inyRest * hor1y + iny * hor2y; float deformedZ = inyRest * hor1z + iny * hor2z; v[0] = deformedX; v[1] = deformedY; v[2] = deformedZ; } } } }
bool SvgWindow::glDraw (const GLMatrix &transform, const GLWindowPaintAttrib &attrib, const CompRegion ®ion, unsigned int mask) { bool status = gWindow->glDraw (transform, attrib, region, mask); if (!status) return status; const CompRegion ® = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ? infiniteRegion : region; if (context && reg.numRects ()) { GLTexture::MatrixList matrix (1); int x1, y1, x2, y2; CompRect rect = context->box.boundingRect (); x1 = MIN (rect.x1 (), sScreen->zoom.x1 ()); y1 = MIN (rect.y1 (), sScreen->zoom.y1 ()); x2 = MAX (rect.x2 (), sScreen->zoom.x2 ()); y2 = MAX (rect.y2 (), sScreen->zoom.y2 ()); rect.setGeometry (x1, y1, x2 - x1, y2 - y1); for (unsigned int i = 0; i < context->texture[0].textures.size (); i++) { matrix[0] = context->texture[0].matrices[i]; gWindow->vertexBuffer ()->begin (); gWindow->glAddGeometry (matrix, context->box, reg); gWindow->vertexBuffer ()->end (); if (mask & PAINT_WINDOW_TRANSLUCENT_MASK) mask |= PAINT_WINDOW_BLEND_MASK; gWindow->glDrawTexture (context->texture[0].textures[i], transform, attrib, mask); if (rect.width () > 0 && rect.height () > 0) { float xScale, yScale; float dx, dy; int width, height; rect.setGeometry (rect.x1 () - 1, rect.y1 () - 1, rect.width () + 1, rect.height () + 1); xScale = screen->width () / (float) (sScreen->zoom.width ()); yScale = screen->height () / (float) (sScreen->zoom.height ()); dx = rect.width (); dy = rect.height (); width = dx * xScale + 0.5f; height = dy * yScale + 0.5f; if (rect != context->rect || width != context->size.width () || height != context->size.height ()) { float x1, y1, x2, y2; context->rect = rect; context->size.setWidth (width); context->size.setHeight (height); dx = context->box.boundingRect ().width (); dy = context->box.boundingRect ().height (); x1 = (rect.x1 () - context->box.boundingRect ().x ()) / dx; y1 = (rect.y1 () - context->box.boundingRect ().y ()) / dy; x2 = (rect.x2 () - context->box.boundingRect ().x ()) / dx; y2 = (rect.y2 () - context->box.boundingRect ().y ()) / dy; finiTexture (context->texture[1]); if (initTexture (context->source, context->texture[1], context->size)) { renderSvg (context->source, context->texture[1], context->size, x1, y1, x2, y2); updateSvgMatrix (); } } for (unsigned int j = 0; j < context->texture[1].textures.size (); j++) { GLTexture::Filter saveFilter; CompRegion r (rect); matrix[0] = context->texture[1].matrices[j]; saveFilter = gScreen->filter (SCREEN_TRANS_FILTER); gScreen->setFilter (SCREEN_TRANS_FILTER, GLTexture::Good); gWindow->vertexBuffer ()->begin (); gWindow->glAddGeometry (matrix, r, reg); gWindow->vertexBuffer ()->end (); gWindow->glDrawTexture (context->texture[1].textures[j], transform, attrib, mask); gScreen->setFilter (SCREEN_TRANS_FILTER, saveFilter); } } else if (context->texture[1].size.width ()) { finiTexture (context->texture[1]); initTexture (source, context->texture[1], CompSize ()); memset (&context->rect, 0, sizeof (BoxRec)); context->size.setWidth (0); context->size.setHeight (0); } } } return status; }