Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions fred2/briefingeditordlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ briefing_editor_dlg::briefing_editor_dlg(CWnd* pParent /*=NULL*/)
m_use_wing = FALSE;
m_use_cargo = FALSE;
//}}AFX_DATA_INIT
m_play_icon = nullptr;
m_voice_id = -1;
m_cur_stage = 0;
m_last_stage = m_cur_icon = m_last_icon = -1;
Expand Down Expand Up @@ -237,8 +238,8 @@ void briefing_editor_dlg::create()
for (auto &sm: Spooled_music)
box->AddString(sm.name);

m_play_bm.LoadBitmap(IDB_PLAY);
((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
m_play_icon = load_button_icon(IDB_PLAY, RGB(192, 192, 192));
((CButton *) GetDlgItem(IDC_PLAY)) -> SetIcon(m_play_icon);

m_current_briefing = 0;
Briefing = &Briefings[m_current_briefing];
Expand Down Expand Up @@ -1411,7 +1412,7 @@ void briefing_editor_dlg::OnEndlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult)
BOOL briefing_editor_dlg::DestroyWindow()
{
Briefing_dialog = nullptr;
m_play_bm.DeleteObject();
if (m_play_icon) DestroyIcon(m_play_icon);
audiostream_close_file(m_voice_id, 0);
return CDialog::DestroyWindow();
}
Expand Down
2 changes: 1 addition & 1 deletion fred2/briefingeditordlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class briefing_editor_dlg : public CDialog
BOOL m_use_cargo;
//}}AFX_DATA

CBitmap m_play_bm;
HICON m_play_icon;

// copy view variables
int m_copy_view_set;
Expand Down
8 changes: 5 additions & 3 deletions fred2/cmdbrief.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "FRED.h"
#include "freddoc.h"
#include "CmdBrief.h"
#include "management.h"
#include "cfile/cfile.h"
#include "sound/audiostr.h"
#include "localization/localize.h"
Expand All @@ -36,6 +37,7 @@ cmd_brief_dlg::cmd_brief_dlg(CWnd* pParent /*=NULL*/)
//}}AFX_DATA_INIT

m_wave_id = -1;
m_play_icon = nullptr;
}

void cmd_brief_dlg::DoDataExchange(CDataExchange* pDX)
Expand Down Expand Up @@ -74,8 +76,8 @@ BOOL cmd_brief_dlg::OnInitDialog()
last_cmd_brief = NULL;

CDialog::OnInitDialog();
m_play_bm.LoadBitmap(IDB_PLAY);
((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
m_play_icon = load_button_icon(IDB_PLAY, RGB(192, 192, 192));
((CButton *) GetDlgItem(IDC_PLAY)) -> SetIcon(m_play_icon);

update_data();
return TRUE;
Expand Down Expand Up @@ -318,7 +320,7 @@ BOOL cmd_brief_dlg::DestroyWindow()
m_wave_id = -1;

update_data();
m_play_bm.DeleteObject();
if (m_play_icon) DestroyIcon(m_play_icon);

// the command briefing is updated whether we close it, click OK, or click Cancel,
// so autosave here instead of in the OK case
Expand Down
2 changes: 1 addition & 1 deletion fred2/cmdbrief.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class cmd_brief_dlg : public CDialog
CString m_wave_filename;
//}}AFX_DATA

CBitmap m_play_bm;
HICON m_play_icon;

// Overrides
// ClassWizard generated virtual function overrides
Expand Down
8 changes: 5 additions & 3 deletions fred2/debriefingeditordlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "FRED.h"
#include "DebriefingEditorDlg.h"
#include "FREDDoc.h"
#include "management.h"
#include "mission/missionbriefcommon.h"
#include "mission/missionparse.h"
#include "globalincs/linklist.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ debriefing_editor_dlg::debriefing_editor_dlg(CWnd* pParent /*=NULL*/)
m_last_stage = -1;
m_voice_id = -1;
select_sexp_node = -1;
m_play_icon = nullptr;
}

void debriefing_editor_dlg::create()
Expand Down Expand Up @@ -148,8 +150,8 @@ void debriefing_editor_dlg::OnInitMenu(CMenu* pMenu)
BOOL debriefing_editor_dlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_play_bm.LoadBitmap(IDB_PLAY);
((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
m_play_icon = load_button_icon(IDB_PLAY, RGB(192, 192, 192));
((CButton *) GetDlgItem(IDC_PLAY)) -> SetIcon(m_play_icon);
CComboBox *box;
box = (CComboBox *) GetDlgItem(IDC_ICON_IMAGE);

Expand Down Expand Up @@ -502,7 +504,7 @@ BOOL debriefing_editor_dlg::DestroyWindow()
{
Debriefing_dialog = nullptr;
audiostream_close_file(m_voice_id, 0);
m_play_bm.DeleteObject();
if (m_play_icon) DestroyIcon(m_play_icon);
return CDialog::DestroyWindow();
}

Expand Down
2 changes: 1 addition & 1 deletion fred2/debriefingeditordlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class debriefing_editor_dlg : public CDialog
int m_current_debriefing;
//}}AFX_DATA

CBitmap m_play_bm;
HICON m_play_icon;

// Overrides
// ClassWizard generated virtual function overrides
Expand Down
7 changes: 4 additions & 3 deletions fred2/eventeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ event_editor::event_editor(CWnd* pParent /*=NULL*/)
m_log_1st_trigger = 0;
m_log_last_trigger = 0;
m_log_state_change = 0;
m_play_icon = nullptr;
}

void event_editor::DoDataExchange(CDataExchange* pDX)
Expand Down Expand Up @@ -203,8 +204,8 @@ BOOL event_editor::OnInitDialog()
MMessage msg;

CDialog::OnInitDialog(); // let the base class do the default work
m_play_bm.LoadBitmap(IDB_PLAY);
((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
m_play_icon = load_button_icon(IDB_PLAY, RGB(192, 192, 192));
((CButton *) GetDlgItem(IDC_PLAY)) -> SetIcon(m_play_icon);

theApp.init_window(&Events_wnd_data, this, 0);
m_event_tree.setup((CEdit *) GetDlgItem(IDC_HELP_BOX));
Expand Down Expand Up @@ -1527,7 +1528,7 @@ BOOL event_editor::DestroyWindow()
audiostream_close_file(m_wave_id, 0);
m_wave_id = -1;

m_play_bm.DeleteObject();
if (m_play_icon) DestroyIcon(m_play_icon);
return CDialog::DestroyWindow();
}

Expand Down
2 changes: 1 addition & 1 deletion fred2/eventeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class event_editor : public CDialog
int m_log_state_change;
//}}AFX_DATA

CBitmap m_play_bm;
HICON m_play_icon;

// Overrides
// ClassWizard generated virtual function overrides
Expand Down
18 changes: 9 additions & 9 deletions fred2/fred.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ BEGIN
PUSHBUTTON "Browse",IDC_BROWSE_AVI,374,194,49,14,0,WS_EX_STATICEDGE
COMBOBOX IDC_WAVE_FILENAME,303,210,67,110,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Browse",IDC_BROWSE_WAVE,374,210,34,14,0,WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,410,210,13,14,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,410,210,13,14,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
COMBOBOX IDC_PERSONA_NAME,303,225,67,57,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Update Stuff",IDC_UPDATE,373,226,50,14
COMBOBOX IDC_MESSAGE_TEAM,304,243,46,76,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
Expand Down Expand Up @@ -1895,7 +1895,7 @@ BEGIN
EDITTEXT IDC_TEXT,7,72,396,85,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
EDITTEXT IDC_VOICE,63,164,83,13,ES_AUTOHSCROLL
PUSHBUTTON "Browse",IDC_BROWSE,150,164,42,14,0,WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,194,164,28,14,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,194,164,28,14,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
COMBOBOX IDC_BRIEFING_MUSIC,205,18,83,135,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_SUBSTITUTE_BRIEFING_MUSIC,205,34,83,135,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
CONTROL "Tree1",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,190,200,218,WS_EX_CLIENTEDGE
Expand Down Expand Up @@ -1957,7 +1957,7 @@ BEGIN
CONTROL "Tree1",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,55,191,260,WS_EX_CLIENTEDGE
EDITTEXT IDC_VOICE,193,7,68,14,ES_AUTOHSCROLL
PUSHBUTTON "Browse",IDC_BROWSE,265,7,34,14,0,WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,311,7,13,14,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,311,7,13,14,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
EDITTEXT IDC_TEXT,204,34,329,143,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
EDITTEXT IDC_REC_TEXT,204,192,329,73,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
LTEXT "Text",IDC_STATIC,204,24,15,8
Expand Down Expand Up @@ -2003,10 +2003,10 @@ FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
LTEXT "Music Files",IDC_STATIC,8,8,42,10
LISTBOX IDC_MUSIC_LIST,11,18,126,94,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "IDB_PLAY",IDC_BUTTON_PLAY_MUSIC,31,118,15,15,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_STOP",IDC_BUTTON_STOP_MUSIC,71,118,15,15,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_NEXT",IDC_BUTTON_NEXT_MUSIC,51,118,15,15,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PREV",IDC_BUTTON_PREV_MUSIC,11,118,15,15,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_BUTTON_PLAY_MUSIC,31,118,15,15,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_STOP",IDC_BUTTON_STOP_MUSIC,71,118,15,15,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_NEXT",IDC_BUTTON_NEXT_MUSIC,51,118,15,15,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PREV",IDC_BUTTON_PREV_MUSIC,11,118,15,15,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
CONTROL "Autoplay",IDC_MUSIC_AUTOPLAY,"Button",BS_3STATE | WS_TABSTOP,94,120,40,10
PUSHBUTTON "Music.tbl",IDC_BUTTON_MUSIC_TBL,50,140,50,14
END
Expand Down Expand Up @@ -2073,7 +2073,7 @@ BEGIN
PUSHBUTTON "Browse",IDC_BROWSE_ANI,334,184,50,14,0,WS_EX_STATICEDGE
EDITTEXT IDC_WAVE_FILENAME,263,202,68,14,ES_AUTOHSCROLL
PUSHBUTTON "Browse",IDC_BROWSE_WAVE,334,202,34,14,0,WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,371,202,13,14,BS_BITMAP,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
PUSHBUTTON "IDB_PLAY",IDC_PLAY,371,202,13,14,BS_ICON,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
DEFPUSHBUTTON "OK",IDOK,334,14,50,14
PUSHBUTTON "Cancel",IDCANCEL,334,31,50,14
LTEXT "Briefing Text",IDC_STATIC,7,44,40,8
Expand Down Expand Up @@ -2403,7 +2403,7 @@ BEGIN
LTEXT "range: 0.1 .. 20.0",IDC_STATIC,157,66,62,11,WS_DISABLED
GROUPBOX "Preview",IDC_SOUND_ENVIRONMENT_TEST,229,50,79,32
PUSHBUTTON "Browse",IDC_BROWSE_WAVE,258,62,44,15
PUSHBUTTON "IDB_PLAY",IDC_PLAY,235,62,17,15,BS_BITMAP,WS_EX_TRANSPARENT
PUSHBUTTON "IDB_PLAY",IDC_PLAY,235,62,17,15,BS_ICON,WS_EX_TRANSPARENT
END

IDD_WARP_PARAMS DIALOGEX 0, 0, 271, 271
Expand Down
62 changes: 62 additions & 0 deletions fred2/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2657,3 +2657,65 @@ void update_texture_replacements(const char *old_name, const char *new_name)
strcpy_s(ii->ship_name, new_name);
}
}

HBITMAP load_btnface_mapped(UINT id)
{
std::array<COLORMAP, 5> cmap;
cmap[0].from = RGB(255, 0, 255); // magenta (transparent background)
cmap[0].to = GetSysColor(COLOR_BTNFACE);
cmap[1].from = RGB(192, 192, 192); // dark gray (traditional background)
cmap[1].to = GetSysColor(COLOR_BTNFACE);
cmap[2].from = RGB(128, 128, 128);
cmap[2].to = GetSysColor(COLOR_BTNSHADOW);
cmap[3].from = RGB(255, 255, 255);
cmap[3].to = GetSysColor(COLOR_BTNHIGHLIGHT);
cmap[4].from = RGB(0, 0, 0);
cmap[4].to = GetSysColor(COLOR_BTNTEXT);
return CreateMappedBitmap(AfxGetResourceHandle(), id, 0, cmap.data(), sz2i(cmap.size()));
}

HICON load_button_icon(UINT id, COLORREF transparent)
{
// Load the resource bitmap as a device-dependent bitmap.
HBITMAP color = (HBITMAP)::LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(id));
if (color == nullptr)
return nullptr;

BITMAP bm;
::GetObject(color, sizeof(bm), &bm);

HDC screen_dc = ::GetDC(nullptr);
HDC color_dc = ::CreateCompatibleDC(screen_dc);
HDC mask_dc = ::CreateCompatibleDC(screen_dc);

// Build a 1-bpp mask: pixels matching the transparent key become white (1),
// everything else black (0). This is the AND mask of the icon.
HBITMAP mask = ::CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, nullptr);
HBITMAP old_color = (HBITMAP)::SelectObject(color_dc, color);
HBITMAP old_mask = (HBITMAP)::SelectObject(mask_dc, mask);

::SetBkColor(color_dc, transparent);
::BitBlt(mask_dc, 0, 0, bm.bmWidth, bm.bmHeight, color_dc, 0, 0, SRCCOPY);

// Punch the transparent pixels in the color bitmap to black (D & ~S), so the
// icon's XOR stage leaves the background untouched where the mask is set.
::BitBlt(color_dc, 0, 0, bm.bmWidth, bm.bmHeight, mask_dc, 0, 0, 0x00220326 /*DSna: D & ~S*/);

::SelectObject(color_dc, old_color);
::SelectObject(mask_dc, old_mask);
::DeleteDC(color_dc);
::DeleteDC(mask_dc);
::ReleaseDC(nullptr, screen_dc);

ICONINFO ii = {};
ii.fIcon = TRUE;
ii.hbmMask = mask;
ii.hbmColor = color;
HICON icon = ::CreateIconIndirect(&ii);

// CreateIconIndirect copies the bitmaps, so the originals can be freed.
::DeleteObject(mask);
::DeleteObject(color);

return icon;
}
10 changes: 10 additions & 0 deletions fred2/management.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ extern int wing_is_player_wing(int wing);
extern void update_custom_wing_indexes();
extern void update_texture_replacements(const char* old_name, const char* new_name);

// Load a button bitmap, remapping its background colors to system colors as needed.
// This mirrors the color substitution MFC performs for toolbar bitmaps. Caller owns
// the returned HBITMAP.
extern HBITMAP load_btnface_mapped(UINT id);

// Build an icon from a button bitmap resource, treating the given color as transparent.
// Icons, unlike bitmaps, render correctly grayed when the button is disabled. Caller
// owns the returned HICON and must call DestroyIcon on it when done.
extern HICON load_button_icon(UINT id, COLORREF transparent);

#endif
31 changes: 23 additions & 8 deletions fred2/musicplayerdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "stdafx.h"
#include "FRED.h"
#include "MainFrm.h"
#include "management.h"
#include "musicplayerdlg.h"
#include "TextViewDlg.h"
#include "mod_table/mod_table.h"
Expand All @@ -23,6 +24,10 @@ music_player_dlg::music_player_dlg(CWnd* pParent /*=nullptr*/)
m_cursor_pos = -1;
m_autoplay = FALSE;

m_play_icon = nullptr;
m_stop_icon = nullptr;
m_next_icon = nullptr;
m_prev_icon = nullptr;
}

void music_player_dlg::DoDataExchange(CDataExchange* pDX)
Expand Down Expand Up @@ -52,17 +57,17 @@ BOOL music_player_dlg::Create()
BOOL r;
r = CDialog::Create(IDD, Fred_main_wnd);

m_play_bm.LoadBitmap(IDB_PLAY);
((CButton*)GetDlgItem(IDC_BUTTON_PLAY_MUSIC))->SetBitmap(m_play_bm);
m_play_icon = load_button_icon(IDB_PLAY, RGB(192, 192, 192));
((CButton*)GetDlgItem(IDC_BUTTON_PLAY_MUSIC))->SetIcon(m_play_icon);

m_stop_bm.LoadBitmap(IDB_STOP);
((CButton*)GetDlgItem(IDC_BUTTON_STOP_MUSIC))->SetBitmap(m_stop_bm);
m_stop_icon = load_button_icon(IDB_STOP, RGB(192, 192, 192));
((CButton*)GetDlgItem(IDC_BUTTON_STOP_MUSIC))->SetIcon(m_stop_icon);

m_next_bm.LoadBitmap(IDB_NEXT);
((CButton*)GetDlgItem(IDC_BUTTON_NEXT_MUSIC))->SetBitmap(m_next_bm);
m_next_icon = load_button_icon(IDB_NEXT, RGB(192, 192, 192));
((CButton*)GetDlgItem(IDC_BUTTON_NEXT_MUSIC))->SetIcon(m_next_icon);

m_prev_bm.LoadBitmap(IDB_PREV);
((CButton*)GetDlgItem(IDC_BUTTON_PREV_MUSIC))->SetBitmap(m_prev_bm);
m_prev_icon = load_button_icon(IDB_PREV, RGB(192, 192, 192));
((CButton*)GetDlgItem(IDC_BUTTON_PREV_MUSIC))->SetIcon(m_prev_icon);

return r;
}
Expand Down Expand Up @@ -219,6 +224,16 @@ void music_player_dlg::OnClose()
CDialog::OnClose();
}

BOOL music_player_dlg::DestroyWindow()
{
if (m_play_icon) { DestroyIcon(m_play_icon); m_play_icon = nullptr; }
if (m_stop_icon) { DestroyIcon(m_stop_icon); m_stop_icon = nullptr; }
if (m_next_icon) { DestroyIcon(m_next_icon); m_next_icon = nullptr; }
if (m_prev_icon) { DestroyIcon(m_prev_icon); m_prev_icon = nullptr; }

return CDialog::DestroyWindow();
}

void music_player_dlg::OnAutoplay()
{
if (m_autoplay == 1)
Expand Down
9 changes: 5 additions & 4 deletions fred2/musicplayerdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ class music_player_dlg : public CDialog {
int m_cursor_pos;
int m_autoplay;

CBitmap m_play_bm;
CBitmap m_stop_bm;
CBitmap m_next_bm;
CBitmap m_prev_bm;
HICON m_play_icon;
HICON m_stop_icon;
HICON m_next_icon;
HICON m_prev_icon;

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL DestroyWindow();

virtual BOOL OnInitDialog();
afx_msg void OnSelMusicList();
Expand Down
Loading
Loading