Example #1
0
void text_field::draw(int active, image *screen)
{
  if (active)
  {
    screen->rectangle(xstart(),y,xend(),yend(),wm->bright_color());
    draw_cur(wm->bright_color(),screen);
  }
  else
  {
    screen->rectangle(xstart(),y,xend(),yend(),wm->dark_color());
    draw_cur(wm->dark_color(),screen);
  }
}
Example #2
0
void read_tty(char ch)
{
	int n;
	if(kb_pi >= R*C)
		printf("input buffer full\n");
	if(ch == '\b') {
		if(kb_pi) {
			kb_pi--;
			goto echo;
		}
		else goto no_echo;
	}
	kb_pend[kb_pi] = ch;
	kb_pi++;
	if(ch == '\n') {
		n = write(pipe_in, kb_pend, kb_pi);
		if(n < kb_pi)
			printf("truncation\n");
		kb_pi = 0;
	}
echo:	write_tty_normal(ch);
	draw_scr(cur_top, p_x1, p_y1, p_x2, p_y2);
	refresh_scr(p_x1, p_y1, p_x2, p_y2);
	pend = 0;
	draw_cur();
no_echo:;
}
Example #3
0
File: main.c Project: outsky/tetris
static void draw(void)
{
    center();
    draw_playgrd();
    draw_preview();
    draw_linerecord();
    draw_blockrecord();
    draw_status();
    draw_cur();
    fflush(stdout);
}
Example #4
0
void write_tty(char *buf, int n)
{
	static int estate;
	static int num, num2;
	static int light, hide;
	static int saved_r, saved_c;
	int i;
	int tmp, tr, tc;
	while(n--) {
		switch(estate) {
		case 0: //normal state
			if(*buf == '\033') {
				estate = 1;
			} else {
				write_tty_normal(*buf);
				estate = estate;
			}
			break;
		case 1: //esc begin
			if(*buf == '[')
				estate = 2;
			else estate = 0;
			break;
		case 2: //meet '['
			if(*buf == 'K') {
				//清除从光标到行尾内容
				estate = 0;
			} else if(*buf == 's') {
				//保存光标位置
				saved_r = add_mod(scr_pos, -cur_top)/C;
				saved_c = add_mod(scr_pos, -cur_top)%C;
				estate = 0;
			} else if(*buf == 'u') {
				//恢复光标位置
				scr_pos = add_mod(cur_top, saved_c+C*saved_r);
				estate = 0;
			} else if(*buf == '?') {
				//隐藏/显示光标
				estate = 6;
			} else if(*buf >= 0 && *buf <= '9') {
				num = *buf - '0';
				estate = 3;
			} else {
				printf("unkown esc seq 1\n");
				estate = 0;
			}
			break;
		case 3: //first arg
			if(*buf == 'm') {
				switch(num) {
				case 0: //关闭所有属性
					light = 0;
					hide = 0;
					cur_fg = color_table[7];
					cur_bg = color_table[0];
					break;
				case 1: //设置高亮
					light = 1;
					break;
				case 4: //下划线
					break;
				case 5: //闪烁
					break;
				case 7: //反显
					tmp = cur_fg;
					cur_fg = cur_bg;
					cur_bg = tmp;
					break;
				case 8: //消隐
					hide = 1;
					break;
				default:
					if(num >= 30 && num <= 37) {
						//前景色
						cur_fg = hide ? cur_bg :
							color_table[num-30+light*8];
					}else if(num >= 40 && num <= 47) {
						//背景色
						cur_bg = color_table[num-40+light*8];
					} else {
						printf("unkown esc seq 2\n");
					}
					break;
				}
				estate = 0;
			} else if(*buf == 'J') {
				if(num == 2) {
					//清屏
					for(i = 0; i < R*C; i++)
					{
						int p = add_mod(i, cur_top);
						scr[p] = ' ';
						fg[p] = color_table[7];
						bg[p] = color_table[0];
					}
					p_x1 = 0; p_y1 = 0;
					p_x2 = C-1; p_y2 = R-1;
					pend = 1;
					estate = 0;
				} else {
					printf("unkown esc seq 3\n");
					estate = 0;
				}
			} else if(*buf == 'A') {
				//上移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tr -= num;
				if(tr < 0) tr = 0;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == 'B') {
				//下移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tr += num;
				if(tr >= R) tr = R-1;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == 'C') {
				//左移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tc -= num;
				if(tc < 0) tc = 0;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == 'D') {
				//右移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tc += num;
				if(tc >= C) tc = C-1;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == ';') {
				estate = 4;
			} else if(*buf >= '0' && *buf <= '9') {
				num = num*10 + *buf - '0';
				estate = estate;
			}
			break;
		case 4: //meet ;
			if(*buf >= '0' && *buf <= '9') {
				num2 = *buf - '0';
				estate = 5;
			} else {
				printf("unkown esc seq 4\n");
				estate = 0;
			}
			break;
		case 5: //second arg
			if(*buf == 'H') {
				//设置光标
				tr = num;
				tc = num2;
				if(tc >= C) tc = C-1;
				if(tr >= R) tr = R-1;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf >= '0' && *buf <= '9') {
				num2 = num2*10 + *buf - '0';
				estate = estate;
			} else {
				printf("unkown esc seq 5\n");
				estate = 0;
			}
			break;
		case 6: //meet ?
			if(*buf >= '0' && *buf <= '9') {
				num2 = *buf - '0';
				estate = 7;
			} else {
				printf("unkown esc seq 6\n");
				estate = 0;
			}
			break;
		case 7:
			if(*buf == 'h') {
				//显示光标
				if(num2 == 25) {
					scr_pos_hide = 0;
				} else printf("unkown esc seq 7\n");
				estate = 0;
			} else if(*buf == 'l') {
				//隐藏光标
				if(num2 == 25) {
					scr_pos_hide = 1;
					printf("cursor hide\n");
				} else printf("unkown esc seq 8\n");
				estate = 0;
			} else if(*buf >= '0' && *buf <= '9') {
				num2 = num2*10 + *buf - '0';
				estate = estate;
			} else {
				printf("unkown esc seq 9\n");
				estate = 0;
			}
			break;
		default:
			printf("esc bug\n");
			exit(1);
			break;
		}
		buf++;
	}
	draw_scr(cur_top, p_x1, p_y1, p_x2, p_y2);
	refresh_scr(p_x1, p_y1, p_x2, p_y2);
	pend = 0;
	draw_cur();
}
Example #5
0
void text_field::handle_event(event &ev, image *screen, InputManager *im)
{
  int xx;
  if (ev.type==EV_KEY)
  {
    switch (ev.key)
    {
      case JK_LEFT : if (cur) { draw_cur(wm->dark_color(),screen); cur--;
                           draw_cur(wm->bright_color(),screen); } break;
      case JK_RIGHT : if (cur<(int)strlen(format)-1) { draw_cur(wm->dark_color(),screen); cur++;
                           draw_cur(wm->bright_color(),screen); } break;
      case JK_END : if (cur!=last_spot())
                          { draw_cur(wm->dark_color(),screen); cur=last_spot();
                            if (cur==(int)strlen(format)-1) cur--;
                           draw_cur(wm->bright_color(),screen); } break;
      case JK_HOME : if (cur)
                          { draw_cur(wm->dark_color(),screen); cur=0;
                           draw_cur(wm->bright_color(),screen); } break;
      case JK_BACKSPACE : if (cur)
         { draw_cur(wm->dark_color(),screen); cur--;
           for (xx=cur; xx<(int)strlen(format)-1; xx++)
             data[xx]=data[xx+1];
           data[strlen(format)-1]=' ';
           draw_text(screen);
           draw_cur(wm->bright_color(),screen);
           wm->push_event(new event(id,(char *)this));
         } break;
      default : if (ev.key>=' ' && ev.key<='~')
         {
           draw_cur(wm->dark_color(),screen);
           for (xx=strlen(format)-1; xx>cur && xx>0; xx--)
             data[xx]=data[xx-1];
           data[cur]=ev.key;
           if (cur<(int)strlen(format)-1)
             cur++;
       data[strlen(format)]=0;
           draw_text(screen);
           draw_cur(wm->bright_color(),screen);
           wm->push_event(new event(id,(char *)this));
         } break;
    }
  }
}