#ifndef CWINDOWSECTION_H
#define CWINDOWSECTION_H

class CWindowSection
{
 protected:
  int PosX, PosY;
  int Width, Height;
  CWindow* Parent;
  float Viewport[4];

 public:
  CWindowSection(CWindow* parent = 0, int x = 0, int y = 0,
                 int width = 200, int height = 200)
    { Parent = parent; PosX = x; PosY = y; Width = width; Height = height; }
  virtual ~CWindowSection() {};

  int GetPosX() const { return PosX; }
  void SetPosX(int x) { PosX = x; }
  int GetPosY() const { return PosY; }
  void SetPosY(int y) { PosY = y; }
  int GetWidth() const { return Width; }
  void SetWidth(int w) { Width = w; }
  int GetHeight() const { return Height; }
  void SetHeight(int h) { Height = h; }
  bool IsIn(int x, int y)
    {
      return ( (x >= PosX) && (x <= PosX + Width) &&
               (y >= PosY) && (y <= PosY + Height) );
    }

  void PushMatrix(void)
    {
      glGetFloatv(GL_VIEWPORT, Viewport);
      glViewport(PosX, g_Window->GetHeight() - Height - PosY, Width, Height);
      glMatrixMode(GL_MODELVIEW);
      glPushMatrix();
      glLoadIdentity();
      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      SetProjection();
    }
  void PopMatrix(void)
    {
      glMatrixMode(GL_PROJECTION);
      glPopMatrix();
      glMatrixMode(GL_MODELVIEW);
      glPopMatrix();
      glViewport((int) Viewport[0], (int) Viewport[1],
                 (int) Viewport[2], (int) Viewport[3]);
    }

  virtual void SetProjection(void) = 0;
};

#endif
