OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pictwind.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implements TPictureWindow
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/window.h>
10#include <owl/gdiobjec.h>
11#include <owl/pictwind.h>
12#include <owl/pointer.h>
13#include <owl/system.h>
14
15namespace owl {
16
18
19//
20/// Constructor for this class. Assumes ownership of the DIB passed in.
21//
23 LPCTSTR title, TModule* module)
24:
25 TWindow(parent, title, module),
26 Dib(dib)
27{
29 if (GetHowToDisplay() == Stretch) {
30 if (dib) {
31 Attr.W = dib->Width();
32 Attr.H = dib->Height();
33 }
34 }
35}
36
37//
38/// String-aware overload
39//
41 TWindow* parent,
42 TDib* dib,
44 const tstring& title,
45 TModule* module
46 )
47 : TWindow(parent, title, module),
48 Dib(dib)
49{
51 if (GetHowToDisplay() == Stretch)
52 {
53 if (dib)
54 {
55 Attr.W = dib->Width();
56 Attr.H = dib->Height();
57 }
58 }
59}
60
61//
62/// Destructor for this class. Deletes the owned DIB.
63//
65{
66 delete Dib;
67}
68
69
70//
71/// Allows changing of the DIB. Returns the old DIB.
72//
73TDib*
75{
76 TDib* retDib = Dib;
77 Dib = newDib;
78 return retDib;
79}
80
81
82//
83/// Paints the DIB onto the window.
84//
85void
86TPictureWindow::Paint(TDC& dc, bool /*erase*/, TRect& /*rect*/)
87{
90
91 TDib* dib = GetDib();
92 if (dib) {
93 if (hasPalette) {
94 palette = new TPalette(*GetDib());
96 dc.RealizePalette();
97 }
98
99 // figure out upper left corner of the client area
100 //
102 TPoint sourcePoint(0, 0);
103
104 // adjust the upper left corner for centering picture
105 //
106 if (HowToDisplay == Center) {
107 // determine offsets
108 //
109 int offsetX = abs(dib->Width() - clientRect.Width()) / 2;
110 if (dib->Width() > clientRect.Width())
111 sourcePoint.x += offsetX;
112 else
113 clientRect.Offset(offsetX, 0);
114
115 int offsetY = abs(dib->Height() - clientRect.Height()) / 2;
116 if (dib->Height() > clientRect.Height())
117 sourcePoint.y += offsetY;
118 else
119 clientRect.Offset(0, offsetY);
120 }
121
122 // adjust the lower right corner
123 //
124 if (HowToDisplay != Stretch) {
125 clientRect.bottom = clientRect.top + dib->Height();
126 clientRect.right = clientRect.left + dib->Width();
127
128 // if the picture is larger than screen dimensions,
129 // adjust the upper left corner.
130 //
131 clientRect.top -= sourcePoint.y;
132 clientRect.left -= sourcePoint.x;
133 }
134
135 // display the dib
136 //
137 switch (HowToDisplay) {
138 case UpperLeft:
139 case Center:
141// if(!dc.SetDIBitsToDevice(clientRect, sourcePoint, *dib)){
142// TSystemMessage().MessageBox();
143// }
144 break;
145 case Stretch: {
146 TRect sourceRect(0, 0, dib->Width(), dib->Height());
148 break;
149 }
150 } // switch HowToDisplay
151
152 dc.RestoreObjects();
153 }
154}
155
156
157//
158/// Changes the formatting of the DIB.
159//
160void
162{
163 HowToDisplay = how;
164 if (IsWindow())
165 Invalidate(true);
166}
167
168
169//
170/// Overridden from TWindow. Returns a unique name to force GetWindowClass to be
171/// called.
172//
174{
175 return TWindowClassName{_T("OWL_PictureWindow")};
176}
177
178
179//
180/// Overridden from TWindow.
181//
182void
188
189
190} // OWL namespace
191/* ========================================================================== */
192
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
virtual int GetDeviceCaps(int index) const
Used under WIN3.1 or later, GetDeviceCaps returns capability information about this DC.
Definition dc.cpp:373
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
int SetDIBitsToDevice(const TRect &dst, const TPoint &src, uint startScan, uint numScans, const void *bits, const BITMAPINFO &bitsInfo, uint16 usage)
The first version sets the pixels in dst (the given destination rectangle on this DC) from the source...
Definition dc.h:2751
void RestoreObjects()
Restores all the original GDI objects to this DC.
Definition dc.cpp:298
int RealizePalette()
Maps to the system palette the logical palette entries selected into this DC.
Definition dc.h:1054
int StretchDIBits(const TRect &dst, const TRect &src, const void *bits, const BITMAPINFO &bitsInfo, uint16 usage, uint32 rop=SRCCOPY)
Copies the color data from src, the source rectangle of pixels in the given DIB (device-independent b...
Definition dc.h:2801
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPalette is the GDI Palette class derived from TGdiObject.
Definition gdiobjec.h:413
TDisplayHow GetHowToDisplay() const
Definition pictwind.h:103
~TPictureWindow()
Destructor for this class. Deletes the owned DIB.
Definition pictwind.cpp:64
TDib * GetDib() const
Definition pictwind.h:94
virtual auto GetWindowClassName() -> TWindowClassName
Overridden from TWindow.
Definition pictwind.cpp:173
void GetWindowClass(WNDCLASS &wndClass)
Overridden from TWindow.
Definition pictwind.cpp:183
TDib * SetDib(TDib *newDib)
Allows changing of the DIB. Returns the old DIB.
Definition pictwind.cpp:74
TDisplayHow
How to display the bitmap within the window.
Definition pictwind.h:40
@ Stretch
Stretch to fit or shrink to fit.
Definition pictwind.h:43
@ Center
Always centered.
Definition pictwind.h:42
@ UpperLeft
Displays the DIB in the upper left corner of the window.
Definition pictwind.h:41
TPictureWindow(TWindow *parent, TDib *dib, TDisplayHow=UpperLeft, LPCTSTR title=0, TModule *module=0)
Constructor for this class. Assumes ownership of the DIB passed in.
Definition pictwind.cpp:22
void SetHowToDisplay(TDisplayHow how)
Changes the formatting of the DIB.
Definition pictwind.cpp:161
void Paint(TDC &dc, bool erase, TRect &rect)
Paints the DIB onto the window.
Definition pictwind.cpp:86
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
virtual void GetWindowClass(WNDCLASS &wndClass)
Redefined by derived classes, GetWindowClass fills the supplied MS-Windows registration class structu...
Definition window.cpp:2247
bool IsWindow() const
Returns true if an HWND is being used.
Definition window.h:2040
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
Definition window.h:2217
virtual void Invalidate(bool erase=true)
Invalidates (mark for painting) the entire client area of a window.
Definition window.h:2822
#define _T(x)
Definition cygwin.h:51
Definition of abstract GDI object class and derived classes.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
bool ToBool(const T &t)
Definition defs.h:291
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
Definition of class TPictureWindow.
Various types of smart pointer templatized classes.
Definition of TSystem, a system information provider class.
Base window class TWindow definition, including HWND encapsulation.