bool som::carregar(string arquivo) { if(!egl_init) return false; string ext = arquivo.substr(arquivo.size()-4,arquivo.size()-1); std::transform(ext.begin(), ext.end(), ext.begin(),static_cast < int(*)(int) > (tolower)); if (ext == ".wav") { tipo = T_WAV; if(smp) { destroy_sample(smp); voice = -1; } smp = load_wav(arquivo.c_str()); if(!smp) { egl_erro("Erro carregando arquivo: " + arquivo); egl_debug = true; return false; } } else { tipo = T_MID; if(mid) { destroy_midi(mid); voice = -1; } mid = load_midi(arquivo.c_str()); if(!mid) { egl_erro("Erro carregando arquivo: " + arquivo); egl_debug = true; return false; } } return true; }
void som::ajustar(int vol, int pan, int freq, int loop) { if (tipo == T_WAV) { if(!smp) return; adjust_sample(smp, vol, pan, freq, loop); volume = vol; posicao = pan; frequencia = freq; } else if (tipo == T_MID) { egl_erro("Não é possível ajustar um som no formato MIDI"); egl_debug = true; } }
bool imagem::carregar(string arquivo, int x, int y, int largura, int altura) { if(!egl_init) { falha = true; falha_str = "sem egl_inicializar() antes de tentar carregar:" + arquivo; return false; } index++; SDL_Surface* btemp; SDL_Surface* bmp_temp; bmp_temp = IMG_Load(arquivo.c_str()); SDL_SetAlpha(bmp_temp,0,0); if(!bmp_temp) { index--; string s_err = "Erro carreg. arq: " + arquivo; egl_erro(s_err); falha = true; falha_str = s_err; return false; } btemp = SDL_CreateRGBSurface(SDL_SWSURFACE, largura, altura, 32, rmask, gmask, bmask, amask); SDL_Rect r_orig; r_orig.x = x; r_orig.y = y; r_orig.w = largura; r_orig.h = altura; SDL_BlitSurface(bmp_temp,&r_orig,btemp,NULL); SDL_FreeSurface(bmp_temp); SDL_SetColorKey(btemp,SDL_SRCCOLORKEY,SDL_MapRGB(tela->format, 255, 0, 255) ); SDL_Surface* remove = btemp; btemp = SDL_DisplayFormatAlpha(btemp); SDL_FreeSurface(remove); bmp.push_back(btemp); return true; }
bool imagem::carregar(string arquivo, bool global) { if(!egl_init) { falha = true; falha_str = "sem egl_inicializar() antes de tentar carregar:" + arquivo; return false; } decl_global = global; index++; SDL_Surface* btemp; btemp = IMG_Load(arquivo.c_str()); if(!btemp) { index--; string s_err = "Erro carreg. arq: " + arquivo; egl_erro(s_err); egl_debug = true; falha = true; falha_str = s_err; return false; } SDL_SetColorKey(btemp,SDL_SRCCOLORKEY,SDL_MapRGB(tela->format, 255, 0, 255) ); SDL_Surface* remove = btemp; btemp = SDL_DisplayFormatAlpha(btemp); SDL_FreeSurface(remove); bmp.push_back(btemp); return true; }