File: BriefScreenEdit.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (195 lines) | stat: -rw-r--r-- 4,867 bytes parent folder | download | duplicates (3)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * Descent 3
 * Copyright (C) 2024 Parallax Software
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// BriefScreenEdit.cpp : implementation file
//

#include "mfc_compatibility.h"
#include "editor.h"
#include "BriefScreenEdit.h"
#include "BriefEdit.h"
#include "BriefMissionFlagsDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBriefScreenEdit dialog

CBriefScreenEdit::CBriefScreenEdit(int screen_idx, CWnd *pParent /*=NULL*/) : CDialog(CBriefScreenEdit::IDD, pParent) {
  //{{AFX_DATA_INIT(CBriefScreenEdit)
  m_sDesc = _T("");
  //}}AFX_DATA_INIT
  m_Screen = screen_idx;
  bm_handle = -1;
  m_Set = m_UnSet = 0;
}

void CBriefScreenEdit::DoDataExchange(CDataExchange *pDX) {
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CBriefScreenEdit)
  DDX_Text(pDX, IDC_BRIEF_ADDS_DESC, m_sDesc);
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBriefScreenEdit, CDialog)
//{{AFX_MSG_MAP(CBriefScreenEdit)
ON_WM_TIMER()
ON_CBN_SELCHANGE(IDC_BRIEF_ADDS_LAYOUT_LIST, OnSelchangeBriefAddsLayoutList)
ON_BN_CLICKED(IDC_MISSIONFLAGS, OnMissionflags)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBriefScreenEdit message handlers

void CBriefScreenEdit::OnOK() {
  CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_ADDS_LAYOUT_LIST);
  int sel = combo->GetCurSel();
  if (sel > 0) {
    combo->GetLBText(sel, layout_str);
  } else {
    layout_str = "";
  }

  if (bm_handle > BAD_BITMAP_HANDLE)
    bm_FreeBitmap(bm_handle);

  CDialog::OnOK();
}

BOOL CBriefScreenEdit::OnInitDialog() {
  CDialog::OnInitDialog();

  CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_ADDS_LAYOUT_LIST);

  // Start the timer
  CWnd::SetTimer(1, 50, NULL);

  combo->AddString("<None>");
  int sel = 0;

  for (int i = 0; i < (*PBnum_layouts); i++) {
    combo->AddString(PBlayouts[i].filename);
    if (m_Screen != -1) {
      if (!stricmp(Briefing_screens[m_Screen].layout, PBlayouts[i].filename))
        sel = i + 1;
    }
  }

  if (m_Screen != -1) {
    m_Set = Briefing_screens[m_Screen].mission_mask_set;
    m_UnSet = Briefing_screens[m_Screen].mission_mask_unset;
  }

  combo->SetCurSel(sel);

  return TRUE;
}

void CBriefScreenEdit::UpdateView(void) {
  CWnd *objwnd;
  RECT rect;
  int x, y, w, h;

  objwnd = GetDlgItem(IDC_BRIEF_ADDS_PICTURE);
  objwnd->GetWindowRect(&rect);
  ScreenToClient(&rect);

  int bmw, bmh;

  Desktop_surf->attach_to_window((unsigned)m_hWnd);

  w = rect.right - rect.left;
  h = rect.bottom - rect.top;

  bmw = w;
  bmh = h;

  static bool first_call = true;

  if (first_call)
    Desktop_surf->clear(rect.left, rect.top, w, h);

  m_ObjectSurf.create(bmw, bmh, BPP_16);

  if (bm_handle > BAD_BITMAP_HANDLE) {
    m_ObjectSurf.load(bm_handle);
  } else
    Desktop_surf->clear(rect.left, rect.top, w, h);

  x = rect.left + (w / 2) - m_ObjectSurf.width() / 2;
  y = rect.top + (h / 2) - m_ObjectSurf.height() / 2;

  Desktop_surf->blt(x, y, &m_ObjectSurf);

  m_ObjectSurf.free();
  Desktop_surf->attach_to_window((unsigned)NULL);

  if (first_call)
    first_call = false;
}

void CBriefScreenEdit::OnTimer(UINT nIDEvent) {
  UpdateView();
  CDialog::OnTimer(nIDEvent);
}

void CBriefScreenEdit::OnSelchangeBriefAddsLayoutList() {
  if (bm_handle > BAD_BITMAP_HANDLE) {
    bm_FreeBitmap(bm_handle);
    bm_handle = -1;
  }

  CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_ADDS_LAYOUT_LIST);
  int sel = combo->GetCurSel();
  if (sel > 0) {
    bm_handle = bm_AllocLoadFileBitmap(PBlayouts[sel - 1].filename, 0);
  }

  CWnd *objwnd;
  RECT rect;
  int w, h;

  objwnd = GetDlgItem(IDC_BRIEF_ADDS_PICTURE);
  objwnd->GetWindowRect(&rect);
  w = rect.right - rect.left;
  h = rect.bottom - rect.top;

  int temp = bm_AllocBitmap(w, h, 0);
  if (temp > BAD_BITMAP_HANDLE) {
    bm_ClearBitmap(temp);
    if (bm_handle > BAD_BITMAP_HANDLE) {
      bm_ScaleBitmapToBitmap(temp, bm_handle);
    }
    bm_FreeBitmap(bm_handle);
    bm_handle = temp;
  }
}

void CBriefScreenEdit::OnMissionflags() {
  CBriefMissionFlagsDlg dlg(m_Set, m_UnSet);

  if (dlg.DoModal()) {
    m_Set = dlg.m_Set;
    m_UnSet = dlg.m_UnSet;
  }
}