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