1 #include "memorywatch-fb.hpp"
7 struct memorywatch_fb_object
: public framebuffer::object
17 framebuffer::font2
* font
;
18 framebuffer::color fg
;
19 framebuffer::color bg
;
20 framebuffer::color halo
;
22 memorywatch_fb_object(const params
& _p
, const std::string
& _msg
);
23 ~memorywatch_fb_object() throw();
24 void operator()(struct framebuffer::fb
<false>& scr
) throw();
25 void operator()(struct framebuffer::fb
<true>& scr
) throw();
26 void clone(framebuffer::queue
& q
) const throw(std::bad_alloc
);
28 template<bool ext
> void draw(struct framebuffer::fb
<ext
>& scr
) throw();
33 memorywatch_fb_object::memorywatch_fb_object(const memorywatch_fb_object::params
& _p
, const std::string
& _msg
)
36 msg
= utf8::to32(_msg
);
39 memorywatch_fb_object::~memorywatch_fb_object() throw() {}
40 void memorywatch_fb_object::operator()(struct framebuffer::fb
<false>& scr
) throw() { draw(scr
); }
41 void memorywatch_fb_object::operator()(struct framebuffer::fb
<true>& scr
) throw() { draw(scr
); }
43 void memorywatch_fb_object::clone(framebuffer::queue
& q
) const throw(std::bad_alloc
) { q
.clone_helper(this); }
45 template<bool ext
> void memorywatch_fb_object::draw(struct framebuffer::fb
<ext
>& scr
) throw()
47 p
.x
+= scr
.get_origin_x();
48 p
.y
+= scr
.get_origin_y();
50 p
.x
+= scr
.get_last_blit_width();
52 p
.y
+= scr
.get_last_blit_height();
53 p
.fg
.set_palette(scr
);
54 p
.bg
.set_palette(scr
);
55 p
.halo
.set_palette(scr
);
57 bool has_halo
= p
.halo
;
62 int64_t max_drawx
= p
.x
;
63 for(size_t i
= 0; i
< msg
.size();) {
65 std::u32string k
= p
.font
->best_ligature_match(msg
, i
);
66 const framebuffer::font2::glyph
& glyph
= p
.font
->lookup_glyph(k
);
72 drawx
= (drawx
+ 64) >> 6 << 6;
75 drawy
+= p
.font
->get_rowadvance();
78 max_drawx
= max(max_drawx
, drawx
);
81 uint64_t width
= max_drawx
- p
.x
;
82 uint64_t height
= drawy
- p
.y
;
93 else if(drawx
+ width
> scr
.get_width())
94 drawx
= scr
.get_width() - width
;
99 else if(drawy
+ height
> scr
.get_height())
100 drawy
= scr
.get_height() - height
;
107 for(size_t i
= 0; i
< msg
.size();) {
108 uint32_t cp
= msg
[i
];
109 std::u32string k
= p
.font
->best_ligature_match(msg
, i
);
110 const framebuffer::font2::glyph
& glyph
= p
.font
->lookup_glyph(k
);
116 drawx
= (drawx
+ 64) >> 6 << 6;
117 } else if(cp
== 10) {
119 drawy
+= p
.font
->get_rowadvance();
121 glyph
.render(scr
, drawx
, drawy
, p
.fg
, p
.bg
, p
.halo
);
122 drawx
+= glyph
.width
;
128 memorywatch_output_fb::memorywatch_output_fb()
133 memorywatch_output_fb::~memorywatch_output_fb()
139 void memorywatch_output_fb::set_rqueue(framebuffer::queue
& rqueue
)
144 void memorywatch_output_fb::set_dtor_cb(std::function
<void(memorywatch_output_fb
&)> cb
)
149 void memorywatch_output_fb::show(const std::string
& iname
, const std::string
& val
)
151 memorywatch_fb_object::params p
;
155 auto e
= enabled
->evaluate();
156 if(!e
.type
->toboolean(e
.value
))
161 auto x
= pos_x
->evaluate();
162 auto y
= pos_y
->evaluate();
163 p
.x
= x
.type
->tosigned(x
.value
);
164 p
.y
= y
.type
->tosigned(y
.value
);
165 p
.alt_origin_x
= alt_origin_x
;
166 p
.alt_origin_y
= alt_origin_y
;
167 p
.cliprange_x
= cliprange_x
;
168 p
.cliprange_y
= cliprange_y
;
173 queue
->create_add
<memorywatch_fb_object
>(p
, val
);
178 void memorywatch_output_fb::reset()