Ejemplo n.º 1
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
    lastchar=-1;
    inputdelay=-1;

    std::string typeface = "";
    std::string blending = "solid";
    std::ifstream fin;
    int faceIndex = 0;
    int fontsize = 0; //actuall size
    fin.open("data/FONTDATA");
    if (!fin.is_open()){
        fontheight=16;
        fontwidth=8;
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        fin >> blending;
        if ((fontwidth <= 4) || (fontheight <= 4)) {
            fontheight=16;
            fontwidth=8;
        }
        fin.close();
    }

    fontblending = (blending=="blended");

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS[OPT_VIEWPORT_X] * 2 + 1)) * fontwidth;
    WindowHeight= (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1) *fontheight;
    if(!WinCreate()) {}// do something here

    std::string sysfnt = find_system_font(typeface, faceIndex);
    if(sysfnt!="") typeface = sysfnt;

    //make fontdata compatible with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/" + typeface + ".ttf";
    }

    //different default font with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/fixedsys.ttf";
    }

    if(fontsize <= 0) fontsize = fontheight - 1;

    // STL_ttf handles bitmap fonts size incorrectly
    if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon"))
        faceIndex = test_face_size(typeface, fontsize, faceIndex);

    font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex);

    //if(!font) something went wrong

    TTF_SetFontStyle(font, TTF_STYLE_NORMAL);

    // glyph height hack by utunnels
    // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics
    // this causes baseline problems for certain fonts
    // I can only guess by check a certain tall character...
    cache_glyphs();

    mainwin = newwin((OPTIONS[OPT_VIEWPORT_Y] * 2 + 1),(55 + (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Ejemplo n.º 2
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
    lastchar = -1;
    inputdelay = -1;

    std::string typeface = "Terminus";
    std::string blending = "solid";
    std::ifstream fin;
    int faceIndex = 0;
    int fontsize = 0; //actuall size
    fin.open("data/FONTDATA");
    if (!fin.is_open()){
        fontwidth = 8;
        fontheight = 16;
        std::ofstream fout;//create data/FONDATA file
        fout.open("data/FONTDATA");
        if(fout.is_open()) {
            fout << typeface << "\n";
            fout << fontwidth << "\n";
            fout << fontheight;
            fout.close();
        }
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        fin >> blending;
        if ((fontwidth <= 4) || (fontheight <= 4)) {
            fontheight = 16;
            fontwidth = 8;
        }
        fin.close();
    }

    fontblending = (blending=="blended");

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;

    if(!InitSDL()) {
        DebugLog() << "Failed to initialize SDL: " << SDL_GetError() << "\n";
        return NULL;
    }

    TERMINAL_WIDTH = OPTIONS["TERMINAL_X"];
    TERMINAL_HEIGHT = OPTIONS["TERMINAL_Y"];

    if(OPTIONS["FULLSCREEN"]) {
        // Fullscreen mode overrides terminal width/height
        SDL_DisplayMode display_mode;
        SDL_GetDesktopDisplayMode(0, &display_mode);

        TERMINAL_WIDTH = display_mode.w / fontwidth;
        TERMINAL_HEIGHT = display_mode.h / fontheight;

        WindowWidth  = display_mode.w;
        WindowHeight = display_mode.h;
    } else {
        WindowWidth= OPTIONS["TERMINAL_X"];
        if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH;
        WindowWidth *= fontwidth;
        WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;
    }

    if(!WinCreate()) {
        DebugLog() << "Failed to create game window: " << SDL_GetError() << "\n";
        return NULL;
    }

    #ifdef SDLTILES
    DebugLog() << "Initializing SDL Tiles context\n";
    tilecontext = new cata_tiles(renderer);
    try {
        tilecontext->init("gfx");
        DebugLog() << "Tiles initialized successfully.\n";
    } catch(std::string err) {
        // use_tiles is the cached value of the USE_TILES option.
        // most (all?) code refers to this to see if cata_tiles should be used.
        // Setting it to false disables this from getting used.
        use_tiles = false;
    }
    #endif // SDLTILES

    #ifdef SDLTILES
    while(!strcasecmp(typeface.substr(typeface.length()-4).c_str(),".bmp") ||
          !strcasecmp(typeface.substr(typeface.length()-4).c_str(),".png")) {
        DebugLog() << "Loading bitmap font [" + typeface + "].\n" ;
        typeface = "data/font/" + typeface;
        SDL_Surface *asciiload = IMG_Load(typeface.c_str());
        if(!asciiload || asciiload->w*asciiload->h < (fontwidth * fontheight * 256)) {
            DebugLog() << "Failed to load bitmap font: " << IMG_GetError() << "\n";
            SDL_FreeSurface(asciiload);
            break;
        }
        Uint32 key = SDL_MapRGB(asciiload->format, 0xFF, 0, 0xFF);
        SDL_SetColorKey(asciiload,SDL_TRUE,key);
        SDL_Surface *ascii_surf[16];
        ascii_surf[0] = SDL_ConvertSurface(asciiload,format,0);
        SDL_SetSurfaceRLE(ascii_surf[0], true);
        SDL_FreeSurface(asciiload);

        for(int a = 1; a < 16; ++a) {
            ascii_surf[a] = SDL_ConvertSurface(ascii_surf[0],format,0);
            SDL_SetSurfaceRLE(ascii_surf[a], true);
        }

        init_colors();
        for(int a = 0; a < 15; ++a) {
            SDL_LockSurface(ascii_surf[a]);
            int size = ascii_surf[a]->h * ascii_surf[a]->w;
            Uint32 *pixels = (Uint32 *)ascii_surf[a]->pixels;
            Uint32 color = (windowsPalette[a].r << 16) | (windowsPalette[a].g << 8) | windowsPalette[a].b;
            for(int i=0;i<size;i++) {
                if(pixels[i] == 0xFFFFFF)
                    pixels[i] = color;
            }
            SDL_UnlockSurface(ascii_surf[a]);
        }

        if(fontwidth)
            tilewidth = ascii_surf[0]->w / fontwidth;

        OutputChar = &OutputImageChar;

        //convert ascii_surf to SDL_Texture
        for(int a = 0; a < 16; ++a) {
            ascii[a] = SDL_CreateTextureFromSurface(renderer,ascii_surf[a]);
            SDL_FreeSurface(ascii_surf[a]);
        }

        mainwin = newwin(get_terminal_height(), get_terminal_width(),0,0);
        return mainwin;
    }
    #endif // SDLTILES

    std::string sysfnt = find_system_font(typeface, faceIndex);
    if(sysfnt != "") typeface = sysfnt;

    //make fontdata compatible with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/" + typeface + ".ttf";
    }

    //different default font with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/fixedsys.ttf";
    }

    DebugLog() << "Loading truetype font [" + typeface + "].\n" ;

    if(fontsize <= 0) fontsize = fontheight - 1;

    // SDL_ttf handles bitmap fonts size incorrectly
    if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon"))
        faceIndex = test_face_size(typeface, fontsize, faceIndex);

    font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex);
    if (font == NULL) {
        DebugLog() << "Failed to load truetype font: " << TTF_GetError() << "\n";
        return NULL;
    }

    TTF_SetFontStyle(font, TTF_STYLE_NORMAL);

    // glyph height hack by utunnels
    // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics
    // this causes baseline problems for certain fonts
    // I can only guess by check a certain tall character...
    cache_glyphs();
    init_colors();

    OutputChar = &OutputFontChar;

    mainwin = newwin(get_terminal_height(), get_terminal_width(),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Ejemplo n.º 3
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
    lastchar = -1;
    inputdelay = -1;

    std::string typeface = "Terminus";
    std::string blending = "solid";
    std::ifstream fin;
    int faceIndex = 0;
    int fontsize = 0; //actuall size
    fin.open("data/FONTDATA");
    if (!fin.is_open()){
        fontwidth = 8;
        fontheight = 16;
        std::ofstream fout;//create data/FONDATA file
        fout.open("data/FONTDATA");
        if(fout.is_open()) {
            fout << typeface << "\n";
            fout << fontwidth << "\n";
            fout << fontheight;
            fout.close();
        }
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        fin >> blending;
        if ((fontwidth <= 4) || (fontheight <= 4)) {
            fontheight = 16;
            fontwidth = 8;
        }
        fin.close();
    }

    fontblending = (blending=="blended");

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;

    if(!InitSDL()) {
        DebugLog() << (std::string)"Failed to initialize SDL!\n";
    }

    #ifdef SDLTILES
    DebugLog() << "Initializing SDL Tiles context\n";
    tilecontext = new cata_tiles;
    tilecontext->init("gfx");
    #endif // SDLTILES
    DebugLog() << (std::string)"Tiles initialized successfully.\n";
    WindowWidth= OPTIONS["TERMINAL_X"];
    if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH;
    WindowWidth *= fontwidth;
    WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;
    if(!WinCreate()) {
        DebugLog() << (std::string)"Failed to create game window!\n";
        return NULL;
    }
    #ifdef SDLTILES
    tilecontext->set_screen(screen);

    while(!strcasecmp(typeface.substr(typeface.length()-4).c_str(),".bmp") ||
          !strcasecmp(typeface.substr(typeface.length()-4).c_str(),".png")) {
        SDL_Surface *asciiload;
        typeface = "data/font/" + typeface;
        asciiload = IMG_Load(typeface.c_str());
        if(!asciiload || asciiload->w*asciiload->h < (fontwidth * fontheight * 256)) {
            SDL_FreeSurface(asciiload);
            break;
        }
        Uint32 key = SDL_MapRGB(asciiload->format, 0xFF, 0, 0xFF);
        SDL_SetColorKey(asciiload,SDL_SRCCOLORKEY,key);
        ascii[0] = SDL_DisplayFormat(asciiload);
        SDL_FreeSurface(asciiload);
        for(int a = 1; a < 16; a++) {
            ascii[a]=SDL_ConvertSurface(ascii[0],ascii[0]->format,ascii[0]->flags);
        }

        init_colors();
        for(int a = 0; a < 15; a++) {
            SDL_LockSurface(ascii[a]);
            int size = ascii[a]->h * ascii[a]->w;
            Uint32 *pixels = (Uint32 *)ascii[a]->pixels;
            Uint32 color = (windowsPalette[a].r << 16) | (windowsPalette[a].g << 8) | windowsPalette[a].b;
            for(int i=0;i<size;i++) {
                if(pixels[i] == 0xFFFFFF)
                    pixels[i] = color;
            }
            SDL_UnlockSurface(ascii[a]);
        }
        if(fontwidth)tilewidth=ascii[0]->w/fontwidth;
        OutputChar = &OutputImageChar;

        mainwin = newwin(OPTIONS["TERMINAL_Y"], OPTIONS["TERMINAL_X"],0,0);
        return mainwin;
    }
    #endif // SDLTILES

    std::string sysfnt = find_system_font(typeface, faceIndex);
    if(sysfnt != "") typeface = sysfnt;

    //make fontdata compatible with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/" + typeface + ".ttf";
    }

    //different default font with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/fixedsys.ttf";
    }

    if(fontsize <= 0) fontsize = fontheight - 1;

    // SDL_ttf handles bitmap fonts size incorrectly
    if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon"))
        faceIndex = test_face_size(typeface, fontsize, faceIndex);

    font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex);

    //if(!font) something went wrong

    TTF_SetFontStyle(font, TTF_STYLE_NORMAL);

    // glyph height hack by utunnels
    // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics
    // this causes baseline problems for certain fonts
    // I can only guess by check a certain tall character...
    cache_glyphs();
    init_colors();

    OutputChar = &OutputFontChar;

    mainwin = newwin(OPTIONS["TERMINAL_Y"], OPTIONS["TERMINAL_X"],0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Ejemplo n.º 4
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
    lastchar=-1;
    inputdelay=-1;

    std::string typeface = "";
    std::string blending = "solid";
    std::ifstream fin;
    int faceIndex = 0;
    int fontsize = 0; //actuall size
    fin.open("data/FONTDATA");
    if (!fin.is_open()){
        fontheight=16;
        fontwidth=8;
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        fin >> blending;
        if ((fontwidth <= 4) || (fontheight <= 4)) {
            fontheight=16;
            fontwidth=8;
        }
        fin.close();
    }

    fontblending = (blending=="blended");

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;

    const int SidebarWidth = (OPTIONS["SIDEBAR_STYLE"] == "narrow") ? 45 : 55;

    WindowWidth= (SidebarWidth + (OPTIONS["VIEWPORT_X"] * 2 + 1));
    if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH;
    WindowWidth *= fontwidth;
    WindowHeight= (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight;
    if(!WinCreate()) {}// do something here

    std::string sysfnt = find_system_font(typeface, faceIndex);
    if(sysfnt!="") typeface = sysfnt;

    //make fontdata compatible with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/" + typeface + ".ttf";
    }

    //different default font with wincurse
    if(!fexists(typeface.c_str())) {
        faceIndex = 0;
        typeface = "data/font/fixedsys.ttf";
    }

    if(fontsize <= 0) fontsize = fontheight - 1;

    // SDL_ttf handles bitmap fonts size incorrectly
    if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon"))
        faceIndex = test_face_size(typeface, fontsize, faceIndex);

    font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex);

    //if(!font) something went wrong

    TTF_SetFontStyle(font, TTF_STYLE_NORMAL);

    // glyph height hack by utunnels
    // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics
    // this causes baseline problems for certain fonts
    // I can only guess by check a certain tall character...
    cache_glyphs();

#ifdef SDLTILES
    // Should NOT be doing this for every damned window I think... keeping too much in memory is wasteful of the tiles.  // Most definitely should not be doing this multiple times...
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(((OPTIONS["SIDEBAR_STYLE"] == "narrow") ? 45 : 55) + (OPTIONS["VIEWPORT_X"] * 2 + 1)),0,0);
    DebugLog() << "Initializing SDL Tiles context\n";
    IMG_Init(IMG_INIT_PNG);
    tilecontext = new cata_tiles;
    tilecontext->init(screen, "gfx");
#else
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(((OPTIONS["SIDEBAR_STYLE"] == "narrow") ? 45 : 55) + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0);
#endif
    return mainwin;   //create the 'stdscr' window and return its ref
}