User

Difference between revisions of "Sascha"

From Guiliani

(Blanked the page)
Line 1: Line 1:
 +
<code>
 +
#include "ExampleControl.h"
 +
#include "GfxWrap.h"
 +
#include "GUIStreamReader.h"
 +
#include "GUIStreamWriter.h"
 +
#include "GUIStreamingException.h"
 +
#include "GUIControlResource.h"
 +
#include "GUIMemLeakWatcher.h" // <-- has to be the last include
  
 +
#define EXAMPLE_CONTROL_CLASS_VERSION 1
 +
// The minimal class version allowed.
 +
#define EXAMPLE_CONTROL_CLASS_MIN_VERSION 1
 +
 +
ExampleControl::ExampleControl(
 +
    CGUICompositeObject *const pParent,
 +
    const eC_Value &vX, const eC_Value &vY,
 +
    const eC_Value &vWidth, const eC_Value &vHeight,
 +
    eC_UInt uiInnerColor, eC_UInt uiBorderColor,
 +
    eC_Value vBorderWidth,
 +
    const ObjectHandle_t &eID)
 +
    : CGUICompositeObject(pParent, vX, vY, vWidth, vHeight, eID),
 +
      m_uiInnerColor(uiInnerColor),
 +
      m_uiBorderColor(uiBorderColor),
 +
      m_vBorderWidth(vBorderWidth)
 +
{
 +
    SetXMLTag("ExampleControl");
 +
}
 +
 +
ExampleControl::ExampleControl()
 +
: m_uiInnerColor(0), m_uiBorderColor(0), m_vBorderWidth(eC_FromInt(0))
 +
{
 +
    SetXMLTag("ExampleControl");
 +
}
 +
 +
void ExampleControl::SetCenterColor(eC_UInt uiInnerColor)
 +
{
 +
    if (uiInnerColor != m_uiInnerColor)
 +
    {
 +
        m_uiInnerColor = uiInnerColor;
 +
        InvalidateArea();
 +
    }
 +
}
 +
 +
void ExampleControl::SetBorderColor(eC_UInt uiBorderColor)
 +
{
 +
    if (uiBorderColor != m_uiBorderColor)
 +
    {
 +
        m_uiBorderColor = uiBorderColor;
 +
        InvalidateArea();
 +
    }
 +
}
 +
 +
void ExampleControl::SetBorderWidth(eC_Value vBorderWidth)
 +
{
 +
    if (vBorderWidth != m_vBorderWidth)
 +
    {
 +
        m_vBorderWidth = vBorderWidth;
 +
        InvalidateArea();
 +
    }
 +
}
 +
 +
void ExampleControl::Flip(const eC_Bool& rbVertical)
 +
{
 +
    if (rbVertical)
 +
    {
 +
        // flip vertical means swap left and right side
 +
        CGUIObject* pkCurrentObject;
 +
        for (int i = 0; i < GetNumberOfChildren(); ++i)
 +
        {
 +
            pkCurrentObject = GetChild(i);
 +
            if (pkCurrentObject->IsCompositeObject())
 +
                pkCurrentObject->IsAnimating(); //Flip(rbVertical);
 +
            else
 +
            {
 +
                pkCurrentObject->SetRelXPos(GetWidth() - (pkCurrentObject->GetWidth() + pkCurrentObject->GetRelXPos()));
 +
                pkCurrentObject->InvalidateArea();
 +
            }
 +
        }
 +
    }
 +
    else
 +
    {
 +
        // flip horizontal means swap top and bottom side
 +
        CGUIObject* pkCurrentObject;
 +
        for (int i = 0; i < GetNumberOfChildren(); ++i)
 +
        {
 +
            pkCurrentObject = GetChild(i);
 +
            if (pkCurrentObject->IsCompositeObject())
 +
                pkCurrentObject->IsAnimating(); //Flip(rbVertical);
 +
            else
 +
            {
 +
                pkCurrentObject->SetRelYPos(GetHeight() - (pkCurrentObject->GetHeight() + pkCurrentObject->GetRelYPos()));
 +
                pkCurrentObject->InvalidateArea();
 +
            }
 +
        }
 +
 +
    }
 +
}
 +
 +
