summaryrefslogtreecommitdiff
path: root/main.h
diff options
context:
space:
mode:
Diffstat (limited to 'main.h')
-rw-r--r--main.h513
1 files changed, 513 insertions, 0 deletions
diff --git a/main.h b/main.h
new file mode 100644
index 0000000..9b855b5
--- /dev/null
+++ b/main.h
@@ -0,0 +1,513 @@
+enum source_type {
+ source_none,
+ source_video,
+ source_image
+};
+
+struct pixel_buffer {
+ void *OriginalBuffer;
+ void *EffectBuffer;
+ void *Scratch;
+ uint16 Width;
+ uint16 Height;
+ uint16 Pitch;
+#if PACKEDRGB
+#else
+ uint32 Channel;
+#endif
+ uint16 BytesPerPixel;
+ bool32 ToUpdate; // Set whenever effects or video frames need to be updated.
+};
+
+struct av_info {
+ AVFormatContext *FileFormatContext;
+ AVCodecParameters *VideoCodecParameters;
+ const AVCodec* VideoCodec;
+ const AVCodecHWConfig* VideoHWConfig;
+ AVPixelFormat HWPixFormat;
+ AVCodecContext *VideoCodecContext;
+ AVPacket *VideoPacket;
+ AVFrame *VideoFrame;
+ AVStream *VideoStream;
+ SwsContext *RGBContext;
+
+ uint16 StreamIndex;
+ real32 FPS;
+ int32 IntFPS;
+ real32 AvgPTSPerSecond;
+ real32 AvgPTSPerFrame;
+ uint64 LastPTS;
+};
+
+struct cache {
+ void *Address;
+ bool32 Cached;
+};
+
+enum whattocallthis {
+ Inactive,
+ Active,
+ Clear
+};
+
+struct cache_pool {
+ cache Frame[2048];
+ cache Intermediate[3];
+ whattocallthis Interact;
+ int16 InteractIndex;
+};
+
+enum memory_table_list {
+
+ // F = file attributes
+ // P = persistent data, but not file-based
+ // B = cached data, often cleared
+
+ F_ProjectSettings,
+ // The majority bloat from these two are the properties.
+ F_Layers,
+ F_Effects,
+ F_Keyframes,
+ F_Strings,
+
+ P_UIState,
+ P_SourceData,
+
+ B_Scratch,
+};
+
+struct memory_table {
+ char *Name;
+ void *Address;
+ uint64 CurrentPosition;
+ uint64 Size;
+};
+
+struct global_memory {
+ void *Address;
+ uint64 CurrentPosition;
+ uint64 Size;
+};
+
+struct memory {
+ memory_table Slot[16];
+};
+
+struct property_channel;
+struct project_layer;
+
+enum display_type
+{
+ standard,
+ levels
+};
+
+enum keyframe_type
+{
+ linear,
+ bezier,
+ hold
+};
+
+// NOTE(fox): One val slot holds 16 bytes of data.
+
+enum var_type
+{
+ type_real,
+ type_color,
+ type_blendmode
+};
+
+
+global_variable char* BlendmodeNames[] = {
+ "Normal",
+ "Multiply",
+ "Color Burn",
+ "Linear Burn",
+ "Add",
+ "Screen",
+ "Overlay",
+ "Soft Light",
+ "Hard Light",
+ "Subtract",
+ "Divide",
+ "Difference"
+};
+
+enum blend_mode
+{
+ blend_normal,
+ blend_multiply,
+ blend_colorburn,
+ blend_linearburn,
+ blend_add,
+ blend_screen,
+ blend_overlay,
+ blend_softlight,
+ blend_hardlight,
+ blend_subtract,
+ blend_divide,
+ blend_difference
+};
+
+union val {
+ real32 f;
+ v4 col;
+ blend_mode blendmode;
+};
+
+struct keyframe {
+ val Value;
+ uint16 FrameNumber;
+ keyframe_type Type;
+ bool32 IsSelected;
+ // The X coordinate for the tangent is in keyframes, and the Y is in units.
+ // Probably should think of something smarter.
+ v2 TangentLeft;
+ v2 TangentRight;
+};
+
+struct keyframe_block {
+ keyframe Keyframe[MAX_KEYFRAMES_PER_BLOCK];
+};
+
+struct property_channel {
+ char *Name;
+ keyframe_block *KeyframeBlock[MAX_KEYFRAME_BLOCKS];
+ uint16 SortedIndex[MAX_KEYFRAMES_PER_BLOCK * MAX_KEYFRAME_BLOCKS];
+ uint16 NumberOfKeyframeBlocks;
+ uint16 NumberOfSelectedKeyframes;
+ uint16 NumberOfTotalKeyframes;
+ val CurrentValue;
+ val MaxVal;
+ val MinVal;
+ val ScrubVal; // increment when dragging on sliders, etc.
+ var_type VarType;
+
+ // TODO(fox): Probably shouldn't store these in the file...
+ // UI
+ val LocalMaxVal;
+ val LocalMinVal;
+ bool32 IsToggled;
+ bool32 IsGraphToggled;
+ real32 GraphLength; // represented in actual screen pixels
+ real32 GraphYOffset;
+ // The size of the window enclosing the graph
+ uint16 GraphWindowHeight;
+};
+
+struct property_header
+{
+ char *Name;
+ val Value;
+ var_type VarType;
+ val MinVal;
+ val MaxVal;
+};
+
+struct effect_header
+{
+ char *Name;
+ void (*func)(pixel_buffer *, memory *, property_channel []);
+ uint16 NumberOfProperties;
+ display_type DisplayType;
+ property_header PropertyHeader[MAX_PROPERTIES_PER_EFFECT];
+};
+
+struct effect {
+ char *Name;
+ void (*func)(pixel_buffer *, memory *, property_channel []);
+ uint16 NumberOfProperties;
+ display_type DisplayType;
+ property_channel Property[MAX_PROPERTIES_PER_EFFECT];
+ bool32 UIIsCollapsed = 0;
+ bool32 IsActive = 1;
+};
+
+
+// Note how pixel_buffer is first in both so we can cast to image_source if we
+// don't care about the AV info.
+
+struct video_source {
+ struct pixel_buffer Raster;
+ av_info AV;
+ int32 VideoFrameOffset; // the "true" position of video layers, separate from StartFrame
+ int32 VideoCurrentFrame;
+};
+
+struct image_source {
+ struct pixel_buffer Raster;
+};
+
+struct transform_info {
+ real32 XAxisPX;
+ real32 XAxisPY;
+ real32 YAxisPX;
+ real32 YAxisPY;
+ real32 LayerWidth;
+ real32 LayerHeight;
+ real32 LayerOpacity;
+ real32 OriginX;
+ real32 OriginY;
+ uint32 BufferPitch;
+ uint32 LayerPitch;
+ rectangle ClipRect;
+ void *SourceBuffer;
+};
+
+struct project_layer {
+ char *Name;
+ blend_mode BlendMode;
+
+ union
+ {
+ property_channel Property[8];
+ struct
+ {
+ property_channel x;
+ property_channel y;
+ property_channel ax;
+ property_channel ay;
+ property_channel rotation;
+ property_channel scale;
+ property_channel opacity;
+ property_channel time;
+ };
+ };
+
+ bool32 IsSelected;
+
+ void *RenderInfo;
+ source_type SourceType;
+
+ effect *Effect[MAX_EFFECTS];
+ uint16 NumberOfEffects;
+
+ uint16 StartFrame;
+ uint16 EndFrame;
+
+ uint32 LayerColor;
+
+ // For rendering
+ transform_info TransformInfo;
+};
+
+// NOTE(fox): I have no idea how people normally do selection; currently I'm
+// treating it more "immediate." Instead of updating a selection state as
+// things are selected, I'm just calling functions that go through all the
+// layers and keyframes to look for the IsSelected bool. If this causes
+// lag I'll switch it to the former.
+
+struct temp_layer_list {
+ int16 LayerIndex[MAX_LAYERS];
+};
+
+struct temp_keyframe_list {
+ keyframe *SelectedKeyframe[50];
+ uint16 Amount;
+};
+
+struct project_data
+{
+ uint16 Width;
+ uint16 Height;
+ uint16 FPS;
+ uint16 NumberOfFrames;
+ uint16 StartFrame;
+ uint16 EndFrame;
+ int16 CurrentFrame;
+
+ // NOTE(fox): Currently I'm handling layer sorting by just saying that
+ // their order in memory is the order of the index and manually moving
+ // their positions.
+
+ project_layer *Layer[MAX_LAYERS];
+ uint16 NumberOfSelectedLayers;
+ uint16 NumberOfLayers;
+
+ char *Source[MAX_SOURCES];
+ uint16 NumberOfSources;
+};
+
+enum tool {
+ DefaultSelect,
+ BrushTool,
+ CropTool,
+ BoxSelect,
+ QuickSelect,
+ PenTool
+};
+
+enum transforms_hotkey_interact {
+ sliding_position,
+ sliding_anchorpoint,
+ sliding_scale,
+ sliding_rotation
+};
+
+struct main_sdl
+{
+ pixel_buffer Buffer;
+ SDL_Texture *Texture;
+ SDL_Event Event;
+ SDL_Window *Window;
+ SDL_Renderer *Renderer;
+};
+
+// used to determine what to copy/paste, delete, etc
+enum selection_type
+{
+ selection_none,
+ selection_layer,
+ selection_effect,
+ selection_keyframe,
+};
+
+struct project_state
+{
+ bool32 UpdateKeyframes = 1;
+ bool32 UpdateFrame = 1; // only refreshes frame; set UpdateKeyframes to update animation
+ bool32 DebugDisableCache = 1;
+ tool Tool = DefaultSelect;
+
+ uint16 LayersToRender[MAX_LAYERS];
+ uint16 NumberOfLayersToRender;
+
+ bool32 IsRunning = 1;
+ bool32 IsPlaying;
+
+ uint16 NumberOfSelectedLayers;
+ int16 MostRecentlySelectedLayer = -1; // convenience for the properties panel
+ selection_type RecentSelectionType = selection_none;
+
+ bool32 IsInteracting;
+ transforms_hotkey_interact TransformsHotkeyInteract;
+
+ int32 MsgTime; // currently in "frames"
+ char *Msg;
+};
+
+struct brush_tool
+{
+ real32 Size;
+ real32 Opacity;
+ real32 Hardness;
+};
+
+enum focused_window
+{
+ focus_viewport,
+ focus_properties,
+ focus_timeline
+};
+
+struct ui
+{
+ real32 TimelineSplit = 200;
+ real32 TimelineZoom;
+
+ ImVec2 CompZoom;
+ ImVec2 CompPos;
+
+ // Used to set UI values on the first frame. Some UI setup in Docking takes
+ // more than 1 frame for some reason, so I'm temporarily extending it.
+ bool32 Initializing = 4;
+
+ // Custom scrolling for the timeline, as ImGui's didn't work well
+ real32 ScrollXOffset;
+ real32 ScrollYOffset;
+
+ // NOTE(fox): Keeping track of mouse delta myself since the ImGui threshold
+ // dragging API doesn't let you do things like subtract the delta easily.
+ real32 DraggingKeyframeThreshold;
+ real32 DraggingLayerThreshold;
+ real32 DraggingTimelineThreshold;
+ real32 KeyframeSpacing = 6;
+
+ ImVec2 BoxStart = ImVec2(0,0);
+ ImVec2 BoxEnd = ImVec2(0,0);
+ bool32 BoxSelectActive = false;
+
+ // Temporary varibles used when zooming in/out
+ v2 TempZoomRatio = V2(1, 1);
+ real32 TempZoomRatioTimeline = 0;
+ real32 TempZoomRatioGraph = 0;
+
+ focused_window FocusedWindow; // Convenience for adding window-specific hotkeys.
+
+ bool32 TemporaryUpdateOverride;
+};
+
+struct imgui_buttonstate
+{
+ bool32 IsItemHovered;
+ bool32 IsItemActive;
+ bool32 IsItemActivated;
+ bool32 IsItemDeactivated;
+ bool32 LeftClick;
+ bool32 RightClick;
+};
+
+struct timeline_properties
+{
+ rectangle Timeline;
+
+ v2i MainWindow;
+ uint16 WindowPadding;
+
+ rectangle EffectPanel;
+
+ rectangle Toolbar;
+ rectangle ColorPanel;
+
+ bool32 RenderSlidingBrush;
+
+ uint16 CompX;
+ uint16 CompY;
+ uint16 TimelineZoom;
+ uint16 CompScale;
+ uint16 FramePadding;
+ uint16 LayerPadding;
+ uint16 TimelineCurrentFrame;
+ int16 TimelineCurrentLayer;
+ uint16 InfoTimelineSplit;
+ bool32 DrawTimeline;
+ bool32 DrawEffectPanel;
+ bool32 DrawComp;
+};
+
+struct sdl_button
+{
+ bool32 IsDown;
+ bool32 SingleClick; // More precisely, when button is released and no dragging/selecting events are happening.
+ int HeldLength;
+};
+
+struct sdl_input
+{
+ v2i Mouse;
+ sdl_button MouseButton[3];
+ rectangle Selection;
+};
+
+struct render_queue
+{
+ project_data *File;
+ project_state *State;
+ pixel_buffer *CompBuffer;
+};
+
+struct thread_info
+{
+ render_queue *RenderInfo;
+ uint16 Index;
+};
+
+struct work_queue_entry {
+ char *StringToPrint;
+};
+
+struct render_entry {
+ rectangle RenderRegion;
+};
+