Exemplo n.º 1
0
static void nuiDrawRect(const nuiRect& out, nuiRenderArray& rArray)
{
  rArray.SetMode(GL_TRIANGLE_STRIP);
  rArray.Reserve(8);
  nuiRect in(out);
  in.Grow(-nuiGetInvScaleFactor(), -nuiGetInvScaleFactor());
  
  rArray.SetVertex(out.Left(), out.Top()); rArray.PushVertex();
  rArray.SetVertex(in.Left(), in.Top()); rArray.PushVertex();

  rArray.SetVertex(out.Right(), out.Top()); rArray.PushVertex();
  rArray.SetVertex(in.Right(), in.Top()); rArray.PushVertex();
  
  rArray.SetVertex(out.Right(), out.Bottom()); rArray.PushVertex();
  rArray.SetVertex(in.Right(), in.Bottom()); rArray.PushVertex();
  
  rArray.SetVertex(out.Left(), out.Bottom()); rArray.PushVertex();
  rArray.SetVertex(in.Left(), in.Bottom()); rArray.PushVertex();

  rArray.SetVertex(out.Left(), out.Top()); rArray.PushVertex();
  rArray.SetVertex(in.Left(), in.Top()); rArray.PushVertex();
}
Exemplo n.º 2
0
bool nuiTextLayout::PrintGlyphs(nuiDrawContext *pContext, float X, float Y, const std::map<nuiTexture*, std::vector<nuiTextGlyph*> >& rGlyphs, bool AlignGlyphPixels) const
{
  std::map<nuiTexture*, std::vector<nuiTextGlyph*> >::const_iterator it = rGlyphs.begin();
  std::map<nuiTexture*, std::vector<nuiTextGlyph*> >::const_iterator end = rGlyphs.end();
  
  bool texturing = pContext->GetState().mTexturing;
  nuiTexture* pOldTexture = pContext->GetTexture();
  if (pOldTexture)
    pOldTexture->Acquire();
  
  pContext->EnableTexturing(true);

  const float f = nuiGetScaleFactor();
  const float i_f = nuiGetInvScaleFactor();
  
  while (it != end)
  {
    nuiTexture* pTexture = it->first;
    pContext->SetTexture(pTexture);
    int size = (int)it->second.size();
    int i;
    
    nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLES);
    pArray->EnableArray(nuiRenderArray::eVertex);
    pArray->EnableArray(nuiRenderArray::eTexCoord);
    pArray->EnableArray(nuiRenderArray::eColor);
    pArray->Reserve(6 * size);

    nuiColor textcolor = pContext->GetTextColor();
    
    for (i = 0; i < size; i++)
    {
      auto& run = *it;
      auto& glyph = *run.second[i];
      const nuiRect& rDest = glyph.mDestRect;
      const nuiRect& rSource = glyph.mSourceRect;

      if (glyph.mUseColor)
        pArray->SetColor(glyph.mColor);
      else
        pArray->SetColor(textcolor);

      nuiSize x1,y1,x2,y2;
      nuiSize tx,ty,tw,th;
      
      x1 = rDest.mLeft + X;
      y1 = rDest.mTop + Y;
      x2 = rDest.mRight + X;
      y2 = rDest.mBottom + Y;

      if (AlignGlyphPixels)
      {
        x1 = ToNearest(x1 * f) * i_f;
        y1 = ToNearest(y1 * f) * i_f;
        x2 = ToNearest(x2 * f) * i_f;
        y2 = ToNearest(y2 * f) * i_f;
      }
      
      tx = rSource.mLeft;
      ty = rSource.mTop;
      tw = rSource.mRight;
      th = rSource.mBottom;
      
      pTexture->ImageToTextureCoord(tx, ty);
      pTexture->ImageToTextureCoord(tw,th);
      
      ///////////////////////////////////////////
      pArray->SetVertex(x1, y1);
      pArray->SetTexCoords(tx, ty);
      pArray->PushVertex();
      
      pArray->SetVertex(x2, y1);
      pArray->SetTexCoords(tw, ty);
      pArray->PushVertex();
      
      pArray->SetVertex(x2, y2);
      pArray->SetTexCoords(tw, th);
      pArray->PushVertex();
      
      ///////////////////////////////////////////
      pArray->SetVertex(x1, y1);
      pArray->SetTexCoords(tx, ty);
      pArray->PushVertex();
      
      pArray->SetVertex(x2, y2);
      pArray->SetTexCoords(tw, th);
      pArray->PushVertex();
      
      pArray->SetVertex(x1, y2);
      pArray->SetTexCoords(tx, th);
      pArray->PushVertex();
    }
    
    //nglString str = pArray->Dump();
    //NGL_OUT("%s", str.GetChars());
    pContext->DrawArray(pArray);
    
    ++it;
  }
  
  pContext->EnableTexturing(texturing);
  pContext->SetTexture(pOldTexture);
  if (pOldTexture)
    pOldTexture->Release();
  
  return true;
}