// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkWindow.h"

#include "vtkCommand.h"

//------------------------------------------------------------------------------
// Construct an instance of vtkRenderWindow with its screen size
// set to 300x300, borders turned on, positioned at (0,0), double
// buffering turned on.
VTK_ABI_NAMESPACE_BEGIN
vtkWindow::vtkWindow()
{
  this->ShowWindow = true;
  this->UseOffScreenBuffers = false;
  this->Size[0] = this->Size[1] = 0;
  this->Position[0] = this->Position[1] = 0;
  this->Mapped = 0;
  const char windowname[] = "Visualization Toolkit";
  this->WindowName = new char[strlen(windowname) + 1];
  strcpy(this->WindowName, windowname);
  this->Erase = 1;
  this->DoubleBuffer = 0;
  this->DPI = 72;
  this->TileViewport[0] = 0;
  this->TileViewport[1] = 0;
  this->TileViewport[2] = 1.0;
  this->TileViewport[3] = 1.0;
  this->TileSize[0] = 0;
  this->TileSize[1] = 0;
  this->TileScale[0] = 1;
  this->TileScale[1] = 1;
}

//------------------------------------------------------------------------------
// Destructor for the vtkWindow object.
vtkWindow::~vtkWindow()
{
  this->SetWindowName(nullptr);
}

//------------------------------------------------------------------------------
int* vtkWindow::GetSize()
{
  this->TileSize[0] = this->Size[0] * this->TileScale[0];
  this->TileSize[1] = this->Size[1] * this->TileScale[1];

  return this->TileSize;
}

//------------------------------------------------------------------------------
int* vtkWindow::GetActualSize()
{
  // Some subclasses override GetSize() to do some additional magic.
  this->GetSize();
  return this->Size;
}

//------------------------------------------------------------------------------
void vtkWindow::SetSize(int a[2])
{
  this->SetSize(a[0], a[1]);
}

//------------------------------------------------------------------------------
void vtkWindow::SetSize(int width, int height)
{
  if (this->Size[0] != width || this->Size[1] != height)
  {
    this->Size[0] = width;
    this->Size[1] = height;
    this->Modified();
    this->InvokeEvent(vtkCommand::WindowResizeEvent, nullptr);
  }
}

//------------------------------------------------------------------------------
int* vtkWindow::GetPosition()
{
  return this->Position;
}

//------------------------------------------------------------------------------
void vtkWindow::SetPosition(int a[2])
{
  this->SetPosition(a[0], a[1]);
}

//------------------------------------------------------------------------------
void vtkWindow::SetPosition(int x, int y)
{
  if (this->Position[0] != x || this->Position[1] != y)
  {
    this->Modified();
    this->Position[0] = x;
    this->Position[1] = y;
  }
}

//------------------------------------------------------------------------------
void vtkWindow::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  os << indent << "Erase: " << (this->Erase ? "On\n" : "Off\n");
  if (this->WindowName)
  {
    os << indent << "Window Name: " << this->WindowName << "\n";
  }
  else
  {
    os << indent << "Window Name: (none)\n";
  }

  // Can only print out the ivars because the window may not have been
  // created yet.
  //  temp = this->GetPosition();
  os << indent << "Position: (" << this->Position[0] << ", " << this->Position[1] << ")\n";
  //  temp = this->GetSize();
  os << indent << "Size: (" << this->Size[0] << ", " << this->Size[1] << ")\n";
  os << indent << "Mapped: " << this->Mapped << "\n";
  os << indent << "ShowWindow: " << this->ShowWindow << "\n";
  os << indent << "UseOffScreenBuffers: " << this->UseOffScreenBuffers << "\n";
  os << indent << "Double Buffered: " << this->DoubleBuffer << "\n";
  os << indent << "DPI: " << this->DPI << "\n";
  os << indent << "TileScale: (" << this->TileScale[0] << ", " << this->TileScale[1] << ")\n";
  os << indent << "TileViewport: (" << this->TileViewport[0] << ", " << this->TileViewport[1]
     << ", " << this->TileViewport[2] << ", " << this->TileViewport[3] << ")\n";
}
VTK_ABI_NAMESPACE_END
