📄 subs.c
字号:
/*****************************************************************************
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: subs.c 615 2007-01-04 18:16:51M nikoro $
*
* The Core Pocket Media Player Subtitle Plugin
* Copyright (c) 2008 Alexander Sorokin
*
****************************************************************************/
#include "../common/common.h"
#include "subs.h"
#include "subtitle.h"
#if defined(TARGET_WIN32) || defined(TARGET_WINCE)
#ifndef STRICT
#define STRICT
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#if _MSC_VER > 1000
#pragma warning(disable : 4201)
#endif
typedef struct subs
{
node Node;
bool_t Allow;
} subs;
static HDC dc;
static int TAIMER;
static int _TAIMER;
static int taim=-1;
void *POldSet;
wchar_t url[1025],filmurl[1025],newurl[1025];
//,newurl[1025];
notify Notify,OldNotify;
BOOL _init=0;
rect viewport;
BOOL loaded=0;
//MessageBoxW(0,L"Hello",L"Message from subs",0);
static const datatable Params[] =
{
{SUBS_ENABLED, TYPE_BOOL, DF_SETUP|DF_CHECKLIST},
{SUBS_THICK, TYPE_BOOL, DF_SETUP|DF_CHECKLIST},
{SUBS_OUTLINE, TYPE_BOOL, DF_SETUP|DF_CHECKLIST},
{SUBS_FORCE_FONT, TYPE_BOOL, DF_SETUP|DF_CHECKLIST},
{SUBS_AL_TOP, TYPE_BOOL, DF_SETUP|DF_CHECKLIST},
{SUBS_BR_AFTER, TYPE_INT, DF_SETUP|DF_INPUT},
{SUBS_SIZE, TYPE_INT, DF_SETUP|DF_INPUT},
{SUBS_TIMING,TYPE_INT,DF_SETUP|DF_NEG,-10*60*20,10*60*20 },
{SUBS_FONT_FACE,TYPE_STRING,DF_SETUP},
DATATABLE_END(SUBS_ID)
};
static int Enum(subs* p, int* No, datadef* Param)
{
int Result = NodeEnumTable(No,Param,Params);
if (Result == ERR_NONE)
{
}
return Result;
}
static int Get(subs* p, int No, void* Data, int Size)
{
int Result = ERR_INVALID_PARAM;
switch (No)
{
case SUBS_ENABLED: GETVALUE(xsubs.allowed,bool_t); break;
case SUBS_THICK: GETVALUE(xsubs.def_bold,bool_t); break;
case SUBS_OUTLINE: GETVALUE(xsubs.def_outlined,bool_t); break;
case SUBS_BR_AFTER: GETVALUE(xsubs.br_after,tick_t); break;
case SUBS_SIZE: GETVALUE(xsubs.def_height,tick_t); break;
case SUBS_FORCE_FONT: GETVALUE(xsubs.force_font,bool_t); break;
case SUBS_AL_TOP: GETVALUE(xsubs.al_top,bool_t); break;
case SUBS_TIMING: GETVALUE(xsubs.timing,tick_t); break;
case SUBS_FONT_FACE: GETSTRING(xsubs.def_font); break;
}
return Result;
}
static int UpdateOrient(BOOL force)
{
node* Player;
bool_t _orient;
Player=Context()->Player;
if (!Player) return 0;
Player->Get(Player,PLAYER_FULLSCREEN,&_orient,sizeof(bool_t));
if (_orient==xsubs.orient && !force) return 0;
xsubs.orient=_orient;
xsubs.dirtystate=0;
if (!xsubs.orient)
{
if (xsubs.al_top) xsubs.margin_top=+20*xsubs.device_width/240; else xsubs.margin_top=viewport.Height+20*xsubs.device_width/240;
xsubs.margin_left=0;
}
else
{
if (xsubs.al_top) xsubs.margin_top=0; else xsubs.margin_top=viewport.Width;
xsubs.margin_left=0;
}
return 1;
}
static int Set(subs* p, int No, const void* Data, int Size)
{
int Result = ERR_INVALID_PARAM;
switch (No)
{
case SUBS_ENABLED: SETVALUE(xsubs.allowed,bool_t,ERR_NONE); filmurl[0]='\0'; break;
case SUBS_THICK: SETVALUE(xsubs.def_bold,bool_t,ERR_NONE); break;
case SUBS_OUTLINE: SETVALUE(xsubs.def_outlined,bool_t,ERR_NONE); break;
case SUBS_BR_AFTER: SETVALUE(xsubs.br_after,tick_t,ERR_NONE); if (xsubs.br_after<10) xsubs.br_after=10; filmurl[0]='\0'; break;
case SUBS_SIZE: SETVALUE(xsubs.def_height,tick_t,ERR_NONE); break;
case SUBS_FORCE_FONT: SETVALUE(xsubs.force_font,bool_t,ERR_NONE); break;
case SUBS_AL_TOP: SETVALUE(xsubs.al_top,bool_t,ERR_NONE); UpdateOrient(1); break;
case SUBS_TIMING: SETVALUE(xsubs.timing,tick_t,ERR_NONE); break;
case SUBS_FONT_FACE: SETSTRING(xsubs.def_font); break;
}
if (Context()->Player && xsubs.allowed) xsubs_init_font();
return Result;
}
static int UpdateUrl()
{
node* Player;
int res;
Player=Context()->Player;
res=Player->Get(Player,PLAYER_LIST_URL,&newurl,sizeof(newurl));
if (res!=ERR_NONE || newurl[0]=='\0' || wcscmp(filmurl,newurl)==0) {newurl[0]='\0'; return 0;}
wcscpy(filmurl,newurl);
wcscpy(url,newurl);
xsubs_free();
xsubs_init(url);
return 1;
}
static void Redraw()
{
DWORD test;
tick_t Time;
node* Player = Context()->Player;
if (Player->Get(Player,PLAYER_POSITION,&Time,sizeof(tick_t)) != ERR_NONE) return;
test=Time*0.06103515625;
xsubs_draw(dc,test);
}
static int PlayerNotify(subs* p,int Id,int Value)
{
if (Id==PLAYER_PLAY) {xsubs.dirtystate=0; UpdateUrl();}
//UpdateOrient(p);
if (OldNotify.Func) return OldNotify.Func(OldNotify.This,Id,Value);
return ERR_NONE;
}
static void CALLBACK Hook(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
node* Video;
DWORD TEST=0xFFFFFFFF;
node* Player = Context()->Player;
//bool_t b = 0;
if (!xsubs.allowed || !Player) return;
if (!_init)
{
while (1)
{
/*memset(&SCREEN,0,sizeof(SCREEN));
if (Player->Get(Player,PLAYER_VOUTPUT,&Video,sizeof(Video))!=ERR_NONE) break;
if (!Video) break;
if (Video->Get(Video,RAW_POINTER,&(SCREEN.buf),sizeof(SCREEN.buf))!=ERR_NONE) break;
if (!SCREEN.buf) break;
if (Video->Get(Video,RAW_WIDTH,&(SCREEN.width),sizeof(SCREEN.width))!=ERR_NONE) break;
if (Video->Get(Video,RAW_HEIGHT,&(SCREEN.height),sizeof(SCREEN.height))!=ERR_NONE) break;
if (Video->Get(Video,RAW_PITCHX,&(SCREEN.dx),sizeof(SCREEN.dx))!=ERR_NONE) break;
if (Video->Get(Video,RAW_PITCHY,&(SCREEN.dy),sizeof(SCREEN.dy))!=ERR_NONE) break;
if (Video->Get(Video,RAW_BPP,&(SCREEN.bpp),sizeof(SCREEN.bpp))!=ERR_NONE) break;
if (Video->Get(Video,RAW_FORMAT,&(SCREEN.format),sizeof(SCREEN.format))!=ERR_NONE) break;*/
loaded=1;
break;
}
dc=GetDC(Context()->Wnd);
xsubs.device_height=GetDeviceCaps(dc,VERTRES);
xsubs.device_width=GetDeviceCaps(dc,HORZRES);
if (Player->Get(Player,PLAYER_SKIN_VIEWPORT,&viewport,sizeof(viewport)) != ERR_NONE) return;
Notify.This=Player;
Notify.Func=(notifyfunc)PlayerNotify;
Player->Get(Player,PLAYER_NOTIFY,&OldNotify,sizeof(OldNotify));
Player->Set(Player,PLAYER_NOTIFY,&Notify,sizeof(Notify));
_init=1;
UpdateOrient(1);
//KillTimer(NULL,TAIMER);
}
/*if (loaded)
{
//memcpy(SCREEN.buf+100*SCREEN.dy,&TEST,sizeof(DWORD));
}*/
//if (_TAIMER%5==0)
UpdateOrient(0);
Redraw();
_TAIMER++;
}
static int Create(subs* p)
{
//p->Overlay.Init=UpdateOrient;
p->Node.Enum = (nodeenum)Enum,
p->Node.Get = (nodeget)Get,
p->Node.Set = (nodeset)Set;
if (!xsubs.def_height)
{
xsubs.def_height=12;
xsubs.def_bold=1;
xsubs.def_outlined=0;
xsubs.timing=0;
xsubs.def_font[0]='\0';
xsubs.al_top=0;
xsubs.br_after=30;
}
xsubs.line_spacing=0;
xsubs.max_lines=2;
xsubs.orient=0;
xsubs.clear_color=0x00000000;
filmurl[0]='\0';
_TAIMER=0;
TAIMER=SetTimer(NULL,0,100,Hook);
return ERR_NONE;
}
static int Delete(subs* p)
{
ReleaseDC(Context()->Wnd,dc);
xsubs_free();
return ERR_NONE;
}
static const nodedef SUBS =
{
sizeof(subs)|CF_GLOBAL|CF_SETTINGS,
SUBS_ID,
NODE_CLASS,
PRI_MINIMUM,
(nodecreate)Create,
//NULL,
(nodedelete)Delete,
};
void SUBS_Init()
{
StringAdd(1,SUBS_ID,NODE_NAME,L"Subtitles");
///StringAdd(1,SUBS_ID,NODE_EXTS,L"srt:S;ssa:S");
StringAdd(1,SUBS_ID,SUBS_ENABLED,L"Enable subtitles");
StringAdd(1,SUBS_ID,SUBS_THICK,L"Bold default font");
StringAdd(1,SUBS_ID,SUBS_OUTLINE,L"Outlined default font");
StringAdd(1,SUBS_ID,SUBS_FORCE_FONT,L"Force default font");
StringAdd(1,SUBS_ID,SUBS_AL_TOP,L"Align at top");
StringAdd(1,SUBS_ID,SUBS_BR_AFTER,L"Break lines after");
StringAdd(1,SUBS_ID,SUBS_SIZE,L"Default font size");
StringAdd(1,SUBS_ID,SUBS_TIMING,L"Timing offset");
StringAdd(1,SUBS_ID,SUBS_FONT_FACE,L"Font name");
NodeRegisterClass(&SUBS);
}
void SUBS_Done()
{
NodeUnRegisterClass(SUBS_ID);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -