Exemplo n.º 1
0
	void sdl_window::activate()
	{
		SDL_RaiseWindow(iHandle);
#ifdef WIN32
		SetWindowPos(static_cast<HWND>(native_handle()), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
#endif
	}
Exemplo n.º 2
0
void VID_Restore (void)
{
	if (!sdl_window)
		return;

	SDL_RestoreWindow(sdl_window);
	SDL_RaiseWindow(sdl_window);
}
Exemplo n.º 3
0
/**
 * @brief Window Creation and recreation.
 */
bool WindowManager::createWindow(bool fullScreen)
{
    // If Window Already Exists, destory so we can recreate it.
    if(m_window)
    {
        //std::cout << "Destroy SDL Window" << std::endl;
        SDL_DestroyWindow(m_window);
        m_window = nullptr;
    }

    int display_height = (m_height / 2);
    int display_width  = (m_width / 2);

    // create window in in full screen or windowed mode.
    if(fullScreen)
    {
        m_window = SDL_CreateWindow("EtherTerm 0.4.6 Alpha Demo - Full Screen",
                                    (m_position_placement % 2 == 0) ? SDL_WINDOWPOS_CENTERED : display_width,
                                    (m_position_placement % 2 == 0) ? SDL_WINDOWPOS_CENTERED : display_height,
                                    m_width,
                                    m_height,
                                    SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP);

        if(!m_window) // window init success
        {
            SDL_Log("Terminal::restartWindowSize() SDL_CreateWindow globalWindow: %s",
                    SDL_GetError());
            assert(m_window);
        }
    }
    else
    {
        m_window = SDL_CreateWindow("EtherTerm 0.4.6 Alpha Demo - Windowed",
                                    (m_position_placement % 2 == 0) ? SDL_WINDOWPOS_CENTERED : display_width,
                                    (m_position_placement % 2 == 0) ? SDL_WINDOWPOS_CENTERED : display_height,
                                    m_width,
                                    m_height,
                                    SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
        if(!m_window) // window init success
        {
            SDL_Log("Terminal::restartWindowSize() SDL_CreateWindow globalWindow: %s",
                    SDL_GetError());
            assert(m_window);
        }
    }

    // Set the Window ID
    m_window_id = SDL_GetWindowID(m_window);

    std::string title = "EtherTerm 0.4.6 Alpha Demo w/ Multiple Windows - Window ID: ";
    title.append(std::to_string(m_window_id));
    SDL_SetWindowTitle(m_window, title.c_str());

    // Display and move focus to the new window.
    SDL_ShowWindow(m_window);
    SDL_RaiseWindow(m_window);
    return true;
}
Exemplo n.º 4
0
void LWindow::focus() {
  //Restore window if needed
  if( !mShown ) {
    SDL_ShowWindow( mWindow );
  }

  //Move window forward
  SDL_RaiseWindow( mWindow );
}
Exemplo n.º 5
0
int	trap_MessageBox(lua_State *s)
{
	const char *msg;
	extern SDL_Window *v_window;

	trap_args(s, "MessageBox", "s", &msg);
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "", msg, v_window);
	SDL_RaiseWindow(v_window);
	return 0;
}
Exemplo n.º 6
0
/////////////////////////////////////////////////////////
// set topmost position on/off
//
/////////////////////////////////////////////////////////
int topmostGemWindow(WindowInfo &info, int state)
{
  static int topmost_state = 0;
  state=!(!state);
  if (state)
  {
    SDL_RaiseWindow(info.win); // FIXME not permanent
  }
  topmost_state = state;
  return topmost_state;
}
Exemplo n.º 7
0
static SDL_bool
WatchJoystick(SDL_Joystick * joystick)
{
    SDL_Window *window = NULL;
    const char *name = NULL;

    retval = SDL_FALSE;
    done = SDL_FALSE;

    /* Create a window to display joystick axis position */
    window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, 0);
    if (window == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
        return SDL_FALSE;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }

    SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(screen);
    SDL_RenderPresent(screen);
    SDL_RaiseWindow(window);

    /* Print info about the joystick we are watching */
    name = SDL_JoystickName(joystick);
    SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
           name ? name : "Unknown Joystick");
    SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
           SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
           SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));

    /* Loop, getting joystick events! */
#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop_arg(loop, joystick, 0, 1);
#else
    while (!done) {
        loop(joystick);
    }
#endif

    SDL_DestroyRenderer(screen);
    screen = NULL;
    SDL_DestroyWindow(window);
    return retval;
}
Exemplo n.º 8
0
/** Native windows should implement BringToFront by making this window the top-most window (i.e. focused).
 *
 * @param bForce	Forces the window to the top of the Z order, even if that means stealing focus from other windows
 *					In general do not pass true for this.  It is really only useful for some windows, like game windows where not forcing it to the front
 *					could cause mouse capture and mouse lock to happen but without the window visible
 */
