static int draw_rec(GFX_CONTAINER *ds, WIDGET *cw, WIDGET *origin, int cx1, int cy1, int cx2, int cy2, int do_update) { int sx1, sy1, sx2, sy2; static int d; int need_update = 0; WIDGET *next; if (!cw) return 0; /* calc intersection between dirty area and current window */ sx1 = MAX(cx1, (d = cw->gen->get_x(cw) + (config_dropshadows ? 0 : win->shadow_left))); sx2 = MIN(cx2, d + cw->gen->get_w(cw) - (config_dropshadows ? 0 : win->shadow_left + win->shadow_right) - 1); sy1 = MAX(cy1, (d = cw->gen->get_y(cw) + (config_dropshadows ? 0 : win->shadow_top))); sy2 = MIN(cy2, d + cw->gen->get_h(cw) - (config_dropshadows ? 0 : win->shadow_top + win->shadow_bottom) - 1); /* if there is an intersection - subdivide area */ if ((sx1 <= sx2) && (sy1 <= sy2)) { gfx->push_clipping(ds, sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1); /* * If an origin is specified, first find out if the specified * origin is visible at the current screen area and then, draw * it (by specifying NULL as origin). In fact, if we specify * an origin != NULL, no drawing is performed at all. */ need_update |= cw->gen->draw(cw, ds, 0, 0, origin); if (origin && need_update) cw->gen->draw(cw, ds, 0, 0, NULL); gfx->pop_clipping(ds); if (need_update && do_update) gfx->update(ds, sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1); /* take care about the rest */ if ((next = cw->gen->get_next(cw)) == NULL) return need_update; if (sx1 > cx1) need_update |= draw_rec(ds, next, origin, cx1, MAX(cy1, sy1), sx1 - 1, MIN(cy2, sy2), do_update); if (sy1 > cy1) need_update |= draw_rec(ds, next, origin, cx1, cy1, cx2, sy1 - 1, do_update); if (sx2 < cx2) need_update |= draw_rec(ds, next, origin, sx2 + 1, MAX(cy1, sy1), cx2, MIN(cy2, sy2), do_update); if (sy2 < cy2) need_update |= draw_rec(ds, next, origin, cx1, sy2 + 1, cx2, cy2, do_update); } else { need_update |= draw_rec(ds, cw->gen->get_next(cw), origin, cx1, cy1, cx2, cy2, do_update); } return need_update; }
static int scr_drawarea(SCREEN *scr, WIDGET *origin, long x, long y, long w, long h) { GFX_CONTAINER *ds = scr->sd->scr_ds; WIDGET *parent; /* is scr child of another widget? we go on with propagating the request */ parent = scr->gen->get_parent(scr); if (parent) return orig_drawarea(scr, origin, x, y, w, h); gfx->reset_clipping(ds); /* if redraw request refers to the screen, reset origin */ if (origin == scr) origin = NULL; return draw_rec(ds, scr->sd->first_win, origin, x, y, x + w - 1, y + h - 1, 1); }
static int scr_drawbehind(SCREEN *scr, WIDGET *win, long x, long y, long w, long h, WIDGET *origin) { int ret = 0; WIDGET *next; if (!win || (win->gen->get_parent(win) != scr)) return 0; next = win->gen->get_next(win); /* if maximum depth is reached, just paint a black box */ if (transparency_depth >= 2) { if (!origin) win->gen->draw_bg(win, scr->sd->scr_ds, x, y, w, h, NULL, 1); return 0; } transparency_depth++; if (next) ret |= draw_rec(scr->sd->scr_ds, next, origin, x, y, x + w - 1, y + h - 1, 0); transparency_depth--; return ret; }
static int scr_drawbehind(SCREEN *scr, WIDGET *win, int x, int y, int w, int h, WIDGET *origin) { int ret = 0; WIDGET *next; GFX_CONTAINER *ds = scr->sd->scr_ds; if (gfx->get_clip_w(ds) <= 0 || gfx->get_clip_h(ds) <= 0) return ret; if (!win || (win->gen->get_parent(win) != scr)) return 0; next = win->gen->get_next(win); /* if maximum depth is reached, just paint a black box */ if (transparency_depth >= 1) { if (!origin) win->gen->draw_bg(win, scr->sd->scr_ds, x, y, w, h, NULL, 1); return 0; } transparency_depth++; if (next) ret |= draw_rec(scr->sd->scr_ds, next, origin, x, y, x + w - 1, y + h - 1, 0); transparency_depth--; return ret; }
void main() { unsigned int lx, ly; shiliu=1; spistar(); //模拟spi初始化 Lcd_Init(); //tft初始化 LCD_CS =0; //打开LCD片选使能 Pant(Cyan); //清屏 //画框 draw_rec(8, 3, 232, 73, Blue); draw_rec(10, 5, 230, 71, Cyan); //画 + - * / draw_rec(8, 76, 58, 116, Blue2); draw_rec(66, 76, 116, 116, Blue2); draw_rec(124, 76, 174, 116, Blue2); draw_rec(182, 76, 232, 116, Blue2); //画 1 2 3 draw_rec(8, 124, 58, 164, Blue2); draw_rec(66, 124, 116, 164, Blue2); draw_rec(124, 124, 174, 164, Blue2); //画 4 5 6 draw_rec(8, 172, 58, 212, Blue2); draw_rec(66, 172, 116, 212, Blue2); draw_rec(124, 172, 174, 212, Blue2); //画 7 8 9 draw_rec(8, 220, 58, 260, Blue2); draw_rec(66, 220, 116, 260, Blue2); draw_rec(124, 220, 174, 260, Blue2); //画 0 C = . draw_rec(8, 268, 58, 308, Blue2); draw_rec(66, 268, 174, 308, Blue2); draw_rec(182, 124, 232, 212, Blue2); draw_rec(182, 220, 232, 308, Blue2); //贴标签 /* LCD_PutString(29, 92, "+", Red, Blue2); LCD_PutString(87, 92, "-", Red, Blue2); LCD_PutString(145, 92, "*", Red, Blue2); LCD_PutString(203, 92, "/", Red, Blue2); LCD_PutString(29, 140, "1", Red, Blue2); LCD_PutString(87, 140, "2", Red, Blue2); LCD_PutString(145, 140, "3", Red, Blue2); LCD_PutString(29, 188, "4", Red, Blue2); LCD_PutString(87, 188, "5", Red, Blue2); LCD_PutString(145, 188, "6", Red, Blue2); LCD_PutString(29, 236, "7", Red, Blue2); LCD_PutString(87, 236, "8", Red, Blue2); LCD_PutString(145, 236, "9", Red, Blue2); LCD_PutString(29, 282, "0", Red, Blue2); LCD_PutString(116, 282, "C", Red, Blue2); LCD_PutString(203, 160, ".", Red, Blue2); LCD_PutString(203, 256, "=", Red, Blue2); */ while (1) { if (Penirq == 0) { AD7843(); lx=240-((TP_X-400)/13); ly=320-((TP_Y-400)/10); //运算符扫描 if (lx >= 8 && lx <= 58 && ly >= 76 && ly <= 116) { op = 0; op_old = op_num; op_num = 0; //LCD_PutString(18, 50, "+", Magenta, Cyan); while (Penirq == 0 && lx >= 8 && lx <= 58 && ly >= 76 && ly <= 116); } if (lx >= 66 && lx <= 116 && ly >= 76 && ly <= 116) { op = 1; op_old = op_num; op_num = 0; //LCD_PutString(18, 50, "-", Magenta, Cyan); while (Penirq == 0 && lx >= 66 && lx <= 116 && ly >= 76 && ly <= 116); } if (lx >= 124 && lx <= 174 && ly >= 76 && ly <= 116) { op = 2; op_old = op_num; op_num = 0; //LCD_PutString(18, 50, "*", Magenta, Cyan); while (Penirq == 0 && lx >= 124 && lx <= 174 && ly >= 76 && ly <= 116); } if (lx >= 182 && lx <= 232 && ly >= 76 && ly <= 116) { op = 3; op_old = op_num; op_num = 0; //LCD_PutString(18, 50, "/", Magenta, Cyan); while (Penirq == 0 && lx >= 182 && lx <= 232 && ly >= 76 && ly <= 116); } //数字按键扫描 // 1 if (lx >= 8 && lx <= 58 && ly >= 124 && ly <= 164) { if (wei(op_num) < 10) { op_num = op_num * 10 + 1; } while (Penirq == 0 && lx >= 8 && lx <= 58 && ly >= 124 && ly <= 164); } //2 if (lx >= 66 && lx <= 116 && ly >= 124 && ly <= 164) { if (wei(op_num) < 10) { op_num = op_num * 10 + 2; while (Penirq == 0 && lx >= 66 && lx <= 116 && ly >= 124 && ly <= 164); } } //3 if (lx >= 124 && lx <= 174 && ly >= 124 && ly <= 164) { if (wei(op_num) < 10) { op_num = op_num * 10 + 3; while (Penirq == 0 && lx >= 124 && lx <= 174 && ly >= 124 && ly <= 164); } } //4 if (lx >= 8 && lx <= 58 && ly >= 172 && ly <= 212) { if (wei(op_num) < 10) { op_num = op_num * 10 + 4; } while (Penirq == 0 && lx >= 8 && lx <= 58 && ly >= 172 && ly <= 212); } //5 if (lx >= 66 && lx <= 116 && ly >= 172 && ly <= 212) { if (wei(op_num) < 10) { op_num = op_num * 10 + 5; } while (Penirq == 0 && lx >= 66 && lx <= 116 && ly >= 172 && ly <= 212); } //6 if (lx >= 124 && lx <= 174 && ly >= 172 && ly <= 212) { if (wei(op_num) < 10) { op_num = op_num * 10 + 6; } while (Penirq == 0 && lx >= 124 && lx <= 174 && ly >= 172 && ly <= 212); } //7 if (lx >= 8 && lx <= 58 && ly >= 220 && ly <= 260) { if (wei(op_num) < 10) { op_num = op_num * 10 + 7; } while (Penirq == 0 && lx >= 8 && lx <= 58 && ly >= 220 && ly <= 260); } //8 if (lx >= 66 && lx <= 116 && ly >= 220 && ly <= 260) { if (wei(op_num) < 10) { op_num = op_num * 10 + 8; } while (Penirq == 0 && lx >= 66 && lx <= 116 && ly >= 220 && ly <= 260); } //9 if (lx >= 124 && lx <= 174 && ly >= 220 && ly <= 260) { if (wei(op_num) < 10) { op_num = op_num * 10 + 9; } while (Penirq == 0 && lx >= 124 && lx <= 174 && ly >= 220 && ly <= 260); } //0 if (lx >= 8 && lx <= 58 && ly >= 268 && ly <= 308) { if (wei(op_num) < 10) { op_num = op_num * 10; } while (Penirq == 0 && lx >= 8 && lx <= 58 && ly >= 268 && ly <= 308); } disnum(op_num); // = //draw_rec(182, 124, 232, 212, Blue2); if (lx >= 182 && lx <= 124 && ly >= 232 && ly <= 212) { switch (op) { case 0: res = op_old + op_num; break; case 1: res = op_old - op_num; break; case 2: res = op_old * op_num; break; case 3: res = op_old / op_num; break; default: res = 0; break; } disnum(res); } } } }