summaryrefslogtreecommitdiffhomepage
path: root/nGenEx/ImgView.cpp
blob: 613667c732dcaaade351812ad81c20f356ed66a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*  Project nGenEx
	Destroyer Studios LLC
	Copyright © 1997-2004. All Rights Reserved.

	SUBSYSTEM:    nGenEx.lib
	FILE:         ImgView.cpp
	AUTHOR:       John DiCamillo


	OVERVIEW
	========
	Bitmap "billboard" Image View class
*/

#include "MemDebug.h"
#include "ImgView.h"
#include "Color.h"
#include "Window.h"
#include "Video.h"
#include "Bitmap.h"
#include "Screen.h"

// +--------------------------------------------------------------------+

ImgView::ImgView(Window* c, Bitmap* bmp)
: View(c), img(bmp), width(0), height(0), x_offset(0), y_offset(0),
blend(Video::BLEND_SOLID)
{
	if (img) {
		width  = img->Width();
		height = img->Height();
	}

	if (width < c->Width())
	x_offset = (c->Width() - width) / 2;

	if (height < c->Height())
	y_offset = (c->Height() - height) / 2;
}

ImgView::~ImgView()
{
}

// +--------------------------------------------------------------------+

void
ImgView::Refresh()
{
	if (img && width > 0 && height > 0)
	window->DrawBitmap(x_offset,
	y_offset,
	x_offset + width,
	y_offset + height,
	img,
	blend);
}

// +--------------------------------------------------------------------+

void
ImgView::SetPicture(Bitmap* bmp)
{
	img      = bmp;
	width    = 0;
	height   = 0;
	x_offset = 0;
	y_offset = 0;

	if (img) {
		width  = img->Width();
		height = img->Height();
	}

	if (window) {
		x_offset = (window->Width()  - width)  / 2;
		y_offset = (window->Height() - height) / 2;
	}
}