示例#1
0
文件: i18n.c 项目: thunderk/stormwar
/*----------------------------------------------------------------------------*/
static void
i18nAdd(Var v)
{
    VarValidator valid;
    I18n_elem elem;
    
    valid = VarValidator_new();
    VarValidator_declareStringVar(valid, "o", "");
    VarValidator_declareStringVar(valid, "t", "");
    VarValidator_validate(valid, v);
    VarValidator_del(valid);
    
    elem = I18n_elem_new(Var_getValueString(Var_getArrayElemByCName(v, "o")), Var_getValueString(Var_getArrayElemByCName(v, "t")));
    if (PtrArray_findSorted(elems, elem) != NULL)
    {
        shellPrintf(LEVEL_ERROR, "Translation already defined: %s", String_get(elem->orig));
        I18n_elem_del(elem);
    }
    else
    {
#ifdef DEBUG_I18N
        PtrArray_insertSorted(debug_notused, elem->orig);
#endif
        PtrArray_insertSorted(elems, elem);
    }
}
示例#2
0
文件: i18n.c 项目: thunderk/stormwar
static void
processDebug()
{
    PtrArrayIterator it;
    
    if (PtrArray_SIZE(elems) == 0)
    {
        shellPrint(LEVEL_DEBUG, "Internationalization had no element set.");
    }
    else
    {
        for (it = PtrArray_START(debug_missing); it != PtrArray_STOP(debug_missing); it++)
        {
            shellPrintf(LEVEL_DEBUG, "Missing translation: %s", String_get(*(String*)it));
        }
        for (it = PtrArray_START(debug_notused); it != PtrArray_STOP(debug_notused); it++)
        {
            shellPrintf(LEVEL_DEBUG, "Unused translation: %s", String_get(*(String*)it));
        }
    }
}
示例#3
0
文件: i18n.c 项目: thunderk/stormwar
/*----------------------------------------------------------------------------*/
char*
pv_i18nTranslate(char* st)
{
    PtrArrayIterator it;
    pv_I18n_elem elem;
    
    if (inited)
    {
        elem.orig = String_new(st);
        it = PtrArray_findSorted(elems, &elem);
#ifdef DEBUG_I18N
        PtrArray_removeIt(debug_notused, PtrArray_findSorted(debug_notused, elem.orig));
#endif
        String_del(elem.orig);
        
        if (it == NULL)
        {
#ifdef DEBUG_I18N
            String s;
            s = String_new(st);
            if (PtrArray_findSorted(debug_missing, s) == NULL)
            {
                PtrArray_insertSorted(debug_missing, s);
            }
            else
            {
                String_del(s);
            }
#endif
            return st;
        }
        else
        {
            return String_get(((I18n_elem)(*it))->trans);
        }
    }
    else
    {
        return st;
    }
}
int SeqerWindow_saveMidiFile(SeqerWindow_t window, char *filename)
{
	if ((filename == NULL) || (filename[0] == '\0'))
	{
		filename = (char *)(String_get(window->document->filename));

		if (filename[0] == '\0')
		{
			return -1;
		}
		else
		{
			return MidiFile_save(window->document->midi_file, filename);
		}
	}
	else
	{
		if (MidiFile_save(window->document->midi_file, filename) < 0)
		{
			return -1;
		}
		else
		{
			int window_number;

			String_set(window->document->filename, (unsigned char *)(filename));

			for (window_number = PointerArray_getSize(window->document->windows) - 1; window_number >= 0; window_number--)
			{
				(*(window->application->filename_change_callback))((SeqerWindow_t)(PointerArray_get(window->document->windows, window_number)));
			}

			return 0;
		}
	}
}
示例#5
0
/*----------------------------------------------------------------------------*/
void
GlTextRender_directRender(GlTextRender tr, String text, GlSurface surf, GlRect rect, Gl2DCoord offsetx, Gl2DCoord offsety)
{
    GlFont font;
    char* st;
    Gl2DCoord x, y;
    GlIterator it;
    GlColor col;
    
    if (tr->font == NULL)
    {
        return;
    }
    font = tr->font;
    tr->render = NULL;

    st = String_get(text);
    
    if ((offsety <= -font->h) || (offsety > rect.h) || (offsetx > rect.w))
    {
        return;
    }
    x = offsetx;
    y = offsety;
    
    /*we fill the font surface with the drawing color (without altering alpha channel)*/
    GlIterator_init(&it, font->surf);
    while (!GlIterator_endReached(it))
    {
        col = GlIterator_getColor(it) & GlColor_Amask;
        col |= (tr->opt.color & (~GlColor_Amask));
        GlIterator_setColor(it, col);
        GlIterator_fwd(&it);
    }
    
    /*draw characters*/
    while (*st != '\0')
    {
        if (*st == '\n')
        {
            y += tr->font->h;
            x = offsetx;
            st++;
            continue;
        }
        
        if (*st == '\r')
        {
            x = offsetx;
            st++;
            continue;
        }
        
        if ((tr->wlimit != 0) && (offsetx + sizeChar(*st, font, tr->opt.monospace) > rect.w))
        {
            x = offsetx;
            y += tr->font->h;
        }
        
        x += drawChar(font, surf, rect, tr->opt.monospace, *st, x, y);
        st++;
    }
}
示例#6
0
/*----------------------------------------------------------------------------*/
GlTextRenderStatus
GlTextRender_render(GlTextRender tr, String text, GlSurface surf, Gl2DCoord posx, Gl2DCoord posy, Uint16 heightlimit)
{
    GlTextRenderStatus ret;
    char* st;
    GlFont font;
    GlIterator it;
    GlRect rct;
    Gl2DSize dw;
    GlColor col;
    
    ret.width = 0;
    ret.height = 0;
    
    if (tr->font == NULL)
    {
        ret.breakevent = GLTEXTRENDER_END;
        return ret;
    }
    font = tr->font;
    
    st = String_get(text);
    
    rct.x = posx;
    rct.y = posy;
    if (tr->wlimit == 0)
    {
        rct.w = GlSurface_getWidth(surf) - posx;
    }
    else
    {
        rct.w = tr->wlimit;
    }
    if (heightlimit == 0)
    {
        rct.h = GlSurface_getHeight(surf) - posy;
    }
    else
    {
        rct.h = heightlimit;
    }
    
    if ((rct.w == 0) || (rct.h == 0))
    {
        ret.breakevent = GLTEXTRENDER_END;
        return ret;
    }
    
    /*we fill the font surface with the drawing color (without altering alpha channel)*/
    if (tr->opt.color != font->lastcolor)
    {
        GlIterator_init(&it, font->surf);
        while (!GlIterator_endReached(it))
        {
            col = GlIterator_getColor(it) & GlColor_Amask;
            col |= (tr->opt.color & (~GlColor_Amask));
            GlIterator_setColor(it, col);
            GlIterator_fwd(&it);
        }
        font->lastcolor = tr->opt.color;
    }
    
    /*draw characters*/
    if (tr->render == text)
    {
        ASSERT(tr->renderpos < String_getLength(text), tr->renderpos = 0);
        st += tr->renderpos;
    }
    else
    {
        tr->render = NULL;
    }
    ret.height = MIN(font->h, rct.h);
    while (*st != '\0')
    {
        if (*st == '\n')
        {
            tr->render = text;
            tr->renderpos = st - String_get(text) + 1;
            ret.breakevent = GLTEXTRENDER_NEWLINE;
            return ret;
        }
        if (*st == '\r')
        {
            tr->render = text;
            tr->renderpos = st - String_get(text) + 1;
            ret.breakevent = GLTEXTRENDER_RETURN;
            return ret;
        }
        if ((tr->wlimit != 0) && (sizeChar(*st, font, tr->opt.monospace) > rct.w))
        {
            tr->render = text;
            tr->renderpos = st - String_get(text);
            ret.breakevent = GLTEXTRENDER_NEWLINE;
            return ret;
        }
        dw = drawChar(font, surf, rct, tr->opt.monospace, *st, 0, 0);
        ret.width += dw;
        rct.x += dw;
        rct.w -= dw;
        st++;
    }
    tr->render = NULL;
    ret.breakevent = GLTEXTRENDER_END;
    return ret;
}
示例#7
0
/*----------------------------------------------------------------------------*/
void
GlTextRender_guessSize(GlTextRender tr, String text, Gl2DSize* r_width, Gl2DSize* r_height)
{
    char* st = String_get(text);
    Uint16 x;
    Uint16 y;
    Uint16 ax;
    
    if (tr->font == NULL)
    {
        *r_width = 0;
        *r_height = 0;
        return;
    }
    
    *r_width = x = 0;
    y = tr->font->h;
    
    while (*st != '\0')
    {
        if (*st == '\n')
        {
            if (x > *r_width)
            {
                *r_width = x;
            }
            x = 0;
            y += tr->font->h;
        }
        else if (*st == '\r')
        {
            if (x > *r_width)
            {
                *r_width = x;
            }
            x = 0;
        }
        else
        {
            if (tr->opt.monospace)
            {
                ax = tr->font->w;
            }
            else
            {
                if (*st == 32)
                {
                    ax = tr->font->wspacing;
                }
                else
                {
                    ax = tr->font->wcrop[(unsigned char)*st];
                }
            }
            
            if ((tr->wlimit != 0) && (x + ax > tr->wlimit))
            {
                /*left limit reached*/
                if (x > *r_width)
                {
                    *r_width = x;
                }
                x = 0;
                y += tr->font->h;
                continue;
            }
            x += ax;
        }
        st++;
    }

    if (x > *r_width)
    {
        *r_width = x;
    }
    *r_height = y;
}
示例#8
0
/*----------------------------------------------------------------------------*/
static void
gltextAddFont(Var vfont)
{
    VarValidator varvalid;
    GlFont font;
    PtrArrayIterator it;
    
    varvalid = VarValidator_new();
    
    /*default values*/
    VarValidator_declareStringVar(varvalid, "font_name", "");
    VarValidator_declareStringVar(varvalid, "font_picture", "");
    VarValidator_declareIntVar(varvalid, "char_width", 1);
    VarValidator_declareIntVar(varvalid, "char_height", 1);
    VarValidator_declareIntVar(varvalid, "hor_spacing", 4);
    
    /*validate*/
    VarValidator_validate(varvalid, vfont);
    VarValidator_del(varvalid);

    /*we create the font*/
    font = (GlFont)MALLOC(sizeof(pv_GlFont));
    font->name = String_newByCopy(Var_getValueString(Var_getArrayElemByCName(vfont, "font_name")));

    shellPrintf(LEVEL_ERRORSTACK, "For font '%s'", String_get(font->name));
    
    font->surf = GlSurface_newFromFile(Var_getValueString(Var_getArrayElemByCName(vfont, "font_picture")));
    font->w = Var_getValueInt(Var_getArrayElemByCName(vfont, "char_width"));
    font->h = Var_getValueInt(Var_getArrayElemByCName(vfont, "char_height"));
    font->wspacing = Var_getValueInt(Var_getArrayElemByCName(vfont, "hor_spacing"));
    font->wcrop = MALLOC(sizeof(Gl2DSize) * 256);
    
    font->lastcolor = GlColor_NULL;
    
    /*some checks*/
    if ((GlSurface_getWidth(font->surf) != font->w * 16)
        || GlSurface_getHeight(font->surf) != font->h * 16)
    {
        shellPrintf(LEVEL_ERROR, "Sizes don't match. Font not added.");
        GlFont_del(font);
    }
    else
    {
        /*we crop for non-monospace drawing*/
        performAutoCrop(font);
        
        /*if the font already exists, we delete the old one*/
        it = PtrArray_findSorted(_fonts, font);
        if (it != NULL)
        {
            shellPrintf(LEVEL_ERROR, "Font already exists, will be replaced by the new one.");
            PtrArray_removeIt(_fonts, it);
        }
    
        /*and add the new one to the font set*/
        PtrArray_insertSorted(_fonts, font);
        
        /*correct the renderers that need this font*/
        for (it = PtrArray_START(_textrenders); it != PtrArray_STOP(_textrenders); it++)
        {
            if ((((GlTextRender)(*it))->fontname != NULL)
             && (String_cmp(&((GlTextRender)(*it))->fontname, &font->name) == 0))
            {
                ((GlTextRender)(*it))->font = font;
            }
        }
    }
    
    shellPopErrorStack();
}
char *SeqerWindow_getFilename(SeqerWindow_t window)
{
	return (char *)(String_get(window->document->filename));
}