void FLinuxWindow::BringToFront( bool bForce )
{
	// TODO Forces the the window to top of z order? Only that? SDL is using XMapRaised which changes the z order
	// so we do not steal focus here I guess.
	if(bForce)
	{
		SDL_RaiseWindow(HWnd);
	}
	else
	{
		SDL_ShowWindow(HWnd);
	}
}
Exemplo n.º 9
0
void PlasmacoreView::configure()
{
  if (isConfigured) { return; }
  isConfigured = true;

  pwindowID = Plasmacore::singleton.getResourceID( this );

  SDL_RaiseWindow(window); // Should we immediately post a focus event? (Mac version does...)

  fprintf( stderr, "PlasmacoreView %s:\n", name );
  fprintf( stderr, "  SDL   WID %d:\n", swindowID );
  fprintf( stderr, "  PCore WID %d:\n", pwindowID );
}
Exemplo n.º 10
0
void App::openShaderDialog() {
	char *out_filepath = nullptr;
	nfdresult_t result = NFD_OpenDialog("frag,glsl,fsh,txt", nullptr, &out_filepath);
	SDL_RaiseWindow(sdl_window); // workaround: focus window again after dialog closes
	
	if (result == NFD_OKAY) {
		struct stat attr;
		if (!stat(out_filepath, &attr)) { // file exists
			shader_file_mtime = (int)attr.st_mtime;
			loadShader(out_filepath);
		}
		free(out_filepath);
	}
}
Exemplo n.º 11
0
void App::saveShaderDialog() {
	char *out_filepath = nullptr;
	nfdresult_t result = NFD_SaveDialog("frag,glsl,fsh,txt", nullptr, &out_filepath);
	SDL_RaiseWindow(sdl_window); // workaround: focus window again after dialog closes

	if (result == NFD_OKAY) {
		if (shader_filepath) free(shader_filepath);
		shader_filepath = out_filepath;

		writeStringToFile(shader_filepath, src_edit_buffer);
		struct stat attr;
		if (!stat(shader_filepath, &attr)) { // file exists
			shader_file_mtime = 0; // force autoreload
		}
	}
}
Exemplo n.º 12
0
void App::openShaderDialog() {
	char *out_file_path = nullptr;
	nfdresult_t result = NFD_OpenDialog("frag,glsl,fsh,txt", nullptr, &out_file_path);
	SDL_RaiseWindow(sdl_window); // workaround: focus window again after dialog closes
	
	if (result == NFD_OKAY) {
		if (file_path) free(file_path);
		file_path = out_file_path;

		struct stat attr;
		if (!stat(file_path, &attr)) { // file exists
			file_mod_time = attr.st_mtime;
			loadShader(file_path, /*initial*/true);
		}
	}
}
Exemplo n.º 13
0
static void video_new_window(int w, int h, bool fs, bool resizable) {
	uint32_t flags = SDL_WINDOW_OPENGL;

	if(fs) {
		flags |= get_fullscreen_flag();
	} else if(resizable) {
		flags |= SDL_WINDOW_RESIZABLE;
	}

	video_new_window_internal(w, h, flags, false);

	log_info("Created a new window: %ix%i (%s)",
		video.current.width,
		video.current.height,
		modeflagsstr(SDL_GetWindowFlags(video.window))
	);

	events_pause_keyrepeat();
	SDL_RaiseWindow(video.window);
}
Exemplo n.º 14
0
GHOST_WindowSDL::GHOST_WindowSDL(GHOST_SystemSDL *system,
                                 const STR_String& title,
                                 GHOST_TInt32 left,
                                 GHOST_TInt32 top,
                                 GHOST_TUns32 width,
                                 GHOST_TUns32 height,
                                 GHOST_TWindowState state,
                                 const GHOST_TEmbedderWindowID parentWindow,
                                 GHOST_TDrawingContextType type,
                                 const bool stereoVisual,
                                 const bool exclusive,
                                 const GHOST_TUns16 numOfAASamples
                                 )
    : GHOST_Window(width, height, state, stereoVisual, exclusive, numOfAASamples),
      m_system(system),
      m_valid_setup(false),
      m_invalid_window(false),
      m_sdl_custom_cursor(NULL)
{

	/* creating the window _must_ come after setting attributes */
	m_sdl_win = SDL_CreateWindow(
	        title,
	        left, top,
	        width, height,
	        SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

	/* now set up the rendering context. */
	if (setDrawingContextType(type) == GHOST_kSuccess) {
		m_valid_setup = true;
		GHOST_PRINT("Created window\n");
	}

	if (exclusive) {
		SDL_RaiseWindow(m_sdl_win);
	}

	setTitle(title);
}
Exemplo n.º 15
0
void Runtime::debugStart(TextEditInput *editWidget, const char *file) {
  char buf[OS_PATHNAME_SIZE + 1];
  bool open;
  int size;

  if (g_debugee != -1) {
    net_print(g_debugee, "l\n");
    open = net_input(g_debugee, buf, sizeof(buf), "\n") > 0;
  } else {
    open = false;
  }

  if (!open) {
    launchDebug(file);
    pause(PAUSE_DEBUG_LAUNCH);
    SDL_RaiseWindow(_window);

    g_debugee = net_connect("localhost", g_debugPort);
    if (g_debugee != -1) {
      net_print(g_debugee, "l\n");
      size = net_input(g_debugee, buf, sizeof(buf), "\n");
      if (size > 0) {
        int *marker = editWidget->getMarkers();
        for (int i = 0; i < MAX_MARKERS; i++) {
          if (marker[i] != -1) {
            net_printf(g_debugee, "b %d\n", marker[i]);
          }
        }
        editWidget->gotoLine(buf);
        appLog("Debug session ready");
      }
    } else {
      appLog("Failed to attach to debug window");
    }
  } else {
    debugStop();
  }
}
Exemplo n.º 16
0
void App::openImageDialog(TextureSlot *texture_slot, bool load_cube_cross) {
	char *out_filepath = nullptr;
	nfdresult_t result = NFD_OpenDialog("tga,png,bmp,jpg,hdr", nullptr, &out_filepath);
	SDL_RaiseWindow(sdl_window); // workaround: focus window again after dialog closes

	if (result == NFD_OKAY) {
		if (load_cube_cross) {
			int out_size;
			GLuint loaded_texture_cube = loadTextureCubeCross(out_filepath,
				/*build_mipmaps*/true, &out_size);
			if (loaded_texture_cube) {
				texture_slot->clear();

				texture_slot->target = GL_TEXTURE_CUBE_MAP;
				texture_slot->texture = loaded_texture_cube;
				texture_slot->image_width = out_size;
				texture_slot->image_height = out_size;
				texture_slot->image_filepath = out_filepath;
			}
		} else {
			int out_width, out_height;
			GLuint loaded_texture = loadTexture2D(out_filepath,
				/*build_mipmaps*/true, &out_width, &out_height);
			if (loaded_texture) { // loading successful
				texture_slot->clear();

				texture_slot->target = GL_TEXTURE_2D;
				setWrapTexture2D(GL_REPEAT, GL_REPEAT);
				texture_slot->texture = loaded_texture;
				texture_slot->image_width = out_width;
				texture_slot->image_height = out_height;
				texture_slot->image_filepath = out_filepath;
			}
		}
	}
}
static SDL_bool
WatchJoystick(SDL_Joystick * joystick)
{
    SDL_Window *window = NULL;
    SDL_Renderer *screen = NULL;
    SDL_Texture *background, *button, *axis, *marker;
    const char *name = NULL;
    SDL_bool retval = SDL_FALSE;
    SDL_bool done = SDL_FALSE, next=SDL_FALSE;
    SDL_Event event;
    SDL_Rect dst;
    int s, _s;
    Uint8 alpha=200, alpha_step = -1;
    Uint32 alpha_ticks;
    char mapping[4096], temp[4096];
    MappingStep *step;
    MappingStep steps[] = {
        {342, 132,  0.0,  MARKER_BUTTON, "x", -1, -1, -1, -1, ""},
        {387, 167,  0.0,  MARKER_BUTTON, "a", -1, -1, -1, -1, ""},
        {431, 132,  0.0,  MARKER_BUTTON, "b", -1, -1, -1, -1, ""},
        {389, 101,  0.0,  MARKER_BUTTON, "y", -1, -1, -1, -1, ""},
        {174, 132,  0.0,  MARKER_BUTTON, "back", -1, -1, -1, -1, ""},
        {233, 132,  0.0,  MARKER_BUTTON, "guide", -1, -1, -1, -1, ""},
        {289, 132,  0.0,  MARKER_BUTTON, "start", -1, -1, -1, -1, ""},        
        {116, 217,  0.0,  MARKER_BUTTON, "dpleft", -1, -1, -1, -1, ""},
        {154, 249,  0.0,  MARKER_BUTTON, "dpdown", -1, -1, -1, -1, ""},
        {186, 217,  0.0,  MARKER_BUTTON, "dpright", -1, -1, -1, -1, ""},
        {154, 188,  0.0,  MARKER_BUTTON, "dpup", -1, -1, -1, -1, ""},
        {77,  40,   0.0,  MARKER_BUTTON, "leftshoulder", -1, -1, -1, -1, ""},
        {91, 0,    0.0,  MARKER_BUTTON, "lefttrigger", -1, -1, -1, -1, ""},
        {396, 36,   0.0,  MARKER_BUTTON, "rightshoulder", -1, -1, -1, -1, ""},
        {375, 0,    0.0,  MARKER_BUTTON, "righttrigger", -1, -1, -1, -1, ""},
        {75,  154,  0.0,  MARKER_BUTTON, "leftstick", -1, -1, -1, -1, ""},
        {305, 230,  0.0,  MARKER_BUTTON, "rightstick", -1, -1, -1, -1, ""},
        {75,  154,  0.0,  MARKER_AXIS,   "leftx", -1, -1, -1, -1, ""},
        {75,  154,  90.0, MARKER_AXIS,   "lefty", -1, -1, -1, -1, ""},        
        {305, 230,  0.0,  MARKER_AXIS,   "rightx", -1, -1, -1, -1, ""},
        {305, 230,  90.0, MARKER_AXIS,   "righty", -1, -1, -1, -1, ""},
    };

    /* Create a window to display joystick axis position */
    window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, 0);
    if (window == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
        return SDL_FALSE;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }
    
    background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
    button = LoadTexture(screen, "button.bmp", SDL_TRUE);
    axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
    SDL_RaiseWindow(window);

    /* scale for platforms that don't give you the window size you asked for. */
    SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

    /* Print info about the joystick we are watching */
    name = SDL_JoystickName(joystick);
    SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
           name ? name : "Unknown Joystick");
    SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
           SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
           SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
    
    SDL_Log("\n\n\
    ====================================================================================\n\
    Press the buttons on your controller when indicated\n\
    (Your controller may look different than the picture)\n\
    If you want to correct a mistake, press backspace or the back button on your device\n\
    To skip a button, press SPACE or click/touch the screen\n\
    To exit, press ESC\n\
    ====================================================================================\n");
    
    /* Initialize mapping with GUID and name */
    SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, SDL_arraysize(temp));
    SDL_snprintf(mapping, SDL_arraysize(mapping), "%s,%s,platform:%s,",
        temp, name ? name : "Unknown Joystick", SDL_GetPlatform());

    /* Loop, getting joystick events! */
    for(s=0; s<SDL_arraysize(steps) && !done;) {
        /* blank screen, set up for drawing this frame. */
        step = &steps[s];
        SDL_strlcpy(step->mapping, mapping, SDL_arraysize(step->mapping));
        step->axis = -1;
        step->button = -1;
        step->hat = -1;
        step->hat_value = -1;
        SDL_SetClipboardText("TESTING TESTING 123");
        
        switch(step->marker) {
            case MARKER_AXIS:
                marker = axis;
                break;
            case MARKER_BUTTON:
                marker = button;
                break;
            default:
                break;
        }
        
        dst.x = step->x;
        dst.y = step->y;
        SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
        next=SDL_FALSE;

        SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);

        while (!done && !next) {
            if (SDL_GetTicks() - alpha_ticks > 5) {
                alpha_ticks = SDL_GetTicks();
                alpha += alpha_step;
                if (alpha == 255) {
                    alpha_step = -1;
                }
                if (alpha < 128) {
                    alpha_step = 1;
                }
            }
            
            SDL_RenderClear(screen);
            SDL_RenderCopy(screen, background, NULL, NULL);
            SDL_SetTextureAlphaMod(marker, alpha);
            SDL_SetTextureColorMod(marker, 10, 255, 21);
            SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
            SDL_RenderPresent(screen);
            
            if (SDL_PollEvent(&event)) {
                switch (event.type) {
                case SDL_JOYAXISMOTION:
                    if (event.jaxis.value > 20000 || event.jaxis.value < -20000) {
                        for (_s = 0; _s < s; _s++) {
                            if (steps[_s].axis == event.jaxis.axis) {
                                break;
                            }
                        }
                        if (_s == s) {
                            step->axis = event.jaxis.axis;
                            SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
                            SDL_snprintf(temp, SDL_arraysize(temp), ":a%u,", event.jaxis.axis);
                            SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
                            s++;
                            next=SDL_TRUE;
                        }
                    }
                    
                    break;
                case SDL_JOYHATMOTION:
                        if (event.jhat.value == SDL_HAT_CENTERED) {
                            break;  /* ignore centering, we're probably just coming back to the center from the previous item we set. */
                        }
                        for (_s = 0; _s < s; _s++) {
                            if (steps[_s].hat == event.jhat.hat && steps[_s].hat_value == event.jhat.value) {
                                break;
                            }
                        }
                        if (_s == s) {
                            step->hat = event.jhat.hat;
                            step->hat_value = event.jhat.value;
                            SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
                            SDL_snprintf(temp, SDL_arraysize(temp), ":h%u.%u,", event.jhat.hat, event.jhat.value );
                            SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
                            s++;
                            next=SDL_TRUE;
                        }
                    break;
                case SDL_JOYBALLMOTION:
                    break;
                case SDL_JOYBUTTONUP:
                    for (_s = 0; _s < s; _s++) {
                        if (steps[_s].button == event.jbutton.button) {
                            break;
                        }
                    }
                    if (_s == s) {
                        step->button = event.jbutton.button;
                        SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
                        SDL_snprintf(temp, SDL_arraysize(temp), ":b%u,", event.jbutton.button);
                        SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
                        s++;
                        next=SDL_TRUE;
                    }
                    break;
                case SDL_FINGERDOWN:
                case SDL_MOUSEBUTTONDOWN:
                    /* Skip this step */
                    s++;
                    next=SDL_TRUE;
                    break;
                case SDL_KEYDOWN:
                    if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
                        /* Undo! */
                        if (s > 0) {
                            SDL_strlcpy(mapping, step->mapping, SDL_arraysize(step->mapping));
                            s--;
                            next = SDL_TRUE;
                        }
                        break;
                    }
                    if (event.key.keysym.sym == SDLK_SPACE) {
                        /* Skip this step */
                        s++;
                        next=SDL_TRUE;
                        break;
                    }
                    
                    if ((event.key.keysym.sym != SDLK_ESCAPE)) {
                        break;
                    }
                    /* Fall through to signal quit */
                case SDL_QUIT:
                    done = SDL_TRUE;
                    break;
                default:
                    break;
                }
            }
        }

    }

    if (s == SDL_arraysize(steps) ) {
        SDL_Log("Mapping:\n\n%s\n\n", mapping);
        /* Print to stdout as well so the user can cat the output somewhere */
        printf("%s\n", mapping);
    }
    
    while(SDL_PollEvent(&event)) {};
    
    SDL_DestroyRenderer(screen);
    SDL_DestroyWindow(window);
    return retval;
}
Exemplo n.º 18
0
static SDL_bool
WatchJoystick(SDL_Joystick * joystick)
{
    SDL_Window *window = NULL;
    SDL_Renderer *screen = NULL;
    const char *name = NULL;
    SDL_bool retval = SDL_FALSE;
    SDL_bool done = SDL_FALSE;
    SDL_Event event;
    int i;

    /* Create a window to display joystick axis position */
    window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, 0);
    if (window == NULL) {
        fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
        return SDL_FALSE;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }

    SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(screen);
    SDL_RenderPresent(screen);
    SDL_RaiseWindow(window);

    /* Print info about the joystick we are watching */
    name = SDL_JoystickName(joystick);
    printf("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
           name ? name : "Unknown Joystick");
    printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
           SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
           SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));

    /* Loop, getting joystick events! */
    while (!done) {
        /* blank screen, set up for drawing this frame. */
        SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
        SDL_RenderClear(screen);

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_JOYAXISMOTION:
                printf("Joystick %d axis %d value: %d\n",
                       event.jaxis.which,
                       event.jaxis.axis, event.jaxis.value);
                break;
            case SDL_JOYHATMOTION:
                printf("Joystick %d hat %d value:",
                       event.jhat.which, event.jhat.hat);
                if (event.jhat.value == SDL_HAT_CENTERED)
                    printf(" centered");
                if (event.jhat.value & SDL_HAT_UP)
                    printf(" up");
                if (event.jhat.value & SDL_HAT_RIGHT)
                    printf(" right");
                if (event.jhat.value & SDL_HAT_DOWN)
                    printf(" down");
                if (event.jhat.value & SDL_HAT_LEFT)
                    printf(" left");
                printf("\n");
                break;
            case SDL_JOYBALLMOTION:
                printf("Joystick %d ball %d delta: (%d,%d)\n",
                       event.jball.which,
                       event.jball.ball, event.jball.xrel, event.jball.yrel);
                break;
            case SDL_JOYBUTTONDOWN:
                printf("Joystick %d button %d down\n",
                       event.jbutton.which, event.jbutton.button);
                break;
            case SDL_JOYBUTTONUP:
                printf("Joystick %d button %d up\n",
                       event.jbutton.which, event.jbutton.button);
                break;
            case SDL_KEYDOWN:
                if ((event.key.keysym.sym != SDLK_ESCAPE) &&
                    (event.key.keysym.sym != SDLK_AC_BACK)) {
                    break;
                }
                /* Fall through to signal quit */
            case SDL_FINGERDOWN:
            case SDL_MOUSEBUTTONDOWN:
            case SDL_QUIT:
                done = SDL_TRUE;
                break;
            default:
                break;
            }
        }
        /* Update visual joystick state */
        SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
        for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
            if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
                DrawRect(screen, (i%20) * 34, SCREEN_HEIGHT - 68 + (i/20) * 34, 32, 32);
            }
        }

        SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
        for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) {
            /* Draw the X/Y axis */
            int x, y;
            x = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
            x *= SCREEN_WIDTH;
            x /= 65535;
            if (x < 0) {
                x = 0;
            } else if (x > (SCREEN_WIDTH - 16)) {
                x = SCREEN_WIDTH - 16;
            }
            ++i;
            if (i < SDL_JoystickNumAxes(joystick)) {
                y = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
            } else {
                y = 32768;
            }
            y *= SCREEN_HEIGHT;
            y /= 65535;
            if (y < 0) {
                y = 0;
            } else if (y > (SCREEN_HEIGHT - 16)) {
                y = SCREEN_HEIGHT - 16;
            }

            DrawRect(screen, x, y, 16, 16);
        }

        SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
        for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
            /* Derive the new position */
            int x = SCREEN_WIDTH/2;
            int y = SCREEN_HEIGHT/2;
            const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);

            if (hat_pos & SDL_HAT_UP) {
                y = 0;
            } else if (hat_pos & SDL_HAT_DOWN) {
                y = SCREEN_HEIGHT-8;
            }

            if (hat_pos & SDL_HAT_LEFT) {
                x = 0;
            } else if (hat_pos & SDL_HAT_RIGHT) {
                x = SCREEN_WIDTH-8;
            }

            DrawRect(screen, x, y, 8, 8);
        }

        SDL_RenderPresent(screen);

        if (SDL_JoystickGetAttached( joystick ) == 0) {
            done = SDL_TRUE;
            retval = SDL_TRUE;  /* keep going, wait for reattach. */
        }
    }

    SDL_DestroyRenderer(screen);
    SDL_DestroyWindow(window);
    return retval;
}
Exemplo n.º 19
0
void Debugger::handle_events()
{
  SDL_Event ev;

  while (SDL_PollEvent(&ev))
  {
    //DEBUGLOG("GOTEVENT 0x%x -", ev.type);
    switch(ev.type)
    {
      case SDL_QUIT:
        BaseD::quitting = true;
        break;
      case SDL_WINDOWEVENT:
      {
        switch(ev.window.event)
        {
          case SDL_WINDOWEVENT_RESIZED:
          {

            int w = ev.window.data1;
            int h = ev.window.data2;

            DEBUGLOG("window resize: w = %d, h = %d\n", w, h);
            /*if (w > monitor_display_mode.w)
              w = monitor_display_mode.w;
            if (h > monitor_display_mode.h)
              h = monitor_display_mode.h;*/

            int wd, hd;
            //if (w > SCREEN_WIDTH)
            //{
            wd = w - Render_Context::w;
            //}
            //else
            //{
             // wd = SCREEN_WIDTH - height;
            //}

            hd = h - Render_Context::h;

            if (abs(wd) < abs(hd)) wd = hd;
            else if (abs(wd) > abs(hd)) hd = wd;

            Render_Context::w += wd;
            Render_Context::h += hd;

            DEBUGLOG("\twindow resize: w = %d, h = %d\n", Render_Context::w, Render_Context::h);
            //DEBUGLOG("%d - %d = %d\n", Render_Context::h, monitor_display_mode.h, Render_Context::h - monitor_display_mode.h);

            if (Render_Context::w > monitor_display_mode.w)
            {
              int tmp_wd = Render_Context::w - monitor_display_mode.w;
              Render_Context::w -= tmp_wd;
              Render_Context::h -= tmp_wd;
              DEBUGLOG("\t\twindow resize: tmp_wd = %d, w = %d, h = %d\n", tmp_wd, Render_Context::w, Render_Context::h);
            }
            if (Render_Context::h > monitor_display_mode.h)
            {
              int tmp_hd = Render_Context::h - monitor_display_mode.h;
              Render_Context::w -= tmp_hd;
              Render_Context::h -= tmp_hd;
              DEBUGLOG("\t\twindow resize: tmp_hd = %d, w = %d, h = %d\n", tmp_hd, Render_Context::w, Render_Context::h);

            }

            SDL_SetWindowSize(sdlWindow, Render_Context::w, Render_Context::h);
            DEBUGLOG("\t\t\twindow resize: w = %d, h = %d\n", Render_Context::w, Render_Context::h);
          } break;
          /*case SDL_WINDOWEVENT_LEAVE:
          {
            DEBUGLOG("Window %d Lost mouse focus\n", ev.window.windowID);
          }
          break;
          case SDL_WINDOWEVENT_ENTER:
          {
            DEBUGLOG("Window %d Gained mouse focus\n", ev.window.windowID);
          }
          break;*/
          case SDL_WINDOWEVENT_FOCUS_LOST:
          {
            DEBUGLOG("Window %d Lost keyboard focus\n", ev.window.windowID);
            if (ev.window.windowID == Render_Context::windowID)
            {
              // OFF context menus
              menu_bar.context_menus.deactivate_all();
            }
          }
          break;
          case SDL_WINDOWEVENT_FOCUS_GAINED:
          {
            DEBUGLOG("Window %d Gained keyboard focus\n", ev.window.windowID);
            //SDL_GetMouseState(&mouse::x, &mouse::y);
            sub_window_experience = NULL;
            for (int i=0; i < NUM_WINDOWS; i++)
            {
              if (ev.window.windowID == window_map[i]->windowID)
              {
                if (window_map[i]->oktoshow)
                {
                  DEBUGLOG("Window_map %d gained experience. :D\n", i);
                  sub_window_experience = (Experience *)window_map[i];
                  //window_map[i]->raise();
                }
                break;
              }
            }
          }
          break;
          case SDL_WINDOWEVENT_SHOWN:
          {
            SDL_Log("Window %d shown", ev.window.windowID);
            for (int i=0; i < NUM_WINDOWS; i++)
            {
              if (ev.window.windowID == window_map[i]->windowID)
              {
                if (!window_map[i]->oktoshow)
                {
                  window_map[i]->hide();
                  /* maybe right here, instead of raising the main window, we should
                    have a history of displayed windows.. and the last one should be raised.
                  */
                  sub_window_experience = NULL;
                  //SDL_RaiseWindow(Render_Context::sdlWindow);
                }
                else
                {
                  sub_window_experience = NULL;
                  DEBUGLOG("Window_map %d gained experience. :D\n", i);
                  sub_window_experience = (Experience *)window_map[i];
                  window_map[i]->raise();
                }
                break;
              }
            }
          }
          break;
          case SDL_WINDOWEVENT_CLOSE:
          {
            SDL_Log("Window %d closed", ev.window.windowID);
            if (ev.window.windowID == Render_Context::windowID)
            {
              // quit app

              SDL_Event quit_ev;
              quit_ev.type = SDL_QUIT;
              SDL_PushEvent(&quit_ev);
            }
            else
            {
              for (int i=0; i < NUM_WINDOWS; i++)
              {
                if (ev.window.windowID == window_map[i]->windowID)
                {
                  window_map[i]->hide();
                  // maybe right here, instead of raising the main window, we should
                  //  have a history of displayed windows.. and the last one should be raised.

                  sub_window_experience = NULL;
                  //SDL_RaiseWindow(Render_Context::sdlWindow);
                  break;
                }
              }
            }
          }
          break;

          default:break;
        }
      } break;
      case SDL_DROPFILE:
      {
        char *dropped_filedir = ev.drop.file;
        // Shows directory of dropped file
        /*SDL_ShowSimpleMessageBox(
            SDL_MESSAGEBOX_INFORMATION,
            "File dropped on window",
            dropped_filedir,
            sdlWindow
        );*/
        BaseD::nfd.free_pathset();
        check_paths_and_reload(&dropped_filedir, 1, true);
        SDL_free(dropped_filedir);    // Free dropped_filedir memory
        SDL_RaiseWindow(sdlWindow);
      } break;
      case SDL_USEREVENT:
      {
        if (ev.user.code == UserEvents::sound_stop)
        {
          sound_stop();
        }
      } break;
      case SDL_MOUSEMOTION:
      {
        mouse::x = ev.motion.x;
        mouse::y = ev.motion.y;
      } break;
      /*case SDL_MOUSEBUTTONDOWN:
        DEBUGLOG("MOUSE BUTTON DOWN -");
      break;
      case SDL_MOUSEBUTTONUP:
        DEBUGLOG("MOUSE BUTTON UP -");
      break;*/

      default:break;
    }
    if (sub_window_experience)
    {
      sub_window_experience->receive_event(ev);
    }
    else exp->receive_event(ev);
  }
}
SDL_bool WatchGameController(SDL_GameController *gamecontroller) {
  const char *name = SDL_GameControllerName(gamecontroller);
  const char *basetitle = "Game Controller Test: ";
  const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
  char *title = (char *)SDL_malloc(titlelen);
  SDL_Window *window = NULL;

  retval = SDL_FALSE;
  done = SDL_FALSE;

  if (title) {
    SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
  }

  /* Create a window to display controller state */
  window =
      SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                       SCREEN_WIDTH, SCREEN_HEIGHT, 0);
  if (window == NULL) {
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n",
                 SDL_GetError());
    return SDL_FALSE;
  }

  screen = SDL_CreateRenderer(window, -1, 0);
  if (screen == NULL) {
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
                 SDL_GetError());
    SDL_DestroyWindow(window);
    return SDL_FALSE;
  }

  SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
  SDL_RenderClear(screen);
  SDL_RenderPresent(screen);
  SDL_RaiseWindow(window);

  /* scale for platforms that don't give you the window size you asked for. */
  SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

  background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
  button = LoadTexture(screen, "button.bmp", SDL_TRUE);
  axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);

  if (!background || !button || !axis) {
    SDL_DestroyRenderer(screen);
    SDL_DestroyWindow(window);
    return SDL_FALSE;
  }
  SDL_SetTextureColorMod(button, 10, 255, 21);
  SDL_SetTextureColorMod(axis, 10, 255, 21);

  /* !!! FIXME: */
  /*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/

  /* Print info about the controller we are watching */
  SDL_Log("Watching controller %s\n", name ? name : "Unknown Controller");

