1 // Copyright (c) 2015 Sergio Gonzalez. All rights reserved.
2 // License: https://github.com/serge-rgb/milton#license
3 
4 // StrokeList
5 //
6 // - Works as a dynamically-sized array for Strokes.
7 // - Pointers to elements in the StrokeList stay valid for the lifetime of the program.
8 
9 
10 #pragma once
11 
12 #include "stroke.h"
13 
14 #include "memory.h"
15 
16 #define STROKELIST_BUCKET_COUNT 4196
17 
18 struct StrokeBucket
19 {
20     Stroke          data[STROKELIST_BUCKET_COUNT];
21     StrokeBucket*   next;
22     Rect            bounding_rect;
23 };
24 
25 struct StrokeList
26 {
27     StrokeBucket    root;
28     i64             count;
29     Stroke*         operator[](i64 i);
30 
31     Arena*          arena;
32 };
33 
34 void strokelist_init_bucket(StrokeBucket* bucket);
35 
36 void push(StrokeList* list, const Stroke& element);
37 Stroke* get(StrokeList* list, i64 idx);
38 Stroke pop(StrokeList* list);
39 Stroke* peek(StrokeList* list);
40 void reset(StrokeList* list);
41 i64 count(StrokeList* list);
42 
43 struct StrokeIterator;
44 
45 Stroke* stroke_iter_init(StrokeList* list, StrokeIterator* iter);
46 Stroke* stroke_iter_next(StrokeIterator* iter);