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

📄 widget_main.c

📁 EGui是一个开源的图形系统软件,类似于QT/Embedded、GTK-FB、MicroWindow。目标是嵌入式平台整合解 决方案。基于Linux Framebuffer 设备驱动上实现。有完
💻 C
字号:
/******************************************************** * Egui code,LGPL * Function : Widget mail function  * Author: asmcos@hotmail.com * Data : 2006-03-21 * $Id: widget_main.c,v 1.9 2006/04/14 20:12:15 hjs Exp $ ********************************************************/#include <stdio.h>#include <Egui.h>#include <widget.h>#include <elist.h>LIST_HEAD(root_widget);EGui_Widget *cursor_widget=NULL;EGui_Widget *focus_widget=NULL;/* parent */int add_to_parent (EGui_Widget *widget,EGui_Widget *parent){  widget_list * c_list, * p_list;    c_list = widget->list;  p_list = parent->list;    c_list->next  = p_list->child;  c_list->prev  = (struct list_head *)p_list;  p_list->child = (struct list_head *)c_list;   /* have more children */  if (c_list->next)    {      c_list->prev = (struct list_head *)c_list;    }  c_list->child = NULL;  }/* end parent */int add_newqueue ( EGui_Widget *widget){  widget_list * list;  /* alloc a node for the new widget */  widget->list = (widget_list * ) malloc (sizeof(widget_list));  if ( widget->list == NULL)    {      printf ("malloc widget_list error!\n");      return -1;    }  memset(widget->list,0,sizeof(widget_list));  list = widget->list;  /* set list */  list->widget = widget;      list->vx = widget->x;  list->vy = widget->y;  list->vw = widget->width;  list->vh = widget->height;  if (widget->parent)    {          add_to_parent (widget,widget->parent);    }  else    {      list_add ((struct list_head *)(list),&root_widget);    }  return 0;}intdel_queue (EGui_Widget *widget){  list_del ((struct list_head *)widget->list);}/* return  * 0 : inside widget * 1 : outside widget */int inside_widget (int x,int y,widget_list * list){  int wx,wy,wx1,wy1;    wx  = list->widget->window->x + list->vx;  wy  = list->widget->window->y + list->vy;  wx1 = list->widget->window->x + list->vw;  wy1 = list->widget->window->y + list->vh;  if ( wx <= x && wy <= y && x < wx1 && y < wy1 )    {      /* x,y in Widget */      return 0;    }  return 1;}widget_list * find_child (int x,int y,widget_list * list ){  int inside;  /* first child */  inside = inside_widget ( x, y, list);  if (inside == 0) 		/* IF_1 */    {      return list ;    }  else				/* ELSE_1 */    {      /* other children,brother */      widget_list * b_list;      b_list = list;            while (b_list->next)	{	  inside = inside_widget ( x, y, (widget_list *)b_list->next);	  	  if (inside == 0)	/* IF_2 */	    {	      list = (widget_list *)b_list->next;	      return list;	    }	  b_list = (widget_list *)b_list->next;	} /* while */    } /* else  IF_1 */  return 0;}EGui_Widget* find_widget_byxy (int x,int y){  int inside = 1;  widget_list * list;    list = (widget_list *)root_widget.next;  /* No any widget */  if ((root_widget.next == &root_widget) || (list->widget == NULL) )    return NULL;     if (cursor_widget != NULL)    inside = inside_widget ( x, y, cursor_widget->list);  /* don't inside current widget */  if (inside)    {      inside = inside_widget ( x, y, list);      /* is point (x,y) within the widget */      while (inside)	{ 	  list   = (widget_list *)list->next;	  if (list == (widget_list *)&root_widget)	    return NULL;	  inside = inside_widget ( x, y, list);	   	}    }  else    {      /* old cursor widget */      list = cursor_widget->list ;    }    /* have widget */  if (list->widget->child)    {       widget_list * c_list;      c_list = find_child(x,y,list->widget->child->list);            if (c_list != 0)	list = c_list;    }    return list->widget;}/* widget event */intcursor_move (EGui_Event *event){  EGui_Widget * widget;    hide_cursor ();    widget = find_widget_byxy (event->x,event->y);  if (widget != NULL)    {      if (widget != cursor_widget)	{	  widget_draw_in (widget);	  if (cursor_widget)	    widget_draw_out (cursor_widget);	  cursor_widget = widget;	}          }  show_cursor (event->x,event->y);}intclick_left (EGui_Event *event){  EGui_Widget * widget;    hide_cursor ();    widget = find_widget_byxy (event->x,event->y);  if (widget != NULL)    {      focus_widget = widget;      if (widget != cursor_widget)	{	  cursor_widget = widget;	}      widget_click_left (widget);    }  show_cursor (event->x,event->y);}int rel_left (EGui_Event *event){  EGui_Widget * widget;    hide_cursor ();    widget = find_widget_byxy (event->x,event->y);  if (widget != NULL)    {      if (widget != cursor_widget)	{	  cursor_widget = widget;	}      widget_rel_left (widget);    }  show_cursor (event->x,event->y);}/*NOTE: cursor's position isn't the same   * with focus_widget. */unsigned char kbd_map[128] =        "\000\0331234567890-=\177\t"                    /* 0x00 - 0x0f */        "qwertyuiop[]\r\000as"                          /* 0x10 - 0x1f */        "dfghjkl;'`\000\\zxcv"                          /* 0x20 - 0x2f */        "bnm,./\000*\000 \000\201\202\203\204\205"      /* 0x30 - 0x3f */        "\206\207\210\211\212\000\000789-456+1"         /* 0x40 - 0x4f */        "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */        "\r\000/";                                      /* 0x60 - 0x6f */int press_key (EGui_Event *event){  EGui_Widget * widget;    hide_cursor ();    widget = focus_widget;  if (widget != NULL)    {      event->code = kbd_map [event->code];      widget_press_key(widget,event);    }  show_cursor (event->x,event->y);}intsend_event_widget (EGui_Event *event){     switch (event->type)    {    case PRESS_KEY:      press_key (event);      break;    case CLICK_LEFT:      click_left (event);      break;    case CLICK_RIGHT:      break;    case CLICK_MIDDLE:      break;    case REL_LEFT:      rel_left (event);      break;    case RELEASE_KEY:      break;    case FOCUS_CHANGED:      break;    case W_SIZE_CHANGED:      break;    case CURSOR_MOVE:      cursor_move (event);      break;    default:      break;        }  return 0;}

⌨️ 快捷键说明

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