void ExampleControl::Rotate(const eC_Int& riDegrees)
 +
{
 +
    switch (riDegrees)
 +
    {
 +
        case 0:
 +
        default:
 +
            // do nothing
 +
            break;
 +
 +
        case 90:
 +
        {
 +
            // rotate 90 degrees clockwise
 +
            // width and height will be swapped
 +
            // x and y of every object will be re-calculated and swapped
 +
 +
            CGUIRect r = GetRelRect();
 +
            SetWidth(r.GetHeight());
 +
            SetHeight(r.GetWidth());
 +
            CGUIObject* pkCurrentObject;
 +
            for (int i = 0; i < GetNumberOfChildren(); ++i)
 +
            {
 +
                pkCurrentObject = GetChild(i);
 +
                r = pkCurrentObject->GetRelRect();
 +
                pkCurrentObject->SetRelXPos(GetWidth() - (r.GetWidth() + r.GetY1()));
 +
                pkCurrentObject->SetRelYPos(r.GetX1());
 +
                pkCurrentObject->SetWidth(r.GetHeight());
 +
                pkCurrentObject->SetHeight(r.GetWidth());
 +
            }
 +
            InvalidateArea();
 +
            InvalidateChildren();
 +
        }
 +
            break;
 +
 +
        case 180:
 +
            Flip(false);
 +
            Flip(true);
 +
            break;
 +
 +
        case 270:
 +
        {
 +
            // rotate 270 degrees clockwise
 +
            // width and height will be swapped
 +
            // x and y of every object will be swapped
 +
 +
            CGUIRect r = GetRelRect();
 +
            SetWidth(r.GetHeight());
 +
            SetHeight(r.GetWidth());
 +
            CGUIObject* pkCurrentObject;
 +
            for (int i = 0; i < GetNumberOfChildren(); ++i)
 +
            {
 +
                pkCurrentObject = GetChild(i);
 +
                r = pkCurrentObject->GetRelRect();
 +
                pkCurrentObject->SetRelXPos(r.GetY1());
 +
                pkCurrentObject->SetRelYPos(r.GetX1());
 +
                pkCurrentObject->SetWidth(r.GetHeight());
 +
                pkCurrentObject->SetHeight(r.GetWidth());
 +
            }
 +
            InvalidateArea();
 +
            InvalidateChildren();
 +
        }
 +
            break;
 +
    }
 +
}
 +
 +
eC_Bool ExampleControl::DoDraw()
 +
{
 +
    CGUIRect kAbsRect(GetAbsRect());
 +
    if (m_vBorderWidth != eC_FromInt(0))
 +
    {
 +
        GETGFX.SetForegroundColor(m_uiBorderColor);
 +
        GETGFX.FilledRect(kAbsRect);
 +
        kAbsRect.Expand(-m_vBorderWidth);
 +
    }
 +
    GETGFX.SetForegroundColor(m_uiInnerColor);
 +
    GETGFX.FilledRect(kAbsRect);
 +
    return true;
 +
}
 +
 +
#if defined(GUILIANI_STREAM_GUI)
 +
void ExampleControl::ReadFromStream()
 +
{
 +
    ReadStreamingHeader(EXAMPLE_CONTROL_CLASS_VERSION, EXAMPLE_CONTROL_CLASS_MIN_VERSION);
 +
 +
    CGUICompositeObject::ReadFromStream();
 +
 +
    m_uiInnerColor  = GETINPUTSTREAM.READ_HEX("InnerColor");
 +
    m_uiBorderColor = GETINPUTSTREAM.READ_HEX("BorderColor");
 +
    m_vBorderWidth  = eC_FromFloat(GETINPUTSTREAM.READ_FLOAT("BorderWidth"));
 +
}
 +
#endif
 +
 +
#if defined(GUILIANI_WRITE_GUI)
 +
