Clipping


Clipping

A clipping region help you limit the area where GDI commands paint. In the code below, it is possible to paint only inside the rectangular region; any pixels that fall outside this rectangle will not be modified.
Una región de recorte le ayuda a limitar el área donde los comandos de GDI pintan. En el código de abajo, es posible pintar solamente dentro de la región rectangular; cualquier pixel que este afuera de este rectángulo no será modificado.

Program.h

....
void Program::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     RECT rcClipping = {0, 0, 100, 100};
     HRGN hRgn = CreateRectRgnIndirect(&rcClipping);
     gdi.SelectClipRgn(hRgn);
     // Paint operations here
     ...

     gdi.SelectClipRgn(NULL);
     DeleteObject(hRgn);
}


Problem 1
Create a Wintempla Window Application called RedCut to test clipping regions. Use Wintempla to check the events shown below.
Cree una Aplicación de Ventana de Wintempla llamada RedCut para probar las regiones. Use Wintempla para checar los eventos mostrados debajo.

RedCutEvents

RedCutRun

RedCut.h
...
class RedCut: public Win::Window
{
public:
     RedCut()
     {
     }
     ~RedCut()
     {
     }
     CG::Region regionMain;
     ...
};


RedCut.cpp
...
void RedCut::Window_Open(Win::Event& e)
{
}

void RedCut::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     gdi.SelectClippingRegion(regionMain);
     for(int y = 0; y < 1000; y+=5)
     {
          if (y > height) break;
          gdi.Line(0, y, width, y);
     }
}

void RedCut::Window_Size(Win::Event& e)
{
     //____________________________________ Left Right Region
     CG::Region regionLeft;
     regionLeft.CreateElliptic(0, height/3, width/2, 2*height/3);
     //
     CG::Region regionRight;
     regionRight.CreateElliptic(width/2, height/3, width, 2*height/3);
     //
     CG::Region regionLeftRight;
     regionLeftRight.Combine(regionLeft, regionRight, RGN_OR);
     //______________________________________ Top Bottom Region
     CG::Region regionTop;
     regionTop.CreateElliptic(width/3, 0, 2*width/3, height/2);
     //
     CG::Region regionBottom;
     regionBottom.CreateElliptic(width/3, height/2, 2*width/3, height);
     //
     CG::Region regionTopBottom;
     regionTopBottom.Combine(regionTop, regionBottom, RGN_OR);
     //______________________________________ Main Clipping Region
     regionMain.Combine(regionLeftRight, regionTopBottom, RGN_XOR);
}



© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home