3 * Copyright (C) 2007, Harbour, All rights reserved.
6 #ifndef _F_LINUX_CONSOLE_DISPLAY_H_
7 #define _F_LINUX_CONSOLE_DISPLAY_H_
9 #include <F_Text_Display.H>
16 class F_Linux_Console_Display : public F_Text_Display {
19 coord_t old_cursor_x, old_cursor_y, cursor_x, cursor_y;
20 coord_t old_mouse_x, old_mouse_y, mouse_x, mouse_y;
21 F_Event_Type_t mouse_ev_t; // current mouse event type
22 F_Pointer_Event_Code_t mouse_ev_c; // current mouse event code
23 F_Text_Symbol symbol_under_mouse_;
24 F_Window *window_belowmouse_;
26 void put_line(coord_t x, coord_t y, dim_t len, F_Text_Symbol *src);
27 void get_line(coord_t x, coord_t y, dim_t len, F_Text_Symbol *dest);
29 inline void put_symbol_region(F_Region *region, F_Text_Symbol_Buffer &src) {
30 for (register coord_t cur_line = region->y(); cur_line < (region->y() + region->h()); cur_line++)
31 put_line(region->x(), cur_line, region->w(), src[((cur_line - region->y()) * region->w())]);
33 inline void get_symbol_region(F_Region *region, F_Text_Symbol_Buffer &dest) {
34 for (register coord_t cur_line = region->y(); cur_line < (region->y() + region->h()); cur_line++)
35 get_line(region->x(), cur_line, region->w(), dest[((cur_line - region->y()) * region->w())]);
40 F_Linux_Console_Display(FILE *vcsa, dim_t w, dim_t h) : F_Text_Display(w, h) {
42 old_mouse_x = old_mouse_y = mouse_x = mouse_y = F_MAX_COORD_T;
43 mouse_ev_t = F_EVENT_NONE;
44 mouse_ev_c = F_POINTER_NONE;
45 window_belowmouse_ = 0;
47 ~F_Linux_Console_Display() { fclose(vcsa_); }
49 // ÏÂÒÁÂÁÙ×ÁÅÔ ÓÏÂÙÔÉÑ É ÐÅÒÅÄÁÅÔ ÉÈ ÄÁÌØÛÅ - ÏËÎÁÍ/×ÉÄÖÅÔÁÍ
50 bool handle(F_Event_t &ev);
51 F_Window *window_belowmouse() { return window_belowmouse_; }
52 void window_belowmouse(F_Window *w) { window_belowmouse_ = w; }
53 // tty magic : cursor on/off
54 void cursor(bool on) {
55 if (on && (cursor_x >= 0) && (cursor_x <= w()) && (cursor_y <= h()) &&
57 fprintf(stdout, "%c%s",27,"[?25h");
59 fprintf(stdout, "%c%s",27,"[?25l");
63 void cursor(coord_t x, coord_t y);
65 void cursor(coord_t *x, coord_t *y);
66 void restore_mouse_pointer() {
67 if ((old_mouse_x == F_MAX_COORD_T) || (old_mouse_y == F_MAX_COORD_T))
69 if ((old_mouse_x < w()) && (old_mouse_y < h())) {
70 put_line(old_mouse_x, old_mouse_y, 1, &symbol_under_mouse_);
73 void draw_mouse_pointer() {
74 if ((mouse_x == F_MAX_COORD_T) || (mouse_y == F_MAX_COORD_T))
76 restore_mouse_pointer();
79 if (mouse_x > (coord_t)(w() - 1))
81 if (mouse_y > (coord_t)(h() - 1))
83 get_line(mouse_x, mouse_y, 1, &symbol_under_mouse_);
84 F_Text_Symbol t = symbol_under_mouse_;
85 bool blink = (symbol_under_mouse_.bg() & 0x8);
86 bool bright = (symbol_under_mouse_.fg() & 0x8);
88 t.fg((~symbol_under_mouse_.fg() & 0x7) | (bright ? 0x8 : 0));
89 t.bg((~symbol_under_mouse_.bg() & 0x7) | (blink ? 0x8 : 0));
90 put_line(mouse_x, mouse_y, 1, &t);
91 old_mouse_x = mouse_x;
92 old_mouse_y = mouse_y;
95 // ÓÏÈÒÁÎÑÅÍ ÜËÒÁÎ × backing store
96 get_symbol_region(this, back_buf);
97 // É ÔÏÖÅ ÓÁÍÏÅ × front store
98 get_symbol_region(this, draw_buf);
99 cursor(&old_cursor_x, &old_cursor_y);
102 put_symbol_region(this, back_buf);
103 cursor(old_cursor_x, old_cursor_y);
107 friend class F_Linux_Console_UI;
109 }; // class F_Linux_Console_Display