void ExampleControl::WriteToStream(const eC_Bool bWriteClassID)
 +
{
 +
    WriteStreamingHeader(bWriteClassID, XMLTAG_CONTROLCLASSID, CTL_EXAMPLE, EXAMPLE_CONTROL_CLASS_VERSION);
 +
 +
    CGUICompositeObject::WriteToStream();
 +
 +
    GETOUTPUTSTREAM.WriteHex(m_uiInnerColor, "InnerColor");
 +
    GETOUTPUTSTREAM.WriteHex(m_uiBorderColor, "BorderColor");
 +
    GETOUTPUTSTREAM.WriteFloat(eC_ToFloat(m_vBorderWidth), "BorderWidth");
 +
 +
    WriteStreamingFooter(bWriteClassID);
 +
}
 +
#endif
 +
</code>

Revision as of 21:12, 10 July 2018

  1. include "ExampleControl.h"
  2. include "GfxWrap.h"
  3. include "GUIStreamReader.h"
  4. include "GUIStreamWriter.h"
  5. include "GUIStreamingException.h"
  6. include "GUIControlResource.h"
  7. include "GUIMemLeakWatcher.h" // <-- has to be the last include
  1. define EXAMPLE_CONTROL_CLASS_VERSION 1

// The minimal class version allowed.

  1. define EXAMPLE_CONTROL_CLASS_MIN_VERSION 1

ExampleControl::ExampleControl(

   CGUICompositeObject *const pParent,
   const eC_Value &vX, const eC_Value &vY,
   const eC_Value &vWidth, const eC_Value &vHeight,
   eC_UInt uiInnerColor, eC_UInt uiBorderColor,
   eC_Value vBorderWidth,
   const ObjectHandle_t &eID)
   : CGUICompositeObject(pParent, vX, vY, vWidth, vHeight, eID),
     m_uiInnerColor(uiInnerColor),
     m_uiBorderColor(uiBorderColor),
     m_vBorderWidth(vBorderWidth)

{

   SetXMLTag("ExampleControl");

}

ExampleControl::ExampleControl()

m_uiInnerColor(0), m_uiBorderColor(0), m_vBorderWidth(eC_FromInt(0))

{

   SetXMLTag("ExampleControl");

}

void ExampleControl::SetCenterColor(eC_UInt uiInnerColor) {

   if (uiInnerColor != m_uiInnerColor)
   {
       m_uiInnerColor = uiInnerColor;
       InvalidateArea();
   }

}

void ExampleControl::SetBorderColor(eC_UInt uiBorderColor) {

   if (uiBorderColor != m_uiBorderColor)
   {
       m_uiBorderColor = uiBorderColor;
       InvalidateArea();
   }

}

void ExampleControl::SetBorderWidth(eC_Value vBorderWidth) {

   if (vBorderWidth != m_vBorderWidth)
   {
       m_vBorderWidth = vBorderWidth;
       InvalidateArea();
   }

}

void ExampleControl::Flip(const eC_Bool& rbVertical) {

   if (rbVertical)
   {
       // flip vertical means swap left and right side
       CGUIObject* pkCurrentObject;
       for (int i = 0; i < GetNumberOfChildren(); ++i)
       {
           pkCurrentObject = GetChild(i);
           if (pkCurrentObject->IsCompositeObject())
               pkCurrentObject->IsAnimating(); //Flip(rbVertical);
           else
           {
               pkCurrentObject->SetRelXPos(GetWidth() - (pkCurrentObject->GetWidth() + pkCurrentObject->GetRelXPos()));
               pkCurrentObject->InvalidateArea();
           }
       }
   }
   else
   {
       // flip horizontal means swap top and bottom side
       CGUIObject* pkCurrentObject;
       for (int i = 0; i < GetNumberOfChildren(); ++i)
       {
           pkCurrentObject = GetChild(i);
           if (pkCurrentObject->IsCompositeObject())
               pkCurrentObject->IsAnimating(); //Flip(rbVertical);
           else
           {
               pkCurrentObject->SetRelYPos(GetHeight() - (pkCurrentObject->GetHeight() + pkCurrentObject->GetRelYPos()));
               pkCurrentObject->InvalidateArea();
           }
       }
   }

}

