static int setup_touch_txt() { int pos, i, sdid, t; static char filename[256]; static char pakname[256]; char *buf, *command, *value; size_t size; ArgList arglist; char argbuf[MAX_ARG_LEN + 1] = ""; float w = nativeWidth; float h = nativeHeight; float hh = w * 480 / 800; SDL_Surface *ts; char *pngb; size_t pngs; getPakName(pakname, -1); sprintf(filename, "/mnt/sdcard/OpenBOR/Saves/%s", pakname); dirExists(filename, 1); sprintf(filename, "/mnt/sdcard/OpenBOR/Saves/%s/touch.txt", pakname); // Read file if( buffer_pakfile(filename, &buf, &size) != 1 && buffer_pakfile("data/touch.txt", &buf, &size) != 1 && buffer_pakfile("/mnt/sdcard/OpenBOR/Saves/touch.txt", &buf, &size) != 1) { return 0; } // Now interpret the contents of buf line by line pos = 0; while(pos < size) { if(ParseArgs(&arglist, buf + pos, argbuf)) { command = GET_ARG(0); if(command && command[0]) { if(stricmp(command, "button") == 0) { sdid = translate_SDID(GET_ARG(1)); if(sdid >= 0) { bx[sdid] = GET_FLOAT_ARG(2) * hh; by[sdid] = GET_FLOAT_ARG(3) * hh; br[sdid] = GET_FLOAT_ARG(4) * hh; t = GET_INT_ARG(5); /* corners: 0 1 3 2 */ if(t == 1 || t == 2) { bx[sdid] = w - bx[sdid]; } if(t == 2 || t == 3) { by[sdid] = h - by[sdid]; } } } else if(stricmp(command, "texture") == 0) { if(buffer_pakfile(GET_ARG(1), &pngb, &pngs)) { ts = pngToSurface(pngb); if(!ts || !(buttons = SDL_CreateTextureFromSurface(renderer, ts))) { printf("error: %s\n", SDL_GetError()); } if(ts) { SDL_FreeSurface(ts); } if(pngb) { free(pngb); } } } else if(stricmp(command, "screendocking") == 0) // change screen position to avoid buttons { screendocking = 0; for(i = 1; ; i++) { value = GET_ARG(i); if(!value || !value[0]) { break; } if(stricmp(value, "left") == 0) { screendocking |= DOCKLEFT; } else if(stricmp(value, "right") == 0) { screendocking |= DOCKRIGHT; } else if(stricmp(value, "top") == 0) { screendocking |= DOCKTOP; } else if(stricmp(value, "bottom") == 0) { screendocking |= DOCKBOTTOM; } else { screendocking = GET_INT_ARG(i); } } } } } // Go to next line pos += getNewLineStart(buf + pos); } if(buf != NULL) { free(buf); buf = NULL; } return 1; }
int video_set_mode(s_videomodes videomodes) { //if(memcmp(&stored_videomodes, &videomodes, sizeof(videomodes))==0) return 1; stored_videomodes = videomodes; int b; int allocTextureWidth, allocTextureHeight; savedata.screen[videoMode][0] = 0; savedata.fullscreen = 1; bytes_per_pixel = videomodes.pixel; b = bytes_per_pixel - 1; //destroy all if(bscreen) { SDL_FreeSurface(bscreen); } bscreen = NULL; if(texture) { SDL_DestroyTexture(texture); } texture = NULL; if(buttons) { SDL_DestroyTexture(buttons); } buttons = NULL; //mysterious crash in sdl 2.0 if these are recreated, so leave them alone for now //if(renderer) SDL_DestroyRenderer(renderer); //renderer = NULL; //if(window) SDL_DestroyWindow(window); //window = NULL; if(videomodes.hRes == 0 && videomodes.vRes == 0) { return 0; } viewportWidth = nativeWidth; viewportHeight = nativeHeight; if(!window && !(window = SDL_CreateWindow("OpenBOR", 0, 0, nativeWidth, nativeHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN))) { printf("error: %s\n", SDL_GetError()); return 0; } if(!renderer && !(renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED))) { printf("error: %s\n", SDL_GetError()); return 0; } SDL_RendererInfo info; SDL_GetRendererInfo(renderer, &info); printf("SDL video Renderer: %s \n", info.name); SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY, savedata.glfilter[savedata.fullscreen] ? "nearest" : "linear", SDL_HINT_DEFAULT); // now create a texture textureWidth = videomodes.hRes; textureHeight = videomodes.vRes; allocTextureWidth = nextpowerof2(textureWidth); allocTextureHeight = nextpowerof2(textureHeight); int format = SDL_MasksToPixelFormatEnum (textureDepths[b], masks[b][0], masks[b][1], masks[b][2], masks[b][3]); if(!(texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, allocTextureWidth, allocTextureHeight))) { printf("error: %s\n", SDL_GetError()); return 0; } setup_touch(); if(!buttons) { bscreen = pngToSurface(buttonpng); if(!bscreen || !(buttons = SDL_CreateTextureFromSurface(renderer, bscreen))) { printf("error: %s\n", SDL_GetError()); return 0; } SDL_FreeSurface(bscreen); bscreen = NULL; } //create a buffer for 8bit mode, masks don't really matter but anyway set them if(bytes_per_pixel == 1) { bscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, textureWidth, textureHeight, textureDepths[b], masks[b][0], masks[b][1], masks[b][2], masks[b][3]); } video_clearscreen(); return 1; }
int SetVideoMode(int w, int h, int bpp, bool gl) { int flags = SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS; static bool last_gl = false; static int last_x = SDL_WINDOWPOS_UNDEFINED; static int last_y = SDL_WINDOWPOS_UNDEFINED; if(gl) flags |= SDL_WINDOW_OPENGL; if(savedata.fullscreen) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; if(!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP)) SDL_GetWindowPosition(window, &last_x, &last_y); if(window && gl != last_gl) { SDL_DestroyWindow(window); window = NULL; } last_gl = gl; if(renderer) SDL_DestroyRenderer(renderer); if(texture) SDL_DestroyTexture(texture); renderer = NULL; texture = NULL; if(window) { if(savedata.fullscreen) { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { #ifndef WIN // hiding and showing the window is problematic on Windows if(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) SDL_HideWindow(window); #endif SDL_SetWindowFullscreen(window, 0); SDL_SetWindowSize(window, w, h); SDL_SetWindowPosition(window, last_x, last_y); SDL_ShowWindow(window); } } else { window = SDL_CreateWindow(windowTitle, last_x, last_y, w, h, flags); if(!window) { printf("Error: failed to create window: %s\n", SDL_GetError()); return 0; } SDL_Surface* icon = (SDL_Surface*)pngToSurface((void*)openbor_icon_32x32_png.data); SDL_SetWindowIcon(window, icon); SDL_FreeSurface(icon); if(!savedata.fullscreen) SDL_GetWindowPosition(window, &last_x, &last_y); } if(!gl) { renderer = SDL_CreateRenderer(window, -1, 0); if(!renderer) { printf("Error: failed to create renderer: %s\n", SDL_GetError()); return 0; } } return 1; }