⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skin.cpp

📁 播放器源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************************
 *                                                                                    *
 * This application contains code from OpenDivX and is released as a "Larger Work"    *
 * under that license. Consistant with that license, this application is released     *
 * under the GNU General Public License.                                              *
 *                                                                                    *
 * The OpenDivX license can be found at: http://www.projectmayo.com/opendivx/docs.php *
 * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html                      *
 *                                                                                    *
 * Copyright (c) 2001 - Project Mayo                                                  *
 *                                                                                    *
 * Authors: Damien Chavarria <adrc at projectmayo.com>                                *
 *                                                                                    *
 **************************************************************************************/


#include "Skin.h"

/*
 * Class Functions
 *
 */

/*
 * Constructor : Loads the default skin
 *
 */


Skin::Skin(HINSTANCE hInstance, HWND hwnd)
{

	this->LoadDefault(hInstance, hwnd);
	
	if(this->skin == NULL ||this->controls == NULL) {
		MessageBox(NULL, "Cannot load default skin!", "Error", MB_OK);
	}

	/*
 	 * Default values for the rects
	 */

	this->menuButton.left   = 2;
	this->menuButton.right  = 14;
	this->menuButton.top    = 3;
	this->menuButton.bottom = 14;

	this->minimizeButton.left   = 266;
	this->minimizeButton.right  = 278;
	this->minimizeButton.top    = 3;
	this->minimizeButton.bottom = 14;

	this->closeButton.left   = 283;
	this->closeButton.right  = 295;
	this->closeButton.top    = 3;
	this->closeButton.bottom = 14;

	this->rewindButton.left   = 15;
	this->rewindButton.right  = 15+29;
	this->rewindButton.top    = 343;
	this->rewindButton.bottom = 360;

	this->stopButton.left   = 52;
	this->stopButton.right  = 52+29;
	this->stopButton.top    = 343;
	this->stopButton.bottom = 360;

	this->playButton.left   = 89;
	this->playButton.right  = 89+29;
	this->playButton.top    = 343;
	this->playButton.bottom = 360;

	this->pauseButton.left   = 126;
	this->pauseButton.right  = 126+29;
	this->pauseButton.top    = 343;
	this->pauseButton.bottom = 360;

	this->forwardButton.left   = 263;
	this->forwardButton.right  = 300;
	this->forwardButton.top    = 343;
	this->forwardButton.bottom = 360;

	this->loadButton.left   = 236;
	this->loadButton.right  = 263+44;
	this->loadButton.top    = 343;
	this->loadButton.bottom = 360;

	this->progressBar.left   = 12;
	this->progressBar.right  = 281;
	this->progressBar.top    = 325;
	this->progressBar.bottom = 332;

	this->volumeBar.left   = 212;
	this->volumeBar.right  = 273;
	this->volumeBar.top    = 296;
	this->volumeBar.bottom = 304;

	this->progressCursor.left   = 15;
	this->progressCursor.right  = 43;
	this->progressCursor.top    = 321;
	this->progressCursor.bottom = 336;

	this->volumeCursor.left   = 250;
	this->volumeCursor.right  = 270;
	this->volumeCursor.top    = 293;
	this->volumeCursor.bottom = 307;
	
	this->volume   = 100;
	this->progress = 0.0;

	this->compactMode = 0;
}

/*
 * Destructor
 *
 */

Skin::~Skin()
{
	DeleteObject((HGDIOBJ) this->skin); 

	DeleteObject((HGDIOBJ) this->controls); 
	DeleteObject((HGDIOBJ) this->bottom); 
	DeleteObject((HGDIOBJ) this->logo); 
}

/*
 * Returns TRUE if the point is
 * inside the given rect...
 *
 */

BOOL Skin::isInsideRect(int x, int y, RECT rect)
{
	return (x > rect.left && x < rect.right && y > rect.top && y < rect.bottom);
}

/*
 * loads the Default Skin
 *
 */

int Skin::LoadDefault(HINSTANCE hInstance, HWND hwnd) {

	HDC   dc, sdc, ddc;
	DWORD i;

	this->skin     = LoadBitmap(hInstance, MAKEINTRESOURCE(ID_SKIN)); 
	this->controls = LoadBitmap(hInstance, MAKEINTRESOURCE(ID_CONTROLS));
	this->logo     = LoadBitmap(hInstance, MAKEINTRESOURCE(ID_LOGO));

	dc = GetDC(hwnd);

	this->bottom = CreateCompatibleBitmap(dc, 256, 115);

	sdc = CreateCompatibleDC(dc);
	SelectObject(sdc, this->skin);

	ddc = CreateCompatibleDC(dc);
	SelectObject(ddc, this->bottom);


	for(i=0; i < 256; i++) {

		BitBlt(ddc, i, 0, 1, 115, sdc, 200, 260, SRCCOPY);
	}

	ReleaseDC(hwnd, dc);
	DeleteDC(sdc);
	DeleteDC(ddc);

	this->skinColor = 0;

	return 1;
}


/*
 * Loads a new skin
 *
 */

int Skin::Load(char *directory, HWND hwnd) {

	HDC   dc, sdc, ddc;
	DWORD i;

	if(directory != NULL) {

		char *mainc, *logoc, *controlsc;

		mainc     = (char *) new char[strlen(directory) + 10];
		strcpy(mainc, directory);

		logoc     = (char *) new char[strlen(directory) + 10];
		strcpy(logoc, directory);
		
		controlsc = (char *) new char[strlen(directory) + 20];
		strcpy(controlsc, directory);

		if(this->skin)
			DeleteObject((HGDIOBJ) this->skin);
		
		if(this->controls)
			DeleteObject((HGDIOBJ) this->controls);

		if(this->logo)
			DeleteObject((HGDIOBJ) this->logo);

		this->skin =     (HBITMAP) LoadImage(NULL, strcat(mainc, "\\main.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
		this->logo =     (HBITMAP) LoadImage(NULL, strcat(logoc, "\\logo.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
		this->controls = (HBITMAP) LoadImage(NULL, strcat(controlsc, "\\controls.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

		free(mainc);
		free(logoc);
		free(controlsc);

		if(this->skin == 0 || this->logo == 0 || this->controls == 0) {

			this->LoadDefault(GetModuleHandle(NULL), hwnd);
		}
		else {

			/*
			 * Do some cache
			 *
			 */

			dc = GetDC(hwnd);

			sdc = CreateCompatibleDC(dc);
			SelectObject(sdc, this->skin);

			ddc = CreateCompatibleDC(dc);
			SelectObject(ddc, this->bottom);


			for(i=0; i < 256; i++) {

				BitBlt(ddc, i, 0, 1, 115, sdc, 200, 260, SRCCOPY);
			}

			ReleaseDC(hwnd, dc);
			DeleteDC(sdc);
			DeleteDC(ddc);

			/*
			 * Now load the background color from the config.txt file
			 */

			SkinFile *skinFile = new SkinFile(directory);

			this->skinColor = skinFile->getColor("background");

			skinFile->Close();	
		}
	}

	return 1;
}

/*
 * Return Default Width
 *
 */

int Skin::GetDefaultWidth()
{
	return DEFAULT_SKIN_WIDTH;	
}

/*
 * Return Default Width
 *
 */


int Skin::GetDefaultHeight()
{
	return DEFAULT_SKIN_HEIGHT;	
}

/*
 * Set volume and Progress
 * (for display only!)
 *
 */

int Skin::SetVolume(HWND hwnd, int new_volume)
{
	int          sizeX, sizeY;
	RECT         clientRect;

	/*
 	 * Get some info about the
	 * window size and all.
	 */

	GetClientRect(hwnd, &clientRect);

	sizeX = clientRect.right - clientRect.left;
	sizeY = clientRect.bottom - clientRect.top;

	this->volume = new_volume;

	this->volumeCursor.left   = 215 + (sizeX - DEFAULT_SKIN_WIDTH) + 35*this->volume/100;
	this->volumeCursor.right  = 235 + (sizeX - DEFAULT_SKIN_WIDTH) + 35*this->volume/100;
	this->volumeCursor.top    = 293 + (sizeY - DEFAULT_SKIN_HEIGHT);
	this->volumeCursor.bottom = 307 + (sizeY - DEFAULT_SKIN_HEIGHT);

	return 1;
}

int Skin::SetProgress(HWND hwnd, double new_progress)
{
	int          sizeX, sizeY;
	RECT         clientRect;

	/*
 	 * Get some info about the
	 * window size and all.
	 */

	GetClientRect(hwnd, &clientRect);

	sizeX = clientRect.right - clientRect.left;
	sizeY = clientRect.bottom - clientRect.top;

	this->progress = new_progress;

	this->progressCursor.left   =  15 + (int)((double)(sizeX - DEFAULT_SKIN_WIDTH + 263 - 28)*this->progress)/100;
	this->progressCursor.right  =  43 + (int)((double)(sizeX - DEFAULT_SKIN_WIDTH + 263 - 28)*this->progress)/100;
	this->progressCursor.top    =  321 + (sizeY - DEFAULT_SKIN_HEIGHT);
	this->progressCursor.bottom =  336 + (sizeY - DEFAULT_SKIN_HEIGHT);

	return 1;
}

int Skin::SetVolumeCursorX(HWND hwnd, int x)
{
	int  the_volume;
	int  sizeX, sizeY;
	RECT clientRect;
	HDC          hdc, bdc;
	
	hdc = GetDC(hwnd);
	bdc = CreateCompatibleDC(hdc);
 
	if(hdc == NULL || bdc == NULL) {

		return 0;
	}

	SelectObject(bdc, this->skin);

	/*
 	 * Get some info about the
	 * window size and all.
	 */

	GetClientRect(hwnd, &clientRect);

	sizeX = clientRect.right - clientRect.left;
	sizeY = clientRect.bottom - clientRect.top;
	
	if(x < volumeBar.left)
		the_volume = 0;
	else {
		if(x > volumeBar.right)
			the_volume = 100;
		else {

			the_volume = (x - volumeBar.left)*100/(volumeBar.right - volumeBar.left);
		}
	}

	SetVolume(hwnd, the_volume);

	BitBlt(hdc, volumeBar.left, volumeBar.top - 5, (volumeBar.right - volumeBar.left), (volumeBar.bottom - volumeBar.top) + 10, 
		   bdc, 212, 291, SRCCOPY);

	SelectObject(bdc, this->controls);

	BitBlt(hdc, volumeCursor.left, volumeCursor.top, (volumeCursor.right - volumeCursor.left), (volumeCursor.bottom - volumeCursor.top), 
		   bdc, 32, 45, SRCCOPY);

	DeleteDC(bdc);
	ReleaseDC(hwnd, hdc);

	return 1;
}

int Skin::SetProgressCursorX(HWND hwnd, int x)
{
	int  the_progress;
	int  sizeX, sizeY, i;
	RECT clientRect;
	HDC  hdc, bdc;
	
	hdc = GetDC(hwnd);
	bdc = CreateCompatibleDC(hdc);
 
	if(hdc == NULL || bdc == NULL) {

		return 0;
	}

	SelectObject(bdc, this->skin);

	/*
 	 * Get some info about the
	 * window size and all.
	 */

	GetClientRect(hwnd, &clientRect);

	sizeX = clientRect.right - clientRect.left;
	sizeY = clientRect.bottom - clientRect.top;
	
	if(x < progressBar.left)
		the_progress = 0;
	else {
		if(x > progressBar.right)
			the_progress = 100;
		else {

			the_progress = (x - progressBar.left)*100/(progressBar.right - progressBar.left);
		}
	}

	SetProgress(hwnd, the_progress);

	BitBlt(hdc, 0, 320 + (sizeY - DEFAULT_SKIN_HEIGHT), 200, 20, bdc, 0, 320, SRCCOPY);

	for(i=0; i < (sizeX - DEFAULT_SKIN_WIDTH); i++) {

		BitBlt(hdc, 200 + i, 320 + (sizeY - DEFAULT_SKIN_HEIGHT), 1, 20, bdc, 200, 320, SRCCOPY);
	}

	BitBlt(hdc, 200 + (sizeX - DEFAULT_SKIN_WIDTH), 320 + (sizeY - DEFAULT_SKIN_HEIGHT), 100, 20, bdc, 200, 320, SRCCOPY);


	SelectObject(bdc, this->controls);

	BitBlt(hdc, progressCursor.left, progressCursor.top, (progressCursor.right - progressCursor.left), (progressCursor.bottom - progressCursor.top), 
		   bdc, 2, 45, SRCCOPY);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -