Initial commit
[forms.git] / F / F_Text_Symbol_Buffer.H
blob18229685c10da9dbc968e58cc4df1bf1ab7dff20
2 #ifndef _F_TEXT_SYMBOL_BUFFER_H_
3 #define _F_TEXT_SYMBOL_BUFFER_H_
5 #include <F_Types.H>
6 #include <F_Text_Symbol.H>
7 #include <F_Point.H>
8 #include <F_Rect.H>
9 #include <F_Region.H>
10 #include <F_Log.H>
12 namespace F {
14 class F_Text_Symbol_Buffer : public F_Rect {
16   F_Text_Symbol *buf;
18  public:
20   F_Text_Symbol_Buffer(dim_t tw, dim_t th) : F_Rect(tw, th) { buf = new F_Text_Symbol[square()]; }
21   F_Text_Symbol_Buffer(F_Rect &r) : F_Rect(r) { buf = new F_Text_Symbol[square()]; }
22   ~F_Text_Symbol_Buffer() { delete [] buf; }
23   void resize(dim_t tw, dim_t th) {
24     delete [] buf;
25     w(tw);
26     h(th);
27     buf = new F_Text_Symbol[square()];
28   }
29   // ÕÖÁÓÔØ ...
30   inline F_Text_Symbol *operator[](unsigned int idx) {
31     if (idx < square())
32       return &(buf[idx]);
33     else
34       bug();
35  }
36   // ËÏÐÉÒÕÅÍ × ÎÁÛ buffer ÉÚ b_src ËÕÓÏÞÅË ÕËÁÚÙ×ÁÅÍÙÊ r_src × ÒÅÇÉÏΠr_dst
37   inline void copy(F_Region &r_src, F_Text_Symbol_Buffer &b_src, F_Region *r_dst) {
38     // ÏÂÌÁÓÔÉ ÄÏÌÖÎÙ ÂÙÔØ ÒÁ×ÎÙ ÐÏ ÛÉÒÉÎÅ/×ÙÓÏÔÅ
39 //    if ((r_src.w() != r_dst->w()) || (r_src.h() != r_dst->h()))
40 //      trace_bug();
41     if (r_dst->w() > w())
42       trace_bug();
43     if (r_dst->h() > h())
44       trace_bug();
45     register coord_t dst_x, src_x, dst_y = r_dst->y(), src_y = r_src.y();
46     register dim_t copy_w = r_src.w(), copy_h = r_src.h();
47     for (; dst_y < (r_dst->y() + copy_h); dst_y++, src_y++) {
48       if ((dst_y < 0) || (dst_y >= h()) || (src_y < 0) || (src_y >= b_src.h()))
49         continue;
50       dst_x = r_dst->x();
51       src_x = r_src.x();
52       for (; dst_x < (r_dst->x() + copy_w); dst_x++, src_x++)
53         if ((dst_x >= 0) && (dst_x < w()) &&
54           (src_x >= 0) && (src_x < b_src.w()))
55             buf[dst_x + dst_y * w()] = b_src.buf[src_x + src_y * b_src.w()];
56   }
57  }
58   inline void copy(F_Region &r_src, F_Text_Symbol_Buffer &b_src, F_Region &r_dst) {
59     copy(r_src, b_src, &r_dst); }
60   // fill all the region with the given symbol
61   inline void fill(F_Region &region, F_Text_Symbol &s) {
62     // clip()...
63     for (coord_t cur_y = region.y(); cur_y < (region.y() + region.h()); cur_y++)
64       for (coord_t cur_x = region.x(); cur_x < (region.x() + region.w()); cur_x++)
65         buf[cur_x + cur_y * w()] = s;
66  }
67   // set the point to the given symbol 
68   inline void set(F_Point &p, F_Text_Symbol &s) { buf[p.x() + p.y() * w()] = s; }
69   // fill all the region with the given color
70   void fill(F_Region &r, F_Color &c);
71   // set the point to the given color
72   void set(F_Point &p, F_Color &c);
74   // get one symbol at the given point
75   inline void get(F_Point &p, F_Text_Symbol *sym) { *sym = buf[p.x() + p.y() * w()]; }
76   // get color at the given point
77   F_Color color_draw(F_Point &p);
78  };
81 #endif