void ExampleControl::Rotate(const eC_Int& riDegrees) {

   switch (riDegrees)
   {
       case 0:
       default:
           // do nothing
           break;
       case 90:
       {
           // rotate 90 degrees clockwise
           // width and height will be swapped
           // x and y of every object will be re-calculated and swapped
           CGUIRect r = GetRelRect();
           SetWidth(r.GetHeight());
           SetHeight(r.GetWidth());
           CGUIObject* pkCurrentObject;
           for (int i = 0; i < GetNumberOfChildren(); ++i)
           {
               pkCurrentObject = GetChild(i);
               r = pkCurrentObject->GetRelRect();
               pkCurrentObject->SetRelXPos(GetWidth() - (r.GetWidth() + r.GetY1()));
               pkCurrentObject->SetRelYPos(r.GetX1());
               pkCurrentObject->SetWidth(r.GetHeight());
               pkCurrentObject->SetHeight(r.GetWidth());
           }
           InvalidateArea();
           InvalidateChildren();
       }
           break;
       case 180:
           Flip(false);
           Flip(true);
           break;
       case 270:
       {
           // rotate 270 degrees clockwise
           // width and height will be swapped
           // x and y of every object will be swapped
           CGUIRect r = GetRelRect();
           SetWidth(r.GetHeight());
           SetHeight(r.GetWidth());
           CGUIObject* pkCurrentObject;
           for (int i = 0; i < GetNumberOfChildren(); ++i)
           {
               pkCurrentObject = GetChild(i);
               r = pkCurrentObject->GetRelRect();
               pkCurrentObject->SetRelXPos(r.GetY1());
               pkCurrentObject->SetRelYPos(r.GetX1());
               pkCurrentObject->SetWidth(r.GetHeight());
               pkCurrentObject->SetHeight(r.GetWidth());
           }
           InvalidateArea();
           InvalidateChildren();
       }
           break;
   }

}

eC_Bool ExampleControl::DoDraw() {

   CGUIRect kAbsRect(GetAbsRect());
   if (m_vBorderWidth != eC_FromInt(0))
   {
       GETGFX.SetForegroundColor(m_uiBorderColor);
       GETGFX.FilledRect(kAbsRect);
       kAbsRect.Expand(-m_vBorderWidth);
   }
   GETGFX.SetForegroundColor(m_uiInnerColor);
   GETGFX.FilledRect(kAbsRect);
   return true;

}

  1. if defined(GUILIANI_STREAM_GUI)

void ExampleControl::ReadFromStream() {

   ReadStreamingHeader(EXAMPLE_CONTROL_CLASS_VERSION, EXAMPLE_CONTROL_CLASS_MIN_VERSION);
   CGUICompositeObject::ReadFromStream();
   m_uiInnerColor  = GETINPUTSTREAM.READ_HEX("InnerColor");
   m_uiBorderColor = GETINPUTSTREAM.READ_HEX("BorderColor");
   m_vBorderWidth  = eC_FromFloat(GETINPUTSTREAM.READ_FLOAT("BorderWidth"));

}

  1. endif
  1. if defined(GUILIANI_WRITE_GUI)

void ExampleControl::WriteToStream(const eC_Bool bWriteClassID) {

   WriteStreamingHeader(bWriteClassID, XMLTAG_CONTROLCLASSID, CTL_EXAMPLE, EXAMPLE_CONTROL_CLASS_VERSION);
   CGUICompositeObject::WriteToStream();
   GETOUTPUTSTREAM.WriteHex(m_uiInnerColor, "InnerColor");
   GETOUTPUTSTREAM.WriteHex(m_uiBorderColor, "BorderColor");
   GETOUTPUTSTREAM.WriteFloat(eC_ToFloat(m_vBorderWidth), "BorderWidth");
   WriteStreamingFooter(bWriteClassID);

}

  1. endif