1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkWindow.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkWindow.h"
16 
17 #include "vtkCommand.h"
18 
19 //------------------------------------------------------------------------------
20 // Construct an instance of vtkRenderWindow with its screen size
21 // set to 300x300, borders turned on, positioned at (0,0), double
22 // buffering turned on.
vtkWindow()23 vtkWindow::vtkWindow()
24 {
25   this->ShowWindow = true;
26   this->UseOffScreenBuffers = false;
27   this->Size[0] = this->Size[1] = 0;
28   this->Position[0] = this->Position[1] = 0;
29   this->Mapped = 0;
30   const char windowname[] = "Visualization Toolkit";
31   this->WindowName = new char[strlen(windowname) + 1];
32   strcpy(this->WindowName, windowname);
33   this->Erase = 1;
34   this->DoubleBuffer = 0;
35   this->DPI = 72;
36   this->TileViewport[0] = 0;
37   this->TileViewport[1] = 0;
38   this->TileViewport[2] = 1.0;
39   this->TileViewport[3] = 1.0;
40   this->TileSize[0] = 0;
41   this->TileSize[1] = 0;
42   this->TileScale[0] = 1;
43   this->TileScale[1] = 1;
44 }
45 
46 //------------------------------------------------------------------------------
47 // Destructor for the vtkWindow object.
~vtkWindow()48 vtkWindow::~vtkWindow()
49 {
50   this->SetWindowName(nullptr);
51 }
52 
53 //------------------------------------------------------------------------------
GetSize()54 int* vtkWindow::GetSize()
55 {
56   this->TileSize[0] = this->Size[0] * this->TileScale[0];
57   this->TileSize[1] = this->Size[1] * this->TileScale[1];
58 
59   return this->TileSize;
60 }
61 
62 //------------------------------------------------------------------------------
GetActualSize()63 int* vtkWindow::GetActualSize()
64 {
65   // Some subclasses override GetSize() to do some additional magic.
66   this->GetSize();
67   return this->Size;
68 }
69 
70 //------------------------------------------------------------------------------
SetSize(int a[2])71 void vtkWindow::SetSize(int a[2])
72 {
73   this->SetSize(a[0], a[1]);
74 }
75 
76 //------------------------------------------------------------------------------
SetSize(int width,int height)77 void vtkWindow::SetSize(int width, int height)
78 {
79   if (this->Size[0] != width || this->Size[1] != height)
80   {
81     this->Size[0] = width;
82     this->Size[1] = height;
83     this->Modified();
84     this->InvokeEvent(vtkCommand::WindowResizeEvent, nullptr);
85   }
86 }
87 
88 //------------------------------------------------------------------------------
GetPosition()89 int* vtkWindow::GetPosition()
90 {
91   return this->Position;
92 }
93 
94 //------------------------------------------------------------------------------
SetPosition(int a[2])95 void vtkWindow::SetPosition(int a[2])
96 {
97   this->SetPosition(a[0], a[1]);
98 }
99 
100 //------------------------------------------------------------------------------
SetPosition(int x,int y)101 void vtkWindow::SetPosition(int x, int y)
102 {
103   if (this->Position[0] != x || this->Position[1] != y)
104   {
105     this->Modified();
106     this->Position[0] = x;
107     this->Position[1] = y;
108   }
109 }
110 
111 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)112 void vtkWindow::PrintSelf(ostream& os, vtkIndent indent)
113 {
114   this->Superclass::PrintSelf(os, indent);
115 
116   os << indent << "Erase: " << (this->Erase ? "On\n" : "Off\n");
117   if (this->WindowName)
118   {
119     os << indent << "Window Name: " << this->WindowName << "\n";
120   }
121   else
122   {
123     os << indent << "Window Name: (none)\n";
124   }
125 
126   // Can only print out the ivars because the window may not have been
127   // created yet.
128   //  temp = this->GetPosition();
129   os << indent << "Position: (" << this->Position[0] << ", " << this->Position[1] << ")\n";
130   //  temp = this->GetSize();
131   os << indent << "Size: (" << this->Size[0] << ", " << this->Size[1] << ")\n";
132   os << indent << "Mapped: " << this->Mapped << "\n";
133   os << indent << "ShowWindow: " << this->ShowWindow << "\n";
134   os << indent << "UseOffScreenBuffers: " << this->UseOffScreenBuffers << "\n";
135   os << indent << "Double Buffered: " << this->DoubleBuffer << "\n";
136   os << indent << "DPI: " << this->DPI << "\n";
137   os << indent << "TileScale: (" << this->TileScale[0] << ", " << this->TileScale[1] << ")\n";
138   os << indent << "TileViewport: (" << this->TileViewport[0] << ", " << this->TileViewport[1]
139      << ", " << this->TileViewport[2] << ", " << this->TileViewport[3] << ")\n";
140 }
141