📄 gdi.c
字号:
// $Id: gdi.c,v 1.21 2000/11/24 09:19:23 ymwei Exp $//// The graphics display interface module of MiniGUI.//// Copyright (C) 1999, 2000, Wei Yongming.// Copyright (C) 1999, 2000, EESG of ICT.//// Current maintainer: Wei Yongming./*** This library is free software; you can redistribute it and/or** modify it under the terms of the GNU Library General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This library 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** Library General Public License for more details.**** You should have received a copy of the GNU Library General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*/// Create date: 1999.01.03//// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------// WEI Yongming 1999/08/21 Tsinghua Clean CFont support Finished// WEI Yongming 1999/08/21 Tsinghua DrawText function Finished// WEI Yongming 1999/10/27 Tsinghua DrawText bug fixing Finished// WEI Yongming 2000/04/19 Wudaokou MFONT support Done.//// TODO:// #include <stdio.h>#include <stdlib.h>#ifndef __ECOS# include <malloc.h>#endif#include <pthread.h>#include <semaphore.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "ctrlclass.h"#include "dc.h"#include "sysfont.h"#include "devfont.h"#include "drawtext.h"#ifndef lintstatic char fileid[] = "$Id: gdi.c,v 1.21 2000/11/24 09:19:23 ymwei Exp $";#endif #define SIZE_CLIPRECTHEAP 100 extern void ShowCursorForGDI (BOOL fShow, const RECT* prc);/************************* global data define ********************************/DC ScreenDC;gal_pixel SysPixelIndex [17];const RGB SysPixelColor [] = { {0x00, 0x00, 0x00}, // transparent --0 0 {0x80, 0x00, 0x00}, // dark red --4 1 {0x00, 0x80, 0x00}, // dark green --2 2 {0x80, 0x80, 0x00}, // dark yellow --5 3 {0x00, 0x00, 0x80}, // dark blue --1 4 {0x80, 0x00, 0x80}, // dark magenta --6 5 {0x00, 0x80, 0x80}, // dark cyan --3 6 {0xC0, 0xC0, 0xC0}, // light gray --7 7 {0x80, 0x80, 0x80}, // dark gray --8 8 {0xFF, 0x00, 0x00}, // red --12 9 {0x00, 0xFF, 0x00}, // green --10 10 {0xFF, 0xFF, 0x00}, // yellow --13 11 {0x00, 0x00, 0xFF}, // blue --9 12 {0xFF, 0x00, 0xFF}, // magenta --14 13 {0x00, 0xFF, 0xFF}, // cyan --11 14 {0xFF, 0xFF, 0xFF}, // light white --15 15 {0x00, 0x00, 0x00} // black --16};// mutex ensuring exclusive access to gdi. pthread_mutex_t gdilock;/************************* global functions declaration **********************/// the following functions, which defined in other module// but used in this module.extern void ShowCursorForGDI (BOOL fShow, const RECT* prc);extern PGCRINFO GetGCRgnInfo (HWND hWnd);/**************************** static data ************************************/// General DCstatic DC DCSlot [DCSLOTNUMBER];// mutex ensuring exclusive access to DC slot. static pthread_mutex_t dcslot;static FREECLIPRECTLIST sg_FreeClipRectList;/************************* static functions declaration **********************/static void dc_InitClipRgnInfo (void);static void dc_InitDC (PDC pdc, HWND hWnd, BOOL bIsClient);static void dc_InitScreenDC (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 (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);}/******************* Initialization and termination of GDI *******************/BOOL InitGDI (){ switch (InitGAL ()) { case ERR_CONFIG_FILE: fprintf (stderr, "GDI: Reading configuration failure!\n"); return FALSE; case ERR_NO_ENGINE: fprintf (stderr, "GDI: No graphics engine defined!\n"); return FALSE; case ERR_NO_MATCH: fprintf (stderr, "GDI: Can not get graphics engine information!\n"); return FALSE; case ERR_GFX_ENGINE: fprintf (stderr, "GDI: Can not initialize graphics engine!\n"); return FALSE; } if (!InitTextBitmapBuffer ()) { fprintf (stderr, "GDI: Can not initialize text bitmap buffer!\n"); goto error; } if (!InitSysFont ()) { fprintf (stderr, "GDI: Can not initialize system fonts!\n"); goto error; }#ifdef _VBF_SUPPORT if (!InitIncoreVBFonts ()) { fprintf (stderr, "GDI: Can not initialize incore var fonts!\n"); goto error; }#endif#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 _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 /* TODO: add other font support here */#ifdef _DEBUG dumpDevFonts ();#endif if (!InitFreeClipRectList (&sg_FreeClipRectList, SIZE_CLIPRECTHEAP)) goto error; pthread_mutex_init(&gdilock, NULL); pthread_mutex_init(&dcslot, NULL); dc_InitClipRgnInfo(); dc_InitScreenDC (); return TRUE;error: TerminateGAL (); return FALSE;}void TerminateGDI( void ){ /* TODO: add other font support here */#ifdef _TTF_SUPPORT TermFreeTypeFonts ();#endif#ifdef _TYPE1_SUPPORT TermType1Fonts();#endif#ifdef _VBF_SUPPORT TermVarBitmapFonts ();#endif#ifdef _RBF_SUPPORT TermRawBitmapFonts ();#endif#ifdef _VBF_SUPPORT TermIncoreVBFonts ();#endif TermSysFont (); ResetDevFont (); TermTextBitmapBuffer (); DestroyFreeClipRectList (&sg_FreeClipRectList); TerminateGAL ();}/* * Function: int GUIAPI GetGDCapability( int iItem) * This Function return DC parameters. * Parameters: * The element want to retrive. * Return: * The parameter. */int GUIAPI GetGDCapability (HDC hdc, int iItem ){ PDC pdc; int iret = -1; pdc = dc_HDC2PDC (hdc); pthread_mutex_lock (&gdilock); // 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 = GAL_Width (pdc->gc) - 1; break; case GDCAP_MAXY: iret = GAL_Height (pdc->gc) - 1; break; } pthread_mutex_unlock(&gdilock); 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -