diff --git a/android/app-android.cpp b/android/app-android.cpp index 21d3298614..d2e6fdd31d 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -210,11 +210,11 @@ extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_touch input_state.mouse_x[pointerId] = (int)x; input_state.mouse_y[pointerId] = (int)y; if (code == 1) { - ILOG("Down: %i %f %f", pointerId, x, y); + //ILOG("Down: %i %f %f", pointerId, x, y); input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId]; input_state.mouse_down[pointerId] = true; } else if (code == 2) { - ILOG("Up: %i %f %f", pointerId, x, y); + //ILOG("Up: %i %f %f", pointerId, x, y); input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId]; input_state.mouse_down[pointerId] = false; } diff --git a/base/PCMain.cpp b/base/PCMain.cpp index fc5759b1ef..0c10212882 100644 --- a/base/PCMain.cpp +++ b/base/PCMain.cpp @@ -204,13 +204,15 @@ int main(int argc, char *argv[]) { InputState input_state; int framecount = 0; - + bool nextFrameMD = 0; while (true) { SDL_Event event; input_state.accelerometer_valid = false; input_state.mouse_valid = true; int done = 0; + + // input_state.mouse_down[1] = nextFrameMD; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { done = 1; @@ -221,19 +223,25 @@ int main(int argc, char *argv[]) { } else if (event.type == SDL_MOUSEMOTION) { input_state.mouse_x[0] = event.motion.x; input_state.mouse_y[0] = event.motion.y; + input_state.mouse_x[1] = event.motion.x + 150; + input_state.mouse_y[1] = event.motion.y; } else if (event.type == SDL_MOUSEBUTTONDOWN) { if (event.button.button == SDL_BUTTON_LEFT) { ///input_state.mouse_buttons_down = 1; - input_state.mouse_down[0] = true; + input_state.mouse_down[0] = true; + nextFrameMD = true; } } else if (event.type == SDL_MOUSEBUTTONUP) { if (event.button.button == SDL_BUTTON_LEFT) { - input_state.mouse_down[0] = false; + input_state.mouse_down[0] = false; + nextFrameMD = false; //input_state.mouse_buttons_up = 1; } } } + + if (done) break; input_state.mouse_last[0] = input_state.mouse_down[0]; diff --git a/gfx_es2/draw_buffer.cpp b/gfx_es2/draw_buffer.cpp index ac4b323bf6..dee035db8a 100644 --- a/gfx_es2/draw_buffer.cpp +++ b/gfx_es2/draw_buffer.cpp @@ -10,7 +10,9 @@ #endif #endif +#include #include + #include "base/logging.h" #include "math/math_util.h" #include "gfx_es2/draw_buffer.h" @@ -86,7 +88,7 @@ void DrawBuffer::V(float x, float y, float z, uint32 color, float u, float v) { } void DrawBuffer::Rect(float x, float y, float w, float h, uint32 color, int align) { - DoAlign(align, &x, &y, w, h); + DoAlign(align, &x, &y, &w, &h); RectVGradient(x, y, w, h, color, color); } @@ -290,22 +292,33 @@ void DrawBuffer::DrawTextShadow(int font, const char *text, float x, float y, Co DrawText(font, text, x, y, color, flags); } -void DrawBuffer::DoAlign(int align, float *x, float *y, float w, float h) { - if (align & ALIGN_HCENTER) *x -= w / 2; - if (align & ALIGN_RIGHT) *x -= w; - if (align & ALIGN_VCENTER) *y -= h / 2; - if (align & ALIGN_BOTTOM) *y -= h; +void DrawBuffer::DoAlign(int flags, float *x, float *y, float *w, float *h) { + if (flags & ALIGN_HCENTER) *x -= *w / 2; + if (flags & ALIGN_RIGHT) *x -= *w; + if (flags & ALIGN_VCENTER) *y -= *h / 2; + if (flags & ALIGN_BOTTOM) *y -= *h; + if (flags & (ROTATE_90DEG_LEFT | ROTATE_90DEG_RIGHT)) { + std::swap(*w, *h); + std::swap(*x, *y); + } } +// ROTATE_* doesn't yet work right. void DrawBuffer::DrawText(int font, const char *text, float x, float y, Color color, int flags) { const AtlasFont &atlasfont = *atlas->fonts[font]; unsigned char cval; float w, h; MeasureText(font, text, &w, &h); if (flags) { - DoAlign(flags, &x, &y, w, h); + DoAlign(flags, &x, &y, &w, &h); } - y+=atlasfont.ascend*fontscaley; + + if (flags & ROTATE_90DEG_LEFT) { + x -= atlasfont.ascend*fontscaley; + // y += h; + } + else + y += atlasfont.ascend*fontscaley; float sx = x; while ((cval = *text++) != '\0') { if (cval == '\n') { @@ -316,17 +329,28 @@ void DrawBuffer::DrawText(int font, const char *text, float x, float y, Color co if (cval < 32) continue; if (cval > 127) continue; AtlasChar c = atlasfont.chars[cval - 32]; - float cx1 = x + c.ox * fontscalex; - float cy1 = y + c.oy * fontscaley; - float cx2 = x + (c.ox + c.pw) * fontscalex; - float cy2 = y + (c.oy + c.ph) * fontscaley; + float cx1, cy1, cx2, cy2; + if (flags & ROTATE_90DEG_LEFT) { + cy1 = y - c.ox * fontscalex; + cx1 = x + c.oy * fontscaley; + cy2 = y - (c.ox + c.pw) * fontscalex; + cx2 = x + (c.oy + c.ph) * fontscaley; + } else { + cx1 = x + c.ox * fontscalex; + cy1 = y + c.oy * fontscaley; + cx2 = x + (c.ox + c.pw) * fontscalex; + cy2 = y + (c.oy + c.ph) * fontscaley; + } V(cx1, cy1, color, c.sx, c.sy); V(cx2, cy1, color, c.ex, c.sy); V(cx2, cy2, color, c.ex, c.ey); V(cx1, cy1, color, c.sx, c.sy); V(cx2, cy2, color, c.ex, c.ey); V(cx1, cy2, color, c.sx, c.ey); - x += c.wx * fontscalex; + if (flags & ROTATE_90DEG_LEFT) + y -= c.wx * fontscalex; + else + x += c.wx * fontscalex; } } diff --git a/gfx_es2/draw_buffer.h b/gfx_es2/draw_buffer.h index 36405c15ab..e79da5e56c 100644 --- a/gfx_es2/draw_buffer.h +++ b/gfx_es2/draw_buffer.h @@ -20,6 +20,11 @@ enum { ALIGN_TOPRIGHT = ALIGN_TOP | ALIGN_RIGHT, ALIGN_BOTTOMLEFT = ALIGN_BOTTOM | ALIGN_LEFT, ALIGN_BOTTOMRIGHT = ALIGN_BOTTOM | ALIGN_RIGHT, + + // Only for text drawing + ROTATE_90DEG_LEFT = 256, + ROTATE_90DEG_RIGHT = 512, + ROTATE_180DEG = 1024, }; struct GLSLProgram; @@ -80,7 +85,7 @@ class DrawBuffer { void DrawImage2GridH(int atlas_image, float x1, float y1, float x2, Color color = COLOR(0xFFFFFF), float scale = 1.0); void MeasureText(int font, const char *text, float *w, float *h); - void DrawText(int font, const char *text, float x, float y, Color color = 0xFFFFFFFF, int flags = 0); + void DrawText(int font, const char *text, float x, float y, Color color = 0xFFFFFFFF, int flags = 0); void DrawTextShadow(int font, const char *text, float x, float y, Color color = 0xFFFFFFFF, int flags = 0); void RotateSprite(int atlas_entry, float x, float y, float angle, float scale, Color color); @@ -93,7 +98,7 @@ class DrawBuffer { void EnableBlend(bool enable); private: - void DoAlign(int align, float *x, float *y, float w, float h); + void DoAlign(int flags, float *x, float *y, float *w, float *h); struct Vertex { float x, y, z; uint8 r, g, b, a; diff --git a/native.vcxproj b/native.vcxproj index df5929eb76..b5bbbc1f44 100644 --- a/native.vcxproj +++ b/native.vcxproj @@ -137,6 +137,7 @@ + @@ -186,6 +187,7 @@ + diff --git a/native.vcxproj.filters b/native.vcxproj.filters index 82845e359b..ea338768b4 100644 --- a/native.vcxproj.filters +++ b/native.vcxproj.filters @@ -156,6 +156,9 @@ base + + util + @@ -281,6 +284,9 @@ base + + util + @@ -322,5 +328,8 @@ {4710a9a2-d1fa-4920-ba1b-a7527902be53} + + {e36ca540-863c-496b-b0f4-b1ece3e72feb} + \ No newline at end of file diff --git a/util/bits/bits.h b/util/bits/bits.h index 1729761e2b..d5c3d7eac6 100644 --- a/util/bits/bits.h +++ b/util/bits/bits.h @@ -37,6 +37,29 @@ inline uint32_t _rotr(uint32_t val, int shift) { return (val << shift) | (val >> (31 - shift)); } +/* +template +class BitArray { +public: + BitArray() { + memset(data, 0, sizeof(data)); + } + + BitArray And(const BitArray &other) { + BitArray retVal; + for (int i = 0; i < DATACOUNT; i++) { + retVal.data[i] = data[i] & other.data[i]; + } + } + +private: + uint32 data[(SZ + 31) / 32]; + enum { + DATACOUNT = (SZ + 31) / 32; + }; +}; +*/ + #endif #endif