| 1 | // MIT License |
| 2 | |
| 3 | // Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com |
| 4 | |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | // of this software and associated documentation files (the "Software"), to deal |
| 7 | // in the Software without restriction, including without limitation the rights |
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | // copies of the Software, and to permit persons to whom the Software is |
| 10 | // furnished to do so, subject to the following conditions: |
| 11 | |
| 12 | // The above copyright notice and this permission notice shall be included in all |
| 13 | // copies or substantial portions of the Software. |
| 14 | |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | // SOFTWARE. |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #include "studio/studio.h" |
| 26 | |
| 27 | typedef struct Code Code; |
| 28 | |
| 29 | struct Code |
| 30 | { |
| 31 | Studio* studio; |
| 32 | tic_mem* tic; |
| 33 | |
| 34 | char* src; |
| 35 | |
| 36 | struct |
| 37 | { |
| 38 | struct |
| 39 | { |
| 40 | char* position; |
| 41 | char* selection; |
| 42 | s32 column; |
| 43 | }; |
| 44 | |
| 45 | char* mouseDownPosition; |
| 46 | s32 delay; |
| 47 | } cursor; |
| 48 | |
| 49 | struct |
| 50 | { |
| 51 | s32 x; |
| 52 | s32 y; |
| 53 | |
| 54 | tic_point start; |
| 55 | |
| 56 | bool active; |
| 57 | |
| 58 | } scroll; |
| 59 | |
| 60 | struct CodeState |
| 61 | { |
| 62 | struct |
| 63 | { |
| 64 | u8 syntax:3; |
| 65 | u8 bookmark:1; |
| 66 | u8 cursor:1; |
| 67 | u8 temp:3; |
| 68 | }; |
| 69 | |
| 70 | char sym; |
| 71 | }* state; |
| 72 | |
| 73 | struct |
| 74 | { |
| 75 | char line[STUDIO_TEXT_BUFFER_WIDTH]; |
| 76 | char size[STUDIO_TEXT_BUFFER_WIDTH]; |
| 77 | tic_color color; |
| 78 | }status; |
| 79 | |
| 80 | u32 tickCounter; |
| 81 | |
| 82 | struct History* history; |
| 83 | |
| 84 | enum |
| 85 | { |
| 86 | TEXT_DRAG_CODE, |
| 87 | TEXT_FIND_MODE, |
| 88 | TEXT_GOTO_MODE, |
| 89 | TEXT_BOOKMARK_MODE, |
| 90 | TEXT_OUTLINE_MODE, |
| 91 | TEXT_EDIT_MODE, |
| 92 | } mode; |
| 93 | |
| 94 | struct |
| 95 | { |
| 96 | char text[STUDIO_TEXT_BUFFER_WIDTH - sizeof "FIND:" ]; |
| 97 | |
| 98 | char* prevPos; |
| 99 | char* prevSel; |
| 100 | } ; |
| 101 | |
| 102 | struct |
| 103 | { |
| 104 | s32 line; |
| 105 | } jump; |
| 106 | |
| 107 | struct |
| 108 | { |
| 109 | tic_outline_item* items; |
| 110 | |
| 111 | s32 size; |
| 112 | s32 index; |
| 113 | s32 scroll; |
| 114 | } ; |
| 115 | |
| 116 | const char* matchedDelim; |
| 117 | bool altFont; |
| 118 | bool shadowText; |
| 119 | |
| 120 | struct |
| 121 | { |
| 122 | s32 pos; |
| 123 | s32 ; |
| 124 | |
| 125 | Movie* movie; |
| 126 | |
| 127 | Movie idle; |
| 128 | Movie show; |
| 129 | Movie hide; |
| 130 | |
| 131 | } anim; |
| 132 | |
| 133 | void(*tick)(Code*); |
| 134 | void(*escape)(Code*); |
| 135 | void(*event)(Code*, StudioEvent); |
| 136 | void(*update)(Code*); |
| 137 | }; |
| 138 | |
| 139 | void initCode(Code*, Studio* studio); |
| 140 | void freeCode(Code*); |
| 141 | |