mouse->pointer

This commit is contained in:
Henrik Rydgard 2012-07-26 17:24:47 +02:00
parent f794440d79
commit 3b3f8242b0
8 changed files with 44 additions and 31 deletions

View file

@ -252,15 +252,13 @@ extern "C" void JNICALL Java_com_turboviking_libnative_NativeApp_touch
}
float scaledX = (int)(x * dp_xscale); // why the (int) cast?
float scaledY = (int)(y * dp_yscale);
input_state.mouse_x[pointerId] = scaledX;
input_state.mouse_y[pointerId] = scaledY;
input_state.pointer_x[pointerId] = scaledX;
input_state.pointer_y[pointerId] = scaledY;
if (code == 1) {
input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId];
input_state.mouse_down[pointerId] = true;
input_state.pointer_down[pointerId] = true;
NativeTouch(pointerId, scaledX, scaledY, 0, TOUCH_DOWN);
} else if (code == 2) {
input_state.mouse_last[pointerId] = input_state.mouse_down[pointerId];
input_state.mouse_down[pointerId] = false;
input_state.pointer_down[pointerId] = false;
NativeTouch(pointerId, scaledX, scaledY, 0, TOUCH_UP);
} else {
NativeTouch(pointerId, scaledX, scaledY, 0, TOUCH_MOVE);

View file

@ -335,7 +335,7 @@ public class NativeActivity extends Activity {
return null;
return input.getText().toString();
}
public void processCommand(String command, String params) {
if (command.equals("launchBrowser")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params));

View file

@ -36,7 +36,7 @@ void NativeDeviceLost();
// Called ~sixty times a second, delivers the current input state.
// Main thread.
void NativeUpdate(const InputState &input);
void NativeUpdate(InputState &input);
// Delivers touch events "instantly", without waiting for the next frame so that NativeUpdate can deliver.
// Useful for triggering audio events, saving a few ms.

View file

@ -102,14 +102,22 @@ void SimulateGamepad(const uint8 *keys, InputState *input) {
input->pad_buttons |= (1<<b);
}
if (keys['I']) input->pad_lstick_y=32000;
else if (keys['K']) input->pad_lstick_y=-32000;
if (keys['J']) input->pad_lstick_x=-32000;
else if (keys['L']) input->pad_lstick_x=32000;
if (keys['8']) input->pad_rstick_y=32000;
else if (keys['2']) input->pad_rstick_y=-32000;
if (keys['4']) input->pad_rstick_x=-32000;
else if (keys['6']) input->pad_rstick_x=32000;
if (keys[SDLK_i])
input->pad_lstick_y=1;
else if (keys[SDLK_k])
input->pad_lstick_y=-1;
if (keys[SDLK_j])
input->pad_lstick_x=-1;
else if (keys[SDLK_l])
input->pad_lstick_x=1;
if (keys[SDLK_KP8])
input->pad_rstick_y=1;
else if (keys[SDLK_KP2])
input->pad_rstick_y=-1;
if (keys[SDLK_KP4])
input->pad_rstick_x=-1;
else if (keys[SDLK_KP6])
input->pad_rstick_x=1;
}
extern void mixaudio(void *userdata, Uint8 *stream, int len) {
@ -251,19 +259,19 @@ int main(int argc, char *argv[]) {
quitRequested = 1;
}
} else if (event.type == SDL_MOUSEMOTION) {
input_state.mouse_x[0] = mx;
input_state.mouse_y[0] = my;
input_state.pointer_x[0] = mx;
input_state.pointer_y[0] = my;
NativeTouch(0, mx, my, 0, TOUCH_MOVE);
} 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.pointer_down[0] = true;
nextFrameMD = true;
NativeTouch(0, mx, my, 0, TOUCH_DOWN);
}
} else if (event.type == SDL_MOUSEBUTTONUP) {
if (event.button.button == SDL_BUTTON_LEFT) {
input_state.mouse_down[0] = false;
input_state.pointer_down[0] = false;
nextFrameMD = false;
//input_state.mouse_buttons_up = 1;
NativeTouch(0, mx, my, 0, TOUCH_UP);
@ -274,7 +282,6 @@ int main(int argc, char *argv[]) {
if (quitRequested)
break;
input_state.mouse_last[0] = input_state.mouse_down[0];
const uint8 *keys = (const uint8 *)SDL_GetKeyState(NULL);
if (keys[SDLK_ESCAPE])
break;

View file

@ -11,6 +11,7 @@
#include <errno.h>
#endif
#include "base/basictypes.h"
class recursive_mutex {
#ifdef _WIN32
@ -33,6 +34,7 @@ public:
pthread_mutex_destroy(&mut_);
#endif
}
bool trylock() {
#ifdef _WIN32
return TryEnterCriticalSection(&mut_) == TRUE;
@ -57,6 +59,7 @@ public:
private:
mutexType mut_;
DISALLOW_COPY_AND_ASSIGN(recursive_mutex);
};
class lock_guard {

View file

@ -27,10 +27,10 @@ static Finger fingers[MAX_FINGERS];
void update(const InputState &state) {
// Mouse / 1-finger-touch control.
if (state.mouse_down[0]) {
if (state.pointer_down[0]) {
fingers[0].down = true;
fingers[0].downX = state.mouse_x[0];
fingers[0].downY = state.mouse_y[0];
fingers[0].downX = state.pointer_x[0];
fingers[0].downY = state.pointer_y[0];
} else {
fingers[0].down = false;
}

View file

@ -34,8 +34,7 @@ struct InputState {
pad_buttons_up(0),
mouse_valid(false),
accelerometer_valid(false) {
memset(mouse_down, 0, sizeof(mouse_down));
memset(mouse_last, 0, sizeof(mouse_last));
memset(pointer_down, 0, sizeof(pointer_down));
}
// Gamepad style input
@ -54,14 +53,16 @@ struct InputState {
// There are up to 8 mice / fingers.
volatile bool mouse_valid;
int mouse_x[MAX_POINTERS];
int mouse_y[MAX_POINTERS];
bool mouse_down[MAX_POINTERS];
bool mouse_last[MAX_POINTERS];
int pointer_x[MAX_POINTERS];
int pointer_y[MAX_POINTERS];
bool pointer_down[MAX_POINTERS];
// Accelerometer
bool accelerometer_valid;
Vec3 acc;
private:
DISALLOW_COPY_AND_ASSIGN(InputState);
};
inline void UpdateInputState(InputState *input) {

View file

@ -76,6 +76,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\zlib;..\native;..\RollerballGL;..\native\ext\glew;..\SDL\include;..\libpng;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -226,7 +228,9 @@
<ClCompile Include="ui\screen.cpp" />
<ClCompile Include="ui\ui.cpp" />
<ClCompile Include="util\bits\bits.cpp" />
<ClCompile Include="util\random\perlin.cpp" />
<ClCompile Include="util\random\perlin.cpp">
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AssemblyAndSourceCode</AssemblerOutput>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">