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

📄 ebprogressbar.c

📁 基于minigui开发的一套图形控件系统
💻 C
📖 第 1 页 / 共 2 页
字号:
// button.c: the Button Control module.
//
// Copyright (C) 2004 TCL Multimedia Electronics Research & Development Center
//
// Current maintainer: Tang jianbin.
/*
**  Alternatively, the contents of this file may be used under the terms 
**  of the Mozilla Public License (the "MPL License") in which case the
**  provisions of the MPL License are applicable instead of those above.
*/
//
// Create date: 2004/2/2
//
// Modify records:
//
//  Who             When        Where       For What                Status
//-----------------------------------------------------------------------------
// 
// 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <minigui/mywindows.h>

#include "ebprogressbar.h"
#include "ebcontrol.h"

//#define   HE_DEBUG(x...)   fprintf(stderr,x)
#define   HE_DEBUG(x...) 

static  BITMAP  Bkbmp;
static  BITMAP  Fillbmp;
static int ProgressBarCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam);

BOOL RegisterEBProgressBarControl()
{
    WNDCLASS WndClass;

    WndClass.spClassName = "ebprogressbar";
    WndClass.dwStyle     = WS_NONE;
    WndClass.dwExStyle   = WS_EX_NONE;
    WndClass.hCursor     = GetSystemCursor (0);
    WndClass.iBkColor    = GetWindowElementColor (BKC_CONTROL_DEF);
    WndClass.WinProc     = ProgressBarCtrlProc;

    return AddNewControlClass (&WndClass) == ERR_OK;
}

void EBProgressBarControlCleanup (void)
{
	UnregisterWindowClass (CTRL_EBPROGRESSBAR);
}


static int pbarDrawPicPos(HWND hWnd, HDC hdc, BOOL fVertical)
{
	int 			pos;
	PROGRESSDATA* 	pData = (PROGRESSDATA*)GetWindowAdditionalData2(hWnd);
	RECT			rect;
	BITMAP			bmp;
	DWORD			pAddData= GetWindowAdditionalData(hWnd);
	char*			tmpfile;
	DWORD			dwStyle = GetWindowStyle(hWnd);
	
	GetClientRect(hWnd, &rect);

	if ( pAddData != 0 && !(dwStyle &EPBS_FASTFILLLINE))
	{
		if (dwStyle & EPBS_BKBMPFILE)
		{
			char bmpfile[MAX_PATH + 1];

			//游标图或者填充图案
			PrefixFileName((const char *)pAddData,"cu",bmpfile,MAX_PATH);

			memset(&bmp, 0, sizeof(BITMAP));
			if ( LoadBitmap(hdc, &bmp, bmpfile) < 0 )
				return -1;
		}
#if 0		
		else if (dwStyle & EPBS_BKBITMAP)
		{
			pbmp = (PBITMAP)pAddData;
		}
#endif
	}
	
	if (dwStyle & EPBS_POSITION)
	{
		if (fVertical)
		{			
			pos = pData->nPos * (RECTH(rect) - bmp.bmHeight) 
				/(pData->nMax - pData->nMin);			
			FillBoxWithBitmap(hdc, rect.left, pos, 0, 0, &bmp);
		}
		else
		{
			pos = pData->nPos * (RECTW(rect) - bmp.bmWidth) 
				/(pData->nMax - pData->nMin);
			FillBoxWithBitmap(hdc, pos, rect.top + 2, 0, 0, &bmp);
		}

	}
	else if(dwStyle &EPBS_FASTFILLLINE)
	{
		pbarFill(hWnd, hdc, pData, &Fillbmp, fVertical);
	}
	else
	{
		pbarFill(hWnd, hdc, pData, &bmp, fVertical);
	}
	return 0;
	
}

