Back to index

unity  6.0.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
unity::CairoBaseWindow Class Reference

#include <CairoBaseWindow.h>

Inheritance diagram for unity::CairoBaseWindow:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CairoBaseWindow ()
virtual ~CairoBaseWindow ()

Protected Member Functions

void Draw (nux::GraphicsEngine &gfxContext, bool forceDraw)

Protected Attributes

nux::ObjectPtr< nux::BaseTexture > texture_bg_
nux::ObjectPtr< nux::BaseTexture > texture_mask_
nux::ObjectPtr< nux::BaseTexture > texture_outline_
bool _use_blurred_background
bool _compute_blur_bkg

Private Member Functions

 NUX_DECLARE_OBJECT_TYPE (CairoBaseWindow, nux::BaseWindow)

Private Attributes

nux::ObjectPtr
< nux::IOpenGLBaseTexture > 
bg_blur_texture_

Detailed Description

Definition at line 28 of file CairoBaseWindow.h.


Constructor & Destructor Documentation

Definition at line 41 of file CairoBaseWindow.cpp.

                                 :
  _use_blurred_background(false),
  _compute_blur_bkg(false)
{
  SetWindowSizeMatchLayout(true);
}

Definition at line 48 of file CairoBaseWindow.cpp.

{
  // nothing to do
}

Member Function Documentation

void unity::CairoBaseWindow::Draw ( nux::GraphicsEngine &  gfxContext,
bool  forceDraw 
) [protected]

Reimplemented in unity::QuicklistView, and unity::Tooltip.

Definition at line 53 of file CairoBaseWindow.cpp.

{
  nux::Geometry base(GetGeometry());

  // Get the background and apply some blur
  if (_use_blurred_background && _compute_blur_bkg)
  {
    auto current_fbo = nux::GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
    nux::GetGraphicsDisplay()->GetGpuDevice()->DeactivateFrameBuffer();

    gfxContext.SetViewport(0, 0, gfxContext.GetWindowWidth(), gfxContext.GetWindowHeight());
    gfxContext.SetScissor(0, 0, gfxContext.GetWindowWidth(), gfxContext.GetWindowHeight());
    gfxContext.GetRenderStates().EnableScissor(false);

    nux::ObjectPtr <nux::IOpenGLBaseTexture> bkg_texture = gfxContext.CreateTextureFromBackBuffer(base.x, base.y, base.width, base.height);

    nux::TexCoordXForm texxform_bkg;
    bg_blur_texture_ = gfxContext.QRP_GetBlurTexture(0, 0, base.width, base.height, bkg_texture, texxform_bkg, nux::color::White, 1.0f, 3);

    if (current_fbo.IsValid())
    {
      current_fbo->Activate(true);
      gfxContext.Push2DWindow(current_fbo->GetWidth(), current_fbo->GetHeight());
    }
    else
    {
      gfxContext.SetViewport(0, 0, gfxContext.GetWindowWidth(), gfxContext.GetWindowHeight());
      gfxContext.Push2DWindow(gfxContext.GetWindowWidth(), gfxContext.GetWindowHeight());
      gfxContext.ApplyClippingRectangle();
    }
    _compute_blur_bkg = false;
  }

  // the elements position inside the window are referenced to top-left window
  // corner. So bring base to (0, 0).
  base.SetX(0);
  base.SetY(0);

  gfxContext.PushClippingRectangle(base);

  /* "Clear" out the background */
  nux::ROPConfig rop;
  rop.Blend = true;
  rop.SrcBlend = GL_ONE;
  rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;

  nux::ColorLayer layer(nux::Color(0x00000000), true, rop);
  nux::GetPainter().PushDrawLayer(gfxContext, base, &layer);

  nux::TexCoordXForm texxform_bg;
  texxform_bg.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
  texxform_bg.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);

  nux::TexCoordXForm texxform_mask;
  texxform_mask.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
  texxform_mask.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);

  if (bg_blur_texture_.IsValid() && texture_mask_.IsValid())
  {
    nux::TexCoordXForm texxform_blur_bkg;

    nux::GetWindowThread()->GetGraphicsEngine().GetRenderStates().SetBlend(true);
    nux::GetWindowThread()->GetGraphicsEngine().GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);

    gfxContext.QRP_2TexMod(
      base.x,
      base.y,
      base.width,
      base.height,
      bg_blur_texture_,
      texxform_blur_bkg,
      nux::color::White,
      texture_mask_->GetDeviceTexture(),
      texxform_mask,
      nux::color::White);
  }

  if (texture_bg_.IsValid() && texture_mask_.IsValid())
  {
    nux::GetWindowThread()->GetGraphicsEngine().GetRenderStates().SetBlend(true);
    nux::GetWindowThread()->GetGraphicsEngine().GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);

    gfxContext.QRP_2TexMod(base.x,
                           base.y,
                           base.width,
                           base.height,
                           texture_bg_->GetDeviceTexture(),
                           texxform_bg,
                           nux::color::White,
                           texture_mask_->GetDeviceTexture(),
                           texxform_mask,
                           nux::color::White);
  }

  if (texture_outline_.IsValid())
  {
    nux::TexCoordXForm texxform;
    texxform.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
    texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);

    nux::GetWindowThread()->GetGraphicsDisplay().GetGraphicsEngine()->GetRenderStates().SetBlend(true);
    nux::GetWindowThread()->GetGraphicsDisplay().GetGraphicsEngine()->GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
    
    gfxContext.QRP_1Tex(base.x,
                        base.y,
                        base.width,
                        base.height,
                        texture_outline_->GetDeviceTexture(),
                        texxform,
                        nux::color::White);
  }

  nux::GetWindowThread()->GetGraphicsDisplay().GetGraphicsEngine()->GetRenderStates().SetBlend(false);
  nux::GetPainter().PopBackground();
  gfxContext.PopClippingRectangle();
}
unity::CairoBaseWindow::NUX_DECLARE_OBJECT_TYPE ( CairoBaseWindow  ,
nux::BaseWindow   
) [private]

Member Data Documentation

Definition at line 43 of file CairoBaseWindow.h.

Definition at line 42 of file CairoBaseWindow.h.

nux::ObjectPtr<nux::IOpenGLBaseTexture> unity::CairoBaseWindow::bg_blur_texture_ [private]

Definition at line 46 of file CairoBaseWindow.h.

nux::ObjectPtr<nux::BaseTexture> unity::CairoBaseWindow::texture_bg_ [protected]

Definition at line 38 of file CairoBaseWindow.h.

nux::ObjectPtr<nux::BaseTexture> unity::CairoBaseWindow::texture_mask_ [protected]

Definition at line 39 of file CairoBaseWindow.h.

nux::ObjectPtr<nux::BaseTexture> unity::CairoBaseWindow::texture_outline_ [protected]

Definition at line 40 of file CairoBaseWindow.h.


The documentation for this class was generated from the following files: