istereo2

diff libs/goatkit/theme.cc @ 7:a3c4fcc9f8f3

- started a goatkit UI theme - font rendering with drawtext and shaders - asset manager (only used by drawtext for now, will replace respath eventually)
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 06:49:25 +0300
parents 3bccfc7d10fe
children 64e15874f3bd
line diff
     1.1 --- a/libs/goatkit/theme.cc	Wed Sep 23 05:44:58 2015 +0300
     1.2 +++ b/libs/goatkit/theme.cc	Thu Sep 24 06:49:25 2015 +0300
     1.3 @@ -103,30 +103,34 @@
     1.4  {
     1.5  	unload();
     1.6  
     1.7 -	std::string fname = std::string(name) + ".gtheme";
     1.8 -	if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) {
     1.9 -		for(size_t i=0; i<search_paths.size(); i++) {
    1.10 -			std::string path = search_paths[i] + "/" + fname;
    1.11 -
    1.12 -			if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
    1.13 -				break;
    1.14 -			}
    1.15 -		}
    1.16 -
    1.17 -		// try the fallback paths
    1.18 -		if(!impl->so) {
    1.19 -			for(int i=0; fallback_paths[i]; i++) {
    1.20 -				std::string path = std::string(fallback_paths[i]) + "/" + fname;
    1.21 +	if(strcmp(name, "GOATKIT_THEME_BUILTIN") == 0) {
    1.22 +		impl->so = RTLD_DEFAULT;
    1.23 +	} else {
    1.24 +		std::string fname = std::string(name) + ".gtheme";
    1.25 +		if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) {
    1.26 +			for(size_t i=0; i<search_paths.size(); i++) {
    1.27 +				std::string path = search_paths[i] + "/" + fname;
    1.28  
    1.29  				if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
    1.30  					break;
    1.31  				}
    1.32  			}
    1.33 -		}
    1.34  
    1.35 -		if(!impl->so) {
    1.36 -			fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name);
    1.37 -			return false;
    1.38 +			// try the fallback paths
    1.39 +			if(!impl->so) {
    1.40 +				for(int i=0; fallback_paths[i]; i++) {
    1.41 +					std::string path = std::string(fallback_paths[i]) + "/" + fname;
    1.42 +
    1.43 +					if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
    1.44 +						break;
    1.45 +					}
    1.46 +				}
    1.47 +			}
    1.48 +
    1.49 +			if(!impl->so) {
    1.50 +				fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name);
    1.51 +				return false;
    1.52 +			}
    1.53  		}
    1.54  	}
    1.55  
    1.56 @@ -144,7 +148,9 @@
    1.57  void Theme::unload()
    1.58  {
    1.59  	if(impl->so) {
    1.60 -		dlclose(impl->so);
    1.61 +		if(impl->so != RTLD_DEFAULT) {
    1.62 +			dlclose(impl->so);
    1.63 +		}
    1.64  		impl->so = 0;
    1.65  	}
    1.66  	impl->func_cache.clear();
    1.67 @@ -248,6 +254,9 @@
    1.68  
    1.69  static void *dlsym(void *so, const char *symbol)
    1.70  {
    1.71 +	if(so == RTLD_DEFAULT) {
    1.72 +		so = GetModuleHandle(0);
    1.73 +	}
    1.74  	return (void*)GetProcAddress(so, symbol);
    1.75  }
    1.76  #endif