aboutsummaryrefslogtreecommitdiff
path: root/src/labeller.h
blob: cf108f5b4ffec8bd87757bd2b0d54ec46ff183c6 (plain)
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
#pragma once
#include <memory>
#include <vector>
#include <string>
#include <utility>
#include <filesystem>

namespace backend {
    struct labeller_impl;

    struct rect {
        int x1=0, x2=0, y1=0, y2=0;
        bool nonzero() const {
            return (x1 != 0 || x1 != 0 || y1 != 0 || y2 != 0);
        }
    };

    struct label {
        label() {}
        label(const std::string& name, double time) : name(name), time(time) {}
        std::string name;
        double time;
        rect location;
    };

    class labeller {
        public:
            labeller(const std::filesystem::path& savepath);
            std::pair<label, label> getSurrounding(double time) const;
            std::vector<label>& getEditableLabels();
            std::vector<std::string> getLabels() const;
            std::vector<std::string> getRectangleLabels() const;
            void applyLabel(std::string name, double time);
            void deleteLabel(double time); // Deletes closest to time, last added if ties
            void undo();
            void redo();
            void save() const;

        private:
            std::shared_ptr<labeller_impl> data;
    };
}