void pbarFill (HWND hWnd, HDC hdc, PROGRESSDATA* pData,PBITMAP pbmp, BOOL fVertical)
{
    RECT    rcClient;
    int     x, y, w, h;
    ldiv_t   ndiv_progress;
    unsigned int     nAllPart;
    unsigned int     nNowPart;
    int     whOne, nRem;
    int     ix, iy;
    int     i;
    int     step;
	DWORD	dwStyle = GetWindowStyle(hWnd);
	gal_pixel	old = PIXEL_invalid;

	if (pData->nPos == 0)
		return;
	
	GetClientRect (hWnd, &rcClient);
	
//一个图案以长度来表示其进度
	if ( dwStyle & EPBS_FILLLINE|| dwStyle & EPBS_FASTFILLLINE)
	{		
		x = rcClient.left + pData->borderwidth;
		y = rcClient.top + pData->borderwidth;
		w = ( RECTW(rcClient) - 2 * pData->borderwidth ) * 
			pData->nPos / (pData->nMax - pData->nMin);
		h = RECTH(rcClient) - 2*pData->borderwidth;

		FillBoxWithBitmap(hdc, x, y, w, h, pbmp);
		return 0;
	}

//单个图案重复填充
//根据步进的大小来设置
//edit by tjb 2004-4-16
#if 0	
    if (pData->nMax == pData->nMin)
        return;
    
    if ((pData->nMax - pData->nMin) > 5)
        step = 5;
    else
        step = 1;
#else
	if (pData->nStepInc)
		step = pData->nStepInc;
	else
		step = 1;
#endif
	
//add by tjb 2004-4-16
	if (dwStyle & EPBS_BKCOLOR)
	{
		PPROGRESSDATA pData=GetWindowAdditionalData2(hWnd);

		if (pData->FillColor)
		{
			old = SetBrushColor(hdc, pData->FillColor);
		}
	}
	if (pData->borderwidth != 0)
	{
	    x = rcClient.left + pData->borderwidth;
	    y = rcClient.top + pData->borderwidth;
	    w = RECTW (rcClient) - (pData->borderwidth *2);
	    h = RECTH (rcClient) - (pData->borderwidth *2);		
	}
	else
	{
	    x = rcClient.left + WIDTH_PBAR_BORDER;
	    y = rcClient.top + WIDTH_PBAR_BORDER;
	    w = RECTW (rcClient) - (WIDTH_PBAR_BORDER << 1);
	    h = RECTH (rcClient) - (WIDTH_PBAR_BORDER << 1);
	}
    ndiv_progress = ldiv (pData->nMax - pData->nMin, step);
    nAllPart = ndiv_progress.quot;
    
    ndiv_progress = ldiv (pData->nPos - pData->nMin, step);
    nNowPart = ndiv_progress.quot;
	
    if (fVertical)
        ndiv_progress = ldiv (h, nAllPart);
    else
        ndiv_progress = ldiv (w, nAllPart);
        
    whOne = ndiv_progress.quot;//一格的大小
    nRem = ndiv_progress.rem;
	
    if(whOne >= 4) 
	{
        if (fVertical) 
		{
            for (i = 0, iy = y + h - 1; i < nNowPart; ++i) 
			{
                if ((iy - whOne) < y) 
                    whOne = iy - y;
				
				if ((dwStyle & EPBS_FILLTYPE)== EPBS_FILLBMPFILE)
#if 0//edit by tjb 2004-5-18
					FillBoxWithBitmap(hdc, x+1, iy - whOne, pbmp->bmWidth - 1, 
									whOne - 1, pbmp);
#else
					FillBoxWithBitmap(hdc, x+1, iy - whOne, pbmp->bmWidth - 1, 
									pbmp->bmHeight, pbmp);
#endif
				else
					FillBox (hdc, x + 1, iy - whOne, w - 2, whOne - 1);
				
                iy -= whOne;
                if(nRem > 0) 
				{
                    iy --;
                    nRem --;
                }
            }
        }
        else 
		{
            for (i = 0, ix = x + 1; i < nNowPart; ++i) 
			{
                if ((ix + whOne) > (x + w)) 
                    whOne = x + w - ix;
				
				if ((dwStyle & EPBS_FILLTYPE)== EPBS_FILLBMPFILE)
				//edit by tjb 2004-5-18
				//修改原因:为了控制填充图案的间隔,画图案时使用其只身的宽度,余下的就是间隔
				//	FillBoxWithBitmap(hdc, ix, y + 1, whOne - 1, pbmp->bmHeight- 1, pbmp);
					FillBoxWithBitmap(hdc, ix, y + 1, pbmp->bmWidth, pbmp->bmHeight- 1, pbmp);
				else
					FillBox (hdc, ix, y + 1, whOne - 1, h - 2);
				
                ix += whOne;
                if(nRem > 0) 
				{
                    ix ++;
                    nRem --;
                }
            }
        }
    }
    else 
	{
        // no vertical support
        double d = (nNowPart*1.0)/nAllPart;
		if ((dwStyle & EPBS_FILLTYPE)== EPBS_FILLBMPFILE)
			FillBoxWithBitmap(hdc, x, y + 1, (int)(w*d), h - 2, pbmp);
		else
			FillBox(hdc, x, y+1, (int)(w*d), h - 2);
    }
		
//add by tjb 2004-4-16
	if (old)
		SetBrushColor(hdc, old);
	
}

static void pbarNormalizeParams (HWND hWnd, 
                PROGRESSDATA* pData, BOOL fNotify)
{
    if (pData->nPos > pData->nMax) 
	{
        if (fNotify)
            NotifyParent (hWnd, GetDlgCtrlID(hWnd), PBN_REACHMAX);
        pData->nPos = pData->nMax;

⌨️ 快捷键说明

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