?? native.c
字號:
/*** $Id: native.c,v 1.56 2003/11/22 11:49:29 weiym Exp $**** native.c: Native Low Level Graphics Engine's interface file**** Copyright (C) 2002, 2003 Feynman Software.** Copyright (C) 2000 ~ 2002 Song Lixin, Wei Yongming, and Chen Lei.**** Add code for MiniGUI-Lite by Wei Yongming, 2001/01/01** Clean code for MiniGUI 1.1.x by Wei Yongming, 2001/09/18** Coordinates transfering for iPAQ by Chen Lei, 2001/12/12** Cleanup for coordinates transfering for iPAQ by Wei Yongming, 2003/05/21**** Created by Song Lixin, 2000/10/18*//*** 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 <stdlib.h>#include <signal.h>#include <unistd.h>#include <string.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "gal.h"#include "native.h"#ifndef _COOR_TRANS#define _COOR_TRANS 0#define _ROT_DIR_CCW 0#endif#if defined(_LITE_VERSION) && !(_STAND_ALONE)#include "ourhdr.h"#include "client.h"#include "sharedres.h"static int __mg_saved_clip_minx, __mg_saved_clip_miny, __mg_saved_clip_maxx, __mg_saved_clip_maxy;static void rotatecoor (int *x1, int *y1, int *x2, int *y2, int Tw, int dir);static int set_effective_clip_rect (PSD psd){ if (__mg_saved_clip_minx < SHAREDRES_CLI_SCR_LX) psd->clipminx = SHAREDRES_CLI_SCR_LX; else psd->clipminx = __mg_saved_clip_minx; if (__mg_saved_clip_miny < SHAREDRES_CLI_SCR_TY) psd->clipminy = SHAREDRES_CLI_SCR_TY; else psd->clipminy = __mg_saved_clip_miny; if (__mg_saved_clip_maxx > (SHAREDRES_CLI_SCR_RX + 1)) psd->clipmaxx = SHAREDRES_CLI_SCR_RX; else psd->clipmaxx = __mg_saved_clip_maxx; if (__mg_saved_clip_maxy > (SHAREDRES_CLI_SCR_BY + 1)) psd->clipmaxy = SHAREDRES_CLI_SCR_BY; else psd->clipmaxy = __mg_saved_clip_maxy; if (psd->clipmaxx < psd->clipminx) return -1; else if (psd->clipmaxy < psd->clipminy) return -1; if (_COOR_TRANS) rotatecoor (&psd->clipminx, &psd->clipminy, &psd->clipmaxx, &psd->clipmaxy, _ROT_DIR_CCW?psd->xres:psd->yres, _ROT_DIR_CCW?0:1); psd->clipmaxx ++; psd->clipmaxy ++; return 0;}#define BLOCK_DRAW_SEM \ if (!mgIsServer && cur_gfx->phygc.psd == gc.psd) \ lock_draw_sem (); \ if (((!mgIsServer && (SHAREDRES_TOPMOST_LAYER != __mg_layer)) || __mg_switch_away)) \ goto leave_drawing; \ if (!mgIsServer && cur_gfx->phygc.psd == gc.psd) \ if (set_effective_clip_rect (gc.psd)) \ goto leave_drawing;#define UNBLOCK_DRAW_SEM \ if (!mgIsServer && cur_gfx->phygc.psd == gc.psd) \leave_drawing: \ unlock_draw_sem ()#else#define BLOCK_DRAW_SEM#define UNBLOCK_DRAW_SEM#endif#ifdef _DEBUG#define debug(fmt, args...) fprintf(stderr, " <native>-%s\t" fmt, __FUNCTION__, ##args);#else#define debug(fmt, args...)#endif/* * leon -- the following drafts will help us */#if 0 Drafts: rects: -/------------------- Tw --------------------/- Porg Px1 Px2 Vorg Vy2 Vy1 Vy <---------------------------------------------> Px -/- | | | | | | | Pw | | | Py1 |---------------------------------------------|Vx1 | | | | | | | | | | | | Ph | |Vw | | | | | Th | | | | | | Vh | | | Py2 |---------------------------------------------|Vx2 | | | | | | | | | | | | -/- Py Vx Tw: Total width Th: Total height Porg: Physical origal Vorg: Virtual origal Px1: Physical x1 Vx1: Virtual x1 Px2: Physical x2 Vx2: Virtual x2 Py1: Physical y1 Vy1: Virtual y1 Py2: Physical y2 Vy2: Virtual y2 Pw: Physical width Vw: Virtual width Ph: Physical height Vh: Virtual height////////////////////////////////////////////////////////////////////// for the buffer refered by putbox, getbox: -/--- Tw ---/- Px0 Po Vy0 Vo Vy <-------------------> Px -/- | | | | | | | | | | | | | | P0 | Py0 |_____._____________| Vx0 Th | | |-------------------| | | | | Py Vx -/-#endif/* * help rutines for coordinate transfer begin */static void swapval (int* v1, int* v2){ int tmp; tmp = *v1; *v1 = *v2; *v2 = tmp;}static void rotatecoor (int *x1, int *y1, int *x2, int *y2, int Tw, int dir /* 0: V->P, 1: P->V */){ int tmp1, tmp2; switch (dir) { case 0: tmp1 = *x1; tmp2 = *x2; *x1 = Tw - 1 - *y2; *x2 = Tw - 1 - *y1; *y1 = tmp1; *y2 = tmp2; break; case 1: tmp1 = *y1; tmp2 = *y2; *y1 = Tw - 1 - *x2; *y2 = Tw - 1 - *x1; *x1 = tmp1; *x2 = tmp2; break; }}static void rotaterect (int* x, int* y, int* w, int* h, int Tw, int dir /* 0: V->P, 1: P->V */){ int tmp; switch (dir) { case 0: tmp = *y; *y = *x; *x = Tw - (tmp + *h); swapval (w, h); break; case 1: tmp = *x; *x = *y; *y = Tw - (tmp + *w); swapval (w, h); break; }}static void rotatepoint (int* x, int* y, int Tw , int dir /* 0: V->P, 1: P->V */){ int tmp; switch (dir) { case 0: tmp = *x; *x = Tw - 1 - *y; *y = tmp; break; case 1: tmp = *y; *y = Tw - 1 - *x; *x = tmp; break; }}static void reverse_buff (char* dst, const char* src, int size, int Bpp){ int i; switch (Bpp) { case 1: for (i = 0; i < size; i++) dst [i] = src [size - i - 1]; break; case 2: { Uint16* _dst = (Uint16*)dst; Uint16* _src = (Uint16*)src; for (i = 0; i < size; i++) _dst [size - i - 1] = _src [i]; break; } case 3: { for (i = 0; i < size * Bpp; i+=3) { dst [size - i - 1] = src [i]; dst [size - i - 2] = src [i + 1]; dst [size - i - 3] = src [i + 2]; } break; } case 4: { Uint32* _dst = (Uint32*)dst; Uint32* _src = (Uint32*)src; for (i = 0; i < size; i++) _dst [size - i - 1] = _src [i]; break; } default: return; }}/* * help rutines for coordinate transfer end *//* * Low Level Graphics Operations */static int bytesperpixel (GAL_GC gc) { return (gc.psd->bpp + 7) / 8; }static int bitsperpixel (GAL_GC gc) { return gc.psd->bpp; }static int width (GAL_GC gc) { if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) return gc.psd->yres; else return gc.psd->xres; }static int height (GAL_GC gc) { if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) return gc.psd->xres; else return gc.psd->yres; }static int colors (GAL_GC gc) { return gc.psd->ncolors; }static int setclipping (GAL_GC gc, int x1, int y1, int x2, int y2){ PSD psd; psd = gc.psd; if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) { if (x1 < 0) x1 = 0; if (y1 < 0) y1 = 0; if (x2 > psd->yres - 1) x2 = psd->yres - 1; if (y2 > psd->xres - 1) y2 = psd->xres - 1; } else { if (x1 < 0) x1 = 0; if (y1 < 0) y1 = 0; if (x2 > psd->xres - 1) x2 = psd->xres - 1; if (y2 > psd->yres - 1) y2 = psd->yres - 1; } psd->doclip = 1;#if defined(_LITE_VERSION) && !(_STAND_ALONE) if (!mgIsServer && psd == cur_gfx->phygc.psd) { __mg_saved_clip_minx = x1; __mg_saved_clip_miny = y1; __mg_saved_clip_maxx = x2; __mg_saved_clip_maxy = y2; } else {#endif if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) rotatecoor (&x1, &y1, &x2, &y2, _ROT_DIR_CCW?psd->xres:psd->yres, _ROT_DIR_CCW?0:1); psd->clipminx = x1; psd->clipminy = y1; psd->clipmaxx = x2 + 1; psd->clipmaxy = y2 + 1;#if defined(_LITE_VERSION) && !(_STAND_ALONE) }#endif return 0;}static void enableclipping (GAL_GC gc){ PSD psd; psd = gc.psd; if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) setclipping (gc, 0, 0, psd->yres - 1, psd->xres - 1); else setclipping (gc, 0, 0, psd->xres - 1, psd->yres - 1);}static void disableclipping (GAL_GC gc){ PSD psd; psd = gc.psd; psd->doclip = 0;}static int getclipping (GAL_GC gc, int* x1, int* y1, int* x2, int* y2){ PSD psd; psd = gc.psd;#if defined(_LITE_VERSION) && !(_STAND_ALONE) if (!mgIsServer && psd == cur_gfx->phygc.psd) { *x1 = __mg_saved_clip_minx; *y1 = __mg_saved_clip_miny; *x2 = __mg_saved_clip_maxx; *y2 = __mg_saved_clip_maxy; } else {#endif *x1 = psd->clipminx; *y1 = psd->clipminy; *x2 = psd->clipmaxx - 1; *y2 = psd->clipmaxy - 1; #if defined(_LITE_VERSION) && !(_STAND_ALONE) }#endif if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) rotatecoor (x1, y1, x2, y2, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?1:0); return 0;}/* * Allocation and release of graphics context */static int allocategc (GAL_GC gc, int width, int height, int depth, GAL_GC* newgc){ int linelen, size; PSD newpsd; void* pixels; int bpp; bpp = gc.psd->bpp; newpsd = gc.psd->AllocateMemGC (gc.psd); if (!newpsd) return -1; if (!native_gen_calcmemgcalloc (newpsd, width, height, 0, bpp, &size, &linelen)) goto fail; pixels = malloc(size); if (!pixels) goto fail; if (gc.psd->flags & PSF_MSBRIGHT) newpsd->flags |= PSF_MSBRIGHT; newpsd->flags |= PSF_ADDRMALLOC; if (!newpsd->MapMemGC (newpsd, width, height, gc.psd->planes, bpp, linelen, size, pixels)) goto fail; newgc->psd = newpsd; setclipping (*newgc, 0, 0, width - 1, height - 1); return 0;fail: newpsd->FreeMemGC (newpsd); return -1;}static void freegc (GAL_GC gc){ PSD psd; psd = gc.psd; if(gc.psd->flags & PSF_ADDRMALLOC) free (gc.psd->addr); psd->FreeMemGC (psd);}/* * Background and foreground colors */static int getbgcolor (GAL_GC gc, gal_pixel* color){ PSD psd; psd = gc.psd; *color = psd->gr_background; return 0;}static int setbgcolor (GAL_GC gc, gal_pixel color){ PSD psd; psd = gc.psd; psd->gr_background = color; return 0;}static int getfgcolor (GAL_GC gc, gal_pixel* color){ PSD psd; psd = gc.psd; *color = psd->gr_foreground; return 0;}static int setfgcolor (GAL_GC gc, gal_pixel color){ PSD psd; psd = gc.psd; psd->gr_foreground = color; return 0;}/* * Convertion between GAL_Color and gal_pixel
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -