Skip to content

Commit

Permalink
Rev.13
Browse files Browse the repository at this point in the history
コメント設定をini設定可能にする変更をマージ
勢い一覧を取得するAPIを変更。BSも表示するようにした。
DirectWriteをデフォルトでは使用しないようにした(iniで設定可)
勢いウィンドウを表示しない設定を追加(hideForceWindow)。
勢いウィンドウから同チャンネルの別サービスに切り替えできなかったのを修正。
大きなディスプレイの場合にコメントが切れる/表示できないのを修正(したはず)。
  • Loading branch information
rutice committed Jun 2, 2012
1 parent 73bc231 commit 43e665b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 26 deletions.
19 changes: 15 additions & 4 deletions CommentPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//#include <wincodec.h>
//#include <wincodecsdk.h>
#include <comip.h>
#include <comdef.h>

#include "CommentPrinter.h"
#include "CommentWindow.h"
Expand Down Expand Up @@ -48,9 +49,12 @@ class GDIPrinter : public Printer {
hWnd_(NULL),
hDC_(NULL)
{
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);

HDC wndDC = GetDC(hWnd_);
memDC_ = CreateCompatibleDC(wndDC);
hBitmap_ = CreateCompatibleBitmap(wndDC, 1920, 1200);
hBitmap_ = CreateCompatibleBitmap(wndDC, rc.right - rc.left, rc.bottom - rc.top);
hPrevBitmap_ = (HBITMAP)SelectObject(memDC_, hBitmap_);

ReleaseDC(hWnd_, wndDC);
Expand Down Expand Up @@ -298,7 +302,11 @@ class DWPrinter : public Printer {

static bool IsAvailable() {
if (isAvailable == -1) {
isAvailable = IsAvailableImpl() ? 1 : 0;
try {
isAvailable = IsAvailableImpl() ? 1 : 0;
} catch (_com_error) {
isAvailable = 0;
}
}
return isAvailable != 0;
}
Expand Down Expand Up @@ -429,14 +437,17 @@ class DWPrinter : public Printer {
COMPTR_TYPEDEF(ID3D10Texture2D);
ID3D10Texture2DPtr texture;
if (SUCCEEDED(hr)) {
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);

D3D10_TEXTURE2D_DESC description = {};
description.ArraySize = 1;
description.BindFlags =
D3D10_BIND_RENDER_TARGET;
description.Format =
DXGI_FORMAT_B8G8R8A8_UNORM;
description.Width = 1920;
description.Height = 1200;
description.Width = rc.right - rc.left;
description.Height = rc.bottom - rc.top;
description.MipLevels = 1;
description.SampleDesc.Count = 1;
description.MiscFlags =
Expand Down
56 changes: 39 additions & 17 deletions NicoJK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ bool CNicoJK::Finalize() {
void CNicoJK::TogglePlugin(bool bEnabled) {
if (bEnabled) {
OnChannelChange();
PostMessage(hForce_, WM_TIMER, TIMER_UPDATE, 0L);
ShowWindow(hForce_, SW_SHOW);
int hideForceWindow = GetPrivateProfileInt(_T("Setting"), _T("hideForceWindow"), 0, szIniFileName_);
if (!hideForceWindow) {
ShowWindow(hForce_, SW_SHOW);
PostMessage(hForce_, WM_TIMER, TIMER_UPDATE, 0L);
}
} else {
ShowWindow(hForce_, SW_HIDE);
StopJK();
Expand Down Expand Up @@ -368,7 +371,7 @@ BOOL CNicoJK::ForceDialog_UpdateForce() {
closesocket(socJkapi_);
}
if (!hGethost_) {
hGethost_ = WSAAsyncGetHostByName(hForce_, WMS_APIJK_HOST, "api.jk.nicovideo.jp", szHostbuf_, MAXGETHOSTSTRUCT);
hGethost_ = WSAAsyncGetHostByName(hForce_, WMS_APIJK_HOST, "jk.nicovideo.jp", szHostbuf_, MAXGETHOSTSTRUCT);
}
return TRUE;
}
Expand Down Expand Up @@ -422,16 +425,30 @@ const wchar_t *CNicoJK::GetXmlInnerElement(const wchar_t *in, const wchar_t *sta
BOOL CNicoJK::ForceDialog_UpdateForceXML() {
wchar_t wcs[102400];
wchar_t channelElem[1024];
MultiByteToWideChar(CP_UTF8, 0, szChannelBuf_, -1, wcs, 10240);
const wchar_t *p = wcs;
MultiByteToWideChar(CP_UTF8, 0, szChannelBuf_, -1, wcs, 102400);

TVTest::ChannelInfo info;
m_pApp->GetCurrentChannelInfo(&info);
int currentJK = GetJKByChannelName(info.szChannelName);

HWND hList = GetDlgItem(hForce_, IDC_FORCELIST);
int iTopItemIndex = ListBox_GetTopIndex(hList);
ListBox_ResetContent(hList);
while(p = GetXmlInnerElement(p, L"<channel>", L"</channel>", channelElem, 1024)) {
int iSelectedItem = -1;
const wchar_t *ptr = wcs;
const wchar_t *tmpt = ptr, *tmpbs;
while(true) {
if (tmpt) {
tmpt = GetXmlInnerElement(ptr, L"<channel>", L"</channel>", channelElem, 1024);
}
if (!tmpt) {
tmpbs = GetXmlInnerElement(ptr, L"<bs_channel>", L"</bs_channel>", channelElem, 1024);
}
ptr = tmpt ? tmpt : tmpbs;
if (!ptr) {
break;
}

wchar_t szJK[100];
GetXmlInnerElement(channelElem, L"<video>", L"</video>", szJK, 100);
wchar_t szName[100];
Expand All @@ -444,9 +461,13 @@ BOOL CNicoJK::ForceDialog_UpdateForceXML() {
ListBox_AddString(hList, szResult);

if (currentJK == _wtoi(szJK + 2)) {
ListBox_SetCurSel(hList, ListBox_GetCount(hList) - 1);
iSelectedItem = ListBox_GetCount(hList) - 1;
ListBox_SetCurSel(hList, iSelectedItem);
}
}
if (iTopItemIndex >= 0) {
ListBox_SetTopIndex(hList, iTopItemIndex);
}
return TRUE;
}

Expand All @@ -460,18 +481,17 @@ BOOL CNicoJK::ForceDialog_OnSelChange(HWND hList) {
if (_tcsncmp(sz, _T("jk"), 2) == 0) {
int jkID = _ttoi(sz + 2);

int iCurrentTuning = m_pApp->GetTuningSpace();
TVTest::ChannelInfo info;
// なんとなく200まで
for (int i=0; i<200; i++) {
if (m_pApp->GetChannelInfo(m_pApp->GetTuningSpace(), i, &info)) {
if (m_pApp->GetChannelInfo(iCurrentTuning, i, &info)) {
int chJK = GetJKByChannelName(info.szChannelName);
// 実況IDが一致するチャンネルに切替
if (jkID == chJK) {
// すでに表示中なら切り替えない
TVTest::ChannelInfo currentInfo;
bool success = m_pApp->GetCurrentChannelInfo(&currentInfo);
if (!success || currentInfo.Channel != info.Channel) {
m_pApp->SetChannel(m_pApp->GetTuningSpace(), i);
if (m_pApp->GetService() != info.ServiceID) {
m_pApp->SetChannel(m_pApp->GetTuningSpace(), i, info.ServiceID);
}
return TRUE;
}
Expand Down Expand Up @@ -560,7 +580,7 @@ INT_PTR CALLBACK CNicoJK::ForceDialogProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPAR
memset(pThis->serversockaddr_.sin_zero, 0, sizeof(pThis->serversockaddr_.sin_zero));
if (connect(pThis->socJkapi_, (struct sockaddr*)&pThis->serversockaddr_, sizeof(pThis->serversockaddr_)) == SOCKET_ERROR) {
if (WSAGetLastError() != WSAEWOULDBLOCK) {
MessageBox(hwnd, _T("ニコニコ実況APIサーバへの接続に失敗しました"), _T("Error"), MB_OK | MB_ICONERROR);
MessageBox(hwnd, _T("ニコニコ実況サーバへの接続に失敗しました"), _T("Error"), MB_OK | MB_ICONERROR);
}
}
}
Expand All @@ -570,7 +590,7 @@ INT_PTR CALLBACK CNicoJK::ForceDialogProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPAR
case WMS_APIJK:
{
SOCKET soc = (SOCKET)wparam;
char *szGetTemplate = "GET /v1/channel.list HTTP/1.0\r\nHost: api.jk.nicovideo.jp\r\nConnection: Close\r\n\r\n";
char *szGetTemplate = "GET /api/v2_app/getchannels HTTP/1.0\r\nHost: jk.nicovideo.jp\r\nConnection: Close\r\n\r\n";
switch(WSAGETSELECTEVENT(lparam)) {
case FD_CONNECT: /* サーバ接続したイベントの場合 */
break;
Expand All @@ -588,7 +608,7 @@ INT_PTR CALLBACK CNicoJK::ForceDialogProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPAR
}
break;
case FD_CLOSE:
if (strlen(buf)) {
if (strlen(pThis->szChannelBuf_)) {
pThis->ForceDialog_UpdateForceXML();
}
closesocket(soc);
Expand All @@ -615,8 +635,10 @@ INT_PTR CALLBACK CNicoJK::ForceDialogProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPAR
break;
case WM_TIMER:
if (pThis) {
// 勢いを更新する
return pThis->ForceDialog_UpdateForce();
if (IsWindowVisible(hwnd)) {
// 勢いを更新する
return pThis->ForceDialog_UpdateForce();
}
}
break;
case WM_SIZE:
Expand Down
11 changes: 9 additions & 2 deletions NicoJK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
[Setting]
; ニコニコ実況SDKを使用するかどうか(デフォルトは 0 = 使用しない)
;useSDK=1
; DirectWriteを使用しない
;
; DirectWriteを使用かどうか(0にすると使える環境では使用)
;(Windows Vistaより古いまたはDirectX 10.1未対応グラボの場合は最初から使用しない)
;disableDWrite=1
disableDWrite=1
;
; 勢いウィンドウを表示しない
; hideForceWindow=1
;
; コメントの描画間隔 (ms) (デフォルトは 33ms)
; timerInterval=33
; コメントの行間隔 (%) (デフォルトは 125%)
Expand Down Expand Up @@ -87,4 +92,6 @@
IMAGICA BS=252
BS日本映画専門ch=255
ディズニーXD=256
Dlife=258
SOLiVE24=910
WNI・910=910
13 changes: 10 additions & 3 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ NicoJK.iniで、
切断時や4時の実況切り替わり時の再接続は未実装。

■DirectWriteについて
Windows Vista以降かつ、DirectX 10.1以降対応のグラボがある環境でのみ
自動的に使用します。
無効にするには disableDWrite=1 としてください。
Windows Vista以降かつ、DirectX 10.1以降対応のグラボがある環境で使用できます。
有効にするには disableDWrite=0 としてください。
有効になっていると、文字が縁取って表示されます。

■テスト環境
Expand All @@ -51,6 +50,14 @@ https://github.com/rutice/NicoJK/downloads
https://github.com/rutice/NicoJK

■更新履歴
rev.13
コメント設定をini設定可能にする変更をマージ
勢い一覧を取得するAPIを変更。BSも表示するようにした。
DirectWriteをデフォルトでは使用しないようにした(iniで設定可)
勢いウィンドウを表示しない設定を追加(hideForceWindow)。
勢いウィンドウから同チャンネルの別サービスに切り替えできなかったのを修正。
大きなディスプレイの場合にコメントが切れる/表示できないのを修正(したはず)。

rev.12
DirectWriteが使える環境では使ってみた
新BSチャンネルを追加した
Expand Down

0 comments on commit 43e665b

Please sign in to comment.