/* Loop, getting controller events! */
#ifdef __EMSCRIPTEN__
  emscripten_set_main_loop_arg(loop, gamecontroller, 0, 1);
#else
  while (!done) {
    loop(gamecontroller);
  }
#endif

  SDL_DestroyRenderer(screen);
  screen = NULL;
  background = NULL;
  button = NULL;
  axis = NULL;
  SDL_DestroyWindow(window);
  return retval;
}
Exemplo n.º 21
0
 void window::begin_text_input_on_window(const window& window)
 {
     SDL_RaiseWindow(window.handle.get());
     SDL_StartTextInput();
 }
Exemplo n.º 22
0
int graphics_SetMode(int width, int height, int fullscreen,
int resizable, const char* title, const char* renderer, char** error) {
    graphics_calculateUnitToPixels(width, height);

#if defined(ANDROID)
    if (!fullscreen) {
        // do not use windowed on Android
        *error = strdup("Windowed mode is not supported on Android");
        return 0;
    }
#endif

    char errormsg[512];

    // initialize SDL video if not done yet
    if (!graphics_InitVideoSubsystem(error)) {
        return 0;
    }

    // think about the renderer we want
#ifndef WINDOWS
#ifdef ANDROID
    char preferredrenderer[20] = "opengles";
#else
    char preferredrenderer[20] = "opengl";
#endif
#else
    char preferredrenderer[20] = "direct3d";
#endif
    int softwarerendering = 0;
    if (renderer) {
        if (strcasecmp(renderer, "software") == 0) {
#ifdef ANDROID
            // we don't want software rendering on Android
#else
            softwarerendering = 1;
            strcpy(preferredrenderer, "software");
#endif
        } else {
            if (strcasecmp(renderer, "opengl") == 0) {
#ifdef ANDROID
                // opengles is the opengl we want for android :-)
                strcpy(preferredrenderer, "opengles");
#else
                // regular opengl on desktop platforms
                strcpy(preferredrenderer, "opengl");
#endif
            }
#ifdef WINDOWS
            // only windows knows direct3d obviously
            if (strcasecmp(renderer,"direct3d") == 0) {
                strcpy(preferredrenderer, "direct3d");
            }
#endif
        }
    }

    // get renderer index
    int rendererindex = -1;
    if (strlen(preferredrenderer) > 0 && !softwarerendering) {
        int count = SDL_GetNumRenderDrivers();
        if (count > 0) {
            int r = 0;
            while (r < count) {
                SDL_RendererInfo info;
                SDL_GetRenderDriverInfo(r, &info);
                if (strcasecmp(info.name, preferredrenderer) == 0) {
                    rendererindex = r;
                    break;
                }
                r++;
            }
        }
    }

    //  see if anything changes at all
    unsigned int oldw = 0;
    unsigned int oldh = 0;
    graphics_GetWindowDimensions(&oldw,&oldh);
    if (mainwindow && mainrenderer &&
    width == (int)oldw && height == (int)oldh) {
        SDL_RendererInfo info;
        SDL_GetRendererInfo(mainrenderer, &info);
        if (strcasecmp(preferredrenderer, info.name) == 0) {
            //  same renderer and resolution
            if (strcmp(SDL_GetWindowTitle(mainwindow), title) != 0) {
                SDL_SetWindowTitle(mainwindow, title);
            }
            //  toggle fullscreen if desired
            if (graphics_IsFullscreen() != fullscreen) {
                graphics_ToggleFullscreen();
            }
            return 1;
        }
    }

    //  Check if we support the video mode for fullscreen -
    //   This is done to avoid SDL allowing impossible modes and
    //   giving us a fake resized/padded/whatever output we don't want.
    if (fullscreen) {
        //  check all video modes in the list SDL returns for us
        int count = graphics_GetNumberOfVideoModes();
        int i = 0;
        int supportedmode = 0;
        while (i < count) {
            int w,h;
            graphics_GetVideoMode(i, &w, &h);
            if (w == width && h == height) {
                supportedmode = 1;
                break;
            }
            i++;
        }
        if (!supportedmode) {
            //  check for desktop video mode aswell
            int w,h;
            graphics_GetDesktopVideoMode(&w,&h);
            if (w == 0 || h == 0 || width != w || height != h) {
                *error = strdup("Video mode is not supported");
                return 0;
            }
        }
    }

    // notify texture manager of device shutdown
    texturemanager_deviceLost();

    // destroy old window/renderer if we got one
    graphics_Close(1);

    // create window
    if (fullscreen) {
        mainwindow = SDL_CreateWindow(title, 0, 0, width, height,
        SDL_WINDOW_FULLSCREEN);
        mainwindowfullscreen = 1;
    } else {
        mainwindow = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_MINIMIZED);
        mainwindowfullscreen = 0;
    }

    if (!mainwindow) {
        snprintf(errormsg, sizeof(errormsg),
        "Failed to open SDL window: %s", SDL_GetError());
        errormsg[sizeof(errormsg)-1] = 0;
        *error = strdup(errormsg);
        return 0;
    }

    // see if we actually ended up with the resolution we wanted:
    int actualwidth, actualheight;
    SDL_GetWindowSize(mainwindow, &actualwidth, &actualheight);
    if (actualwidth != width || actualheight != height) {
        if (fullscreen) {  // we failed to get the requested resolution:
            SDL_DestroyWindow(mainwindow);
            snprintf(errormsg, sizeof(errormsg), "Failed to open "
            "SDL window: ended up with other resolution than requested");
            *error = strdup(errormsg);
            return 0;
        }
    }

    // Create renderer
    if (!softwarerendering) {
        mainrenderer = SDL_CreateRenderer(mainwindow, rendererindex,
        SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
        if (!mainrenderer) {
            softwarerendering = 1;
            strcpy(preferredrenderer, "software");
        }
    }
    if (softwarerendering) {
        mainrenderer = SDL_CreateRenderer(mainwindow, -1,
        SDL_RENDERER_SOFTWARE);
    }
    if (!mainrenderer) {
        // we failed to create the renderer
        if (mainwindow) {
            // destroy window aswell in case it is open
            SDL_DestroyWindow(mainwindow);
            mainwindow = NULL;
        }
        if (softwarerendering) {
            snprintf(errormsg, sizeof(errormsg),
            "Failed to create SDL renderer (backend software): %s",
            SDL_GetError());
        } else {
            SDL_RendererInfo info;
            SDL_GetRenderDriverInfo(rendererindex, &info);
            snprintf(errormsg, sizeof(errormsg),
            "Failed to create SDL renderer (backend %s): %s",
            info.name, SDL_GetError());
        }
        errormsg[sizeof(errormsg)-1] = 0;
        *error = strdup(errormsg);
        return 0;
    } else {
        SDL_RendererInfo info;
        SDL_GetRendererInfo(mainrenderer, &info);
    }

    // notify texture manager that device is back
    texturemanager_deviceRestored();

    // Transfer textures back to SDL
    /*if (!graphicstexturelist_TransferTexturesToHW()) {
        SDL_RendererInfo info;
        SDL_GetRendererInfo(mainrenderer, &info);
        snprintf(errormsg, sizeof(errormsg),
        "Failed to create SDL renderer (backend %s): "
        "Cannot recreate textures", info.name);
        *error = strdup(errormsg);
        SDL_DestroyRenderer(mainrenderer);
        SDL_DestroyWindow(mainwindow);
        return 0;
    }*/

    // Re-focus window if previously focussed
    if (!inbackground) {
        SDL_RaiseWindow(mainwindow);
    }

    graphicsactive = 1;
    return 1;
}
Exemplo n.º 23
0
SDL_bool
WatchGameController(SDL_GameController * gamecontroller)
{
    /* This is indexed by SDL_GameControllerButton. */
    static const struct { int x; int y; } button_positions[] = {
        {387, 167},  /* A */
        {431, 132},  /* B */
        {342, 132},  /* X */
        {389, 101},  /* Y */
        {174, 132},  /* BACK */
        {233, 132},  /* GUIDE */
        {289, 132},  /* START */
        {75,  154},  /* LEFTSTICK */
        {305, 230},  /* RIGHTSTICK */
        {77,  40},   /* LEFTSHOULDER */
        {396, 36},   /* RIGHTSHOULDER */
        {154, 188},  /* DPAD_UP */
        {154, 249},  /* DPAD_DOWN */
        {116, 217},  /* DPAD_LEFT */
        {186, 217},  /* DPAD_RIGHT */
    };

    /* This is indexed by SDL_GameControllerAxis. */
    static const struct { int x; int y; double angle; } axis_positions[] = {
        {75,  154, 0.0},  /* LEFTX */
        {75,  154, 90.0},  /* LEFTY */
        {305, 230, 0.0},  /* RIGHTX */
        {305, 230, 90.0},  /* RIGHTY */
        {91, 0, 90.0},     /* TRIGGERLEFT */
        {375, 0, 90.0},    /* TRIGGERRIGHT */
    };

    const char *name = SDL_GameControllerName(gamecontroller);
    const char *basetitle = "Game Controller Test: ";
    const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
    char *title = (char *)SDL_malloc(titlelen);
    SDL_Texture *background, *button, *axis;
    SDL_Window *window = NULL;
    SDL_Renderer *screen = NULL;
    SDL_bool retval = SDL_FALSE;
    SDL_bool done = SDL_FALSE;
    SDL_Event event;
    int i;

    if (title) {
        SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
    }

    /* Create a window to display controller state */
    window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, 0);
    if (window == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
        return SDL_FALSE;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }

    SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(screen);
    SDL_RenderPresent(screen);
    SDL_RaiseWindow(window);

    /* scale for platforms that don't give you the window size you asked for. */
    SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

    background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
    button = LoadTexture(screen, "button.bmp", SDL_TRUE);
    axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);

    if (!background || !button || !axis) {
        SDL_DestroyRenderer(screen);
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }
    SDL_SetTextureColorMod(button, 10, 255, 21);
    SDL_SetTextureColorMod(axis, 10, 255, 21);

    /* !!! FIXME: */
    /*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/

    /* Print info about the controller we are watching */
    SDL_Log("Watching controller %s\n",  name ? name : "Unknown Controller");

    /* Loop, getting controller events! */
    while (!done) {
        /* blank screen, set up for drawing this frame. */
        SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
        SDL_RenderClear(screen);
        SDL_RenderCopy(screen, background, NULL, NULL);

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                if (event.key.keysym.sym != SDLK_ESCAPE) {
                    break;
                }
                /* Fall through to signal quit */
            case SDL_QUIT:
                done = SDL_TRUE;
                break;
            default:
                break;
            }
        }

        /* Update visual controller state */
        for (i = 0; i < SDL_CONTROLLER_BUTTON_MAX; ++i) {
            if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
                const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
                SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, 0);
            }
        }

        for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
            const Sint16 deadzone = 8000;  /* !!! FIXME: real deadzone */
            const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
            if (value < -deadzone) {
                const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
                const double angle = axis_positions[i].angle;
                SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
            } else if (value > deadzone) {
                const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
                const double angle = axis_positions[i].angle + 180.0;
                SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
            }
        }

        SDL_RenderPresent(screen);

        if (!SDL_GameControllerGetAttached(gamecontroller)) {
            done = SDL_TRUE;
            retval = SDL_TRUE;  /* keep going, wait for reattach. */
        }
    }

    SDL_DestroyRenderer(screen);
    SDL_DestroyWindow(window);
    return retval;
}
Exemplo n.º 24
0
static int display(struct vidisp_st *st, const char *title,
		   const struct vidframe *frame)
{
	void *pixels;
	uint8_t *p;
	int pitch, ret;
	unsigned i, h;

	if (!vidsz_cmp(&st->size, &frame->size)) {
		if (st->size.w && st->size.h) {
			info("sdl: reset size: %u x %u ---> %u x %u\n",
			     st->size.w, st->size.h,
			     frame->size.w, frame->size.h);
		}
		sdl_reset(st);
	}

	if (!st->window) {
		Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS;
		char capt[256];

		if (st->fullscreen)
			flags |= SDL_WINDOW_FULLSCREEN;

		if (title) {
			re_snprintf(capt, sizeof(capt), "%s - %u x %u",
				    title, frame->size.w, frame->size.h);
		}
		else {
			re_snprintf(capt, sizeof(capt), "%u x %u",
				    frame->size.w, frame->size.h);
		}

		st->window = SDL_CreateWindow(capt,
					      SDL_WINDOWPOS_CENTERED,
					      SDL_WINDOWPOS_CENTERED,
					      frame->size.w, frame->size.h,
					      flags);
		if (!st->window) {
			warning("sdl: unable to create sdl window: %s\n",
				SDL_GetError());
			return ENODEV;
		}

		st->size = frame->size;

		SDL_RaiseWindow(st->window);
		SDL_SetWindowBordered(st->window, true);
		SDL_ShowWindow(st->window);
	}

	if (!st->renderer) {

		Uint32 flags = 0;

		flags |= SDL_RENDERER_ACCELERATED;
		flags |= SDL_RENDERER_PRESENTVSYNC;

		st->renderer = SDL_CreateRenderer(st->window, -1, flags);
		if (!st->renderer) {
			warning("sdl: unable to create renderer: %s\n",
				SDL_GetError());
			return ENOMEM;
		}
	}

	if (!st->texture) {

		st->texture = SDL_CreateTexture(st->renderer,
						SDL_PIXELFORMAT_IYUV,
						SDL_TEXTUREACCESS_STREAMING,
						frame->size.w, frame->size.h);
		if (!st->texture) {
			warning("sdl: unable to create texture: %s\n",
				SDL_GetError());
			return ENODEV;
		}
	}

	ret = SDL_LockTexture(st->texture, NULL, &pixels, &pitch);
	if (ret != 0) {
		warning("sdl: unable to lock texture (ret=%d)\n", ret);
		return ENODEV;
	}

	p = pixels;
	for (i=0; i<3; i++) {

		const uint8_t *s   = frame->data[i];
		const unsigned stp = frame->linesize[0] / frame->linesize[i];
		const unsigned sz  = frame->size.w / stp;

		for (h = 0; h < frame->size.h; h += stp) {

			memcpy(p, s, sz);

			s += frame->linesize[i];
			p += (pitch / stp);
		}
	}

	SDL_UnlockTexture(st->texture);

	/* Blit the sprite onto the screen */
	SDL_RenderCopy(st->renderer, st->texture, NULL, NULL);

	/* Update the screen! */
	SDL_RenderPresent(st->renderer);

	return 0;
}
Exemplo n.º 25
0
void GraphicsWindowSDL2::raiseWindow()
{
    SDL_RaiseWindow(mWindow);
}
Exemplo n.º 26
0
static void SDL_change_mode(int x_res, int y_res, int w_x_res, int w_y_res)
{
  Uint32 flags;

  assert(pthread_equal(pthread_self(), dosemu_pthread_self));
  v_printf("SDL: using mode %dx%d %dx%d %d\n", x_res, y_res, w_x_res,
	   w_y_res, SDL_csd.bits);
  if (surface) {
    SDL_FreeSurface(surface);
    SDL_DestroyTexture(texture_buf);
  }
  if (x_res > 0 && y_res > 0) {
    texture_buf = SDL_CreateTexture(renderer,
        pixel_format,
        SDL_TEXTUREACCESS_STREAMING,
        x_res, y_res);
    if (!texture_buf) {
      error("SDL target texture failed: %s\n", SDL_GetError());
      leavedos(99);
    }
    surface = SDL_CreateRGBSurface(0, x_res, y_res, SDL_csd.bits,
            SDL_csd.r_mask, SDL_csd.g_mask, SDL_csd.b_mask, 0);
    if (!surface) {
      error("SDL surface failed: %s\n", SDL_GetError());
      leavedos(99);
    }
  } else {
    surface = NULL;
    texture_buf = NULL;
  }

  if (config.X_fixed_aspect)
    SDL_RenderSetLogicalSize(renderer, w_x_res, w_y_res);
  flags = SDL_GetWindowFlags(window);
  if (!(flags & SDL_WINDOW_MAXIMIZED))
    SDL_SetWindowSize(window, w_x_res, w_y_res);
  set_resizable(use_bitmap_font
		|| vga.mode_class == GRAPH, w_x_res, w_y_res);
  if (!initialized) {
    initialized = 1;
    SDL_ShowWindow(window);
    SDL_RaiseWindow(window);
    m_cursor_visible = 1;
    if (config.X_fullscreen)
      render_gain_focus();
  }
  SDL_RenderClear(renderer);
  SDL_RenderPresent(renderer);
  if (texture_buf) {
    SDL_SetRenderTarget(renderer, texture_buf);
    SDL_RenderClear(renderer);
  }

  m_x_res = w_x_res;
  m_y_res = w_y_res;
  win_width = x_res;
  win_height = y_res;
  /* forget about those rectangles */
  sdl_rects_num = 0;

  update_mouse_coords();
}
Exemplo n.º 27
0
 void Window::focus() const {
     SDL_RaiseWindow(_wnd);
 }
Exemplo n.º 28
0
void
WatchGameController(SDL_GameController * gamecontroller)
{
    SDL_Window *window = NULL;
    SDL_Renderer *screen = NULL;
    const char *name = NULL;
    int done = 0;
    SDL_Event event;
    int i;

    /* Create a window to display controller axis position */
    window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    if (window == NULL) {
        fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
        return;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return;
    }

    SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(screen);
    SDL_RenderPresent(screen);
	SDL_RaiseWindow(window);

    /* Print info about the controller we are watching */
    name = SDL_GameControllerName(gamecontroller);
    printf("Watching controller %s\n",  name ? name : "Unknown Controller");
    
    /* Loop, getting controller events! */
    while (!done) {
        /* blank screen, set up for drawing this frame. */
        SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
        SDL_RenderClear(screen);

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_CONTROLLERAXISMOTION:
                printf("Controller %d axis %d value: %d\n",
                       event.caxis.which,
                       event.caxis.axis, event.caxis.value);
                break;
            case SDL_CONTROLLERBUTTONDOWN:
                printf("Controller %d button %d down\n",
                       event.cbutton.which, event.cbutton.button);
                break;
            case SDL_CONTROLLERBUTTONUP:
                printf("Controller %d button %d up\n",
                       event.cbutton.which, event.cbutton.button);
                break;
            case SDL_KEYDOWN:
                if (event.key.keysym.sym != SDLK_ESCAPE) {
                    break;
                }
                /* Fall through to signal quit */
            case SDL_QUIT:
                done = 1;
				s_ForceQuit = SDL_TRUE;
                break;
            default:
                break;
            }
        }
        /* Update visual controller state */
        SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
        for (i = 0; i <SDL_CONTROLLER_BUTTON_MAX; ++i) {
            if (SDL_GameControllerGetButton(gamecontroller, i) == SDL_PRESSED) {
                DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32);
            }
        }

        SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
        for (i = 0; i < SDL_CONTROLLER_AXIS_MAX / 2; ++i) {
            /* Draw the X/Y axis */
            int x, y;
            x = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 0)) + 32768);
            x *= SCREEN_WIDTH;
            x /= 65535;
            if (x < 0) {
                x = 0;
            } else if (x > (SCREEN_WIDTH - 16)) {
                x = SCREEN_WIDTH - 16;
            }
            y = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 1)) + 32768);
            y *= SCREEN_HEIGHT;
            y /= 65535;
            if (y < 0) {
                y = 0;
            } else if (y > (SCREEN_HEIGHT - 16)) {
                y = SCREEN_HEIGHT - 16;
            }

            DrawRect(screen, x, y, 16, 16);
        }

        SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);

        SDL_RenderPresent(screen);
		
		if ( !done )
			done = SDL_GameControllerGetAttached( gamecontroller ) == 0;
    }

    SDL_DestroyRenderer(screen);
    SDL_DestroyWindow(window);
}
Exemplo n.º 29
0
	void SDLWindow::Focus () {
		
		SDL_RaiseWindow (sdlWindow);
		
	}
Exemplo n.º 30
0
/**
 * @brief Set Current Window to Focus
 */
void WindowManager::grabWindow()
{
    SDL_RaiseWindow(m_window);
}