summaryrefslogtreecommitdiffhomepage
path: root/Magic2/GridProps.cpp
blob: d375ea91a0445efe831a61eb6e649eee33795691 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*  Project Magic 2.0
    Destroyer Studios LLC
    Copyright © 1997-2004. All Rights Reserved.

    SUBSYSTEM:    Magic.exe
    FILE:         GridProps.cpp
    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Grid Properties Dialog implementation file
*/


#include "stdafx.h"
#include "Magic.h"
#include "GridProps.h"
#include "Grid.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// +--------------------------------------------------------------------+
// GridProps dialog
// +--------------------------------------------------------------------+

GridProps::GridProps(Grid* g, CWnd* pParent /*=NULL*/)
	: CDialog(GridProps::IDD, pParent), grid(g)
{
	//{{AFX_DATA_INIT(GridProps)
	mGridShow         = grid->IsShow();
	mGridSnap         = grid->IsSnap();
	mReferencePlan    = grid->GetReferencePlan();
	mReferenceFront   = grid->GetReferenceFront();
	mReferenceSide    = grid->GetReferenceSide();
	mGridSize         = grid->GetSize();
	//}}AFX_DATA_INIT
}

static const char* C(CString& str)
{
   static char buf[512];
   int i;
   for (i = 0; i < str.GetLength(); i++)
      buf[i] = (char) str.GetAt(i);
	buf[i] = 0;

   return buf;
}

void GridProps::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(GridProps)
	DDX_Check(pDX, IDC_GRID_SHOW, mGridShow);
	DDX_Check(pDX, IDC_GRID_SNAP, mGridSnap);
	DDX_Text(pDX, IDC_REFERENCE_PLAN, mReferencePlan);
	DDX_Text(pDX, IDC_REFERENCE_FRONT, mReferenceFront);
	DDX_Text(pDX, IDC_REFERENCE_SIDE, mReferenceSide);
	DDX_Text(pDX, IDC_GRID_SIZE, mGridSize);
	DDV_MinMaxInt(pDX, mGridSize, 1, 64);
	//}}AFX_DATA_MAP

   // if saving, write the values back to the grid
   if (pDX->m_bSaveAndValidate) {
      grid->SetSnap(mGridSnap ? true : false);
      grid->SetShow(mGridShow ? true : false);
      grid->SetSize(mGridSize);

      grid->SetReferencePlan(C(mReferencePlan));
      grid->SetReferenceFront(C(mReferenceFront));
      grid->SetReferenceSide(C(mReferenceSide));
   }
}


BEGIN_MESSAGE_MAP(GridProps, CDialog)
	//{{AFX_MSG_MAP(GridProps)
	ON_BN_CLICKED(IDC_FILE_PLAN, OnFilePlan)
	ON_BN_CLICKED(IDC_FILE_FRONT, OnFileFront)
	ON_BN_CLICKED(IDC_FILE_SIDE, OnFileSide)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

static void OnImageFile(CString& strImageFile)
{
   char filename[512];
   filename[0] = '\0';
   CFileDialog ofd(TRUE, "pcx");
   
   ofd.m_ofn.lpstrFilter = "PCX Files\0*.pcx\0All Files\0*.*\0\0";
   ofd.m_ofn.lpstrFile   = filename;
   ofd.m_ofn.nMaxFile    = sizeof(filename);
   
   if (ofd.DoModal() != IDOK)
      return;

   char tex_name[512];
   sprintf(tex_name, "%s", ofd.GetFileName().GetBuffer(0));

   strImageFile = tex_name;
}

void GridProps::OnFilePlan() 
{
   OnImageFile(mReferencePlan);
   UpdateData(FALSE);
}

void GridProps::OnFileFront() 
{
   OnImageFile(mReferenceFront);
   UpdateData(FALSE);
}

void GridProps::OnFileSide() 
{
   OnImageFile(mReferenceSide);
   UpdateData(FALSE);
}