Скачиваний:
26
Добавлен:
01.05.2014
Размер:
4.77 Кб
Скачать
/*  Project first

		Copyright © 1997 by US. All Rights Reserved.

		SUBSYSTEM:    first.exe Application
		FILE:         bkgndwin.cpp
		AUTHOR:       US


		OVERVIEW
		========
		Source file for implementation of TBackgroundWindow (TWindow).
*/

#include <owl\owlpch.h>
#pragma hdrstop

#include <string.h>
#include <stdio.h>
#include <math.h>

#include "bkgndwin.h"
#include "firstapp.h"
#include "w-data.h"
#include "draw.h"

//
// Build a response table for all messages/commands handled
// by the application.
//
DEFINE_RESPONSE_TABLE1(TBackgroundWindow, TWindow)
//{{TBackgroundWindowRSP_TBL_BEGIN}}
		EV_WM_SIZE,
		EV_CHILD_NOTIFY_ALL_CODES(IDS_HZOOMSLIDER, UpdateHZoom),
		EV_CHILD_NOTIFY_ALL_CODES(IDS_VZOOMSLIDER, UpdateVZoom),
		EV_CHILD_NOTIFY_ALL_CODES(IDS_HSHIFTSCROLL, UpdateHShift),
		EV_CHILD_NOTIFY_ALL_CODES(IDS_VSHIFTSCROLL, UpdateVShift),
//{{TBackgroundWindowRSP_TBL_END}}
END_RESPONSE_TABLE;


//{{TBackgroundWindow Implementation}}


TBackgroundWindow::TBackgroundWindow (TWindow* parent, const char far* title, TModule* module):
		TWindow(parent, title, module)
{
		// Override the default window style for TWindow.
		Attr.Style |= WS_CHILD | WS_BORDER | WS_VISIBLE;

		// Change the window's background color
//		SetBkgndColor(RGB(0xFF, 0xFF, 0xFF));


		HZoomSlider = new THSlider(this, IDS_HZOOMSLIDER, 20, 1, 100, 20, IDB_ZOOMTHUMB);
		VZoomSlider = new THSlider(this, IDS_VZOOMSLIDER, 300, 1, 100, 20, IDB_ZOOMTHUMB);
		HZoomText = new TStatic(this, IDS_HZOOMTEXT, "Гориз. x 1", 130, 1, 80, 20, 10);
		VZoomText = new TStatic(this, IDS_VZOOMTEXT, "Верт.  x 1", 230, 1, 80, 20, 10);

		HShiftScroll = new TScrollBar(this, IDS_HSHIFTSCROLL, 2, 385, 610, 17, TRUE);
		VShiftScroll = new TScrollBar(this, IDS_VSHIFTSCROLL, 610, 2, 17, 385, FALSE);
}


TBackgroundWindow::~TBackgroundWindow ()
{
		Destroy();

		// INSERT>> Your destructor code here.

}


void TBackgroundWindow::Paint (TDC& dc, BOOL erase, TRect& rect)
{
		TWindow::Paint(dc, erase, rect);

		PaintData(dc, rect, FALSE);
}



void TBackgroundWindow::EvSize (UINT sizeType, TSize& size)
{
		TWindow::EvSize(sizeType, size);

		AdjustSliderPosition();

		Invalidate(TRUE);
}


void TBackgroundWindow::SetupWindow ()
{
		TWindow::SetupWindow();

		AdjustSliderPosition();

		HZoomSlider->SetRange(0, 4);
		HZoomSlider->SetRuler(1, FALSE);
		HZoomSlider->SetPosition(HPos = 0);
		VZoomSlider->SetRange(0, 4);
		VZoomSlider->SetRuler(1, FALSE);
		VZoomSlider->SetPosition(VPos = 0);

		HMagnify = VMagnify = 1;

		HShiftScroll->SetRange(0, 0);
		VShiftScroll->SetRange(0, 0);
}

void TBackgroundWindow::AdjustSliderPosition(void)
{
	TRect rect, srect;
	unsigned width, height;

	GetWindowRect(rect);
	width = rect.right - rect.left;
	height = rect.bottom - rect.top;
	VZoomSlider->GetWindowRect(srect);
	srect.left = width - 120;
	srect.right = width - 20;
	srect.top = 1; srect.bottom = 21;
	VZoomSlider->MoveWindow(srect);

	srect.left = width - 210;
	srect.right = width - 130;
	srect.top = 1; srect.bottom = 21;
	VZoomText->MoveWindow(srect);

	srect.left = 2;
	srect.right = width - 19;
	srect.top = height - 19;
	srect.bottom = height - 2;
	HShiftScroll->MoveWindow(srect);

	srect.left = width - 19;
	srect.right = width - 2;
	srect.top = 2;
	srect.bottom = height - 19;
	VShiftScroll->MoveWindow(srect);
}

void TBackgroundWindow::UpdateHZoom(UINT notifyCode)
{
	char msg[14];
	unsigned pos = HZoomSlider->GetPosition();

	if (notifyCode == 3 && pos > HPos+1)
			HZoomSlider->SetPosition(pos = HPos+1);
	else
		if (notifyCode == 2 && pos < HPos-1)
			HZoomSlider->SetPosition(pos = HPos-1);
	sprintf(msg, "Гориз. x%2d", (HMagnify = 1 << (HPos = pos)));
	HZoomText->SetText(msg);

	HShiftScroll->SetRange(0, (HMagnify - 1) * 10);
	HShiftScroll->SetPosition(HShift = 0);

	if (notifyCode == 8)
		PaintDataOnly(this);
}

void TBackgroundWindow::UpdateVZoom(UINT notifyCode)
{
	char msg[14];
	unsigned pos = VZoomSlider->GetPosition();

	if (notifyCode == 3 && pos > VPos+1)
			VZoomSlider->SetPosition(pos = VPos+1);
	else
		if (notifyCode == 2 && pos < VPos-1)
			VZoomSlider->SetPosition(pos = VPos-1);
	sprintf(msg, "Верт.  x%2d", (VMagnify = 1 << (VPos = pos)));
	VZoomText->SetText(msg);

	VShiftScroll->SetRange(0, (VMagnify - 1) * 10);
	VShiftScroll->SetPosition(VShift = 0);

	if (notifyCode == 8)
		PaintDataOnly(this);
}

void TBackgroundWindow::UpdateHShift(UINT /*notifyCode*/)
{
	HShift = HShiftScroll->GetPosition();

	PaintDataOnly(this);
}

void TBackgroundWindow::UpdateVShift(UINT /*notifyCode*/)
{
	VShift = VShiftScroll->GetPosition();

	PaintDataOnly(this);
}

Соседние файлы в папке SOURCE