Skip to content

Commit

Permalink
add smear for preview circle
Browse files Browse the repository at this point in the history
  • Loading branch information
azmr committed May 6, 2018
1 parent 90595b8 commit d0f5088
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
28 changes: 5 additions & 23 deletions geometer.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ UPDATE_AND_RENDER(UpdateAndRender)

State->iSaveAction = State->iCurrentAction;
State->iCurrentLayer = 1;
State->FX[FX_Smear] = 1;

Memory->IsInitialized = 1;
}
Expand Down Expand Up @@ -760,7 +761,6 @@ UPDATE_AND_RENDER(UpdateAndRender)
else { State->tBasis = 1.f; }
basis Basis = AnimateBasis(pBASIS, State->tBasis, BASIS);

local_persist f32 StartAlpha, EndAlpha = 1.f, dAlpha = 0.01f;
keyboard_state Keyboard = Input.New->Keyboard;
mouse_state Mouse = Input.New->Mouse;
mouse_state pMouse = Input.Old->Mouse;
Expand Down Expand Up @@ -792,30 +792,18 @@ UPDATE_AND_RENDER(UpdateAndRender)
b32 Up = C_PanUp.EndedDown;
b32 Left = C_PanLeft.EndedDown;
b32 Right = C_PanRight.EndedDown;
/* f32 PanSpeed = 15.f * Basis.Zoom; */
f32 PanSpeed = 15.f * Basis.Zoom;
if(Down != Up)
{
#if 0
if (Down) { NewBasis.Offset = V2Add(NewBasis.Offset, V2Mult(-PanSpeed, Perp(NewBasis.XAxis))); }
else/*Up*/ { NewBasis.Offset = V2Add(NewBasis.Offset, V2Mult( PanSpeed, Perp(NewBasis.XAxis))); }
#else
if (Down) { EndAlpha -= dAlpha; }
else/*Up*/ { EndAlpha += dAlpha; }
EndAlpha = Clamp01(EndAlpha);
#endif
BasisIsChanged = 1;
}

if(Left != Right)
{
#if 0
if (Left) { NewBasis.Offset = V2Add(NewBasis.Offset, V2Mult(-PanSpeed, NewBasis.XAxis )); }
else/*Right*/ { NewBasis.Offset = V2Add(NewBasis.Offset, V2Mult( PanSpeed, NewBasis.XAxis )); }
#else
if (Left) { StartAlpha -= dAlpha; }
else/*Right*/ { StartAlpha += dAlpha; }
StartAlpha = Clamp01(StartAlpha);
#endif
BasisIsChanged = 1;
}

Expand Down Expand Up @@ -1764,22 +1752,16 @@ dont_append_selection:;
v2 poSSSelect = ToScreen(poSelect);
v2 poSSSaved = ToScreen(State->poSaved);
b32 DrawPreviewCircle = ! ScreenIsInsideCircle(ScreenBB, poSSSelect, SSLength * SSLength);
Draw->Smear = V2Sub(pSSSnapMouseP, SSSnapMouseP);
switch(State->InputMode)
{ // draw mode-dependent preview
case MODE_Normal:
{
// TODO (UI): animate when (un)snapping
if(DrawPreviewCircle)
{
#if 0
pSSSnapMouseP;
#else
DEBUG_LIVE_if(Effects_Smear)
{ DrawCircleSmear(Draw, SSSnapMouseP, SSLength, V2Sub(pSSSnapMouseP, SSSnapMouseP), StartAlpha, EndAlpha, Col_Preview); }
char SmearBuf[512];
ssprintf(SmearBuf, "Start Alpha: %.3f; End Alpha: %.3f", StartAlpha, EndAlpha);
blit16_TextExplicit(Draw->Buffer.Memory, 0xFF000000, 2, -Draw->Buffer.Width, Draw->Buffer.Height, 0, 300, 50, SmearBuf);
#endif
if(State->FX[FX_Smear])
{ DrawCircleLineSmear(Draw, SSSnapMouseP, SSLength, Col_Preview); }
DrawCircleLine(Draw, SSSnapMouseP, SSLength, Col_Preview);
}
if(C_ShapeLock.EndedDown)
Expand Down
35 changes: 24 additions & 11 deletions geometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,22 @@ ShapeEq(shape S1, shape S2)
return Result;
}

// TODO: other smears

#define FN_CIRCLE(name) void name(struct draw_buffer *Draw, v2 Centre, f32 Radius, colour Colour)
#define FN_2VEC(name, v_1, v_2) void name(struct draw_buffer *Draw, v2 v_1, v2 v_2, colour Colour)

struct draw_buffer;
#define FN_DrawSeg( name) void name(struct draw_buffer *Draw, v2 Point1, v2 Point2, colour Colour)
#define FN_DrawLine( name) void name(struct draw_buffer *Draw, v2 P, v2 Dir, colour Colour)
#define FN_DrawCircleFill( name) void name(struct draw_buffer *Draw, v2 Centre, f32 Radius, colour Colour)
#define FN_DrawCircleLine( name) void name(struct draw_buffer *Draw, v2 Centre, f32 Radius, colour Colour)
#define FN_DrawCircleSmear(name) void name(struct draw_buffer *Draw, v2 Centre, f32 Radius, v2 Smear, f32 StartAlpha, f32 EndAlpha, colour Colour)
#define FN_DrawArcLine( name) void name(struct draw_buffer *Draw, v2 Centre, f32 Radius, v2 A, v2 B, colour Colour)
#define FN_DrawRectFill( name) void name(struct draw_buffer *Draw, v2 vMin, v2 vMax, colour Colour)
#define FN_DrawRectLine( name) void name(struct draw_buffer *Draw, v2 vMin, v2 vMax, colour Colour)
#define FN_ClearBuffer( name) void name(image_buffer Buffer)
#define FN_ClipBuffer( name) image_buffer name(image_buffer Buffer, v2 Offset, v2 Size)
#define FN_DrawSeg( name) FN_2VEC(name, Point1, Point2)
#define FN_DrawLine( name) FN_2VEC(name, P, Dir)
#define FN_DrawCircleFill(name) FN_CIRCLE(name)
#define FN_DrawCircleLine(name) FN_CIRCLE(name)
#define FN_DrawRectFill( name) FN_2VEC(name, vMin, vMax)
#define FN_DrawRectLine( name) FN_2VEC(name, vMin, vMax)
#define FN_DrawArcLine( name) void name(struct draw_buffer *Draw, v2 Centre, f32 Radius, v2 A, v2 B, colour Colour)
#define FN_ClearBuffer( name) void name(image_buffer Buffer)
#define FN_ClipBuffer( name) image_buffer name(image_buffer Buffer, v2 Offset, v2 Size)
#define FN_DrawCircleLineSmear(name) FN_CIRCLE(name)

#define FN(prefix, fn) FN_##fn (prefix ## fn)

Expand All @@ -158,7 +163,7 @@ struct draw_buffer;
DRAW_FN(DrawLine) \
DRAW_FN(DrawCircleFill) \
DRAW_FN(DrawCircleLine) \
DRAW_FN(DrawCircleSmear) \
DRAW_FN(DrawCircleLineSmear) \
DRAW_FN(DrawArcLine) \
DRAW_FN(DrawRectFill) \
DRAW_FN(DrawRectLine) \
Expand All @@ -179,6 +184,7 @@ typedef struct draw_buffer
// TODO: unions etc
image_buffer Buffer;
f32 StrokeWidth;
v2 Smear;

#define DRAW_FN(name)\
fn_##name *name;
Expand All @@ -199,6 +205,12 @@ typedef struct debug
global_variable debug Debug;
#define DebugPrint() Debug.Print(&Debug.Buffer, &Debug.Font, DebugText.Text, Debug.FontSize, Debug.P.X, Debug.P.Y, 0, BLACK)

typedef enum {
FX_Smear,

FX_COUNT,
} fx;

// TODO: add prev valid shape snap point for when cursor is at circle centre
typedef struct state
{
Expand Down Expand Up @@ -252,6 +264,7 @@ typedef struct state
v2 pSnapMouseP; // TODO (opt): remove?
f32 tSnapMouseP;

b8 FX[FX_COUNT];
u8 SavedStatus[2];
// NOTE: woefully underspecced:
u64 OverflowTest;
Expand Down
14 changes: 7 additions & 7 deletions win32_geometer.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,12 @@ internal FN(OpenGL, DrawCircleFill)
GLCircleFill(Centre, Radius);
}

internal FN(OpenGL, DrawCircleSmear)
// TODO: other smears
internal FN(OpenGL, DrawCircleLineSmear)
{
(void)Draw;
GLCircleLinearSmear(Centre, Radius, Smear, StartAlpha, EndAlpha, Colour);
colour StartColour = BLANK_COLOUR;
colour EndColour = PreMultiplyColour(Colour, 0.3f);
GLCircleLinearSmear(Centre, Radius, Draw->Smear, StartColour, EndColour);
}

internal FN(OpenGL, DrawArcLine)
Expand Down Expand Up @@ -868,13 +870,11 @@ internal FN(Software, DrawCircleLine)
internal FN(Software, DrawCircleFill)
{ CircleFill(Draw->Buffer, Centre, Radius, Colour); }


internal FN(Software, DrawCircleSmear)
internal FN(Software, DrawCircleLineSmear)
{
#if 1
// do nothing
(void)Draw; (void)StartAlpha; (void)EndAlpha; (void)Smear;
(void)Radius; (void)Centre; (void)Colour;
(void)Draw; (void)Radius; (void)Centre; (void)Colour;

#elif 0
// Multiple lines trailing behind
Expand Down

0 comments on commit d0f5088

Please sign in to comment.