1 #include "framebuffer-font2.hpp"
2 #include "memorywatch-fb.hpp"
11 struct fb_object
: public framebuffer::object
21 framebuffer::font2
* font
;
22 framebuffer::color fg
;
23 framebuffer::color bg
;
24 framebuffer::color halo
;
26 fb_object(const params
& _p
, const std::string
& _msg
);
28 void operator()(struct framebuffer::fb
<false>& scr
) throw();
29 void operator()(struct framebuffer::fb
<true>& scr
) throw();
30 void clone(framebuffer::queue
& q
) const throw(std::bad_alloc
);
32 template<bool ext
> void draw(struct framebuffer::fb
<ext
>& scr
) throw();
37 fb_object::fb_object(const fb_object::params
& _p
, const std::string
& _msg
)
40 msg
= utf8::to32(_msg
);
43 fb_object::~fb_object() throw() {}
44 void fb_object::operator()(struct framebuffer::fb
<false>& scr
) throw() { draw(scr
); }
45 void fb_object::operator()(struct framebuffer::fb
<true>& scr
) throw() { draw(scr
); }
47 void fb_object::clone(framebuffer::queue
& q
) const throw(std::bad_alloc
) { q
.clone_helper(this); }
49 template<bool ext
> void fb_object::draw(struct framebuffer::fb
<ext
>& scr
) throw()
51 p
.x
+= scr
.get_origin_x();
52 p
.y
+= scr
.get_origin_y();
54 p
.x
+= scr
.get_last_blit_width();
56 p
.y
+= scr
.get_last_blit_height();
57 p
.fg
.set_palette(scr
);
58 p
.bg
.set_palette(scr
);
59 p
.halo
.set_palette(scr
);
61 bool has_halo
= p
.halo
;
66 int64_t max_drawx
= p
.x
;
67 for(size_t i
= 0; i
< msg
.size();) {
69 std::u32string k
= p
.font
->best_ligature_match(msg
, i
);
70 const framebuffer::font2::glyph
& glyph
= p
.font
->lookup_glyph(k
);
76 drawx
= (drawx
+ 64) >> 6 << 6;
79 drawy
+= p
.font
->get_rowadvance();
82 max_drawx
= max(max_drawx
, drawx
);
85 uint64_t width
= max_drawx
- p
.x
;
86 uint64_t height
= drawy
- p
.y
;
97 else if(drawx
+ width
> scr
.get_width())
98 drawx
= scr
.get_width() - width
;
103 else if(drawy
+ height
> scr
.get_height())
104 drawy
= scr
.get_height() - height
;
111 for(size_t i
= 0; i
< msg
.size();) {
112 uint32_t cp
= msg
[i
];
113 std::u32string k
= p
.font
->best_ligature_match(msg
, i
);
114 const framebuffer::font2::glyph
& glyph
= p
.font
->lookup_glyph(k
);
120 drawx
= (drawx
+ 64) >> 6 << 6;
121 } else if(cp
== 10) {
123 drawy
+= p
.font
->get_rowadvance();
125 glyph
.render(scr
, drawx
, drawy
, p
.fg
, p
.bg
, p
.halo
);
126 drawx
+= glyph
.width
;
132 output_fb::output_fb()
137 output_fb::~output_fb()
143 void output_fb::set_rqueue(framebuffer::queue
& rqueue
)
148 void output_fb::set_dtor_cb(std::function
<void(output_fb
&)> cb
)
153 void output_fb::show(const std::string
& iname
, const std::string
& val
)
159 auto e
= enabled
->evaluate();
160 if(!e
.type
->toboolean(e
._value
))
165 auto x
= pos_x
->evaluate();
166 auto y
= pos_y
->evaluate();
167 p
.x
= x
.type
->tosigned(x
._value
);
168 p
.y
= y
.type
->tosigned(y
._value
);
169 p
.alt_origin_x
= alt_origin_x
;
170 p
.alt_origin_y
= alt_origin_y
;
171 p
.cliprange_x
= cliprange_x
;
172 p
.cliprange_y
= cliprange_y
;
177 queue
->create_add
<fb_object
>(p
, val
);
182 void output_fb::reset()