⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.c

📁 EGui是一个开源的图形系统软件,类似于QT/Embedded、GTK-FB、MicroWindow。目标是嵌入式平台整合解 决方案。基于Linux Framebuffer 设备驱动上实现。有完
💻 C
字号:
/******************************************************** * Egui code,LGPL * Function : Egui library on Linux framebuffer  * Author: asmcos@hotmail.com * Data : 2006-02-22 * $Id: window.c,v 1.16 2006/04/05 17:16:21 hjs Exp $ ********************************************************/#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <sys/ioctl.h>#include <sys/types.h>#include <linux/fb.h>#include <Egui.h>#include <font_8x16.h> 		/* Egui default font */EGui_Window * Ewindow;int save_self = 0;#define C_WIDTH   10#define C_HEIGHT  17#define T___ 0xFF000000#define BORD 0x00FFFFFF //white#define X___ 0x00       //blackstatic unsigned long cursor_pixel [C_WIDTH * C_HEIGHT] = {BORD,T___,T___,T___,T___,T___,T___,T___,T___,T___,BORD,BORD,T___,T___,T___,T___,T___,T___,T___,T___,BORD,X___,BORD,T___,T___,T___,T___,T___,T___,T___,BORD,X___,X___,BORD,T___,T___,T___,T___,T___,T___,BORD,X___,X___,X___,BORD,T___,T___,T___,T___,T___,BORD,X___,X___,X___,X___,BORD,T___,T___,T___,T___,BORD,X___,X___,X___,X___,X___,BORD,T___,T___,T___,BORD,X___,X___,X___,X___,X___,X___,BORD,T___,T___,BORD,X___,X___,X___,X___,X___,X___,X___,BORD,T___,BORD,X___,X___,X___,X___,X___,X___,X___,X___,BORD,BORD,X___,X___,X___,X___,X___,BORD,BORD,BORD,BORD,BORD,X___,X___,BORD,X___,X___,BORD,T___,T___,T___,BORD,X___,BORD,T___,BORD,X___,X___,BORD,T___,T___,BORD,BORD,T___,T___,BORD,X___,X___,BORD,T___,T___,T___,T___,T___,T___,T___,BORD,X___,X___,BORD,T___,T___,T___,T___,T___,T___,BORD,X___,X___,BORD,T___,T___,T___,T___,T___,T___,T___,BORD,BORD,T___,T___};static unsigned char *old_cursor;  static int old_x = -1,old_y = -1;static int hide = 1;int init_cursor ( EGui_Window * ewindow){  int j,i,count;  unsigned long * p;  int cursor_y = C_HEIGHT;  int cursor_x = C_WIDTH;  Ecolor color;    /*   *conversion cursor RGB to pixel   */  p = cursor_pixel;  for (j=0;j<cursor_y;j++)    {      for (i=0;i<cursor_x;i++)	{	  if (p[i+ j * cursor_x] != T___)	  {	    count = i + j * cursor_x;	    color.b = p[count] & 0xFF;	    color.g = (p[count] >> 8) & 0xFF;	    color.r = (p[count] >> 16) & 0xFF;	    p[count] = pixel_from_rgb (ewindow,&color); 	  }	}    }  old_cursor = (unsigned char *)malloc ( cursor_x * cursor_y * ewindow->fbinfo->p_bpp);  if (old_cursor == NULL)    {      printf ("CURSOR malloc ERROR\n");    }}intdraw_cursor (int x,int y,unsigned long *p, EGui_Window * ewindow){  int i;  int j;  EGui_FBinfo * fbinfo= ewindow->fbinfo;  Ecolor color;  int cursor_y = C_HEIGHT;  int cursor_x = C_WIDTH;    if ((x + cursor_x) > ewindow->max_width)    return;  if ((y + cursor_y) > ewindow->max_height)    return;  for (j=0;j<cursor_y;j++)    {      for (i=0;i<cursor_x;i++)	{	  if (p[i+ j * cursor_x] != T___)	    {	      /* It is unsafe, r,g,b is empty.	       */	      color.pixel = p[i+ j * cursor_x];	      Egui_wpixel(x+i,y+j,&color,ewindow);	    }	}    }}int write_cursor_buf (int x,int y,unsigned char *p, EGui_Window *ewindow){  int cursor_y = C_HEIGHT;  int cursor_x = C_WIDTH;    old_x = x;  old_y = y;  if ((x + cursor_x) > ewindow->max_width)    return;  if ((y + cursor_y) > ewindow->max_height)    return;  Egui_writebuf (x,y,cursor_x,cursor_y,cursor_x,p,ewindow);}intsave_cursor_buf (int x,int y,unsigned char *p, EGui_Window * ewindow){  int cursor_y = C_HEIGHT;  int cursor_x = C_WIDTH;    old_x = x;  old_y = y;  if ((x + cursor_x) > ewindow->max_width)    return;  if ((y + cursor_y) > ewindow->max_height)    return;  Egui_readbuf (x,y,cursor_x,cursor_y,p,ewindow);}int move_mouse (int x,int y){  //first move mouse ,don't need restore  hide_cursor ( );  show_cursor (x,y);}inthide_cursor ( void ){				  /* cursor had hid */  if (hide)    return 1;  hide = 1;  write_cursor_buf(old_x,old_y,old_cursor,Ewindow);}intshow_cursor (int x,int y){  hide = 0;  save_cursor_buf (x,y,old_cursor,Ewindow);  draw_cursor (x,y,cursor_pixel,Ewindow);}intmove_window ( EGui_Event * event, EGui_Window * ewindow){  int x,y,re_x,re_y;  x    = event->x;  y    = event->y;  re_x = x - old_x;  re_y = y - old_y;  hide_cursor( );    save_selfwindow (ewindow);  restore_window (ewindow,re_x,re_y);  ewindow->x += re_x;  if (ewindow->x < 0)    ewindow->x = 0;  if ((ewindow->x + ewindow->width ) > ewindow->max_width)    ewindow->x = ewindow->max_width - ewindow->width;			      ewindow->y += re_y;    if (ewindow->y < 0)    ewindow->y = 0;  if ((ewindow->y + ewindow->height) > ewindow->max_height)    ewindow->y = ewindow->max_height - ewindow->height;   ioctl ( eguifd,EGUI_REPORT_EVENT,ewindow);  move_selfwindow (ewindow);  show_cursor( x, y );  }int move_selfwindow (  EGui_Window *ewindow){  int x,y,width,height;  int i;  int color;  save_window (ewindow);  x       = ewindow->x;  y       = ewindow->y;  width   = ewindow->width;  height  = ewindow->height;  Egui_writebuf (x,y,width,height,width,ewindow->saveself,ewindow);}intrestore_window(  EGui_Window *ewindow, int re_x,int re_y){  int x,y,width,height;  int i;  int color;  x       = ewindow->x;  y       = ewindow->y;  width   = ewindow->width;  height  = ewindow->height;    /* When window be moved,   * maybe there are 2 rectanges gap.   */  Egui_writebuf (x,y,width,height,width,ewindow->savebuf,ewindow);}int save_selfwindow ( EGui_Window * ewindow){  int x,y,width,height;  int i;  int color;  if (save_self != 0)	return 0;  save_self = 1;  x       = ewindow->x;  y       = ewindow->y;  width   = ewindow->width;  height  = ewindow->height;   Egui_readbuf (x,y,width,height,ewindow->saveself,ewindow);}int save_window( EGui_Window * ewindow){  int x,y,width,height;  int i;  int color;  x       = ewindow->x;  y       = ewindow->y;  width   = ewindow->width;  height  = ewindow->height;    Egui_readbuf (x,y,width,height,ewindow->savebuf,ewindow);}EGui_Window *Egui_CreateWindow ( EGui_FBinfo *fbinfo,short x,short y,		  short width,short height, Ecolor * bgcolor,char window_type){    EGui_Window *ewindow;    ewindow = ( EGui_Window *) malloc (sizeof ( EGui_Window));  if (ewindow == NULL)    {      printf ("Egui : malloc a new window failed!\n");      return NULL;    }    ewindow->pid = getpid ( );    ewindow->x            = x ;  ewindow->y            = y ;  ewindow->width        = width + 2 * FRAME_W;  ewindow->height       = height + 2 * FRAME_W + TITLE_H;  ewindow->bgcolor      = bgcolor;  ewindow->window_type  = window_type;  ewindow->fbinfo       = fbinfo;  ewindow->title_h      = TITLE_H;  ewindow->frame_w      = FRAME_W;  fbinfo->ewindow       = ewindow;  ewindow->max_width    = fbinfo->screen_width  - 1; /* pixel start from 0*/  ewindow->max_height   = fbinfo->screen_height - 1;    if ((ewindow->width  + ewindow->x) > ewindow->max_width)    ewindow->width = ewindow->max_width - ewindow->x;  if ((ewindow->height  + ewindow->y) > ewindow->max_height)    ewindow->height = ewindow->max_height - ewindow->y;  /* buffer save pixel 's int data type RGB value */  ewindow->savebuf = (unsigned char *) malloc (ewindow->width * fbinfo->p_bpp * ewindow->height);  ewindow->saveself = (unsigned char *) malloc (ewindow->width * fbinfo->p_bpp * ewindow->height);  if (ewindow->savebuf == NULL || ewindow->saveself == NULL)    {      printf ("Egui : malloc window buffer failed!\n");      return NULL;    }  if (window_type == EGUI_WINDOW_ROOT)    {      ewindow->title_h = ewindow->frame_w = 0;    }  /* Ewindow only for move window */  Ewindow              = ewindow;  if(ioctl ( eguifd,EGUI_NEWWINDOW,ewindow))    {      /* new window failed */      free (ewindow->savebuf);      free (ewindow);      Ewindow = NULL;            return NULL;    }  color_from_rgb (ewindow,bgcolor);  init_cursor(ewindow);        printf ("New windows id = %d\n",ewindow->id);        return ewindow;}intEgui_drawwindow ( EGui_Window *ewindow){  int x,y,width,height;  int i,w,h;  Ecolor color;  Efont *font;  x       = ewindow->x;  y       = ewindow->y;  width   = ewindow->width;  height  = ewindow->height;  w       = ewindow->frame_w;  h       = ewindow->title_h;  save_window(ewindow);  /*Only TOPWindow need Title Bar*/  if (ewindow->window_type == EGUI_WINDOW_TOP)    {      /**/      color.r = color.g = color.b = 0xFF;//white          color_from_rgb (ewindow,&color);      Egui_rect (0,0,width-3,height-3,&color,ewindow);            color.r = color.g = color.b = 0xCC;//gray          color_from_rgb (ewindow,&color);      Egui_rect (1,1,width-2,height-2,&color,ewindow);            color.r = color.g = color.b = 0xA0;//gray          color_from_rgb (ewindow,&color);      Egui_rect (2,2,width-1,height-1,&color,ewindow);                  /* draw Title bar */      for ( i = w; i< (ewindow->title_h + w); i++)	{	  color.r = color.g = color.b = 0x5F * i / (ewindow->title_h+w) + 0xA0;	  color_from_rgb (ewindow,&color);	  Egui_line (w,i,ewindow->width - w - 1,i,&color,ewindow);	}      new_color(ewindow,&color,0xE0);      Egui_drawstring(4,3,ewindow->name,font,&color,ewindow);    }}int Egui_SetWindowName (EGui_Window * ewindow,char * name){  int len;    len = strlen (name);  if (len > NAMELEN)    len = NAMELEN;  else    ewindow->name[len] = '\0';  strncpy (ewindow->name,name,len);}intEgui_CloseWindow ( EGui_Window * ewindow){  ioctl ( eguifd,EGUI_CLOSEWINDOW,ewindow);  free (ewindow->savebuf);  free (ewindow);  Ewindow = NULL;  return 0;   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -