?? gdi.c
字號(hào):
/*** $Id: gdi.c,v 1.55 2005/01/10 07:30:45 weiym Exp $**** The graphics display interface module of MiniGUI.**** Copyright (C) 2003 Feynman Software.** Copyright (C) 1999 ~ 2002 Wei Yongming.**** Current maintainer: Wei Yongming.**** Create date: 1999/01/03*//*** 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*//*** TODO:*/ #include <stdio.h>#include <stdlib.h>#include <string.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "cursor.h"#include "internals.h"#include "ctrlclass.h"#include "dc.h"#include "sysfont.h"#include "devfont.h"#include "drawtext.h"#if defined(_LITE_VERSION) && !defined(_STAND_ALONE) #include "ourhdr.h" #include "client.h" #include "sharedres.h" #include "drawsemop.h"#endif/************************* global data define ********************************/DC __mg_screen_dc;gal_pixel SysPixelIndex [17];// This should be the standard EGA palette.const RGB SysPixelColor [] = { {0x00, 0x00, 0x00}, // transparent --0 {0x00, 0x00, 0x80}, // dark blue --1 {0x00, 0x80, 0x00}, // dark green --2 {0x00, 0x80, 0x80}, // dark cyan --3 {0x80, 0x00, 0x00}, // dark red --4 {0x80, 0x00, 0x80}, // dark magenta --5 {0x80, 0x80, 0x00}, // dark yellow --6 {0x80, 0x80, 0x80}, // dark gray --7 {0xC0, 0xC0, 0xC0}, // light gray --8 {0x00, 0x00, 0xFF}, // blue --9 {0x00, 0xFF, 0x00}, // green --10 {0x00, 0xFF, 0xFF}, // cyan --11 {0xFF, 0x00, 0x00}, // red --12 {0xFF, 0x00, 0xFF}, // magenta --13 {0xFF, 0xFF, 0x00}, // yellow --14 {0xFF, 0xFF, 0xFF}, // light white --15 {0x00, 0x00, 0x00} // black --16};#ifndef _LITE_VERSION// mutex ensuring exclusive access to gdi. pthread_mutex_t __mg_gdilock;#endif/************************* global functions declaration **********************/// the following functions, which defined in other module// but used in this module.extern PGCRINFO GetGCRgnInfo (HWND hWnd);/**************************** static data ************************************/// General DCstatic DC DCSlot [DCSLOTNUMBER];#ifndef _LITE_VERSION// mutex ensuring exclusive access to DC slot. static pthread_mutex_t dcslot;#endifstatic BLOCKHEAP sg_FreeClipRectList;/************************* static functions declaration **********************/static void dc_InitClipRgnInfo (void);static void dc_InitDC (PDC pdc, HWND hWnd, BOOL bIsClient);static void dc_Init_ScreenDC (void);/************************** inline functions *********************************/inline void WndRect(HWND hWnd, PRECT prc){ PCONTROL pParent; PCONTROL pCtrl; pParent = pCtrl = (PCONTROL) hWnd; if (hWnd == HWND_DESKTOP) { *prc = g_rcScr; return; } prc->left = pCtrl->left; prc->top = pCtrl->top; prc->right = pCtrl->right; prc->bottom = pCtrl->bottom; while ((pParent = pParent->pParent)) { prc->left += pParent->cl; prc->top += pParent->ct; prc->right += pParent->cl; prc->bottom += pParent->ct; }}inline void WndClientRect(HWND hWnd, PRECT prc){ PCONTROL pCtrl; PCONTROL pParent; pParent = pCtrl = (PCONTROL) hWnd; if (hWnd == HWND_DESKTOP) { *prc = g_rcScr; return; } prc->left = pCtrl->cl; prc->top = pCtrl->ct; prc->right = pCtrl->cr; prc->bottom = pCtrl->cb; while ((pParent = pParent->pParent)) { prc->left += pParent->cl; prc->top += pParent->ct; prc->right += pParent->cl; prc->bottom += pParent->ct; }}static void RestrictControlECRGN (CLIPRGN* crgn, PCONTROL pCtrl){ RECT rc; PCONTROL pRoot = (PCONTROL) (pCtrl->pMainWin); int off_x = 0, off_y = 0; do { PCONTROL pParent = pCtrl; rc.left = pRoot->cl + off_x; rc.top = pRoot->ct + off_y; rc.right = pRoot->cr + off_x; rc.bottom = pRoot->cb + off_y; IntersectClipRect (crgn, &rc); if (IsEmptyClipRgn (crgn)) return; if (pRoot == pCtrl->pParent) break; off_x += pRoot->cl; off_y += pRoot->ct; while (TRUE) { if (pRoot->children == pParent->pParent->children) { pRoot = pParent; break; } pParent = pParent->pParent; } } while (TRUE);}#ifdef _LITE_VERSION#if !defined(_STAND_ALONE)static void _clipped_by_server (PDC pdc){ /* * Subtract the server clipping rects. */ if (pdc->scr_sig != SHAREDRES_SCRINFO.signature) { int i; RECT* crcs = SHAREDRES_SCRINFO.clip_rects; SetClipRgn (&__mg_screen_dc.ecrgn, &__mg_screen_dc.DevRC); for (i = 0; i < MAX_SRV_CLIP_RECTS; i++) { if (!IsRectEmpty (crcs + i)) SubtractClipRect (&pdc->ecrgn, crcs + i); } pdc->scr_sig = SHAREDRES_SCRINFO.signature; }}#endifPDC __mg_check_ecrgn (HDC hdc){ PDC pdc = dc_HDC2PDC(hdc); if (dc_IsGeneralDC (pdc)) { if (!dc_GenerateECRgn (pdc, FALSE)) { return NULL; } }#if !defined(_STAND_ALONE) if (!mgIsServer && pdc == &__mg_screen_dc) _clipped_by_server (pdc);#endif return pdc;}#endif/******************* Initialization and termination of GDI *******************/BOOL InitScreenDC (void){ InitFreeClipRectList (&sg_FreeClipRectList, SIZE_CLIPRECTHEAP); #ifndef _LITE_VERSION pthread_mutex_init (&__mg_gdilock, NULL); pthread_mutex_init (&dcslot, NULL);#endif dc_InitClipRgnInfo(); dc_Init_ScreenDC (); return TRUE;}void TerminateScreenDC (void){ DestroyFreeClipRectList (&sg_FreeClipRectList);#ifndef _LITE_VERSION pthread_mutex_destroy (&__mg_gdilock); pthread_mutex_destroy (&dcslot);#endif}BOOL InitGDI (void){ if (!InitTextBitmapBuffer ()) { fprintf (stderr, "GDI: Can not initialize text bitmap buffer!\n"); goto error; }#ifdef _RBF_SUPPORT#ifdef _INCORE_RES if (!InitIncoreRBFonts ()) { fprintf (stderr, "GDI: Can not initialize incore RBF fonts!\n"); goto error; }#endif#endif#ifdef _VBF_SUPPORT if (!InitIncoreVBFonts ()) { fprintf (stderr, "GDI: Can not initialize incore VBF fonts!\n"); goto error; }#endif#ifndef _INCORE_RES#ifdef _RBF_SUPPORT if (!InitRawBitmapFonts ()) { fprintf (stderr, "GDI: Can not initialize raw bitmap fonts!\n"); goto error; }#endif#ifdef _VBF_SUPPORT if (!InitVarBitmapFonts ()) { fprintf (stderr, "GDI: Can not initialize var bitmap fonts!\n"); goto error; }#endif#ifdef _QPF_SUPPORT if (!InitQPFonts ()) { fprintf (stderr, "GDI: Can not initialize QPF fonts!\n"); goto error; }#endif#ifndef _LITE_VERSION#ifdef _TTF_SUPPORT if (!InitFreeTypeFonts ()) { fprintf (stderr, "GDI: Can not initialize TrueType fonts!\n"); goto error; }#endif#ifdef _TYPE1_SUPPORT if (!InitType1Fonts ()) { fprintf (stderr, "GDI: Can not initialize Type1 fonts!\n"); goto error; }#endif#endif /* !_LITE_VERSION */#endif /* !_INCORE_RES */ /* TODO: add other font support here */#ifdef _DEBUG dumpDevFonts ();#endif if (!InitSysFont ()) { fprintf (stderr, "GDI: Can not create system fonts!\n"); goto error; } return TRUE;error: return FALSE;}void TerminateGDI( void ){ TermSysFont (); /* TODO: add other font support here */#ifndef _INCORE_RES#ifndef _LITE_VERSION#ifdef _TTF_SUPPORT TermFreeTypeFonts ();#endif#ifdef _TYPE1_SUPPORT TermType1Fonts();#endif#ifdef _QPF_SUPPORT TermQPFonts ();#endif#endif /* !_LITE_VERSION */#ifdef _VBF_SUPPORT TermVarBitmapFonts ();#endif#ifdef _RBF_SUPPORT TermRawBitmapFonts ();#endif#ifdef _VBF_SUPPORT TermIncoreVBFonts ();#endif#ifdef _RBF_SUPPORT#ifdef _INCORE_RES TermIncoreRBFonts ();#endif#endif#endif /* _INCORE_RES */ ResetDevFont (); TermTextBitmapBuffer ();}/* * Function: int GUIAPI GetGDCapability( int iItem) * This Function return DC parameters. * Parameters: * The element want to retrive. * Return: * The parameter. */unsigned int GUIAPI GetGDCapability (HDC hdc, int iItem ){ PDC pdc; unsigned int iret = 0xFFFFFFFF; pdc = dc_HDC2PDC (hdc);#ifndef _LITE_VERSION pthread_mutex_lock (&__mg_gdilock);#endif // set graphics context. GAL_SetGC (pdc->gc); switch (iItem) { case GDCAP_DEPTH: iret = GAL_BitsPerPixel (pdc->gc); break; case GDCAP_BPP: iret = GAL_BytesPerPixel (pdc->gc); break; case GDCAP_COLORNUM: iret = GAL_Colors (pdc->gc); break; case GDCAP_HPIXEL: iret = GAL_Width (pdc->gc); break; case GDCAP_VPIXEL: iret = GAL_Height (pdc->gc); break; case GDCAP_MAXX: iret = RECTW (pdc->DevRC) - 1; break; case GDCAP_MAXY: iret = RECTH (pdc->DevRC) - 1; break; }#ifndef _LITE_VERSION pthread_mutex_unlock(&__mg_gdilock);#endif return iret;}// This function init clip region in all DC slots.static void dc_InitClipRgnInfo(void){ int i; for (i=0; i<DCSLOTNUMBER; i++) { // Local clip region InitClipRgn(&DCSlot[i].lcrgn, &sg_FreeClipRectList); // Global clip region info DCSlot[i].pGCRInfo = NULL; DCSlot[i].oldage = 0; // Effective clip region InitClipRgn(&DCSlot[i].ecrgn, &sg_FreeClipRectList); } }// This function generates effective clip region from// local clip region and global clip region.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -