summaryrefslogtreecommitdiff
path: root/src/paint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/paint.cpp')
-rw-r--r--src/paint.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/paint.cpp b/src/paint.cpp
new file mode 100644
index 0000000..f3170e5
--- /dev/null
+++ b/src/paint.cpp
@@ -0,0 +1,103 @@
+
+static void
+SlidingBrush(pixel_buffer *Buffer, v2i Pos, brush_tool Brush)
+{
+ v2i Min = {0,0};
+ v2i Max = Min + (int16)Brush.Size;
+
+ v2 Center = {(real32)Max.x / 2.0f, (real32)Max.y / 2.0f};
+ real32 MaxLength = sqrt(LengthSq(Center));
+
+ v2i LayerMin = Pos - (Brush.Size / 2);
+ v2i LayerMax = Pos + (Brush.Size / 2);
+
+ rectangle LayerBounds = {0, 0, Buffer->Width, Buffer->Height};
+ rectangle Paint = ClipRectangle({LayerMin, LayerMax}, LayerBounds);
+
+ uint8 *Row = ((uint8 *)Buffer->OriginalBuffer + Buffer->Pitch*Paint.Min.y);
+ for(int Y = Paint.Min.y;
+ Y < Paint.Max.y;
+ ++Y)
+ {
+ uint32 *Pixel = (uint32 *)(Row + Paint.Min.x*sizeof(uint32));
+ for(int X = Paint.Min.x;
+ X < Paint.Max.x;
+ ++X)
+ {
+ v2 Pos = V2(abs(Center.x - (X - Paint.Min.x)), abs(Center.y - (Y - Paint.Min.y)));
+ real32 L = sqrt(LengthSq(Pos)) + Center.x;
+ real32 Gradient = pow(Ceil(L, MaxLength) / MaxLength, Brush.Hardness);
+ RenderAlpha(Pixel, ColToUint32({1.0f, 0.0f, 0.0f, 1.0f - Gradient}));
+ Pixel++;
+ }
+ Row += Buffer->Pitch;
+ }
+}
+
+/*
+static void
+Paint(sdl_input Input, project_layer *Layer, brush_tool Brush)
+{
+ int16 X = Input.Mouse.x - UI.CompX; // convert to comp space
+ int16 Y = Input.Mouse.y - UI.CompY;
+
+ real32 Rad = (Layer->rotation.CurrentValue.f * (PI / 180));
+ real32 s = Layer->scale.CurrentValue.f;
+ v2 Scale = {Layer->Raster.Width * s, Layer->Raster.Height * s};
+
+ v2 XAxis = (Layer->Raster.Width * s)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Layer->Raster.Height * -s)*V2(sin(Rad), -cos(Rad));
+
+ real32 AnchorX = Layer->ax.CurrentValue.f;
+ real32 AnchorY = Layer->ay.CurrentValue.f;
+
+ v2 Pos = {Layer->x.CurrentValue.f, Layer->y.CurrentValue.f};
+ v2 Origin = Pos - (XAxis * AnchorX) - (YAxis * AnchorY);
+
+ real32 XLengthSq = 1.0f / LengthSq(XAxis);
+ real32 YLengthSq = 1.0f / LengthSq(YAxis);
+
+ v2 CurrentPixel = V2(X, Y);
+ v2 StartVector = CurrentPixel - Origin;
+
+ real32 U = XLengthSq*Inner(StartVector, XAxis);
+ real32 V = YLengthSq*Inner(StartVector, YAxis);
+
+ v2i TexelCoord = {};
+ TexelCoord.x = 1.0f + ((U*(real32)(Layer->Raster.Width - 1)) + 0.5f);
+ TexelCoord.y = 1.0f + ((V*(real32)(Layer->Raster.Height - 1)) + 0.5f);
+
+ v2i Min = {0,0};
+ v2i Max = Min + (int16)Brush.Size;
+
+ v2 Center = {(real32)Max.x / 2.0f, (real32)Max.y / 2.0f};
+ real32 MaxLength = sqrt(LengthSq(Center));
+
+ v2i LayerMin = TexelCoord - (Brush.Size / 2);
+ v2i LayerMax = TexelCoord + (Brush.Size / 2);
+
+ rectangle LayerBounds = {0, 0, Layer->Raster.Width, Layer->Raster.Height};
+ rectangle Paint = {LayerMin, LayerMax};
+
+ uint8 *Row = ((uint8 *)Layer->Raster.OriginalBuffer + Layer->Raster.Pitch*Paint.Min.y);
+ for(int Y = Paint.Min.y;
+ Y < Paint.Max.y;
+ ++Y)
+ {
+ uint32 *Pixel = (uint32 *)(Row + Paint.Min.x*sizeof(uint32));
+ for(int X = Paint.Min.x;
+ X < Paint.Max.x;
+ ++X)
+ {
+ if (X < Layer->Raster.Width && X > 0) {
+ v2 Pos = V2(abs(Center.x - (X - Paint.Min.x)), abs(Center.y - (Y - Paint.Min.y)));
+ real32 L = sqrt(LengthSq(Pos)) + Center.x;
+ real32 Gradient = pow(Ceil(L, MaxLength) / MaxLength, Brush.Hardness);
+ RenderAlpha(Pixel, ColToUint32({1.0f, 1.0f, 1.0f, 1.0f - Gradient}));
+ }
+ Pixel++;
+ }
+ Row += Layer->Raster.Pitch;
+ }
+}
+*/