1 #include "framebuffer-font2.hpp"
2 #include "memorywatch-fb.hpp"
10 struct fb_object
: public framebuffer::object
20 framebuffer::font2
* font
;
21 framebuffer::color fg
;
22 framebuffer::color bg
;
23 framebuffer::color halo
;
25 fb_object(const params
& _p
, const std::string
& _msg
);
27 void operator()(struct framebuffer::fb
<false>& scr
) throw();
28 void operator()(struct framebuffer::fb
<true>& scr
) throw();
29 void clone(framebuffer::queue
& q
) const throw(std::bad_alloc
);
31 template<bool ext
> void draw(struct framebuffer::fb
<ext
>& scr
) throw();
36 fb_object::fb_object(const fb_object::params
& _p
, const std::string
& _msg
)
39 msg
= utf8::to32(_msg
);
42 fb_object::~fb_object() throw() {}
43 void fb_object::operator()(struct framebuffer::fb
<false>& scr
) throw() { draw(scr
); }
44 void fb_object::operator()(struct framebuffer::fb
<true>& scr
) throw() { draw(scr
); }
46 void fb_object::clone(framebuffer::queue
& q
) const throw(std::bad_alloc
) { q
.clone_helper(this); }
48 template<bool ext
> void fb_object::draw(struct framebuffer::fb
<ext
>& scr
) throw()
50 p
.x
+= scr
.get_origin_x();
51 p
.y
+= scr
.get_origin_y();
53 p
.x
+= scr
.get_last_blit_width();
55 p
.y
+= scr
.get_last_blit_height();
56 p
.fg
.set_palette(scr
);
57 p
.bg
.set_palette(scr
);
58 p
.halo
.set_palette(scr
);
60 bool has_halo
= p
.halo
;
65 int64_t max_drawx
= p
.x
;
66 for(size_t i
= 0; i
< msg
.size();) {
68 std::u32string k
= p
.font
->best_ligature_match(msg
, i
);
69 const framebuffer::font2::glyph
& glyph
= p
.font
->lookup_glyph(k
);
75 drawx
= (drawx
+ 64) >> 6 << 6;
78 drawy
+= p
.font
->get_rowadvance();
81 max_drawx
= max(max_drawx
, drawx
);
84 uint64_t width
= max_drawx
- p
.x
;
85 uint64_t height
= drawy
- p
.y
;
96 else if(drawx
+ width
> scr
.get_width())
97 drawx
= scr
.get_width() - width
;
102 else if(drawy
+ height
> scr
.get_height())
103 drawy
= scr
.get_height() - height
;
110 for(size_t i
= 0; i
< msg
.size();) {
111 uint32_t cp
= msg
[i
];
112 std::u32string k
= p
.font
->best_ligature_match(msg
, i
);
113 const framebuffer::font2::glyph
& glyph
= p
.font
->lookup_glyph(k
);
119 drawx
= (drawx
+ 64) >> 6 << 6;
120 } else if(cp
== 10) {
122 drawy
+= p
.font
->get_rowadvance();
124 glyph
.render(scr
, drawx
, drawy
, p
.fg
, p
.bg
, p
.halo
);
125 drawx
+= glyph
.width
;
131 output_fb::output_fb()
136 output_fb::~output_fb()
142 void output_fb::set_rqueue(framebuffer::queue
& rqueue
)
147 void output_fb::set_dtor_cb(std::function
<void(output_fb
&)> cb
)
152 void output_fb::show(const std::string
& iname
, const std::string
& val
)
158 auto e
= enabled
->evaluate();
159 if(!e
.type
->toboolean(e
._value
))
164 auto x
= pos_x
->evaluate();
165 auto y
= pos_y
->evaluate();
166 p
.x
= x
.type
->tosigned(x
._value
);
167 p
.y
= y
.type
->tosigned(y
._value
);
168 p
.alt_origin_x
= alt_origin_x
;
169 p
.alt_origin_y
= alt_origin_y
;
170 p
.cliprange_x
= cliprange_x
;
171 p
.cliprange_y
= cliprange_y
;
176 queue
->create_add
<fb_object
>(p
, val
);
181 void output_fb::reset()