📄 window_manager.c
字号:
/*..........................................................................*//* *//* L a s t W a v e K e r n e l 3 . 0 *//* *//* Copyright (C) 1998-2003 Emmanuel Bacry. *//* email : lastwave@cmap.polytechnique.fr *//* *//*..........................................................................*//* *//* This program is a 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 (in a file named COPYRIGHT); *//* if not, write to the Free Software Foundation, Inc., *//* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//*..........................................................................*//****************************************************************************//* *//* window_manager.c The Machine dependent Graphic functions *//* This is the intermediate layer */ /* */ /****************************************************************************/#include "lastwave.h"#include "xx_system.h"#include <time.h>static char flagInvisible = NO;static FONT currentFont = NULL;/***************************************//* Initialization *//***************************************/static void WInitFont(void);char isDisplayBLittle = NO;void WOpenGraphics(void){ if (GraphicMode) XXOpenGraphics(); WInitFont(); isDisplayBLittle = WIsDisplayBLittle();}void WCloseGraphics(void){ if (GraphicMode) XXCloseGraphics();}void WFlush(void){ if (GraphicMode) XXFlush();}/**********************//* Set the attributes *//**********************//* Change the current color */void WSetColor(WINDOW win,unsigned long color){ int pixel; if (win->flagHide) return; if (win->frame == (FRAME) NULL && !PSMode) Errorf("Weird error"); if (color & invisibleColor) { flagInvisible = YES; return; } else flagInvisible = NO; if (PSMode) PSSetColor(color); else if (GraphicMode) { pixel = Color2Pixel(color); XXSetColor(win->frame,pixel); } } /* Set the style of the line */void WSetLineStyle(WINDOW win,int lineStyle){ if (win->flagHide) return; if (win->frame == (FRAME) NULL && !PSMode) Errorf("Weird error"); if (PSMode) PSSetLineStyle(lineStyle); else if (GraphicMode) XXSetLineStyle(win->frame,lineStyle); }/* Change the size of the pen */void WSetPenSize(WINDOW win,int size){ if (win->flagHide) return; if (win->frame == (FRAME) NULL && !PSMode) Errorf("Weird error"); if (PSMode) PSSetPenSize(size); else if (GraphicMode) XXSetPenSize(win->frame,size); }/* Change the mode of the pen */void WSetPenMode(WINDOW win, int mode){ if (win->flagHide) return; if (win->frame == (FRAME) NULL && !PSMode) Errorf("Weird error"); if (PSMode) PSSetPenMode(mode); else if (GraphicMode) XXSetPenMode(win->frame, mode);}/* Set the clipping rectangle */static int clipX,clipY,clipW,clipH;static WINDOW clipWin = NULL;void WSetClipRect(WINDOW win, int x, int y, int w, int h){ if (win != (WINDOW) NULL) { if (win->flagHide) return; if (win->frame == (FRAME) NULL && !PSMode) Errorf("Weird error"); clipWin = win; clipX = x; clipY = y; clipW = w; clipH = h; if (PSMode) PSSetClipRect(x,y,w,h); else if (GraphicMode) XXSetClipRect(win->frame,x,y,w,h); } else clipWin = NULL;}/* if (GraphicMode) { if (win != NULL && win->frame != (FRAME) NULL) { if (win->flagHide) return; clipWin = win; clipX = x; clipY = y; clipW = w; clipH = h; if (PSMode) PSSetClipRect(x,y,w,h); else XXSetClipRect(win->frame,x,y,w,h); } else clipWin = (WINDOW) NULL; }}*//* Get the clipping rectangle */void WGetClipRect(WINDOW *win, int *x, int *y, int *w, int *h){ *win = clipWin; *x = clipX; *y = clipY; *w = clipW; *h = clipH; }/************************************* * * Managing Pixmaps * ************************************/ static unsigned char *pixMapData = NULL;static int pixMapNCols = 0;static int pixMapNRows = 0;static int depth = 0;static int pixMapRowBytes;void WInitPixMap(int nRows, int nCols){ if (PSMode) PSInitPixMap(nRows,nCols); else if (GraphicMode) { if (pixMapData != NULL) { XXDeletePixMap(); pixMapData = NULL; } depth = WDepth(); XXAllocPixMap(nCols,nRows,&pixMapData,&pixMapRowBytes); pixMapNCols = nCols; pixMapNRows = nRows; }}void WSetPixelPixMap(int i, int j, unsigned long color){ unsigned long pixel; int shift; unsigned short r,g,b; if (PSMode) PSSetPixelPixMap(i, j, color); else if (GraphicMode) { if (i < 0 || i >= pixMapNRows) { Warningf("WSetPixelPixMap() : Bad 'i' index %d",i); return; } if (j < 0 || j >= pixMapNCols) { Warningf("WSetPixelPixMap() : Bad 'j' index %d",j); return; }// pixel = Color2Pixel(color); Color2RGB(color,&r,&g,&b); *(pixMapData+pixMapRowBytes*i+j*3) = (unsigned char) (r/256); *(pixMapData+pixMapRowBytes*i+j*3+1) = (unsigned char) (g/256); *(pixMapData+pixMapRowBytes*i+j*3+2) = (unsigned char) (b/256); return; switch(depth) { case 8 : *(pixMapData+pixMapRowBytes*i+j) = pixel & 0xFF; break; case 16 : shift = pixMapRowBytes*i+2*j; if (isDisplayBLittle) { *(pixMapData+shift) = pixel & 0xFF; *(pixMapData+shift+1) = (pixel & 0xFF00)>>8; } else { *(pixMapData+shift+1) = pixel & 0xFF; *(pixMapData+shift) = (pixel & 0xFF00)>>8; } break; case 24 : case 32 : shift = pixMapRowBytes*i+4*j; if (isDisplayBLittle) { *(pixMapData+shift+3) = (pixel & 0xFF000000)>>24; *(pixMapData+shift+2) = (pixel & 0xFF0000)>>16; *(pixMapData+shift+1) = (pixel & 0xFF00)>>8; *(pixMapData+shift) = pixel & 0xFF; } else { *(pixMapData+shift) = (pixel & 0xFF000000)>>24; *(pixMapData+shift+1) = (pixel & 0xFF0000)>>16; *(pixMapData+shift+2) = (pixel & 0xFF00)>>8; *(pixMapData+shift+3) = pixel & 0xFF; } break; default : Errorf("SetPixelPixMap() : Do not know how to deal with that screen depth"); } }} /* Display the current pixmap *//* ??? PB if winX,winY are completly out of bounds */void WDisplayPixMap(WINDOW win,int winX,int winY){ if (win->flagHide) return; if (flagPSMode == YES) PSDisplayPixMap(winX,winY); else if (GraphicMode) { XXDisplayPixMap(win->frame,winX,winY); XXDeletePixMap(); pixMapData = NULL; }}char WIsDisplayBLittle(void){ if (!GraphicMode) return(NO); return(XXIsDisplayBLittle());}/********************************************************//* Other functions *//********************************************************/void ErrorWindow(){ int r; AHASHELEM e; WINDOW win; /* We loop on the windows */ for (r = 0; r<theWindowsHT->nRows;r++) { for (e = theWindowsHT->rows[r]; e != NULL; e = e->next) { win = (WINDOW) e; if (win->frame == NULL) continue; XXErrorFrame(win->frame); } }}/* Create a frame */FRAME WNewFrame(char *title, int x, int y,int w, int h){ if (GraphicMode) return(XXNewFrame(title,x,y,w,h)); else return((FRAME) NULL);}/* Delete a frame */void WDeleteFrame(FRAME frame){ if (frame == (FRAME) NULL) return; if (GraphicMode) { if (clipWin && clipWin->frame == frame) clipWin = (WINDOW) NULL; XXDeleteFrame(frame); }}/* Change the size the position and the title of a window */void WChangeFrame(FRAME frame,char *title, int x, int y, int w, int h){ if (frame == (FRAME) NULL) return; if (GraphicMode) XXChangeFrame(frame,title,x,y,w,h);}/* Gets the window associated to a frame */WINDOW Frame2Window(FRAME frame) { int r; AHASHELEM e; WINDOW win; if (frame == (FRAME) NULL) return(NULL); /* We loop on the windows */ for (r = 0; r<theWindowsHT->nRows;r++) { for (e = theWindowsHT->rows[r]; e != NULL; e = e->next) { win = (WINDOW) e; if (win->frame == frame) return(win); } } return(NULL);}WINDOW WGetFrontWindow(void){ return(Frame2Window(XXGetFrontFrame()));}void WFrontWindow(WINDOW win){ XXFrontFrame(win->frame);}/********************************************************//* Event managing *//* Return the next event of type EventMask on the queue *//* Return 0 if no event *//* EventMask = 1- BUTTONDOWN - Param : x,y,button 2- REFRESH - Param : x,y,dx,dy The parameters corresponds to the area of the window which has to be refreshed. This event must take care of the change of size/position of the window (this is indicated by dx < 0) 3- KEYPRESS/KEYRELEASE - Param : key,x,y 4- ENTERWINDOW - no param 5- LEAVEWINDOW - no param Any combination of those is possible *//********************************************************//* Turn the autorepeat on */void WAutoRepeatOn(void){ if (GraphicMode) XXAutoRepeatOn();}/* Turn the autorepeat off */void WAutoRepeatOff(void){ if (GraphicMode) XXAutoRepeatOff();}/****************************************//* Color stuff *//****************************************//* * Set the current colormap according to the values of red, green and blue. * The first color is the cursor color. * The next 'nCursorColors' are the colors that must behave 'well' during a PenInverse mode * Returns the number of colors that are used. */int WSetColormap(unsigned short red[],unsigned short green[],unsigned short blue[], unsigned long pixels[], int nCols, int flagSharedColormap, int mouseMode){ unsigned short r,g,b; if (GraphicMode) { Color2RGB(mColor,&r,&g,&b); return(XXSetColormap(red,green,blue,pixels,nCols,flagSharedColormap,mouseMode,r,g,b)); } return(nCols);}/* Animate one color */void WAnimateColor(unsigned long c, unsigned short r, unsigned short g, unsigned short b){ if (GraphicMode) XXAnimateColor(Color2Pixel(c),r,g,b);}/* Returns the number of colors available */int WNumOfColors(void){ if (GraphicMode) return(XXNumOfColors()); else return(65536);}/* Returns the depth of the screen */int WDepth(void){ if (GraphicMode) return(XXDepth()); else return(32);}/* * Is the screen BW ? */int WIsBWScreen(void){ if (GraphicMode) return(XXIsBWScreen()); else return(NO);}/* * Type of the screen */char *WScreenType(void){ if (GraphicMode) return(XXScreenType()); else return("TrueColor");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -