Key event buffer overflow crash fixed; switched draw_string over to Vec2 and returning the distance measured in deltas

This commit is contained in:
Allen Webster 2019-02-24 14:54:57 -08:00
parent 258257eb45
commit 410b90d44c
12 changed files with 341 additions and 322 deletions

View File

@ -11,6 +11,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "4coder_base_types.h" #include "4coder_base_types.h"
#include "4coder_base_types.cpp"
#include "4coder_lib/4coder_arena.h" #include "4coder_lib/4coder_arena.h"
#include "4coder_lib/4coder_heap.h" #include "4coder_lib/4coder_heap.h"
#include "4coder_lib/4coder_string.h" #include "4coder_lib/4coder_string.h"

View File

@ -1,23 +1,66 @@
/* /*
* Mr. 4th Dimention - Allen Webster * 4coder base types
*
* 15.05.2015
*
* Math functions for 4coder
*
*/ */
// TOP // TOP
#define C_MATH 1 #define C_MATH 1
/* static i32
* Scalar operators ceil32(f32 v){
*/ return(((v)>0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)+1.f)) ):( ((i32)(v)) ));
}
static i32
floor32(f32 v){
return(((v)<0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)-1.f)) ):( ((i32)(v)) ));
}
static i32
round32(f32 v){
return(floor32(v + 0.5f));
}
static i32
trun32(f32 v){
return((i32)(v));
}
static i32
div_ceil(i32 n, i32 d){
return( ((n) % (d) != 0) + ((n) / (d)) );
}
static i32
l_round_up_i32(i32 x, i32 b){
i32 t = x + b - 1;
return(t - (t%b));
}
static u32
l_round_up_u32(u32 x, u32 b){
i32 t = x + b - 1;
return(t - (t%b));
}
static u32 round_up_pot_u32(u32 x){
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
++x;
return(x);
}
////////////////////////////////
// scalars
#define DEG_TO_RAD (0.0174533f) #define DEG_TO_RAD (0.0174533f)
internal f32 static f32
ABS(f32 x){ ABS(f32 x){
if (x < 0) x = -x; if (x < 0) x = -x;
return(x); return(x);
@ -26,7 +69,7 @@ ABS(f32 x){
#if C_MATH #if C_MATH
#include <math.h> #include <math.h>
internal f32 static f32
MOD(f32 x, i32 m){ MOD(f32 x, i32 m){
f32 whole; f32 whole;
f32 frac = modff(x, &whole); f32 frac = modff(x, &whole);
@ -34,30 +77,30 @@ MOD(f32 x, i32 m){
return(r); return(r);
} }
internal f32 static f32
SQRT(f32 x){ SQRT(f32 x){
f32 r = sqrtf(x); f32 r = sqrtf(x);
return(r); return(r);
} }
internal f32 static f32
SIN(f32 x_degrees){ SIN(f32 x_degrees){
f32 r = sinf(x_degrees * DEG_TO_RAD); f32 r = sinf(x_degrees * DEG_TO_RAD);
return(r); return(r);
} }
internal f32 static f32
COS(f32 x_degrees){ COS(f32 x_degrees){
f32 r = cosf(x_degrees * DEG_TO_RAD); f32 r = cosf(x_degrees * DEG_TO_RAD);
return(r); return(r);
} }
#endif #endif
/* ////////////////////////////////
* Vectors
*/
internal Vec2 // vectors
static Vec2
V2(f32 x, f32 y){ V2(f32 x, f32 y){
Vec2 result = {}; Vec2 result = {};
result.x = x; result.x = x;
@ -65,7 +108,7 @@ V2(f32 x, f32 y){
return(result); return(result);
} }
internal Vec3 static Vec3
V3(f32 x, f32 y, f32 z){ V3(f32 x, f32 y, f32 z){
Vec3 result = {}; Vec3 result = {};
result.x = x; result.x = x;
@ -74,7 +117,7 @@ V3(f32 x, f32 y, f32 z){
return(result); return(result);
} }
internal Vec4 static Vec4
V4(f32 x, f32 y, f32 z, f32 w){ V4(f32 x, f32 y, f32 z, f32 w){
Vec4 result = {}; Vec4 result = {};
result.x = x; result.x = x;
@ -84,7 +127,37 @@ V4(f32 x, f32 y, f32 z, f32 w){
return(result); return(result);
} }
internal Vec2_i32 static Vec2
V2(Vec2_i32 pi){
return(V2((f32)pi.x, (f32)pi.y));
}
static Vec3
V3(Vec3_i32 pi){
return(V3((f32)pi.x, (f32)pi.y, (f32)pi.z));
}
static Vec4
V4(Vec4_i32 pi){
return(V4((f32)pi.x, (f32)pi.y, (f32)pi.z, (f32)pi.w));
}
static Vec2
V2(Vec2 pi){
return(pi);
}
static Vec3
V3(Vec3 pi){
return(pi);
}
static Vec4
V4(Vec4 pi){
return(pi);
}
static Vec2_i32
V2i32(i32 x, i32 y){ V2i32(i32 x, i32 y){
Vec2_i32 result = {}; Vec2_i32 result = {};
result.x = x; result.x = x;
@ -92,7 +165,7 @@ V2i32(i32 x, i32 y){
return(result); return(result);
} }
internal Vec3_i32 static Vec3_i32
V3i32(i32 x, i32 y, i32 z){ V3i32(i32 x, i32 y, i32 z){
Vec3_i32 result = {}; Vec3_i32 result = {};
result.x = x; result.x = x;
@ -101,7 +174,7 @@ V3i32(i32 x, i32 y, i32 z){
return(result); return(result);
} }
internal Vec4_i32 static Vec4_i32
V4i32(i32 x, i32 y, i32 z, i32 w){ V4i32(i32 x, i32 y, i32 z, i32 w){
Vec4_i32 result = {}; Vec4_i32 result = {};
result.x = x; result.x = x;
@ -111,7 +184,37 @@ V4i32(i32 x, i32 y, i32 z, i32 w){
return(result); return(result);
} }
internal Vec2 static Vec2_i32
V2i32(Vec2_f32 pi){
return(V2i32((i32)pi.x, (i32)pi.y));
}
static Vec3_i32
V3i32(Vec3_f32 pi){
return(V3i32((i32)pi.x, (i32)pi.y, (i32)pi.z));
}
static Vec4_i32
V4i32(Vec4_f32 pi){
return(V4i32((i32)pi.x, (i32)pi.y, (i32)pi.z, (i32)pi.w));
}
static Vec2_i32
V2i32(Vec2_i32 pi){
return(pi);
}
static Vec3_i32
V3i32(Vec3_i32 pi){
return(pi);
}
static Vec4_i32
V4i32(Vec4_i32 pi){
return(pi);
}
static Vec2
operator+(Vec2 a, Vec2 b){ operator+(Vec2 a, Vec2 b){
Vec2 result; Vec2 result;
result.x = a.x + b.x; result.x = a.x + b.x;
@ -119,7 +222,7 @@ operator+(Vec2 a, Vec2 b){
return(result); return(result);
} }
internal Vec3 static Vec3
operator+(Vec3 a, Vec3 b){ operator+(Vec3 a, Vec3 b){
Vec3 result; Vec3 result;
result.x = a.x + b.x; result.x = a.x + b.x;
@ -128,7 +231,7 @@ operator+(Vec3 a, Vec3 b){
return(result); return(result);
} }
internal Vec4 static Vec4
operator+(Vec4 a, Vec4 b){ operator+(Vec4 a, Vec4 b){
Vec4 result; Vec4 result;
result.x = a.x + b.x; result.x = a.x + b.x;
@ -138,7 +241,7 @@ operator+(Vec4 a, Vec4 b){
return(result); return(result);
} }
internal Vec2 static Vec2
operator-(Vec2 a, Vec2 b){ operator-(Vec2 a, Vec2 b){
Vec2 result; Vec2 result;
result.x = a.x - b.x; result.x = a.x - b.x;
@ -146,7 +249,7 @@ operator-(Vec2 a, Vec2 b){
return(result); return(result);
} }
internal Vec3 static Vec3
operator-(Vec3 a, Vec3 b){ operator-(Vec3 a, Vec3 b){
Vec3 result; Vec3 result;
result.x = a.x - b.x; result.x = a.x - b.x;
@ -155,7 +258,7 @@ operator-(Vec3 a, Vec3 b){
return(result); return(result);
} }
internal Vec4 static Vec4
operator-(Vec4 a, Vec4 b){ operator-(Vec4 a, Vec4 b){
Vec4 result; Vec4 result;
result.x = a.x - b.x; result.x = a.x - b.x;
@ -165,7 +268,7 @@ operator-(Vec4 a, Vec4 b){
return(result); return(result);
} }
internal Vec2 static Vec2
operator*(Vec2 a, f32 k){ operator*(Vec2 a, f32 k){
Vec2 result; Vec2 result;
result.x = a.x * k; result.x = a.x * k;
@ -173,7 +276,7 @@ operator*(Vec2 a, f32 k){
return(result); return(result);
} }
internal Vec3 static Vec3
operator*(Vec3 a, f32 k){ operator*(Vec3 a, f32 k){
Vec3 result; Vec3 result;
result.x = a.x * k; result.x = a.x * k;
@ -182,7 +285,7 @@ operator*(Vec3 a, f32 k){
return(result); return(result);
} }
internal Vec4 static Vec4
operator*(Vec4 a, f32 k){ operator*(Vec4 a, f32 k){
Vec4 result; Vec4 result;
result.x = a.x * k; result.x = a.x * k;
@ -192,7 +295,7 @@ operator*(Vec4 a, f32 k){
return(result); return(result);
} }
internal Vec2 static Vec2
operator*(f32 k, Vec2 a){ operator*(f32 k, Vec2 a){
Vec2 result; Vec2 result;
result.x = a.x * k; result.x = a.x * k;
@ -200,7 +303,7 @@ operator*(f32 k, Vec2 a){
return(result); return(result);
} }
internal Vec3 static Vec3
operator*(f32 k, Vec3 a){ operator*(f32 k, Vec3 a){
Vec3 result; Vec3 result;
result.x = a.x * k; result.x = a.x * k;
@ -209,7 +312,7 @@ operator*(f32 k, Vec3 a){
return(result); return(result);
} }
internal Vec4 static Vec4
operator*(f32 k, Vec4 a){ operator*(f32 k, Vec4 a){
Vec4 result; Vec4 result;
result.x = a.x * k; result.x = a.x * k;
@ -218,142 +321,142 @@ operator*(f32 k, Vec4 a){
result.w = a.w * k; result.w = a.w * k;
return(result);} return(result);}
internal Vec2& static Vec2&
operator+=(Vec2 &a, Vec2 b){ operator+=(Vec2 &a, Vec2 b){
a = (a + b); a = (a + b);
return a; return a;
} }
internal Vec3& static Vec3&
operator+=(Vec3 &a, Vec3 b){ operator+=(Vec3 &a, Vec3 b){
a = (a + b); a = (a + b);
return a; return a;
} }
internal Vec4& static Vec4&
operator+=(Vec4 &a, Vec4 b){ operator+=(Vec4 &a, Vec4 b){
a = (a + b); a = (a + b);
return a; return a;
} }
internal Vec2& static Vec2&
operator-=(Vec2 &a, Vec2 b){ operator-=(Vec2 &a, Vec2 b){
a = (a - b); a = (a - b);
return a; return a;
} }
internal Vec3& static Vec3&
operator-=(Vec3 &a, Vec3 b){ operator-=(Vec3 &a, Vec3 b){
a = (a - b); a = (a - b);
return a; return a;
} }
internal Vec4& static Vec4&
operator-=(Vec4 &a, Vec4 b){ operator-=(Vec4 &a, Vec4 b){
a = (a - b); a = (a - b);
return a; return a;
} }
internal Vec2& static Vec2&
operator*=(Vec2 &a, f32 k){ operator*=(Vec2 &a, f32 k){
a = (a*k); a = (a*k);
return a; return a;
} }
internal Vec3& static Vec3&
operator*=(Vec3 &a, f32 k){ operator*=(Vec3 &a, f32 k){
a = (a*k); a = (a*k);
return a; return a;
} }
internal Vec4& static Vec4&
operator*=(Vec4 &a, f32 k){ operator*=(Vec4 &a, f32 k){
a = (a*k); a = (a*k);
return a; return a;
} }
internal b32 static b32
operator==(Vec2 a, Vec2 b){ operator==(Vec2 a, Vec2 b){
return(a.x == b.x && a.y == b.y); return(a.x == b.x && a.y == b.y);
} }
internal b32 static b32
operator!=(Vec2 a, Vec2 b){ operator!=(Vec2 a, Vec2 b){
return(!(a.x == b.x && a.y == b.y)); return(!(a.x == b.x && a.y == b.y));
} }
internal b32 static b32
operator==(Vec3 a, Vec3 b){ operator==(Vec3 a, Vec3 b){
return(a.x == b.x && a.y == b.y && a.z == b.z); return(a.x == b.x && a.y == b.y && a.z == b.z);
} }
internal b32 static b32
operator!=(Vec3 a, Vec3 b){ operator!=(Vec3 a, Vec3 b){
return(!(a.x == b.x && a.y == b.y && a.z == b.z)); return(!(a.x == b.x && a.y == b.y && a.z == b.z));
} }
internal b32 static b32
operator==(Vec4 a, Vec4 b){ operator==(Vec4 a, Vec4 b){
return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
} }
internal b32 static b32
operator!=(Vec4 a, Vec4 b){ operator!=(Vec4 a, Vec4 b){
return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w)); return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w));
} }
internal b32 static b32
operator==(Vec2_i32 a, Vec2_i32 b){ operator==(Vec2_i32 a, Vec2_i32 b){
return(a.x == b.x && a.y == b.y); return(a.x == b.x && a.y == b.y);
} }
internal b32 static b32
operator!=(Vec2_i32 a, Vec2_i32 b){ operator!=(Vec2_i32 a, Vec2_i32 b){
return(!(a.x == b.x && a.y == b.y)); return(!(a.x == b.x && a.y == b.y));
} }
internal b32 static b32
operator==(Vec3_i32 a, Vec3_i32 b){ operator==(Vec3_i32 a, Vec3_i32 b){
return(a.x == b.x && a.y == b.y && a.z == b.z); return(a.x == b.x && a.y == b.y && a.z == b.z);
} }
internal b32 static b32
operator!=(Vec3_i32 a, Vec3_i32 b){ operator!=(Vec3_i32 a, Vec3_i32 b){
return(!(a.x == b.x && a.y == b.y && a.z == b.z)); return(!(a.x == b.x && a.y == b.y && a.z == b.z));
} }
internal b32 static b32
operator==(Vec4_i32 a, Vec4_i32 b){ operator==(Vec4_i32 a, Vec4_i32 b){
return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w); return(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
} }
internal b32 static b32
operator!=(Vec4_i32 a, Vec4_i32 b){ operator!=(Vec4_i32 a, Vec4_i32 b){
return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w)); return(!(a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w));
} }
internal f32 static f32
dot(Vec2 a, Vec2 b){ dot(Vec2 a, Vec2 b){
f32 result; f32 result;
result = a.x*b.x + a.y*b.y; result = a.x*b.x + a.y*b.y;
return result; return result;
} }
internal f32 static f32
dot(Vec3 a, Vec3 b){ dot(Vec3 a, Vec3 b){
f32 result; f32 result;
result = a.x*b.x + a.y*b.y + a.z*b.z; result = a.x*b.x + a.y*b.y + a.z*b.z;
return result; return result;
} }
internal f32 static f32
dot(Vec4 a, Vec4 b){ dot(Vec4 a, Vec4 b){
f32 result; f32 result;
result = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; result = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w;
return result; return result;
} }
internal Vec3 static Vec3
cross(Vec3 a, Vec3 b){ cross(Vec3 a, Vec3 b){
Vec3 result; Vec3 result;
result.x = a.y*b.z - b.y*a.z; result.x = a.y*b.z - b.y*a.z;
@ -362,14 +465,14 @@ cross(Vec3 a, Vec3 b){
return result; return result;
} }
internal Vec2 static Vec2
hadamard(Vec2 a, Vec2 b){ hadamard(Vec2 a, Vec2 b){
a.x *= b.x; a.x *= b.x;
a.y *= b.y; a.y *= b.y;
return(a); return(a);
} }
internal Vec3 static Vec3
hadamard(Vec3 a, Vec3 b){ hadamard(Vec3 a, Vec3 b){
a.x *= b.x; a.x *= b.x;
a.y *= b.y; a.y *= b.y;
@ -377,7 +480,7 @@ hadamard(Vec3 a, Vec3 b){
return(a); return(a);
} }
internal Vec4 static Vec4
hadamard(Vec4 a, Vec4 b){ hadamard(Vec4 a, Vec4 b){
a.x *= b.x; a.x *= b.x;
a.y *= b.y; a.y *= b.y;
@ -386,17 +489,17 @@ hadamard(Vec4 a, Vec4 b){
return(a); return(a);
} }
internal Vec2 static Vec2
perp(Vec2 v){ perp(Vec2 v){
return(V2(-v.y, v.x)); return(V2(-v.y, v.x));
} }
internal Vec2 static Vec2
polar_to_cartesian(f32 theta_degrees, f32 length){ polar_to_cartesian(f32 theta_degrees, f32 length){
return(V2(COS(theta_degrees), SIN(theta_degrees))*length); return(V2(COS(theta_degrees), SIN(theta_degrees))*length);
} }
internal Vec2 static Vec2
rotate(Vec2 v, f32 theta_degrees){ rotate(Vec2 v, f32 theta_degrees){
f32 c = COS(theta_degrees); f32 c = COS(theta_degrees);
f32 s = SIN(theta_degrees); f32 s = SIN(theta_degrees);
@ -404,36 +507,34 @@ rotate(Vec2 v, f32 theta_degrees){
v.x*s + v.y*c)); v.x*s + v.y*c));
} }
/* ////////////////////////////////
*Lerps, Clamps, Thresholds, Etc
*/
internal f32 static f32
lerp(f32 a, f32 t, f32 b){ lerp(f32 a, f32 t, f32 b){
return(a + (b-a)*t); return(a + (b-a)*t);
} }
internal i32 static i32
lerp(i32 a, f32 t, i32 b){ lerp(i32 a, f32 t, i32 b){
return((i32)(lerp((f32)a, t, (f32)b))); return((i32)(lerp((f32)a, t, (f32)b)));
} }
internal Vec2 static Vec2
lerp(Vec2 a, f32 t, Vec2 b){ lerp(Vec2 a, f32 t, Vec2 b){
return(a + (b-a)*t); return(a + (b-a)*t);
} }
internal Vec3 static Vec3
lerp(Vec3 a, f32 t, Vec3 b){ lerp(Vec3 a, f32 t, Vec3 b){
return(a + (b-a)*t); return(a + (b-a)*t);
} }
internal Vec4 static Vec4
lerp(Vec4 a, f32 t, Vec4 b){ lerp(Vec4 a, f32 t, Vec4 b){
return(a + (b-a)*t); return(a + (b-a)*t);
} }
internal f32 static f32
unlerp(f32 a, f32 x, f32 b){ unlerp(f32 a, f32 x, f32 b){
f32 r = x; f32 r = x;
if (b != a){ if (b != a){
@ -442,7 +543,7 @@ unlerp(f32 a, f32 x, f32 b){
return(r); return(r);
} }
internal f32 static f32
clamp(f32 a, f32 n, f32 z){ clamp(f32 a, f32 n, f32 z){
if (n < a){ if (n < a){
n = a; n = a;
@ -453,7 +554,7 @@ clamp(f32 a, f32 n, f32 z){
return(n); return(n);
} }
internal i32 static i32
clamp(i32 a, i32 n, i32 z){ clamp(i32 a, i32 n, i32 z){
if (n < a){ if (n < a){
n = a; n = a;
@ -464,7 +565,7 @@ clamp(i32 a, i32 n, i32 z){
return(n); return(n);
} }
internal i64 static i64
clamp(i64 a, i64 n, i64 z){ clamp(i64 a, i64 n, i64 z){
if (n < a){ if (n < a){
n = a; n = a;
@ -475,7 +576,7 @@ clamp(i64 a, i64 n, i64 z){
return(n); return(n);
} }
internal u32 static u32
clamp(u32 a, u32 n, u32 z){ clamp(u32 a, u32 n, u32 z){
if (n < a){ if (n < a){
n = a; n = a;
@ -486,7 +587,7 @@ clamp(u32 a, u32 n, u32 z){
return(n); return(n);
} }
internal u64 static u64
clamp(u64 a, u64 n, u64 z){ clamp(u64 a, u64 n, u64 z){
if (n < a){ if (n < a){
n = a; n = a;
@ -497,15 +598,12 @@ clamp(u64 a, u64 n, u64 z){
return(n); return(n);
} }
#define clamp_top(a,b) Min(a,b) ////////////////////////////////
#define clamp_bottom(a,b) Max(a,b)
/* // color
*Color
*/
// TODO(allen): Convert colors to Vec4 // TODO(allen): Convert colors to Vec4
internal u32 static u32
color_blend(u32 a, f32 t, u32 b){ color_blend(u32 a, f32 t, u32 b){
union{ union{
u8 byte[4]; u8 byte[4];
@ -523,7 +621,7 @@ color_blend(u32 a, f32 t, u32 b){
return R.comp; return R.comp;
} }
internal Vec3 static Vec3
unpack_color3(u32 color){ unpack_color3(u32 color){
Vec3 result; Vec3 result;
result.r = ((color >> 16) & 0xFF) / 255.f; result.r = ((color >> 16) & 0xFF) / 255.f;
@ -532,7 +630,7 @@ unpack_color3(u32 color){
return result; return result;
} }
internal Vec4 static Vec4
unpack_color4(u32 color){ unpack_color4(u32 color){
Vec4 result; Vec4 result;
result.a = ((color >> 24) & 0xFF) / 255.f; result.a = ((color >> 24) & 0xFF) / 255.f;
@ -542,7 +640,7 @@ unpack_color4(u32 color){
return result; return result;
} }
internal u32 static u32
pack_color4(Vec4 color){ pack_color4(Vec4 color){
u32 result = u32 result =
((u8)(color.a*255) << 24) | ((u8)(color.a*255) << 24) |
@ -552,7 +650,7 @@ pack_color4(Vec4 color){
return result; return result;
} }
internal Vec4 static Vec4
rgba_to_hsla(Vec4 rgba){ rgba_to_hsla(Vec4 rgba){
Vec4 hsla = {}; Vec4 hsla = {};
f32 max, min, delta; f32 max, min, delta;
@ -608,7 +706,7 @@ rgba_to_hsla(Vec4 rgba){
return hsla; return hsla;
} }
internal Vec4 static Vec4
hsla_to_rgba(Vec4 hsla){ hsla_to_rgba(Vec4 hsla){
if (hsla.h >= 1.f){ if (hsla.h >= 1.f){
hsla.h = 0.f; hsla.h = 0.f;
@ -633,11 +731,9 @@ hsla_to_rgba(Vec4 hsla){
return(rgba); return(rgba);
} }
// ////////////////////////////////
// Rectangle Operations
//
internal i32_Rect static i32_Rect
i32R(i32 l, i32 t, i32 r, i32 b){ i32R(i32 l, i32 t, i32 r, i32 b){
i32_Rect rect = {}; i32_Rect rect = {};
rect.x0 = l; rect.x0 = l;
@ -647,12 +743,12 @@ i32R(i32 l, i32 t, i32 r, i32 b){
return(rect); return(rect);
} }
internal i32_Rect static i32_Rect
i32R_xy_wh(i32 x, i32 y, i32 w, i32 h){ i32R_xy_wh(i32 x, i32 y, i32 w, i32 h){
return(i32R(x, y, x + w, y + h)); return(i32R(x, y, x + w, y + h));
} }
internal i32_Rect static i32_Rect
i32R(f32_Rect r){ i32R(f32_Rect r){
i32_Rect rect = {}; i32_Rect rect = {};
rect.x0 = (i32)r.x0; rect.x0 = (i32)r.x0;
@ -662,7 +758,7 @@ i32R(f32_Rect r){
return(rect); return(rect);
} }
internal f32_Rect static f32_Rect
f32R(f32 l, f32 t, f32 r, f32 b){ f32R(f32 l, f32 t, f32 r, f32 b){
f32_Rect rect = {}; f32_Rect rect = {};
rect.x0 = l; rect.x0 = l;
@ -672,7 +768,7 @@ f32R(f32 l, f32 t, f32 r, f32 b){
return(rect); return(rect);
} }
internal f32_Rect static f32_Rect
f32R(i32_Rect r){ f32R(i32_Rect r){
f32_Rect rect = {}; f32_Rect rect = {};
rect.x0 = (f32)r.x0; rect.x0 = (f32)r.x0;
@ -682,22 +778,22 @@ f32R(i32_Rect r){
return(rect); return(rect);
} }
internal i32 static i32
rect_equal(i32_Rect r1, i32_Rect r2){ rect_equal(i32_Rect r1, i32_Rect r2){
return(r1.x0 == r2.x0 && r1.y0 == r2.y0 && r1.x1 == r2.x1 && r1.y1 == r2.y1); return(r1.x0 == r2.x0 && r1.y0 == r2.y0 && r1.x1 == r2.x1 && r1.y1 == r2.y1);
} }
internal i32 static i32
hit_check(i32 x, i32 y, i32 x0, i32 y0, i32 x1, i32 y1){ hit_check(i32 x, i32 y, i32 x0, i32 y0, i32 x1, i32 y1){
return(x >= x0 && x < x1 && y >= y0 && y < y1); return(x >= x0 && x < x1 && y >= y0 && y < y1);
} }
internal i32 static i32
hit_check(i32 x, i32 y, i32_Rect rect){ hit_check(i32 x, i32 y, i32_Rect rect){
return(hit_check(x, y, rect.x0, rect.y0, rect.x1, rect.y1)); return(hit_check(x, y, rect.x0, rect.y0, rect.x1, rect.y1));
} }
internal i32_Rect static i32_Rect
get_inner_rect(i32_Rect outer, i32 margin){ get_inner_rect(i32_Rect outer, i32 margin){
i32_Rect r = {}; i32_Rect r = {};
r.x0 = outer.x0 + margin; r.x0 = outer.x0 + margin;
@ -707,7 +803,7 @@ get_inner_rect(i32_Rect outer, i32 margin){
return(r); return(r);
} }
internal f32_Rect static f32_Rect
get_inner_rect(f32_Rect outer, f32 margin){ get_inner_rect(f32_Rect outer, f32 margin){
f32_Rect r = {}; f32_Rect r = {};
r.x0 = outer.x0 + margin; r.x0 = outer.x0 + margin;
@ -717,38 +813,38 @@ get_inner_rect(f32_Rect outer, f32 margin){
return(r); return(r);
} }
internal i32 static i32
rect_height(i32_Rect rect){ rect_height(i32_Rect rect){
return(rect.y1 - rect.y0); return(rect.y1 - rect.y0);
} }
internal i32 static i32
rect_width(i32_Rect rect){ rect_width(i32_Rect rect){
return(rect.x1 - rect.x0); return(rect.x1 - rect.x0);
} }
internal i32 static i32
fits_inside(i32_Rect rect, i32_Rect outer){ fits_inside(i32_Rect rect, i32_Rect outer){
return(rect.x0 >= outer.x0 && rect.x1 <= outer.x1 && rect.y0 >= outer.y0 && rect.y1 <= outer.y1); return(rect.x0 >= outer.x0 && rect.x1 <= outer.x1 && rect.y0 >= outer.y0 && rect.y1 <= outer.y1);
} }
internal i32 static i32
interval_overlap(f32 a0, f32 a1, f32 b0, f32 b1){ interval_overlap(f32 a0, f32 a1, f32 b0, f32 b1){
return(a0 < b1 && b0 < a1); return(a0 < b1 && b0 < a1);
} }
internal i32 static i32
rect_overlap(f32_Rect a, f32_Rect b){ rect_overlap(f32_Rect a, f32_Rect b){
return(interval_overlap(a.x0, a.x1, b.x0, b.x1) && return(interval_overlap(a.x0, a.x1, b.x0, b.x1) &&
interval_overlap(a.y0, a.y1, b.y0, b.y1)); interval_overlap(a.y0, a.y1, b.y0, b.y1));
} }
internal f32 static f32
rect_height(f32_Rect rect){ rect_height(f32_Rect rect){
return(rect.y1 - rect.y0); return(rect.y1 - rect.y0);
} }
internal f32 static f32
rect_width(f32_Rect rect){ rect_width(f32_Rect rect){
return(rect.x1 - rect.x0); return(rect.x1 - rect.x0);
} }

View File

@ -58,6 +58,10 @@ typedef double f64;
#define Max(a,b) (((a)>(b))?(a):(b)) #define Max(a,b) (((a)>(b))?(a):(b))
#define Min(a,b) (((a)<(b))?(a):(b)) #define Min(a,b) (((a)<(b))?(a):(b))
#define clamp_top(a,b) Min(a,b)
#define clamp_bottom(a,b) Max(a,b)
//#define clamp(a,x,b) Min(
//////////////////////////////// ////////////////////////////////
struct Vec2_f32{ struct Vec2_f32{

View File

@ -141,7 +141,7 @@ struct Application_Links;
#define SEND_EXIT_SIGNAL_SIG(n) void n(Application_Links *app) #define SEND_EXIT_SIGNAL_SIG(n) void n(Application_Links *app)
#define SET_WINDOW_TITLE_SIG(n) bool32 n(Application_Links *app, String title) #define SET_WINDOW_TITLE_SIG(n) bool32 n(Application_Links *app, String title)
#define GET_MICROSECONDS_TIMESTAMP_SIG(n) Microsecond_Time_Stamp n(Application_Links *app) #define GET_MICROSECONDS_TIMESTAMP_SIG(n) Microsecond_Time_Stamp n(Application_Links *app)
#define DRAW_STRING_SIG(n) float n(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy) #define DRAW_STRING_SIG(n) float n(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta)
#define GET_STRING_ADVANCE_SIG(n) float n(Application_Links *app, Face_ID font_id, String str) #define GET_STRING_ADVANCE_SIG(n) float n(Application_Links *app, Face_ID font_id, String str)
#define DRAW_RECTANGLE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color) #define DRAW_RECTANGLE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color)
#define DRAW_RECTANGLE_OUTLINE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color) #define DRAW_RECTANGLE_OUTLINE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color)
@ -904,7 +904,7 @@ static bool32 is_fullscreen(Application_Links *app){return(app->is_fullscreen(ap
static void send_exit_signal(Application_Links *app){(app->send_exit_signal(app));} static void send_exit_signal(Application_Links *app){(app->send_exit_signal(app));}
static bool32 set_window_title(Application_Links *app, String title){return(app->set_window_title(app, title));} static bool32 set_window_title(Application_Links *app, String title){return(app->set_window_title(app, title));}
static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp(app));} static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp(app));}
static float draw_string(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy){return(app->draw_string(app, font_id, str, x, y, color, flags, dx, dy));} static float draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string(app, font_id, str, point, color, flags, delta));}
static float get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance(app, font_id, str));} static float get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance(app, font_id, str));}
static void draw_rectangle(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle(app, rect, color));} static void draw_rectangle(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle(app, rect, color));}
static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline(app, rect, color));} static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline(app, rect, color));}
@ -1055,7 +1055,7 @@ static bool32 is_fullscreen(Application_Links *app){return(app->is_fullscreen_(a
static void send_exit_signal(Application_Links *app){(app->send_exit_signal_(app));} static void send_exit_signal(Application_Links *app){(app->send_exit_signal_(app));}
static bool32 set_window_title(Application_Links *app, String title){return(app->set_window_title_(app, title));} static bool32 set_window_title(Application_Links *app, String title){return(app->set_window_title_(app, title));}
static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp_(app));} static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp_(app));}
static float draw_string(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy){return(app->draw_string_(app, font_id, str, x, y, color, flags, dx, dy));} static float draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string_(app, font_id, str, point, color, flags, delta));}
static float get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance_(app, font_id, str));} static float get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance_(app, font_id, str));}
static void draw_rectangle(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_(app, rect, color));} static void draw_rectangle(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_(app, rect, color));}
static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline_(app, rect, color));} static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline_(app, rect, color));}

View File

@ -418,7 +418,6 @@ cpp_token_category_from_type(Cpp_Token_Type type){
cat = CPP_TOKEN_CAT_OPERATOR; cat = CPP_TOKEN_CAT_OPERATOR;
}break; }break;
case CPP_TOKEN_VOID: case CPP_TOKEN_VOID:
case CPP_TOKEN_BOOL: case CPP_TOKEN_BOOL:
case CPP_TOKEN_CHAR: case CPP_TOKEN_CHAR:

View File

@ -4231,22 +4231,24 @@ DOC(Returns a microsecond resolution timestamp.)
return(system->now_time()); return(system->now_time());
} }
internal void internal Vec2
draw_helper__view_space_to_screen_space(Models *models, i32 *x, i32 *y){ draw_helper__view_space_to_screen_space(Models *models, Vec2 point){
i32_Rect region = models->render_rect; i32_Rect region = models->render_rect;
*x += region.x0; point.x += (f32)region.x0;
*y += region.y0; point.y += (f32)region.y0;
return(point);
} }
internal void internal f32_Rect
draw_helper__view_space_to_screen_space(Models *models, f32_Rect *rect){ draw_helper__view_space_to_screen_space(Models *models, f32_Rect rect){
i32_Rect region = models->render_rect; i32_Rect region = models->render_rect;
f32 x_corner = (f32)region.x0; f32 x_corner = (f32)region.x0;
f32 y_corner = (f32)region.y0; f32 y_corner = (f32)region.y0;
rect->x0 += x_corner; rect.x0 += x_corner;
rect->y0 += y_corner; rect.y0 += y_corner;
rect->x1 += x_corner; rect.x1 += x_corner;
rect->y1 += y_corner; rect.y1 += y_corner;
return(rect);
} }
// NOTE(allen): Coordinate space of draw calls: // NOTE(allen): Coordinate space of draw calls:
@ -4254,65 +4256,61 @@ draw_helper__view_space_to_screen_space(Models *models, f32_Rect *rect){
// To make text scroll with the buffer users should read the view's scroll position and subtract it first. // To make text scroll with the buffer users should read the view's scroll position and subtract it first.
API_EXPORT float API_EXPORT float
Draw_String(Application_Links *app, Face_ID font_id, String str, int32_t x, int32_t y, int_color color, uint32_t flags, float dx, float dy) Draw_String(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta)
{ {
f32 result = 0.f;
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;
if (models->render_view == 0){ if (models->render_view == 0){
float w = font_string_width(models->system, models->target, font_id, str); result = font_string_width(models->system, models->target, font_id, str);
return(w);
} }
else{
Style *style = &models->styles.styles[0]; Style *style = &models->styles.styles[0];
Theme *theme_data = &style->theme; Theme *theme_data = &style->theme;
draw_helper__view_space_to_screen_space(models, &x, &y); point = draw_helper__view_space_to_screen_space(models, point);
u32 actual_color = finalize_color(theme_data, color); u32 actual_color = finalize_color(theme_data, color);
float w = draw_string_base(models->system, models->target, font_id, str, x, y, result = draw_string(models->system, models->target, font_id, str, point, actual_color, flags, delta);
actual_color, flags, dx, dy); }
return(w); return(result);
} }
API_EXPORT float API_EXPORT float
Get_String_Advance(Application_Links *app, Face_ID font_id, String str) Get_String_Advance(Application_Links *app, Face_ID font_id, String str)
{ {
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;
float w = font_string_width(models->system, models->target, font_id, str); return(font_string_width(models->system, models->target, font_id, str));
return(w);
} }
API_EXPORT void API_EXPORT void
Draw_Rectangle(Application_Links *app, f32_Rect rect, int_color color) Draw_Rectangle(Application_Links *app, f32_Rect rect, int_color color)
{ {
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;
if (models->render_view == 0){ if (models->render_view != 0){
return;
}
Style *style = &models->styles.styles[0]; Style *style = &models->styles.styles[0];
Theme *theme_data = &style->theme; Theme *theme_data = &style->theme;
draw_helper__view_space_to_screen_space(models, &rect); rect = draw_helper__view_space_to_screen_space(models, rect);
u32 actual_color = finalize_color(theme_data, color); u32 actual_color = finalize_color(theme_data, color);
draw_rectangle(models->target, rect, actual_color); draw_rectangle(models->target, rect, actual_color);
} }
}
API_EXPORT void API_EXPORT void
Draw_Rectangle_Outline(Application_Links *app, f32_Rect rect, int_color color) Draw_Rectangle_Outline(Application_Links *app, f32_Rect rect, int_color color)
{ {
Models *models = (Models*)app->cmd_context; Models *models = (Models*)app->cmd_context;
if (models->render_view == 0){ if (models->render_view != 0){
return;
}
Style *style = &models->styles.styles[0]; Style *style = &models->styles.styles[0];
Theme *theme_data = &style->theme; Theme *theme_data = &style->theme;
draw_helper__view_space_to_screen_space(models, &rect); rect = draw_helper__view_space_to_screen_space(models, rect);
u32 actual_color = finalize_color(theme_data, color); u32 actual_color = finalize_color(theme_data, color);
draw_rectangle_outline(models->target, rect, actual_color); draw_rectangle_outline(models->target, rect, actual_color);
} }
}
API_EXPORT Face_ID API_EXPORT Face_ID
Get_Default_Font_For_View(Application_Links *app, View_ID view_id) Get_Default_Font_For_View(Application_Links *app, View_ID view_id)

View File

@ -15,7 +15,7 @@
#include "4coder_API/4coder_custom.h" #include "4coder_API/4coder_custom.h"
#include "4ed_defines.h" #include "4ed_defines.h"
#include "4ed_math.h" //#include "4ed_math.h"
#include "4ed_font.h" #include "4ed_font.h"
#include "4ed_system.h" #include "4ed_system.h"

View File

@ -101,47 +101,6 @@ typedef double f64;
#define FixSize(s) struct{ u8 __size_fixer__[s]; } #define FixSize(s) struct{ u8 __size_fixer__[s]; }
internal i32 ceil32(f32 v){
return(((v)>0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)+1.f)) ):( ((i32)(v)) ));
}
internal i32 floor32(f32 v){
return(((v)<0)?( (v == (i32)(v))?((i32)(v)):((i32)((v)-1.f)) ):( ((i32)(v)) ));
}
internal i32 round32(f32 v){
return(floor32(v + 0.5f));
}
internal i32 trun32(f32 v){
return((i32)(v));
}
internal i32 div_ceil(i32 n, i32 d){
return( ((n) % (d) != 0) + ((n) / (d)) );
}
internal i32 l_round_up_i32(i32 x, i32 b){
i32 t = x + b - 1;
return(t - (t%b));
}
internal u32 l_round_up_u32(u32 x, u32 b){
i32 t = x + b - 1;
return(t - (t%b));
}
internal u32 round_up_pot_u32(u32 x){
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
++x;
return(x);
}
#define DrCase(PC) case PC: goto resumespot_##PC #define DrCase(PC) case PC: goto resumespot_##PC
#define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } #define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; }
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }

View File

@ -120,28 +120,33 @@ draw_font_glyph(Render_Target *target, Face_ID font_id, u32 codepoint, f32 x, f3
render_end_push(target, h); render_end_push(target, h);
} }
// TODO(allen): do(merge draw_string_base into draw_string) internal Vec2
snap_point_to_boundary(Vec2 point){
point.x = (f32)(floor32(point.x));
point.y = (f32)(floor32(point.y));
return(point);
}
internal f32 internal f32
draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_id, String str_, i32 x_, i32 y_, u32 color, draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point,
u32 flags, f32 dx, f32 dy){ u32 color, u32 flags, Vec2 delta){
f32 x = 0; f32 total_delta = 0.f;
Font_Pointers font = system->font.get_pointers_by_id(font_id); Font_Pointers font = system->font.get_pointers_by_id(font_id);
if (font.valid != 0){ if (font.valid != 0){
f32 y = (f32)y_; point = snap_point_to_boundary(point);
x = (f32)x_;
f32 byte_advance = font.metrics->byte_advance; f32 byte_advance = font.metrics->byte_advance;
f32 *sub_advances = font.metrics->sub_advances; f32 *sub_advances = font.metrics->sub_advances;
u8 *str = (u8*)str_.str; u8 *str = (u8*)string.str;
u8 *str_end = str + str_.size; u8 *str_end = str + string.size;
Translation_State tran = {}; Translation_State tran = {};
Translation_Emits emits = {}; Translation_Emits emits = {};
for (u32 i = 0; str < str_end; ++str, ++i){ for (u32 i = 0; str < str_end; ++str, ++i){
translating_fully_process_byte(system, font, &tran, *str, i, str_.size, &emits); translating_fully_process_byte(system, font, &tran, *str, i, string.size, &emits);
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits); TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
@ -149,11 +154,11 @@ draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_i
if (behavior.do_codepoint_advance){ if (behavior.do_codepoint_advance){
u32 codepoint = step.value; u32 codepoint = step.value;
if (color != 0){ if (color != 0){
draw_font_glyph(target, font_id, codepoint, x, y, color, flags); draw_font_glyph(target, font_id, codepoint, point.x, point.y, color, flags);
} }
f32 d = font_get_glyph_advance(system, font.settings, font.metrics, font.pages, codepoint); f32 d = font_get_glyph_advance(system, font.settings, font.metrics, font.pages, codepoint);
x += d*dx; point += d*delta;
y += d*dy; total_delta += d;
} }
else if (behavior.do_number_advance){ else if (behavior.do_number_advance){
u8 n = (u8)(step.value); u8 n = (u8)(step.value);
@ -161,70 +166,48 @@ draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_i
u8 cs[3]; u8 cs[3];
cs[0] = '\\'; cs[0] = '\\';
byte_to_ascii(n, cs+1); byte_to_ascii(n, cs+1);
Vec2 pp = point;
f32 xx = x;
f32 yy = y;
for (u32 j = 0; j < 3; ++j){ for (u32 j = 0; j < 3; ++j){
draw_font_glyph(target, font_id, cs[j], xx, yy, color, flags); draw_font_glyph(target, font_id, cs[j], pp.x, pp.y, color, flags);
xx += dx*sub_advances[j]; pp += delta*sub_advances[j];
yy += dy*sub_advances[j];
} }
} }
point += byte_advance*delta;
x += dx*byte_advance; total_delta += byte_advance;
y += dy*byte_advance;
} }
} }
} }
} }
return(x); return(total_delta);
} }
internal f32 internal f32
draw_string_base(System_Functions *system, Render_Target *target, Face_ID font_id, String str_, i32 x_, i32 y_, u32 color){ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point,
f32 result = draw_string_base(system, target, font_id, str_, x_, y_, color, 0, 1.f, 0.f); u32 color){
return(result); return(draw_string(system, target, font_id, string, point, color, 0, V2(1.f, 0.f)));
} }
internal f32 internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String str, i32 x, i32 y, u32 color, draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point,
u32 flags, f32 dx, f32 dy){ u32 color, u32 flags, Vec2 delta){
f32 w = draw_string_base(system, target, font_id, str, x, y, color, flags, dx, dy); return(draw_string(system, target, font_id, make_string_slowly(str), point, color, flags, delta));
return(w);
} }
internal f32 internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, i32 x, i32 y, u32 color, draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point,
u32 flags, f32 dx, f32 dy){ u32 color){
String string = make_string_slowly(str); return(draw_string(system, target, font_id, make_string_slowly(str), point, color, 0, V2(1.f, 0.f)));
f32 w = draw_string_base(system, target, font_id, string, x, y, color, flags, dx, dy);
return(w);
}
internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String str, i32 x, i32 y, u32 color){
f32 w = draw_string(system, target, font_id, str, x, y, color, 0, 1.f, 0.f);
return(w);
}
internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, i32 x, i32 y, u32 color){
f32 w = draw_string(system, target, font_id, str, x, y, color, 0, 1.f, 0.f);
return(w);
} }
internal f32 internal f32
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String str){ font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String str){
f32 w = draw_string_base(system, target, font_id, str, 0, 0, 0); return(draw_string(system, target, font_id, str, V2(0, 0), 0, 0, V2(0, 0)));
return(w);
} }
internal f32 internal f32
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, char *str){ font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, char *str){
String string = make_string_slowly(str); return(draw_string(system, target, font_id, make_string_slowly(str), V2(0, 0), 0, 0, V2(0, 0)));
f32 w = draw_string_base(system, target, font_id, string, 0, 0, 0);
return(w);
} }
// BOTTOM // BOTTOM

View File

@ -99,10 +99,8 @@ struct Shift_Information{
}; };
struct File_Bar{ struct File_Bar{
f32 pos_x; Vec2 pos;
f32 pos_y; Vec2 text_shift;
f32 text_shift_x;
f32 text_shift_y;
i32_Rect rect; i32_Rect rect;
Face_ID font_id; Face_ID font_id;
}; };

View File

@ -98,25 +98,10 @@ do_step_file_view(System_Functions *system, Models *models, View *view, i32_Rect
//////////////////////////////// ////////////////////////////////
internal void
draw_text_field(System_Functions *system, Render_Target *target, View *view, Models *models, Face_ID font_id, i32_Rect rect, String p, String t){
if (target != 0){
Style *style = &models->styles.styles[0];
u32 back_color = style->theme.colors[Stag_Margin];
u32 text1_color = style->theme.colors[Stag_Default];
u32 text2_color = style->theme.colors[Stag_Pop1];
i32 x = rect.x0;
i32 y = rect.y0 + 2;
draw_rectangle(target, rect, back_color);
x = ceil32(draw_string(system, target, font_id, p, x, y, text2_color));
draw_string(system, target, font_id, t, x, y, text1_color);
}
}
internal void internal void
intbar_draw_string(System_Functions *system, Render_Target *target, File_Bar *bar, String str, u32 char_color){ intbar_draw_string(System_Functions *system, Render_Target *target, File_Bar *bar, String str, u32 char_color){
draw_string(system, target, bar->font_id, str, (i32)(bar->pos_x + bar->text_shift_x), (i32)(bar->pos_y + bar->text_shift_y), char_color); Vec2 p = bar->pos + bar->text_shift;
bar->pos_x += font_string_width(system, target, bar->font_id, str); bar->pos.x += draw_string(system, target, bar->font_id, str, p, char_color);
} }
internal void internal void
@ -133,10 +118,8 @@ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Model
if (target != 0){ if (target != 0){
bar.font_id = file->settings.font_id; bar.font_id = file->settings.font_id;
bar.pos_x = (f32)bar.rect.x0; bar.pos = V2(bar.rect.p0);
bar.pos_y = (f32)bar.rect.y0; bar.text_shift = V2(0.f, 2.f);
bar.text_shift_y = 2;
bar.text_shift_x = 0;
draw_rectangle(target, bar.rect, back_color); draw_rectangle(target, bar.rect, back_color);
@ -248,11 +231,11 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
u32 back_color = style->theme.colors[Stag_Back]; u32 back_color = style->theme.colors[Stag_Back];
u32 text1_color = style->theme.colors[Stag_Default]; u32 text1_color = style->theme.colors[Stag_Default];
u32 text2_color = style->theme.colors[Stag_Pop1]; u32 text2_color = style->theme.colors[Stag_Pop1];
i32 x = query_bar_rect.x0; Vec2 p = V2(query_bar_rect.p0);
i32 y = query_bar_rect.y0 + 2; p.y += 2.f;
draw_rectangle(target, query_bar_rect, back_color); draw_rectangle(target, query_bar_rect, back_color);
x = ceil32(draw_string(system, target, font_id, slot->query_bar->prompt, x, y, text2_color)); p.x += draw_string(system, target, font_id, slot->query_bar->prompt, p, text2_color);
draw_string(system, target, font_id, slot->query_bar->string, x, y, text1_color); draw_string(system, target, font_id, slot->query_bar->string, p, text1_color);
} }
view->widget_height = (f32)bar_count*(view->line_height + 2); view->widget_height = (f32)bar_count*(view->line_height + 2);
@ -298,11 +281,10 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
u32 margin_color = get_margin_color(style, item->activation_level); u32 margin_color = get_margin_color(style, item->activation_level);
f32_Rect inner = get_inner_rect(item_rect, 3); f32_Rect inner = get_inner_rect(item_rect, 3);
draw_rectangle(target, inner, back); draw_rectangle(target, inner, back);
i32 x = (i32)inner.x0 + 3; Vec2 p = V2(inner.p0) + V2(3.f, line_height*0.5f - 1.f);
i32 y = (i32)inner.y0 + line_height/2 - 1; p.x += draw_string(system, target, font_id, item->option.string, p, text_color);
x = ceil32(draw_string(system, target, font_id, item->option.string, x, y, text_color)); p.x += font_string_width(system, target, font_id, make_lit_string(" "));
x += (i32)font_string_width(system, target, font_id, " "); draw_string(system, target, font_id, item->option.status, p, pop_color);
draw_string(system, target, font_id, item->option.status, x, y, pop_color);
draw_margin(target, item_rect, inner, margin_color); draw_margin(target, item_rect, inner, margin_color);
}break; }break;
@ -312,11 +294,10 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
u32 text1 = style->theme.colors[Stag_Default]; u32 text1 = style->theme.colors[Stag_Default];
u32 text2 = style->theme.colors[Stag_Pop1]; u32 text2 = style->theme.colors[Stag_Pop1];
draw_rectangle(target, item_rect, back); draw_rectangle(target, item_rect, back);
i32 x = (i32)item_rect.x0; Vec2 p = V2(item_rect.p0) + V2(0.f, 2.f);
i32 y = (i32)item_rect.y0 + 2; p.x += draw_string(system, target, font_id, item->text_field.query, p, text2);
x = ceil32(draw_string(system, target, font_id, item->text_field.query, x, y, text2)); p.x += font_string_width(system, target, font_id, make_lit_string(" "));
x += (i32)font_string_width(system, target, font_id, " "); p.x += draw_string(system, target, font_id, item->text_field.string, p, text1);
draw_string(system, target, font_id, item->text_field.string, x, y, text1);
}break; }break;
case UIType_ColorTheme: case UIType_ColorTheme:
@ -334,32 +315,29 @@ do_render_file_view(System_Functions *system, View *view, Models *models, GUI_Sc
draw_margin(target, item_rect, inner, margin_color); draw_margin(target, item_rect, inner, margin_color);
draw_rectangle(target, inner, back); draw_rectangle(target, inner, back);
i32 y = (i32)inner.y0; Vec2 p = V2(inner.p0);
i32 x = (i32)inner.x0;
String str = item->color_theme.string; String str = item->color_theme.string;
if (str.str == 0){ if (str.str == 0){
str = style_preview->name; str = style_preview->name;
} }
x = ceil32(draw_string(system, target, font_id, str, x, y, text_color)); p.x += draw_string(system, target, font_id, str, p, text_color);
i32 font_x = (i32)(inner.x1 - font_string_width(system, target, font_id, font_name)); f32 font_x = inner.x1 - font_string_width(system, target, font_id, font_name);
if (font_x > x + 10){ if (font_x > p.x + 10.f){
draw_string(system, target, font_id, font_name, font_x, y, text_color); draw_string(system, target, font_id, font_name, V2(font_x, p.y), text_color);
} }
i32 height = font.metrics->height; i32 height = font.metrics->height;
x = (i32)inner.x0; p = V2(inner.x0, p.y + (f32)height);
y += height; p.x += draw_string(system, target, font_id, "if", p, keyword_color);
x = ceil32(draw_string(system, target, font_id, "if", x, y, keyword_color)); p.x += draw_string(system, target, font_id, "(x < ", p, text_color);
x = ceil32(draw_string(system, target, font_id, "(x < ", x, y, text_color)); p.x += draw_string(system, target, font_id, "0", p, int_constant_color);
x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color)); p.x += draw_string(system, target, font_id, ") { x = ", p, text_color);
x = ceil32(draw_string(system, target, font_id, ") { x = ", x, y, text_color)); p.x += draw_string(system, target, font_id, "0", p, int_constant_color);
x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color)); p.x += draw_string(system, target, font_id, "; } ", p, text_color);
x = ceil32(draw_string(system, target, font_id, "; } ", x, y, text_color)); p.x += draw_string(system, target, font_id, "// comment", p, comment_color);
x = ceil32(draw_string(system, target, font_id, "// comment", x, y, comment_color));
x = (i32)inner.x0; p = V2(inner.x0, p.y + (f32)height);
y += height; draw_string(system, target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", p, text_color);
draw_string(system, target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", x, y, text_color);
}break; }break;
} }
} }

View File

@ -43,7 +43,8 @@
# include "4coder_default_bindings.cpp" # include "4coder_default_bindings.cpp"
#endif #endif
#include "4ed_math.h" #include "4coder_base_types.cpp"
//#include "4ed_math.h"
#include "4ed_font.h" #include "4ed_font.h"
#include "4ed_system.h" #include "4ed_system.h"
@ -1748,12 +1749,13 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
b8 *control_keys = win32vars.input_chunk.pers.control_keys; b8 *control_keys = win32vars.input_chunk.pers.control_keys;
i32 control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys); i32 control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys);
Assert(*count < KEY_INPUT_BUFFER_SIZE); if (*count < KEY_INPUT_BUFFER_SIZE){
data[*count].character = 0; data[*count].character = 0;
data[*count].character_no_caps_lock = 0; data[*count].character_no_caps_lock = 0;
data[*count].keycode = key; data[*count].keycode = key;
memcpy(data[*count].modifiers, control_keys, control_keys_size); memcpy(data[*count].modifiers, control_keys, control_keys_size);
++(*count); ++(*count);
}
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
} }
@ -1792,12 +1794,13 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
} }
} }
Assert(*count < KEY_INPUT_BUFFER_SIZE); if (*count < KEY_INPUT_BUFFER_SIZE){
data[*count].character = character; data[*count].character = character;
data[*count].character_no_caps_lock = character_no_caps_lock; data[*count].character_no_caps_lock = character_no_caps_lock;
data[*count].keycode = character_no_caps_lock; data[*count].keycode = character_no_caps_lock;
memcpy(data[*count].modifiers, control_keys, control_keys_size); memcpy(data[*count].modifiers, control_keys, control_keys_size);
++(*count); ++(*count);
}
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
}break; }break;