~aleteoryx/muditaos

ref: 402a7416378afb1864120c3aef3854bee610d457 muditaos/module-gui/gui/core/Context.hpp -rw-r--r-- 2.1 KiB
402a7416 — Piotr Tański [EGD-5026] Change Eink service code structure 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * Context.hpp
 *
 *  Created on: 6 maj 2019
 *      Author: robert
 */

#ifndef GUI_CORE_CONTEXT_HPP_
#define GUI_CORE_CONTEXT_HPP_

#include <cstdint>
#include <iostream>
#include "Common.hpp"

namespace gui
{

    class Context
    {
      protected:
        int16_t x, y;
        uint32_t w, h;
        uint8_t *data;

      public:
        Context();
        Context(uint16_t width, uint16_t height);
        virtual ~Context();

        /**
         * @brief Creates new context using provided coordinates. If there is no common part Context with 0 width and 0
         * height is returned.
         */
        Context *get(int16_t gx, int16_t gy, uint16_t width, uint16_t height);
        /**
         * @brief Pastes provided context into current one. Overlapping content will be inserted into current context.
         */
        void insert(int16_t ix, int16_t iy, Context *context);
        /**
         * @brief Pastes provided context into current one. Overlapping content will be inserted into current context.
         */
        void insertArea(
            int16_t ix, int16_t iy, int16_t iareaX, int16_t iareaY, int16_t iareaW, int16_t iareaH, Context *context);
        /**
         * @brief Fills whole context with specified colour;
         */
        void fill(uint8_t colour);
        /**
         * @brief returns pointer to context's data;
         */
        inline uint8_t *getData()
        {
            return data;
        };
        inline int16_t getX()
        {
            return x;
        };
        inline int16_t getY()
        {
            return y;
        };
        inline uint16_t getW()
        {
            return w;
        };
        inline uint16_t getH()
        {
            return h;
        };

        inline bool addressInData(const uint8_t *ptr) const
        {
            return (ptr >= data) && (ptr < data + w * h);
        }

        friend std::ostream &operator<<(std::ostream &out, const Context &c);
    };

} /* namespace gui */

#endif /* GUI_CORE_CONTEXT_HPP_ */