?? cursor-lite.c
字號:
/*** $Id: cursor-lite.c,v 1.51 2004/04/16 08:39:36 weiym Exp $**** cursor-lite.c: Cursor support module for MiniGUI-Lite** Cursor managed by server globally.**** Copyright (C) 2003 Feynman Software.** Copyright (C) 1999 ~ 2002 Wei Yongming.**** Current maintainer: Wei Yongming.**** Create date: 1999/01/06*//*** 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*/#include <stdio.h>#include <stddef.h>#include <stdlib.h>#include <malloc.h>#include <string.h>#include <errno.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "internals.h"#include "ctrlclass.h"#include "inline.h"#include "memops.h"#include "gal.h"#include "dc.h"#include "cursor.h"#include "ial.h"#include "sharedres.h"#include "ourhdr.h"#include "client.h"#include "server.h"#include "drawsemop.h"#include "readbmp.h"int __mg_csrimgsize;int __mg_csrimgpitch;static int oldx = -1, oldy;static RECT cliprc = {0, 0, 0, 0};#ifdef _CURSOR_SUPPORT#define CSR_SAVEDBITS ((BYTE*)mgSharedRes + (((PG_RES)mgSharedRes)->svdbitsoffset))#define CSR_CURSORX (((PG_RES)mgSharedRes)->cursorx)#define CSR_CURSORY (((PG_RES)mgSharedRes)->cursory)#define CSR_OLDBOXLEFT (((PG_RES)mgSharedRes)->oldboxleft)#define CSR_OLDBOXTOP (((PG_RES)mgSharedRes)->oldboxtop)#define CSR_CURRENT ((PCURSOR)((PG_RES)mgSharedRes)->csr_current)#define CSR_XHOTSPOT (((PG_RES)mgSharedRes)->xhotspot)#define CSR_YHOTSPOT (((PG_RES)mgSharedRes)->yhotspot)#define CSR_SHOW_COUNT (((PG_RES)mgSharedRes)->csr_show_count)static PCURSOR *sys_cursors;static HCURSOR def_cursor;static BYTE* cursorbits = NULL;#if 0 /* FIXME: I do not know why this can not work :( */Uint8* GetPixelUnderCursor (int x, int y, gal_pixel* pixel){ Uint8* dst = NULL; lock_cursor_sem (); if (CSR_SHOW_COUNT >= 0 && CSR_CURRENT && x >= CSR_OLDBOXLEFT && y >= CSR_OLDBOXTOP && (x < CSR_OLDBOXLEFT + CURSORWIDTH) && (y < CSR_OLDBOXTOP + CURSORHEIGHT) && get_hidecursor_sem_val () == 0) { int _x = x - CSR_OLDBOXLEFT; int _y = y - CSR_OLDBOXTOP; dst = CSR_SAVEDBITS + _y * __mg_csrimgpitch + _x * __gal_screen->format->BytesPerPixel; *pixel = _mem_get_pixel (dst, __gal_screen->format->BytesPerPixel); } unlock_cursor_sem (); return dst;}#endif// Cursor creating and destroying.static HCURSOR srvCreateCursor (int xhotspot, int yhotspot, int w, int h, const BYTE* pANDBits, const BYTE* pXORBits, int colornum){ PCURSOR pcsr; if (w != CURSORWIDTH || h != CURSORHEIGHT) return 0; if (!(pcsr = (PCURSOR)malloc (sizeof (CURSOR)))) return 0; if (!(pcsr->AndBits = malloc (__mg_csrimgsize))) { free(pcsr); return 0; } if (!(pcsr->XorBits = malloc (__mg_csrimgsize))) { free (pcsr->AndBits); free (pcsr); return 0; } pcsr->xhotspot = xhotspot; pcsr->yhotspot = yhotspot; pcsr->width = w; pcsr->height = h;#ifdef _USE_NEWGAL if (colornum == 1) { ExpandMonoBitmap (HDC_SCREEN, pcsr->AndBits, __mg_csrimgpitch, pANDBits, MONOPITCH, w, h, MYBMP_FLOW_UP, 0, 0xFFFFFFFF); ExpandMonoBitmap (HDC_SCREEN, pcsr->XorBits, __mg_csrimgpitch, pXORBits, MONOPITCH, w, h, MYBMP_FLOW_UP, 0, 0xFFFFFFFF); } else if (colornum == 4) { ExpandMonoBitmap (HDC_SCREEN, pcsr->AndBits, __mg_csrimgpitch, pANDBits, MONOPITCH, w, h, MYBMP_FLOW_UP, 0, 0xFFFFFFFF); Expand16CBitmap (HDC_SCREEN, pcsr->XorBits, __mg_csrimgpitch, pXORBits, MONOPITCH*4, w, h, MYBMP_FLOW_UP, NULL); }#else if (colornum == 1) { ExpandMonoBitmap (HDC_SCREEN, w, h, pANDBits, MONOPITCH, MYBMP_FLOW_UP, pcsr->AndBits, __mg_csrimgpitch, 0, 0xFFFFFFFF); ExpandMonoBitmap (HDC_SCREEN, w, h, pXORBits, MONOPITCH, MYBMP_FLOW_UP, pcsr->XorBits, __mg_csrimgpitch, 0, 0xFFFFFFFF); } else if (colornum == 4) { ExpandMonoBitmap (HDC_SCREEN, w, h, pANDBits, MONOPITCH, MYBMP_FLOW_UP, pcsr->AndBits, __mg_csrimgpitch, 0, 0xFFFFFFFF); Expand16CBitmap (HDC_SCREEN, w, h, pXORBits, MONOPITCH*4, MYBMP_FLOW_UP, pcsr->XorBits, __mg_csrimgpitch, NULL); }#endif /* _USE_NEWGAL */ return (HCURSOR)pcsr;}#define _LEN_BITS (MONOPITCH * CURSORHEIGHT)HCURSOR GUIAPI CreateCursor (int xhotspot, int yhotspot, int w, int h, const BYTE* pANDBits, const BYTE* pXORBits, int colornum){ if (mgIsServer) { return srvCreateCursor (xhotspot, yhotspot, w, h, pANDBits, pXORBits, colornum); } else { HCURSOR hcursor; REQUEST req; int len_and_bits, len_xor_bits; int* tmp; if (w != CURSORWIDTH || h != CURSORHEIGHT) return 0; len_and_bits = _LEN_BITS; len_xor_bits = _LEN_BITS * ((colornum == 1) ? 1 : 4); req.id = REQID_CREATECURSOR; req.len_data = sizeof (int) * 6 + len_and_bits + len_xor_bits; if ((tmp = (int*) ALLOCATE_LOCAL (req.len_data)) == NULL) return 0; tmp [0] = xhotspot; tmp [1] = yhotspot; tmp [2] = w; tmp [3] = h; tmp [4] = colornum; tmp [5] = _LEN_BITS; memcpy (tmp + 6, pANDBits, len_and_bits); memcpy ((BYTE*)(tmp + 6) + len_and_bits, pXORBits, len_xor_bits); req.data = tmp; if (cli_request (&req, &hcursor, sizeof (HCURSOR)) < 0) hcursor = 0; DEALLOCATE_LOCAL (tmp); return hcursor; }}static HCURSOR srvLoadCursorFromFile (const char* filename){ FILE* fp; WORD wTemp; int ret = 0; int w, h, xhot, yhot, colornum; DWORD size, offset; DWORD imagesize, imagew, imageh; BYTE* image; if( !(fp = fopen(filename, "rb")) ) return 0; fseek(fp, sizeof(WORD), SEEK_SET); // the cbType of struct CURSORDIR. wTemp = MGUI_ReadLE16FP (fp); if(wTemp != 2) goto error; // skip the cdCount of struct CURSORDIR, we always use the first cursor. fseek(fp, sizeof(WORD), SEEK_CUR); // cursor info, read the members of struct CURSORDIRENTRY. w = fgetc (fp); // the width of first cursor. h = fgetc (fp); // the height of first cursor. if (w != CURSORWIDTH || h != CURSORHEIGHT) goto error; fseek(fp, sizeof(BYTE)*2, SEEK_CUR); // skip the bColorCount and bReserved. wTemp = MGUI_ReadLE16FP (fp); xhot = wTemp; wTemp = MGUI_ReadLE16FP (fp); yhot = wTemp; size = MGUI_ReadLE32FP (fp); offset = MGUI_ReadLE32FP (fp); // read the cursor image info. fseek(fp, offset, SEEK_SET); fseek(fp, sizeof(DWORD), SEEK_CUR); // skip the biSize member. imagew = MGUI_ReadLE32FP (fp); imageh = MGUI_ReadLE32FP (fp); // check the biPlanes member; wTemp = MGUI_ReadLE16FP (fp); if(wTemp != 1) goto error; // check the biBitCount member; wTemp = MGUI_ReadLE16FP (fp); if(wTemp > 4) goto error; colornum = (int)wTemp; fseek(fp, sizeof(DWORD), SEEK_CUR); // skip the biCompression members. imagesize = MGUI_ReadLE32FP (fp); // skip the rest members and the color table. fseek(fp, sizeof(DWORD)*4 + sizeof(BYTE)*(4<<colornum), SEEK_CUR); // allocate memory for image. if ((image = (BYTE*)ALLOCATE_LOCAL (imagesize)) == NULL) goto error; // read image fread (image, imagesize, 1, fp); ret = srvCreateCursor (xhot, yhot, w, h, image + (imagesize - MONOSIZE), image, colornum); DEALLOCATE_LOCAL (image);error: fclose (fp); return ret;}HCURSOR GUIAPI LoadCursorFromFile (const char* filename){ if (mgIsServer) { return srvLoadCursorFromFile (filename); } else { HCURSOR hcursor; REQUEST req; req.id = REQID_LOADCURSOR; req.data = filename; req.len_data = strlen (filename) + 1; if (cli_request (&req, &hcursor, sizeof (HCURSOR)) < 0) return 0; return hcursor; }}HCURSOR GUIAPI LoadCursorFromMem (const void* area){ const Uint8* p = (Uint8*)area; WORD wTemp; int w, h, xhot, yhot, colornum; DWORD size, offset; DWORD imagesize, imagew, imageh; p += sizeof (WORD); wTemp = MGUI_ReadLE16Mem (&p); if(wTemp != 2) goto error; // skip the cdCount of struct CURSORDIR, we always use the first cursor. p += sizeof (WORD); // cursor info, read the members of struct CURSORDIRENTRY. w = *p++; // the width of first cursor. h = *p++; // the height of first cursor. if (w != CURSORWIDTH || h != CURSORHEIGHT) goto error; // skip the bColorCount and bReserved. p += sizeof(BYTE)*2; xhot = MGUI_ReadLE16Mem (&p); yhot = MGUI_ReadLE16Mem (&p); size = MGUI_ReadLE32Mem (&p); offset = MGUI_ReadLE32Mem (&p); // read the cursor image info. p = (Uint8*)area + offset; // skip the biSize member. p += sizeof (DWORD); imagew = MGUI_ReadLE32Mem (&p); imageh = MGUI_ReadLE32Mem (&p); // check the biPlanes member; wTemp = MGUI_ReadLE16Mem (&p); if (wTemp != 1) goto error; // check the biBitCount member; wTemp = MGUI_ReadLE16Mem (&p); if (wTemp > 4) goto error; colornum = wTemp; // skip the biCompression members. p += sizeof (DWORD); imagesize = MGUI_ReadLE32Mem (&p); // skip the rest members and the color table. p += sizeof(DWORD)*4 + sizeof(BYTE)*(4<<colornum); return CreateCursor (xhot, yhot, w, h, p + (imagesize - MONOSIZE), p, colornum);error: return 0;}static BOOL srvDestroyCursor (HCURSOR hcsr){ int i; PCURSOR pcsr = (PCURSOR)hcsr; if (pcsr == NULL) return TRUE; for (i = 0; i < ((PG_RES)mgSharedRes)->csrnum; i++) { if (pcsr == sys_cursors [i]) return FALSE; } free(pcsr->AndBits); free(pcsr->XorBits); free(pcsr); return TRUE;}BOOL GUIAPI DestroyCursor (HCURSOR hcsr){ if (mgIsServer) { return srvDestroyCursor (hcsr); } else { REQUEST req; BOOL ret_value; req.id = REQID_DESTROYCURSOR; req.data = &hcsr; req.len_data = sizeof (HCURSOR); if (cli_request (&req, &ret_value, sizeof (BOOL)) < 0) return FALSE; return ret_value; }}static void init_system_cursor (void){ int csrid; unsigned char* temp; temp = mgSharedRes + ((PG_RES)mgSharedRes)->csroffset; temp += sizeof (PCURSOR) * ((PG_RES)mgSharedRes)->csrnum; for (csrid = 0; csrid < ((PG_RES)mgSharedRes)->csrnum; csrid++) { if (!(sys_cursors [csrid] = (PCURSOR) malloc (sizeof(CURSOR)))) return; sys_cursors [csrid]->xhotspot = ((PCURSOR)temp)->xhotspot; sys_cursors [csrid]->yhotspot = ((PCURSOR)temp)->yhotspot; sys_cursors [csrid]->width = ((PCURSOR)temp)->width; sys_cursors [csrid]->height = ((PCURSOR)temp)->height; sys_cursors [csrid]->AndBits = temp + sizeof(CURSOR); sys_cursors [csrid]->XorBits = temp + sizeof(CURSOR) + __mg_csrimgsize; temp += (sizeof(CURSOR) + 2 * __mg_csrimgsize); }}HCURSOR GUIAPI GetSystemCursor (int csrid){ if (csrid >= ((PG_RES)mgSharedRes)->csrnum || csrid < 0) return 0; return (HCURSOR) (sys_cursors [csrid]);}HCURSOR GUIAPI GetDefaultCursor (void){ return def_cursor;}#ifdef _USE_NEWGALstatic BITMAP csr_bmp = {BMP_TYPE_NORMAL, 0, 0, 0, 0, CURSORWIDTH, CURSORHEIGHT};#endifBOOL InitCursor (void){ sys_cursors = mgSharedRes + ((PG_RES)mgSharedRes)->csroffset; if (mgIsServer) { if (!(cursorbits = malloc (__mg_csrimgsize))) { return FALSE; } init_system_cursor (); CSR_CURRENT = NULL; CSR_SHOW_COUNT = 0; CSR_OLDBOXLEFT = -100;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -