-
Notifications
You must be signed in to change notification settings - Fork 10
/
stroke_history.h
65 lines (50 loc) · 1.85 KB
/
stroke_history.h
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
//---------------------------------------------------------------------------
#pragma once
#include "cyclic_queue.h"
#include "state.h"
#include "stroke.h"
#include <assert.h>
//---------------------------------------------------------------------------
class StenoSegmentList;
//---------------------------------------------------------------------------
struct StenoStrokeHistoryEntry {
StenoStroke stroke;
StenoState state;
size_t conversionCount;
void Set(StenoStroke stroke, StenoState state, size_t conversionCount) {
this->stroke = stroke;
this->state = state;
this->conversionCount = conversionCount;
}
};
//---------------------------------------------------------------------------
const size_t STENO_STROKE_HISTORY_SIZE = 256;
class StenoStrokeHistory
: public CyclicQueue<StenoStrokeHistoryEntry, STENO_STROKE_HISTORY_SIZE> {
public:
void PruneIfFull() {
if (IsFull()) {
Prune();
}
}
void Add(StenoStroke stroke, StenoState state, size_t conversionCount) {
assert(IsNotFull());
CyclicQueue::Add().Set(stroke, state, conversionCount);
}
// When undo is pressed, returns how many items should be removed
// from the list up to maxCount.
size_t GetUndoCount(size_t maxCount) const;
void UpdateDefinitionBoundaries(size_t startingOffset,
const StenoSegmentList &segments);
size_t GetStartingStroke(size_t maximumCount) const;
// Returns the offset of the word start. result <= index.
size_t GetIndexOfWordStart(size_t index) const;
void SetBackCombineUndo() { Back().state.shouldCombineUndo = true; }
void SetBackNoCombineUndo() { Back().state.shouldCombineUndo = false; }
void SetBackHasManualStateChange() {
Back().state.isManualStateChange = true;
}
private:
void Prune();
};
//---------------------------------------------------------------------------