PsfPlayer: remove d3dx9 dependency

This commit is contained in:
Mahmood(Thunder07) 2017-11-19 00:02:46 +00:00
parent b47142bc12
commit 4d0155921b
4 changed files with 172 additions and 314 deletions

View File

@ -1,37 +1,49 @@
#include "SpuRegView.h"
#include "win32/Rect.h"
#define LINE_COUNT (29)
#define LINE_SPACING (2)
#define FONT_SIZE (8)
#define WNDSTYLE (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP)
#define WNDSTYLEEX (0)
CSpuRegView::CSpuRegView(HWND parentWnd, const TCHAR* title)
: CDirectXControl(parentWnd, WS_VSCROLL | WS_HSCROLL)
, m_spu(nullptr)
CSpuRegView::CSpuRegView(HWND parentWnd, const RECT& rect, const TCHAR* title)
: m_spu(nullptr)
, m_title(title)
, m_offsetX(0)
, m_offsetY(0)
, m_pageSizeX(0)
, m_pageSizeY(0)
, m_maxScrollX(0)
, m_maxScrollY(0)
{
CreateResources();
m_canvasWidth = GetFontWidth() * 67;
m_canvasHeight = (GetFontHeight() + LINE_SPACING) * LINE_COUNT;
InitializeScrollBars();
Create(WNDSTYLEEX, Framework::Win32::CDefaultWndClass::GetName(), _T(""), WS_OVERLAPPED | WNDSTYLE, rect, parentWnd, this);
int ydpi = GetDeviceCaps(GetDC(NULL), LOGPIXELSY);
int lineHeight = MulDiv(20, ydpi, 96);
m_listView = new Framework::Win32::CListView(m_hWnd, Framework::Win32::CRect(0, 0, 1, 1), WS_VSCROLL | LVS_REPORT);
m_extrainfo = new Framework::Win32::CStatic(m_hWnd, Framework::Win32::CRect(0, 0, 1, 1));
m_pLayout = Framework::CVerticalLayout::Create();
m_pLayout->InsertObject(Framework::Win32::CLayoutWindow::CreateCustomBehavior(100, 100, 1, 1, m_listView));
m_pLayout->InsertObject(Framework::Win32::CLayoutWindow::CreateTextBoxBehavior(100, lineHeight*2, m_extrainfo));
CreateColumns();
m_listView->SetExtendedListViewStyle(m_listView->GetExtendedListViewStyle() | LVS_EX_FULLROWSELECT);
SetTimer(m_hWnd, NULL, 16, NULL);
}
CSpuRegView::~CSpuRegView()
{
}
long CSpuRegView::OnSize(unsigned int type, unsigned int x, unsigned int y)
{
InitializeScrollBars();
return CDirectXControl::OnSize(type, x, y);
if (m_pLayout != nullptr)
{
RECT rc = GetClientRect();
SetSizePosition(rc);
m_pLayout->SetRect(rc.left, rc.top, rc.right, rc.bottom);
m_pLayout->RefreshGeometry();
Redraw();
return Framework::Win32::CWindow::OnSize(type, x, y);
}
return false;
}
long CSpuRegView::OnTimer(WPARAM param)
@ -43,194 +55,6 @@ long CSpuRegView::OnTimer(WPARAM param)
return TRUE;
}
long CSpuRegView::OnHScroll(unsigned int type, unsigned int position)
{
switch(type)
{
case SB_LINEDOWN:
m_offsetX += 1;
break;
case SB_LINEUP:
m_offsetX -= 1;
break;
case SB_PAGEDOWN:
m_offsetX += m_pageSizeX;
break;
case SB_PAGEUP:
m_offsetX -= m_pageSizeX;
break;
case SB_THUMBTRACK:
m_offsetX = position;
break;
case SB_THUMBPOSITION:
m_offsetX = position;
break;
}
if(m_offsetX < 0) m_offsetX = 0;
if(m_offsetX > m_maxScrollX) m_offsetX = m_maxScrollX;
UpdateHorizontalScroll();
return FALSE;
}
long CSpuRegView::OnVScroll(unsigned int type, unsigned int position)
{
switch(type)
{
case SB_LINEDOWN:
m_offsetY += 1;
break;
case SB_LINEUP:
m_offsetY -= 1;
break;
case SB_PAGEDOWN:
m_offsetY += m_pageSizeY;
break;
case SB_PAGEUP:
m_offsetY -= m_pageSizeY;
break;
case SB_THUMBTRACK:
m_offsetY = position;
break;
case SB_THUMBPOSITION:
m_offsetY = position;
break;
}
if(m_offsetY < 0) m_offsetY = 0;
if(m_offsetY > m_maxScrollY) m_offsetY = m_maxScrollY;
UpdateVerticalScroll();
return FALSE;
}
long CSpuRegView::OnMouseWheel(int, int, short delta)
{
m_offsetY -= delta / 40;
m_offsetY = std::max<int>(m_offsetY, 0);
m_offsetY = std::min<int>(m_offsetY, m_maxScrollY);
UpdateVerticalScroll();
return TRUE;
}
long CSpuRegView::OnKeyDown(WPARAM keyId, LPARAM)
{
if(keyId == VK_LEFT || keyId == VK_RIGHT)
{
m_offsetX += (keyId == VK_LEFT ? -5 : 5);
m_offsetX = std::max<int>(m_offsetX, 0);
m_offsetX = std::min<int>(m_offsetX, m_maxScrollX);
UpdateHorizontalScroll();
}
if(keyId == VK_UP || keyId == VK_DOWN)
{
m_offsetY += (keyId == VK_UP ? -5 : 5);
m_offsetY = std::max<int>(m_offsetY, 0);
m_offsetY = std::min<int>(m_offsetY, m_maxScrollY);
UpdateVerticalScroll();
}
return TRUE;
}
LRESULT CSpuRegView::OnGetDlgCode(WPARAM, LPARAM)
{
return DLGC_WANTARROWS;
}
int32 CSpuRegView::GetFontWidth()
{
if(m_device.IsEmpty()) return 0;
TEXTMETRIC textMetric = {};
m_font->GetTextMetrics(&textMetric);
return textMetric.tmAveCharWidth;
}
int32 CSpuRegView::GetFontHeight()
{
HDC dc = GetDC(NULL);
int32 result = MulDiv(FONT_SIZE, GetDeviceCaps(dc, LOGPIXELSY), 72);
ReleaseDC(NULL, dc);
return result;
}
void CSpuRegView::CreateResources()
{
if(m_device.IsEmpty()) return;
int32 fontHeight = GetFontHeight();
D3DXCreateFont(m_device, -fontHeight, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Courier New"), &m_font);
}
void CSpuRegView::InitializeScrollBars()
{
RECT clientRect = GetClientRect();
m_offsetX = 0;
m_offsetY = 0;
m_pageSizeX = clientRect.right;
m_maxScrollX = std::max<int>(m_canvasWidth - (m_pageSizeX - 1), 0);
m_pageSizeY = clientRect.bottom;
m_maxScrollY = std::max<int>(m_canvasHeight - (m_pageSizeY - 1), 0);
{
SCROLLINFO scrollInfo;
memset(&scrollInfo, 0, sizeof(SCROLLINFO));
scrollInfo.cbSize = sizeof(SCROLLINFO);
scrollInfo.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
scrollInfo.nMin = 0;
scrollInfo.nMax = m_canvasWidth;
scrollInfo.nPos = m_offsetX;
scrollInfo.nPage = m_pageSizeX;
SetScrollInfo(m_hWnd, SB_HORZ, &scrollInfo, TRUE);
}
{
SCROLLINFO scrollInfo;
memset(&scrollInfo, 0, sizeof(SCROLLINFO));
scrollInfo.cbSize = sizeof(SCROLLINFO);
scrollInfo.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
scrollInfo.nMin = 0;
scrollInfo.nMax = m_canvasHeight;
scrollInfo.nPos = m_offsetY;
scrollInfo.nPage = m_pageSizeY;
SetScrollInfo(m_hWnd, SB_VERT, &scrollInfo, TRUE);
}
}
void CSpuRegView::UpdateHorizontalScroll()
{
SCROLLINFO scrollInfo;
memset(&scrollInfo, 0, sizeof(SCROLLINFO));
scrollInfo.cbSize = sizeof(SCROLLINFO);
scrollInfo.fMask = SIF_POS;
scrollInfo.nPos = m_offsetX;
SetScrollInfo(m_hWnd, SB_HORZ, &scrollInfo, TRUE);
}
void CSpuRegView::UpdateVerticalScroll()
{
SCROLLINFO scrollInfo;
memset(&scrollInfo, 0, sizeof(SCROLLINFO));
scrollInfo.cbSize = sizeof(SCROLLINFO);
scrollInfo.fMask = SIF_POS;
scrollInfo.nPos = m_offsetY;
SetScrollInfo(m_hWnd, SB_VERT, &scrollInfo, TRUE);
}
void CSpuRegView::OnDeviceResetting()
{
m_font->OnLostDevice();
}
void CSpuRegView::OnDeviceReset()
{
m_font->OnResetDevice();
}
void CSpuRegView::SetSpu(Iop::CSpuBase* spu)
{
m_spu = spu;
@ -238,42 +62,78 @@ void CSpuRegView::SetSpu(Iop::CSpuBase* spu)
void CSpuRegView::Refresh()
{
if(m_device.IsEmpty()) return;
if(!TestDevice()) return;
D3DCOLOR backgroundColor = ConvertSysColor(GetSysColor(COLOR_BTNFACE));
D3DCOLOR textColor = ConvertSysColor(GetSysColor(COLOR_WINDOWTEXT));
m_device->Clear(0, NULL, D3DCLEAR_TARGET, backgroundColor, 1.0f, 0);
m_device->BeginScene();
CLineDrawer drawer(m_font, textColor, -m_offsetX, -m_offsetY);
{
std::tstring text = m_title + _T(" VLEFT VRIGH PITCH ADDRE ADSRL ADSRR ADSRVOLU REPEA ");
drawer.Draw(text.c_str(), text.length());
drawer.Feed();
}
if(m_spu != nullptr)
{
TCHAR channelStatus[Iop::CSpuBase::MAX_CHANNEL + 1];
for(unsigned int i = 0; i < Iop::CSpuBase::MAX_CHANNEL; i++)
{
unsigned int index = m_listView->FindItemData(i);
if(index == -1)
{
TCHAR temp[5];
_stprintf(temp, _T("CH%0.2i"), i);
LVITEM itm;
memset(&itm, 0, sizeof(LVITEM));
itm.mask = LVIF_TEXT | LVIF_PARAM;
itm.lParam = i;
itm.iItem = i;
itm.pszText = const_cast<TCHAR*>(temp);
index = m_listView->InsertItem(itm);
}
Iop::CSpuBase::CHANNEL& channel(m_spu->GetChannel(i));
TCHAR temp[256];
_stprintf(temp, _T("CH%0.2i %0.4X %0.4X %0.4X %0.6X %0.4X %0.4X %0.8X %0.6X\r\n"),
i,
channel.volumeLeft,
channel.volumeRight,
channel.pitch,
channel.address,
channel.adsrLevel,
channel.adsrRate,
channel.adsrVolume,
channel.repeat);
drawer.Draw(temp);
{
TCHAR temp[5];
_stprintf(temp, _T("%0.4X"), channel.volumeLeft);
m_listView->SetItemText(index, 1, temp);
}
{
TCHAR temp[5];
_stprintf(temp, _T("%0.4X"), channel.volumeRight);
m_listView->SetItemText(index, 2, temp);
}
{
TCHAR temp[5];
_stprintf(temp, _T("%0.4X"), channel.pitch);
m_listView->SetItemText(index, 3, temp);
}
{
TCHAR temp[7];
_stprintf(temp, _T("%0.6X"), channel.address);
m_listView->SetItemText(index, 4, temp);
}
{
TCHAR temp[5];
_stprintf(temp, _T("%0.4X"), channel.adsrLevel);
m_listView->SetItemText(index, 5, temp);
}
{
TCHAR temp[5];
_stprintf(temp, _T("%0.4X"), channel.adsrRate);
m_listView->SetItemText(index, 6, temp);
}
{
TCHAR temp[9];
_stprintf(temp, _T("%0.8X"), channel.adsrVolume);
m_listView->SetItemText(index, 7, temp);
}
{
TCHAR temp[7];
_stprintf(temp, _T("%0.6X"), channel.repeat);
m_listView->SetItemText(index, 8, temp);
}
TCHAR status = _T('0');
switch(channel.status)
@ -296,16 +156,9 @@ void CSpuRegView::Refresh()
channelStatus[i] = status;
}
drawer.Feed();
channelStatus[Iop::CSpuBase::MAX_CHANNEL] = 0;
{
TCHAR temp[256];
_stprintf(temp, _T("CH_STAT: %s"), channelStatus);
drawer.Draw(temp);
}
{
TCHAR revbStat[Iop::CSpuBase::MAX_CHANNEL + 1];
@ -315,33 +168,74 @@ void CSpuRegView::Refresh()
revbStat[i] = (stat & (1 << i)) ? _T('1') : _T('0');
}
revbStat[Iop::CSpuBase::MAX_CHANNEL] = 0;
TCHAR temp[256];
_stprintf(temp, _T("CH_REVB: %s"), revbStat);
drawer.Draw(temp);
_stprintf(temp, _T("CH_STAT: %s\nCH_REVB: %s"), channelStatus, revbStat);
m_extrainfo->SetText(temp);
}
}
m_device->EndScene();
m_device->Present(NULL, NULL, NULL, NULL);
}
CSpuRegView::CLineDrawer::CLineDrawer(const FontPtr& font, D3DCOLOR color, int posX, int posY)
: m_posX(posX)
, m_posY(posY)
, m_font(font)
, m_color(color)
void CSpuRegView::CreateColumns()
{
LVCOLUMN col;
RECT rc = GetClientRect();
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = const_cast<TCHAR*>(m_title.c_str());
col.mask = LVCF_TEXT;
m_listView->InsertColumn(0, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("VLEFT");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(1, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("VRIGH");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(2, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("PITCH");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(3, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("ADDRE");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(4, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("ADSRL");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(5, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("ADSRR");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(6, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("ADSRVOLU");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(7, col);
memset(&col, 0, sizeof(LVCOLUMN));
col.pszText = _T("REPEA");
col.mask = LVCF_TEXT;
m_listView->InsertColumn(8, col);
m_listView->SetColumnWidth(0, rc.right / 10);
m_listView->SetColumnWidth(1, rc.right / 10);
m_listView->SetColumnWidth(2, rc.right / 10);
m_listView->SetColumnWidth(3, rc.right / 10);
m_listView->SetColumnWidth(4, rc.right / 8);
m_listView->SetColumnWidth(5, rc.right / 10);
m_listView->SetColumnWidth(6, rc.right / 10);
m_listView->SetColumnWidth(7, rc.right / 7);
m_listView->SetColumnWidth(8, rc.right / 8);
}
void CSpuRegView::CLineDrawer::Draw(const TCHAR* text, int length)
{
m_font->DrawText(NULL, text, length, Framework::Win32::CRect(m_posX, m_posY, 1, 1), DT_NOCLIP, m_color);
Feed();
}
void CSpuRegView::CLineDrawer::Feed()
{
m_posY += GetFontHeight() + LINE_SPACING;
}

View File

@ -1,14 +1,17 @@
#pragma once
#include <d3dx9.h>
#include "ui_win32/DirectXControl.h"
#include "win32/Window.h"
#include "win32/ListView.h"
#include "iop/Iop_SpuBase.h"
#include "win32/ComPtr.h"
#include "win32/LayoutWindow.h"
#include "layout/VerticalLayout.h"
#include "win32/Static.h"
class CSpuRegView : public CDirectXControl
class CSpuRegView : public Framework::Win32::CWindow
{
public:
CSpuRegView(HWND, const TCHAR*);
CSpuRegView(HWND, const RECT& rect, const TCHAR*);
virtual ~CSpuRegView();
void SetSpu(Iop::CSpuBase*);
@ -17,53 +20,16 @@ protected:
virtual long OnSize(unsigned int, unsigned int, unsigned int) override;
virtual long OnTimer(WPARAM) override;
virtual long OnHScroll(unsigned int, unsigned int) override;
virtual long OnVScroll(unsigned int, unsigned int) override;
virtual long OnMouseWheel(int, int, short) override;
virtual long OnKeyDown(WPARAM, LPARAM) override;
virtual LRESULT OnGetDlgCode(WPARAM, LPARAM) override;
virtual void Refresh() override;
virtual void OnDeviceResetting() override;
virtual void OnDeviceReset() override;
void Refresh();
private:
typedef Framework::Win32::CComPtr<ID3DXFont> FontPtr;
class CLineDrawer
{
public:
CLineDrawer(const FontPtr&, D3DCOLOR, int, int);
void Draw(const TCHAR*, int = -1);
void Feed();
private:
int m_posX;
int m_posY;
FontPtr m_font;
D3DCOLOR m_color;
};
int32 GetFontWidth();
static int32 GetFontHeight();
void CreateResources();
void InitializeScrollBars();
void UpdateHorizontalScroll();
void UpdateVerticalScroll();
void CreateColumns();
Iop::CSpuBase* m_spu;
FontPtr m_font;
uint32 m_canvasWidth = 0;
uint32 m_canvasHeight = 0;
std::tstring m_title;
int m_offsetX;
int m_offsetY;
int m_pageSizeX;
int m_pageSizeY;
int m_maxScrollX;
int m_maxScrollY;
Framework::Win32::CListView* m_listView;
Framework::Win32::CStatic* m_extrainfo;
Framework::FlatLayoutPtr m_pLayout;
};

View File

@ -7,7 +7,7 @@ CSpuRegViewPanel::CSpuRegViewPanel(HWND parentWnd, const TCHAR* title)
{
SetClassPtr();
m_regView = new CSpuRegView(m_hWnd, title);
m_regView = new CSpuRegView(m_hWnd, GetClientRect(), title);
RefreshLayout();
}

View File

@ -164,7 +164,6 @@ if(TARGET_PLATFORM_MACOS)
endif(TARGET_PLATFORM_MACOS)
if(TARGET_PLATFORM_WIN32)
find_package(DirectX9 REQUIRED)
set(AUDIO_LIBS)
if(OPENAL_FOUND)
add_library(SH_OpenAL SHARED ../Source/SH_OpenAL.cpp ../Source/win32_ui/SH_OpenAL/DllMain.cpp)
@ -218,7 +217,7 @@ if(TARGET_PLATFORM_WIN32)
)
add_executable(PsfPlayer WIN32 ${WIN32_SRC} ../Source/win32_ui/Res.rc)
target_link_libraries(PsfPlayer PUBLIC ${DirectX_D3DX9_LIBRARY} ${PROJECT_LIBS} ${CMAKE_CURRENT_SOURCE_DIR}/../../../../Dependencies/tdemu-1.10/TDEmu64.lib ${AUDIO_LIBS})
target_link_libraries(PsfPlayer PUBLIC ${PROJECT_LIBS} ${CMAKE_CURRENT_SOURCE_DIR}/../../../../Dependencies/tdemu-1.10/TDEmu64.lib ${AUDIO_LIBS})
target_include_directories(PsfPlayer
PUBLIC
../Source
@ -226,7 +225,6 @@ if(TARGET_PLATFORM_WIN32)
../../../Source/ui_win32
../../../Source/gs/GSH_OpenGL
${CMAKE_CURRENT_SOURCE_DIR}/../../../../Dependencies/tdemu-1.10
${DirectX_D3DX9_INCLUDE_DIR}
)
include(PrecompiledHeader)
add_precompiled_header(PsfPlayer StdAfx.h FORCEINCLUDE SOURCE_CXX ../Source/win32_ui/StdAfx.cpp)