Colored touchbuttons, portafixes

This commit is contained in:
Henrik Rydgard 2012-10-30 16:23:08 +01:00
parent 5a5f599e1b
commit 1ea568990d
7 changed files with 49 additions and 26 deletions

View file

@ -26,7 +26,8 @@ LOCAL_SRC_FILES :=\
file/file_util.cpp \
file/zip_read.cpp \
json/json_writer.cpp \
math/math_util.cpp.arm \
math/curves.cpp \
math/math_util.cpp \
math/lin/aabb.cpp.arm \
math/lin/plane.cpp.arm \
math/lin/quat.cpp.arm \
@ -51,7 +52,7 @@ LOCAL_SRC_FILES :=\
util/random/perlin.cpp
LOCAL_CFLAGS := -O2 -DGL_GLEXT_PROTOTYPES -fsigned-char
LOCAL_CFLAGS := -O2 -DGL_GLEXT_PROTOTYPES -fsigned-char -fno-strict-aliasing
LOCAL_CPPFLAGS := -fno-exceptions -fno-rtti -std=gnu++0x
LOCAL_LDLIBS := -lz
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ext/libzip

View file

@ -203,9 +203,12 @@ extern "C" void Java_com_turboviking_libnative_NativeRenderer_displayResize(JNIE
extern "C" void Java_com_turboviking_libnative_NativeRenderer_displayRender(JNIEnv *env, jobject obj) {
if (renderer_inited) {
UpdateInputState(&input_state);
NativeUpdate(input_state);
{
lock_guard guard(input_state.lock);
NativeUpdate(input_state);
EndInputState(&input_state);
}
NativeRender();
EndInputState(&input_state);
time_update();
} else {
ELOG("Ended up in nativeRender even though app has quit.%s", "");
@ -266,6 +269,7 @@ extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_touch
extern "C" void Java_com_turboviking_libnative_NativeApp_keyDown
(JNIEnv *, jclass, jint key) {
ILOG("Keydown %i", key);
lock_guard guard(input_state.lock);
// Need a mechanism to release these.
switch (key) {
case 1: // Back
@ -282,7 +286,8 @@ extern "C" void Java_com_turboviking_libnative_NativeApp_keyDown
extern "C" void Java_com_turboviking_libnative_NativeApp_keyUp
(JNIEnv *, jclass, jint key) {
ILOG("Keyup %i", key);
ILOG("Keyup %i", key);
lock_guard guard(input_state.lock);
// Need a mechanism to release these.
switch (key) {
case 1: // Back

View file

@ -78,6 +78,9 @@ static void stripTailDirSlashes(std::string &fname)
// Returns true if file filename exists
bool exists(const std::string &filename)
{
#ifdef _WIN32
return GetFileAttributes(filename.c_str()) != 0xFFFFFFFF;
#else
struct stat64 file_info;
std::string copy(filename);
@ -86,11 +89,15 @@ bool exists(const std::string &filename)
int result = stat64(copy.c_str(), &file_info);
return (result == 0);
#endif
}
// Returns true if filename is a directory
bool isDirectory(const std::string &filename)
{
#ifdef _WIN32
return (GetFileAttributes(filename.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else
struct stat64 file_info;
std::string copy(filename);
@ -104,6 +111,7 @@ bool isDirectory(const std::string &filename)
}
return S_ISDIR(file_info.st_mode);
#endif
}
size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files) {

View file

@ -158,7 +158,7 @@ inline void rot(float *v, float angle, float xc, float yc) {
}
void DrawBuffer::DrawImageRotated(int atlas_image, float x, float y, float scale, float angle, Color color) {
void DrawBuffer::DrawImageRotated(int atlas_image, float x, float y, float scale, float angle, Color color, bool mirror_h) {
const AtlasImage &image = atlas->images[atlas_image];
float w = (float)image.w * scale;
float h = (float)image.h * scale;
@ -174,13 +174,20 @@ void DrawBuffer::DrawImageRotated(int atlas_image, float x, float y, float scale
{x2, y2},
{x1, y2},
};
float u1 = image.u1;
float u2 = image.u2;
if (mirror_h) {
float temp = u1;
u1 = u2;
u2 = temp;
}
const float uv[6][2] = {
{image.u1, image.v1},
{image.u2, image.v1},
{image.u2, image.v2},
{image.u1, image.v1},
{image.u2, image.v2},
{image.u1, image.v2},
{u1, image.v1},
{u2, image.v1},
{u2, image.v2},
{u1, image.v1},
{u2, image.v2},
{u1, image.v2},
};
for (int i = 0; i < 6; i++) {
rot(v[i], angle, x, y);

View file

@ -94,7 +94,7 @@ public:
void MeasureImage(int atlas_image, float *w, float *h);
void DrawImage(int atlas_image, float x, float y, float scale, Color color = COLOR(0xFFFFFF), int align = ALIGN_TOPLEFT);
void DrawImageStretch(int atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF));
void DrawImageRotated(int atlas_image, float x, float y, float scale, float angle, Color color = COLOR(0xFFFFFF)); // Always centers
void DrawImageRotated(int atlas_image, float x, float y, float scale, float angle, Color color = COLOR(0xFFFFFF), bool mirror_h = false); // Always centers
void DrawTexRect(float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2, Color color);
// Results in 18 triangles. Kind of expensive for a button.
void DrawImage4Grid(int atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF), float corner_scale = 1.0);

View file

@ -4,8 +4,8 @@
#include "input/input_state.h"
#include "virtual_input.h"
TouchButton::TouchButton(const Atlas *atlas, int imageIndex, int overlayImageIndex, int button, int rotationAngle)
: atlas_(atlas), imageIndex_(imageIndex), overlayImageIndex_(overlayImageIndex), button_(button)
TouchButton::TouchButton(const Atlas *atlas, int imageIndex, int overlayImageIndex, int button, int rotationAngle, bool mirror_h)
: atlas_(atlas), imageIndex_(imageIndex), overlayImageIndex_(overlayImageIndex), button_(button), mirror_h_(mirror_h)
{
memset(pointerDown, 0, sizeof(pointerDown));
w_ = atlas_->images[imageIndex_].w;
@ -29,20 +29,19 @@ void TouchButton::update(InputState &input_state)
}
}
void TouchButton::draw(DrawBuffer &db)
void TouchButton::draw(DrawBuffer &db, uint32_t color)
{
uint32_t color = 0xAAFFFFFF;
float scale = 1.0f;
if (isDown_) {
color = 0xFFFFFFFF;
color |= 0xFF000000;
scale = 2.0f;
}
db.DrawImageRotated(imageIndex_, x_ + w_/2, y_ + h_/2, scale, rotationAngle_, color);
// We only mirror background
db.DrawImageRotated(imageIndex_, x_ + w_/2, y_ + h_/2, scale, rotationAngle_, color, mirror_h_);
if (overlayImageIndex_ != -1)
db.DrawImageRotated(overlayImageIndex_, x_ + w_/2, y_ + h_/2, scale, rotationAngle_, color);
}
TouchStick::TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex, int stick)
: atlas_(atlas), bgImageIndex_(bgImageIndex), stickImageIndex_(stickImageIndex), stick_(stick)
{
@ -78,9 +77,9 @@ void TouchStick::update(InputState &input_state)
}
}
void TouchStick::draw(DrawBuffer &db)
void TouchStick::draw(DrawBuffer &db, uint32_t color)
{
if (bgImageIndex_ != -1)
db.DrawImage(bgImageIndex_, stick_x_, stick_y_, 1.0f, 0xFFFFFFFF, ALIGN_CENTER);
db.DrawImage(stickImageIndex_, stick_x_ + stick_delta_x_, stick_y_ + stick_delta_y_, 1.0f, 0xFFFFFFFF, ALIGN_CENTER);
db.DrawImage(bgImageIndex_, stick_x_, stick_y_, 1.0f, color, ALIGN_CENTER);
db.DrawImage(stickImageIndex_, stick_x_ + stick_delta_x_, stick_y_ + stick_delta_y_, 1.0f, color, ALIGN_CENTER);
}

View file

@ -5,14 +5,15 @@
class DrawBuffer;
// Multitouch-enabled emulation of a hardware button.
// Many of these can be pressed simultaneously with multitouch.
// (any finger will work, simultaneously with other virtual button/stick actions).
class TouchButton
{
public:
TouchButton(const Atlas *atlas, int imageIndex, int overlayImageIndex, int button, int rotationAngle = 0);
TouchButton(const Atlas *atlas, int imageIndex, int overlayImageIndex, int button, int rotationAngle = 0, bool mirror_h = false);
void update(InputState &input_state);
void draw(DrawBuffer &db);
void draw(DrawBuffer &db, uint32_t color);
void setPos(float x, float y) {
x_ = x - w_ / 2;
@ -32,6 +33,7 @@ private:
int overlayImageIndex_;
int button_;
float rotationAngle_;
bool mirror_h_;
float x_, y_;
float w_;
@ -45,6 +47,7 @@ private:
// Multi-touch enabled virtual joystick
// Many of these can be used simultaneously with multitouch.
// (any finger will work, simultaneously with other virtual button/stick actions).
class TouchStick
{
@ -52,7 +55,7 @@ public:
TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex, int stick);
void update(InputState &input_state);
void draw(DrawBuffer &db);
void draw(DrawBuffer &db, uint32_t color);
void setPos(float x, float y) {
stick_x_ = x;