📄 draw.c
字号:
/*
** $Id: draw.c,v 1.25 2004/04/19 06:10:33 snig Exp $
**
** General drawing of GDI
**
** Copyright (C) 2003 Feynman Software.
** Copyright (C) 2000 ~ 2002 Wei Yongming.
**
** Current maintainer: Wei Yongming.
** Create date: 2000/06/12, derived from original gdi.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
*/
/*
** 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 "internals.h"
#include "ctrlclass.h"
#include "dc.h"
#include "cursor.h"
extern BOOL dc_GenerateECRgn (PDC pdc, BOOL fForce);
/*********************** Generl drawing support ******************************/
void GUIAPI SetPixel(HDC hdc, int x, int y, gal_pixel c)
{
PDC pdc;
PCLIPRECT pClipRect;
RECT rcOutput;
pdc = dc_HDC2PDC (hdc);
if (dc_IsGeneralHDC(hdc)) {
pthread_mutex_lock (&pdc->pGCRInfo->lock);
if (!dc_GenerateECRgn (pdc, FALSE)) {
pthread_mutex_unlock (&pdc->pGCRInfo->lock);
return;
}
}
coor_LP2SP (pdc, &x, &y);
rcOutput.left = x - 1;
rcOutput.top = y - 1;
rcOutput.right = x + 1;
rcOutput.bottom = y + 1;
pthread_mutex_lock (&__mg_gdilock);
IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
if (!dc_IsMemHDC(hdc)) ShowCursorForGDI (FALSE, &rcOutput);
// set graphics context.
GAL_SetGC (pdc->gc);
GAL_SetFgColor (pdc->gc, c);
pClipRect = pdc->ecrgn.head;
while(pClipRect)
{
if(PtInRect(&(pClipRect->rc), x, y)) {
GAL_DrawPixel (pdc->gc, x, y, c);
break;
}
pClipRect = pClipRect->next;
}
if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
pthread_mutex_unlock(&__mg_gdilock);
if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}
void GUIAPI SetPixelRGB(HDC hdc, int x, int y, int r, int g, int b)
{
PDC pdc;
PCLIPRECT pClipRect;
RECT rcOutput;
gal_pixel pixel;
GAL_Color color;
pdc = dc_HDC2PDC (hdc);
if (dc_IsGeneralHDC(hdc)) {
pthread_mutex_lock (&pdc->pGCRInfo->lock);
if (!dc_GenerateECRgn (pdc, FALSE)) {
pthread_mutex_unlock (&pdc->pGCRInfo->lock);
return;
}
}
coor_LP2SP (pdc, &x, &y);
rcOutput.left = x - 1;
rcOutput.top = y - 1;
rcOutput.right = x + 1;
rcOutput.bottom = y + 1;
pthread_mutex_lock (&__mg_gdilock);
IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);
// set graphics context.
GAL_SetGC (pdc->gc);
color.r = r; color.g = g, color.b = b;
pixel = GAL_MapColor (pdc->gc, &color);
GAL_SetFgColor (pdc->gc, pixel);
pClipRect = pdc->ecrgn.head;
while (pClipRect)
{
if(PtInRect(&(pClipRect->rc), x, y)) {
GAL_DrawPixel (pdc->gc, x, y, pixel);
break;
}
pClipRect = pClipRect->next;
}
if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
pthread_mutex_unlock(&__mg_gdilock);
if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}
gal_pixel GUIAPI GetPixel(HDC hdc, int x, int y)
{
PDC pdc;
PCLIPRECT pClipRect;
int color = 0;
RECT rcOutput;
pdc = dc_HDC2PDC(hdc);
if (dc_IsGeneralHDC(hdc)) {
pthread_mutex_lock (&pdc->pGCRInfo->lock);
if (!dc_GenerateECRgn (pdc, FALSE)) {
pthread_mutex_unlock (&pdc->pGCRInfo->lock);
return PIXEL_invalid;
}
}
coor_LP2SP (pdc, &x, &y);
rcOutput.left = x - 1;
rcOutput.top = y - 1;
rcOutput.right = x + 1;
rcOutput.bottom = y + 1;
pthread_mutex_lock (&__mg_gdilock);
IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
if (!dc_IsMemHDC (hdc)) ShowCursorForGDI (FALSE, &rcOutput);
// set graphics context.
GAL_SetGC (pdc->gc);
pClipRect = pdc->ecrgn.head;
while(pClipRect)
{
if(PtInRect(&(pClipRect->rc), x, y)) {
GAL_GetPixel (pdc->gc, x, y, &color);
break;
}
pClipRect = pClipRect->next;
}
if (!dc_IsMemHDC (hdc)) ShowCursorForGDI (TRUE, &rcOutput);
pthread_mutex_unlock(&__mg_gdilock);
if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
return color;
}
void GUIAPI GetPixelRGB(HDC hdc, int x, int y, int* r, int* g, int* b)
{
PDC pdc;
PCLIPRECT pClipRect;
gal_pixel pixel;
GAL_Color color;
RECT rcOutput;
pdc = dc_HDC2PDC(hdc);
if (dc_IsGeneralHDC(hdc)) {
pthread_mutex_lock (&pdc->pGCRInfo->lock);
if (!dc_GenerateECRgn (pdc, FALSE)) {
pthread_mutex_unlock (&pdc->pGCRInfo->lock);
return;
}
}
coor_LP2SP(pdc, &x, &y);
rcOutput.left = x - 1;
rcOutput.top = y - 1;
rcOutput.right = x + 1;
rcOutput.bottom = y + 1;
*r = 0;
*g = 0;
*b = 0;
pthread_mutex_lock (&__mg_gdilock);
IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
if (!dc_IsMemHDC (hdc)) ShowCursorForGDI (FALSE, &rcOutput);
// set graphics context.
GAL_SetGC (pdc->gc);
pClipRect = pdc->ecrgn.head;
while(pClipRect)
{
if (PtInRect (&(pClipRect->rc), x, y) ) {
GAL_GetPixel (pdc->gc, x, y, &pixel);
GAL_UnmapPixel (pdc->gc, pixel, &color);
*r = color.r;
*g = color.g;
*b = color.b;
break;
}
pClipRect = pClipRect->next;
}
if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
pthread_mutex_unlock(&__mg_gdilock);
if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}
gal_pixel GUIAPI RGB2Pixel (HDC hdc, int r, int g, int b)
{
PDC pdc;
gal_pixel pixel;
GAL_Color color;
color.r = r;
color.g = g;
color.b = b;
pdc = dc_HDC2PDC (hdc);
pthread_mutex_lock (&__mg_gdilock);
GAL_SetGC (pdc->gc);
pixel = GAL_MapColor (pdc->gc, &color);
pthread_mutex_unlock (&__mg_gdilock);
return pixel;
}
void GUIAPI MoveTo (HDC hdc, int x, int y)
{
PDC pdc;
pdc = dc_HDC2PDC(hdc);
pdc->CurPenPos.x = x;
pdc->CurPenPos.y = y;
}
void GUIAPI LineTo (HDC hdc, int x, int y)
{
PCLIPRECT pClipRect;
PDC pdc;
RECT rcOutput;
int startx, starty;
pdc = dc_HDC2PDC(hdc);
startx = pdc->CurPenPos.x;
starty = pdc->CurPenPos.y;
// Move the current pen pos.
pdc->CurPenPos.x = x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -