~aleteoryx/muditaos

ref: 2276ceed679b93a3a891e4f5739ade9e13991c5a muditaos/module-services/service-eink/board/linux/renderer/src/RArea.cpp -rw-r--r-- 1.6 KiB
2276ceed — Radoslaw Wicik [EGD-3743] Update copyrights in fies 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * RArea.cpp
 *
 *  Created on: 24 kwi 2019
 *      Author: robert
 */
#include <gtkmm.h>
#include <cairomm/context.h>
#include <gdkmm/pixbuf.h>
#include "RArea.hpp"

RArea::RArea() : data{nullptr}
{}

RArea::~RArea()
{}

bool RArea::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
    if (data != nullptr) {
        Glib::RefPtr<Gdk::Pixbuf> image = Gdk::Pixbuf::create_from_data(reinterpret_cast<guchar *>(data),
                                                                        Gdk::COLORSPACE_RGB, // GdkColorspace
                                                                        false,               // has_alpha
                                                                        8,                   // bits_per_sample
                                                                        480,                 // width
                                                                        600,                 // height,
                                                                        3 * 480);            // rowstride,

        Gtk::Allocation allocation = get_allocation();
        const int width            = allocation.get_width();
        const int height           = allocation.get_height();

        // Draw the image in the middle of the drawing area
        Gdk::Cairo::set_source_pixbuf(cr, image, (width - image->get_width()) / 2, (height - image->get_height()) / 2);

        cr->paint();
        return true;
    }
    return false;
}