update ffmpeg to 4.1, add sketcher plugin, crikey tweaks, titler colorpicker, keyfram...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / undostack.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef UNDOSTACK_H
23 #define UNDOSTACK_H
24
25 #include <stdio.h>
26 #include <stdint.h>
27
28 #include "linklist.h"
29 #include "stringfile.inc"
30
31 #define UNDOLEVELS 500
32 #define UNDO_KEY_INTERVAL 100
33
34
35 #define hash_sz2 8
36 #define hash_sz  (1<<hash_sz2)
37 #define hash_sz1 (hash_sz-1)
38 #define va 0
39 #define vb 1
40
41 class UndoHash
42 {
43 public:
44         UndoHash(char *txt, int len, UndoHash *nxt);
45         ~UndoHash();
46
47         UndoHash *nxt;
48         char *txt;  int len;
49         int line[2], occurs[2];
50 };
51
52 class UndoHashTable
53 {
54 public:
55         UndoHashTable();
56         ~UndoHashTable();
57         UndoHash *add(char *txt, int len);
58
59         UndoHash *table[hash_sz];
60         UndoHash *bof, *eof;
61 };
62
63 class UndoLine
64 {
65 public:
66         UndoLine(UndoHash *hash, char *tp);
67         UndoLine(UndoHashTable *hash, char *txt, int len);
68         ~UndoLine();
69         int eq(UndoLine *ln);
70
71         char *txt;  int len;
72         UndoHash *hash;
73 };
74
75 class UndoVersion : public ArrayList<UndoLine *>
76 {
77 public:
78         UndoVersion(int v) { ver = v; }
79         ~UndoVersion() { remove_all_objects(); }
80         int ver;
81
82         void scan_lines(UndoHashTable *hash, char *sp, char *ep);
83 };
84
85
86 class UndoStackItem : public ListItem<UndoStackItem>
87 {
88 public:
89         UndoStackItem();
90         ~UndoStackItem();
91
92 // Must be inserted into the list before calling this, so it can get the
93 // previous key buffer.
94         void set_data(char *data);
95         void set_description(char *description);
96         void set_filename(char *filename);
97         const char* get_description();
98         void set_flags(uint64_t flags);
99
100 // Decompress the buffers and return them in a newly allocated string.
101 // The string must be deleted by the user.
102         char* get_data();
103         char* get_filename();
104         int get_size();
105         int is_key();
106         uint64_t get_flags();
107
108         void set_creator(void *creator);
109         void* get_creator();
110
111         void save(FILE *fp);
112         void load(FILE *fp);
113 private:
114 // command description for the menu item
115         char *description;
116
117 // key undo buffer or incremental undo buffer
118         int key;
119
120 // type of modification
121         uint64_t load_flags;
122
123 // data after the modification for redos
124         char *data;
125         int data_size;
126
127 // pointer to the object which set this undo buffer
128         void *creator;
129
130         char *session_filename;
131 };
132
133 class UndoStack : public List<UndoStackItem>
134 {
135 public:
136         UndoStack();
137         ~UndoStack();
138
139 // get current undo/redo stack item
140         UndoStackItem *get_current_undo();
141         UndoStackItem *get_current_redo();
142
143 // Create a new undo entry and put on the stack.
144 // The current pointer points to the new entry.
145 // delete future undos if in the middle
146 // delete undos older than UNDOLEVELS if last
147         UndoStackItem* push();
148
149 // move to the next undo entry for a redo
150         UndoStackItem* pull_next();
151
152         void save(FILE *fp);
153         void load(FILE *fp);
154         void dump(FILE *fp=stdout);
155
156         UndoStackItem* current;
157 };
158
159 #endif