本文整理汇总了C++中SDL_BUTTON函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_BUTTON函数的具体用法?C++ SDL_BUTTON怎么用?C++ SDL_BUTTON使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_BUTTON函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exaIsMouseButtonDown
bool exaIsMouseButtonDown (unsigned char button)
{
if (SDL_BUTTON (button) &mbuttondown) return true;
return false;
}
示例2: SDL_BUTTON
bool InputManager::mouseDown(int button) const {
return _mouseState & SDL_BUTTON(button);
}
示例3: return
bool InputManager::mousePressed(int button) const {
return (_mouseState & SDL_BUTTON(button))
&& !(_prevMouseState & SDL_BUTTON(button));
}
示例4: SDL_GetKeyboardState
bool controls::inputUpdate(SDL_Event* evt)
{
const Uint8* keystate = SDL_GetKeyboardState(NULL);
//KEY PRESSES
if (keystate[SDL_SCANCODE_RETURN])
{
ENTER = true;
cout << "ENTER PRESSED" << endl;
return ENTER;
}
if (keystate[SDL_SCANCODE_UP])
{
UP = true;
cout << "UP PRESSED" << endl;
return UP;
}
if (keystate[SDL_SCANCODE_DOWN])
{
DOWN = true;
cout << "DOWN PRESSED" << endl;
return DOWN;
}
if (keystate[SDL_SCANCODE_LEFT])
{
LEFT = true;
cout << "LEFT PRESSED" << endl;
return LEFT;
}
if (keystate[SDL_SCANCODE_RIGHT])
{
RIGHT = true;
cout << "RIGHT PRESSED" << endl;
return RIGHT;
}
Uint32 SDL_GetMouseState(int* x, int* y);
SDL_PumpEvents();
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))
{
MOUSELEFT = true;
cout << "MOUSE LEFT PRESSED" << endl;
return MOUSELEFT;
}
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))
{
MOUSERIGHT = true;
cout << "MOUSE RIGHT PRESSED" << endl;
return MOUSERIGHT;
}
//KEY RELEASES
if (!keystate[SDL_SCANCODE_RETURN])
{
ENTER = false;
return ENTER;
}
if (!keystate[SDL_SCANCODE_UP])
{
UP = false;
return UP;
}
if (!keystate[SDL_SCANCODE_DOWN])
{
DOWN = false;
return DOWN;
}
if (!keystate[SDL_SCANCODE_LEFT])
{
LEFT = false;
return LEFT;
}
if (!keystate[SDL_SCANCODE_RIGHT])
{
RIGHT = false;
return RIGHT;
}
return false;
}
示例5: main
//.........这里部分代码省略.........
//Load Models->GameModels
//-----------------------------------------------------------------------------------------SHADERSETUP--------------------------------------------
if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader){
cout << endl << "SHADER LOG: -------------------------------------------------------- BEGIN" << endl;
// Simple Normal Shader without SpecMap
normalShader = new Shader("normal.vert", "normal.frag");
normalShader->useShader();
normalShader->setAttribute1i("diffuseMap0", 0);
normalShader->setAttribute1i("normalMap1", 1);
normalShader->setAttribute1f("SpecularPower", 2.0f);
normalShader->setAttribute4f("Specular", 0.5, 0.5, 0.5, 1.0);
normalShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
normalShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
normalShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);
// Normal Shader with SpecMap
normalSpecShader = new Shader("normalSpec.vert", "normalSpec.frag");
normalSpecShader->useShader();
normalSpecShader->setAttribute1i("diffuseMap0", 0);
normalSpecShader->setAttribute1i("normalMap1", 1);
normalSpecShader->setAttribute1i("specularMap2", 2);
normalSpecShader->setAttribute1f("SpecularPower", 2.0f);
normalSpecShader->setAttribute4f("Specular", 0.5, 0.5, 0.5, 1.0);
normalSpecShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
normalSpecShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
normalSpecShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);
// Simple LambertShader with DiffuseMap
diffuseShader = new Shader("lambertDiffuse.vert", "lambertDiffuse.frag");
diffuseShader->useShader();
diffuseShader->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
diffuseShader->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
diffuseShader->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);
lambertShader_static = new Shader("lambert_static.vert", "lambert_static.frag");
lambertShader_static->useShader();
lambertShader_static->setAttribute4f("Ambient", 0.3, 0.3, 0.3, 1.0);
lambertShader_static->setAttribute4f("Diffuse", 1, 1, 1, 1.0);
lambertShader_static->setAttribute3f("fvLightPosition", 50.3f, 18.9f, 27.2f);
cout << endl << "SHADER LOG: ---------------------------------------------------------- END" << endl;
}
else{
cout << endl << "GLSL not supported" << endl;
}
//-----------------------------------------------------------------------------------------SHADERSETUP--------------------------------------------
/**************************************ALL THE ONE TIME SCENE SETUP GOES HERE*******************************************/
// Main Engine Loop
bool isRunning = true;
SDL_Event event;
while (isRunning )
{
//Gets states of the Mouse and stroes them in the struct
SDL_GetMouseState(&mouseState.x, &mouseState.y);
mouseState.LeftButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1);
mouseState.MiddleButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2);
mouseState.RightButtonDown = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3);
drawMainScene(window); // calls stuff that needs to update every frame
//Event loop
while (SDL_PollEvent(&event)){
if (event.type == SDL_QUIT)
isRunning = false;
}
if (viewportNavigation())
isRunning = false;
}
delete teapodModel;
delete lambertShader_static;
delete diffuseShader;
delete normalShader;
delete normalSpecShader;
GAEngine::Unitialize();
SDL_Quit();
return 1;
}
示例6: handle_mouse
void IntroState::handle_mouse(const int x, const int y, const Uint8 mouse_button_state) {
if (mouse_button_state & SDL_BUTTON(1)) {
std::cout << "Mouse Button 1(left) is pressed.\n" << x << " , " << y << std::endl;
}
}
示例7: SDL_GetMouseState
bool BaseAppInput::handleMouse(void)
{
Uint8 buttons = SDL_GetMouseState(NULL, NULL);
bool left = buttons & SDL_BUTTON(1);
bool right = buttons & SDL_BUTTON(2);
bool middle = buttons & SDL_BUTTON(3);
//fire our own mouse up/down events
if (left)
{
if (!mWasLeftDown)
{
if (! fireLeftMouseDown() )
{
return false;
}
}
}
else
{
if (mWasLeftDown)
{
if (! fireLeftMouseUp() )
{
return false;
}
}
}
if (right)
{
if (!mWasRightDown)
{
if (! fireRightMouseDown() )
{
return false;
}
}
}
else
{
if (mWasRightDown)
{
if (! fireRightMouseUp() )
{
return false;
}
}
}
if (middle)
{
if (!mWasMiddleDown)
{
if (! fireMiddleMouseDown() )
{
return false;
}
}
}
else
{
if (mWasMiddleDown)
{
if (! fireMiddleMouseUp() )
{
return false;
}
}
}
mWasLeftDown = left;
mWasRightDown = right;
mWasMiddleDown = middle;
return true;
}
示例8: while
int GP2X_Events::thread() {
static int l_x = 0;
static int l_y = 0;
static int l_button = 0;
while(m_running) {
m_dx = 0;
m_dy = 0;
m_button = 0;
// UP
if(SDL_JoystickGetButton(m_joy, 0)) {
m_dy = -1;
}
// DOWN
if(SDL_JoystickGetButton(m_joy, 4)) {
m_dy = 1;
}
// LEFT
if(SDL_JoystickGetButton(m_joy, 2)) {
m_dx = -1;
}
// RIGHT
if(SDL_JoystickGetButton(m_joy, 6)) {
m_dx = 1;
}
// UP - LEFT
if(SDL_JoystickGetButton(m_joy, 1)) {
m_dy = -1;
m_dx = -1;
}
// UP - RIGHT
if(SDL_JoystickGetButton(m_joy, 7)) {
m_dy = -1;
m_dx = 1;
}
// DOWN - LEFT
if(SDL_JoystickGetButton(m_joy, 3)) {
m_dy = 1;
m_dx = -1;
}
// DOWN - RIGHT
if(SDL_JoystickGetButton(m_joy, 5)) {
m_dy = 1;
m_dx = 1;
}
// CLICK
if(SDL_JoystickGetButton(m_joy, 18)) {
m_button |= SDL_BUTTON(1);
}
// A
if(SDL_JoystickGetButton(m_joy, 12)) {
m_button |= SDL_BUTTON(2);
}
// B
if(SDL_JoystickGetButton(m_joy, 13)) {
m_button |= SDL_BUTTON(3);
}
// X
if(SDL_JoystickGetButton(m_joy, 14)) {
m_button |= SDL_BUTTON(1);
}
m_x += m_dx * 2;
m_y += m_dy * 2;
if(l_x != m_x || l_y != m_y) {
SDL_WarpMouse(m_x, m_y);
SDL_Event event;
event.type = SDL_MOUSEMOTION;
event.motion.type = SDL_MOUSEMOTION;
event.motion.state = (m_button & SDL_BUTTON(1)) ? SDL_PRESSED : SDL_RELEASED;
event.motion.x = m_x;
event.motion.y = m_y;
event.motion.xrel = 0;
event.motion.yrel = 0;
SDL_PushEvent(&event);
}
if(l_button != m_button) {
bool l_1 = (l_button & SDL_BUTTON(1)) == SDL_BUTTON(1);
bool m_1 = (m_button & SDL_BUTTON(1)) == SDL_BUTTON(1);
bool l_2 = (l_button & SDL_BUTTON(2)) == SDL_BUTTON(2);
bool m_2 = (m_button & SDL_BUTTON(2)) == SDL_BUTTON(2);
bool l_3 = (l_button & SDL_BUTTON(3)) == SDL_BUTTON(3);
bool m_3 = (m_button & SDL_BUTTON(3)) == SDL_BUTTON(3);
//.........这里部分代码省略.........
示例9: sdl_mouseUpdate
void sdl_mouseUpdate()
{
displayAspectRatio = (float)displayWidth / (float)displayHeight;
int mouse_x, mouse_y;
unsigned int mouseButtonState;
mouseButtonState = SDL_GetMouseState(&mouse_x, &mouse_y);
//printf("%u,%u -> ", mouse_x, mouse_y);
// uint to float position;
mousePos.a[0] = (float)mouse_x / (float)displayWidth;
mousePos.a[1] = (float)mouse_y / (float)displayHeight;
// correct to center of screen
mousePos.a[0] -= 0.5;
mousePos.a[1] -= 0.5;
// mutliply by 2
mousePos.a[0] *= 2.0;
mousePos.a[1] *= 2.0;
// correct aspect ratio
mousePos.a[0] *= displayAspectRatio;
// mouse y is inverted
mousePos.a[1] *= -1;
if (mouseButtonState&SDL_BUTTON(1)) // normally the left button
{
if (mouseButtons[1].pressed)
mouseButtons[1].pressedLf = true;
else
mouseButtons[1].pressed = true;
}
else
{
mouseButtons[1].pressed = false;
mouseButtons[1].pressedLf = false;
}
if (mouseButtonState&SDL_BUTTON(3))
{
if (mouseButtons[3].pressed)
mouseButtons[3].pressedLf = true;
else
mouseButtons[3].pressed = true;
}
else
{
mouseButtons[3].pressed = false;
mouseButtons[3].pressedLf = false;
}
}
示例10: main
//.........这里部分代码省略.........
}
SDL_WM_SetCaption("VGS mk-II SR for Linux",NULL);
/* Initialize Surface */
surface=SDL_SetVideoMode(XSIZE*2,YSIZE*2,16,SDL_SWSURFACE);
if(NULL==surface) {
fprintf(stderr,"Could not create the surface.\n");
return 1;
}
if(2!=surface->format->BytesPerPixel) {
fprintf(stderr,"This display does not support 16bit color.\n");
return 1;
}
printf("Created surface: %dx%d\n",surface->w,surface->h);
/* Initialize sound system */
if(init_sound()) {
fprintf(stderr,"Could not create the sound thread.\n");
return 1;
}
/* Initialize user program */
if(vgs2_init()) {
fprintf(stderr,"Initialization of the app has failed.\n");
return 2;
}
make_pallet();
n=0;
while(1) {
ticks=SDL_GetTicks();
SDL_PollEvent(&event);
if(event.type==SDL_QUIT) break;
if(SDL_GetMouseState(&mx,&my)&SDL_BUTTON(1)) {
mx/=2;
my/=2;
if(!_touch.s) {
_touch.dx=0;
_touch.dy=0;
_touch.px=mx;
_touch.py=my;
_touch.cx=mx;
_touch.cy=my;
} else {
_touch.dx=mx-_touch.px;
_touch.dy=my-_touch.py;
_touch.px=_touch.cx;
_touch.py=_touch.cy;
_touch.cx=mx;
_touch.cy=my;
}
_touch.s=1;
_touch.t++;
} else {
_touch.s=0;
_touch.t=0;
}
if(_pause) {
if(vgs2_pause()) break;
} else {
if(vgs2_loop()) break;
}
if(SDL_MUSTLOCK(surface) && SDL_LockSurface(surface)<0) {
fprintf(stderr,"Skip frame: could not locked surface.\n");
usleep(100000);
continue;
示例11: gui_message_loop
bool gui_message_loop(void)
{
SDL_Event event;
static int x,y,xybutton = 0;
while (SDL_WaitEvent(&event))
{
sim_enter_irq_handler();
switch(event.type)
{
case SDL_KEYDOWN:
case SDL_KEYUP:
button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN);
break;
#ifdef HAVE_TOUCHSCREEN
case SDL_MOUSEMOTION:
if (event.motion.state & SDL_BUTTON(1))
touchscreen_event(event.motion.x, event.motion.y);
break;
#endif
case SDL_MOUSEBUTTONDOWN:
switch ( event.button.button ) {
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELUP:
button_event( SDLK_UP, true );
break;
case SDL_BUTTON_WHEELDOWN:
button_event( SDLK_DOWN, true );
break;
#endif
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
x = event.button.x;
y = event.button.y;
}
if ( background ) {
xybutton = xy2button( event.button.x, event.button.y );
if( xybutton ) {
button_event( xybutton, true );
break;
}
}
#ifdef HAVE_TOUCHSCREEN
touchscreen_event(event.button.x, event.button.y);
#endif
break;
default:
break;
}
if (debug_wps && event.button.button == 1)
{
if ( background )
#ifdef HAVE_REMOTE
if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
else
printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
#else
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
#endif
else
if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
#ifdef HAVE_REMOTE
else
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
#endif
}
break;
case SDL_MOUSEBUTTONUP:
switch ( event.button.button ) {
/* The scrollwheel button up events are ignored as they are queued immediately */
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x,
#define SQUARE(x) ((x)*(x))
y, (int)sqrt( SQUARE(x-(int)event.button.x)
+ SQUARE(y-(int)event.button.y)) );
}
if ( background && xybutton ) {
button_event( xybutton, false );
xybutton = 0;
}
#ifdef HAVE_TOUCHSCREEN
else
button_event(BUTTON_TOUCHSCREEN, false);
#endif
break;
default:
break;
}
break;
case SDL_QUIT:
{
//.........这里部分代码省略.........
示例12: SDL_handle_events
//.........这里部分代码省略.........
SDL_process_key_xkb(x11_display, event.key);
else
#endif
#endif
SDL_process_key(event.key);
break;
case SDL_KEYUP: {
SDL_Keysym keysym = event.key.keysym;
wait_kup = 0;
if (copypaste && (keysym.sym == SDLK_LSHIFT ||
keysym.sym == SDLK_RSHIFT)) {
copypaste = 0;
if (!m_cursor_visible)
SDL_ShowCursor(SDL_DISABLE);
}
#ifdef X_SUPPORT
#if HAVE_XKB
if (x11_display && config.X_keycode)
SDL_process_key_xkb(x11_display, event.key);
else
#endif
#endif
SDL_process_key(event.key);
break;
}
case SDL_MOUSEBUTTONDOWN:
{
int buttons = SDL_GetMouseState(NULL, NULL);
#if CONFIG_SDL_SELECTION
if (window_has_focus() && !shift_pressed()) {
clear_selection_data();
} else if (vga.mode_class == TEXT && !grab_active) {
if (event.button.button == SDL_BUTTON_LEFT)
start_selection(x_to_col(event.button.x, m_x_res),
y_to_row(event.button.y, m_y_res));
else if (event.button.button == SDL_BUTTON_RIGHT)
start_extend_selection(x_to_col(event.button.x, m_x_res),
y_to_row(event.button.y, m_y_res));
else if (event.button.button == SDL_BUTTON_MIDDLE) {
char *paste = SDL_GetClipboardText();
if (paste)
paste_text(paste, strlen(paste), "utf8");
}
break;
}
#endif /* CONFIG_SDL_SELECTION */
mouse_move_buttons(buttons & SDL_BUTTON(1),
buttons & SDL_BUTTON(2),
buttons & SDL_BUTTON(3));
break;
}
case SDL_MOUSEBUTTONUP:
{
int buttons = SDL_GetMouseState(NULL, NULL);
#if CONFIG_SDL_SELECTION
if (vga.mode_class == TEXT && !grab_active) {
t_unicode *sel = end_selection();
if (sel) {
char *send_text = get_selection_string(sel, "utf8");
SDL_SetClipboardText(send_text);
free(send_text);
}
}
#endif /* CONFIG_SDL_SELECTION */
mouse_move_buttons(buttons & SDL_BUTTON(1),
示例13: SDL_GetRelativeMouseState
void GameWorldPanel::handleMouse(double dt)
{
static_cast<void>(dt);
const auto &renderer = this->getGameState()->getRenderer();
const uint32_t mouse = SDL_GetRelativeMouseState(nullptr, nullptr);
const bool leftClick = (mouse & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
if (leftClick)
{
// Horizontal camera movement rough draft. The original camera controls for
// Arena are bad, but I am simulating them before thinking of adding modern
// 3D camera support (like Daggerfall) as an option.
const Int2 screenDimensions = renderer.getWindowDimensions();
const Int2 mousePosition = this->getMousePosition();
// Strength of turning is determined by proximity of the mouse cursor to
// the left or right screen edge.
const double dx = [this, &mousePosition, &screenDimensions]()
{
const int mouseX = mousePosition.getX();
// Native cursor regions (scaled to the current window).
const Rect &middleLeft = *this->nativeCursorRegions.at(3).get();
const Rect &middleRight = *this->nativeCursorRegions.at(5).get();
// Measure the magnitude of rotation. -1.0 is left, 1.0 is right.
double percent = 0.0;
if (middleLeft.contains(mousePosition))
{
percent = -1.0 + (static_cast<double>(mouseX) / middleLeft.getWidth());
}
else if (middleRight.contains(mousePosition))
{
percent = static_cast<double>(mouseX - middleRight.getLeft()) /
middleRight.getWidth();
}
// Reduce the magnitude by a lot as a baseline. Sensitivity can be
// tweaked in the options.
percent *= 0.010;
// No NaNs or infinities allowed.
return std::isfinite(percent) ? percent : 0.0;
}();
auto &player = this->getGameState()->getGameData()->getPlayer();
const auto &options = this->getGameState()->getOptions();
// Yaw the camera left or right. No vertical movement in classic camera mode.
player.rotate(dx, 0.0, options.getHorizontalSensitivity(),
options.getVerticalSensitivity(), options.getVerticalFOV());
}
// Later in development, a 3D camera would be fun (more like Daggerfall), but
// for now the objective is to more closely resemble the original game, so the
// rough draft 3D camera code below is commented out as a result.
// Make the camera look around.
/*int dx, dy;
const auto mouse = SDL_GetRelativeMouseState(&dx, &dy);
bool leftClick = (mouse & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
bool rightClick = (mouse & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
bool turning = ((dx != 0) || (dy != 0)) && leftClick;
if (turning)
{
auto dimensions = this->getGameState()->getRenderer().getWindowDimensions();
double dxx = static_cast<double>(dx) / static_cast<double>(dimensions.getX());
double dyy = static_cast<double>(dy) / static_cast<double>(dimensions.getY());
// Pitch and/or yaw the camera.
const auto &options = this->getGameState()->getOptions();
this->getGameState()->getGameData()->getPlayer().rotate(dxx, -dyy,
options.getHorizontalSensitivity(), options.getVerticalSensitivity(),
options.getVerticalFOV());
}*/
}
示例14: checkInputs
///sprawdza sygnały z myszy i klawiatury i wykonuje odpowiednie rzeczy
bool checkInputs()
{
bool quit = false;
auto effectInstanceList=getEffectInstanceList();
auto controllerInstanceList=getControllerInstanceList();
while (SDL_PollEvent(&event))
{
const Uint8 *state = SDL_GetKeyboardState(NULL);
switch(event.type)
{
case SDL_QUIT:
quit = true;
break;
case SDL_MOUSEBUTTONDOWN:
{
int x=event.button.x;
int y=event.button.y;
if(event.button.button==SDL_BUTTON_LEFT && !(state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && !(state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]))
{
for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
{
if(it->second->receiveClick(x, y, ME_PRESS))break;
}
for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
{
if(it->second->receiveClick(x, y, ME_PRESS))break;
}
}
else
if(event.button.button==SDL_BUTTON_RIGHT || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT])))
{
for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
{
if(it->second->receiveSecondClick(x, y, ME_PRESS))break;
}
for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
{
if(it->second->receiveSecondClick(x, y, ME_PRESS))break;
}
}
else
if(event.button.button==SDL_BUTTON_MIDDLE || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL])))
{
for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();)
{
auto it2=it;
++it;
if(it2->second->receiveThridClick(x, y, ME_PRESS))break;
}
for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
{
auto it2=it;
++it;
if(it2->second->receiveThridClick(x, y, ME_PRESS))break;
}
}
}
break;
case SDL_MOUSEBUTTONUP:
{
int x=event.button.x;
int y=event.button.y;
if(event.button.button==SDL_BUTTON_LEFT && !(state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT]) && !(state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]))
{
for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
{
it->second->receiveClick(x, y, ME_RELEASE);
}
for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
{
it->second->receiveClick(x, y, ME_RELEASE);
}
}
else
if(event.button.button==SDL_BUTTON_RIGHT || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LALT] || state[SDL_SCANCODE_RALT])))
{
for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();++it)
{
it->second->receiveSecondClick(x, y, ME_RELEASE);
}
for(auto it=controllerInstanceList->rbegin();it!=controllerInstanceList->rend();++it)
{
it->second->receiveSecondClick(x, y, ME_RELEASE);
}
}
else
if(event.button.button==SDL_BUTTON_MIDDLE || (event.button.button==SDL_BUTTON_LEFT && (state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL])))
{
for(auto it=effectInstanceList->rbegin();it!=effectInstanceList->rend();)
{
auto it2=it;
++it;
it2->second->receiveThridClick(x, y, ME_RELEASE);
//.........这里部分代码省略.........
示例15: switch
void CEvent::OnEvent(SDL_Event* Event) {
switch(Event->type) {
case SDL_ACTIVEEVENT: {
switch(Event->active.state) {
case SDL_APPMOUSEFOCUS: {
if ( Event->active.gain )
OnMouseFocus();
else
OnMouseBlur();
break;
}
case SDL_APPINPUTFOCUS: {
if ( Event->active.gain )
OnInputFocus();
else
OnInputBlur();
break;
}
case SDL_APPACTIVE: {
if ( Event->active.gain )
OnRestore();
else
OnMinimize();
break;
}
}
break;
}
case SDL_KEYDOWN: {
OnKeyDown(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
break;
}
case SDL_KEYUP: {
OnKeyUp(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
break;
}
case SDL_MOUSEMOTION: {
OnMouseMove(Event->motion.x,Event->motion.y,Event->motion.xrel,Event->motion.yrel,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
break;
}
case SDL_MOUSEBUTTONDOWN: {
switch(Event->button.button) {
case SDL_BUTTON_LEFT: {
OnLButtonDown(Event->button.x,Event->button.y);
break;
}
case SDL_BUTTON_RIGHT: {
OnRButtonDown(Event->button.x,Event->button.y);
break;
}
case SDL_BUTTON_MIDDLE: {
OnMButtonDown(Event->button.x,Event->button.y);
break;
}
}
break;
}
case SDL_MOUSEBUTTONUP: {
switch(Event->button.button) {
case SDL_BUTTON_LEFT: {
OnLButtonUp(Event->button.x,Event->button.y);
break;
}
case SDL_BUTTON_RIGHT: {
OnRButtonUp(Event->button.x,Event->button.y);
break;
}
case SDL_BUTTON_MIDDLE: {
OnMButtonUp(Event->button.x,Event->button.y);
break;
}
}
break;
}
case SDL_JOYAXISMOTION: {
OnJoyAxis(Event->jaxis.which,Event->jaxis.axis,Event->jaxis.value);
break;
}
case SDL_JOYBALLMOTION: {
OnJoyBall(Event->jball.which,Event->jball.ball,Event->jball.xrel,Event->jball.yrel);
break;
}
case SDL_JOYHATMOTION: {
OnJoyHat(Event->jhat.which,Event->jhat.hat,Event->jhat.value);
break;
}
case SDL_JOYBUTTONDOWN: {
OnJoyButtonDown(Event->jbutton.which,Event->jbutton.button);
break;
}
case SDL_JOYBUTTONUP: {
//.........这里部分代码省略.........