Пример #1
0
Sint32 LunaFontSprite::DrawCharaRotateXYZ(LFONTSPRITE lFontSpr, const char *pStr,
                    CLunaRect *pDst, Float Pz, D3DCOLOR Color,
                    Sint32 AngleX, Sint32 AngleY, Sint32 AngleZ)
{
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        int ch = PL_Text_ReadChar(&pStr, g_lunaUseCharSet);
        if (ch != 0) {
            unsigned int index = s_CharToIndex(fontspr, ch);
            if (index < fontspr->charMax) {
                const LFDCharEntry *entry = &fontspr->lfdCharEntries[index];
                if (entry->sheetNo >= 0 && entry->sheetNo < fontspr->sheetCount) {
                    CLunaRect src;
                    float w = F(entry->x2 - entry->x1);
                    float h = F(entry->y2 - entry->y1);
                    src.Px = F(entry->x1); src.Py = F(entry->y1);
                    src.Sx = w; src.Sy = h;
                    
                    LunaSprite::DrawSquareRotateXYZ(
                        fontspr->sheetSprites[entry->sheetNo],
                        pDst, Pz, &src, Color,
                        AngleX, AngleY, AngleZ, 1);
                }
            }
        }
    }
    
    return 0;
}
int PL_Texture_BlitSurface(int textureRefID, SDL_Surface *surface, const SDL_Rect *rect) {
    TextureRef *textureref = (TextureRef*)PL_Handle_GetData(textureRefID, DXHANDLE_TEXTURE);
    SDL_Texture *texture;
    if (textureref == NULL || textureref->texture == NULL) {
        return -1;
    }
    
    texture = textureref->texture;
    
    /* Convert to target format if different. */
    if (textureref->format != surface->format->format) {
        SDL_Surface *tempSurface = SDL_ConvertSurfaceFormat(surface, textureref->format, 0);
        if (SDL_MUSTLOCK(tempSurface)) {
            SDL_LockSurface(tempSurface);
            SDL_UpdateTexture(texture, rect, tempSurface->pixels, tempSurface->pitch);
            SDL_UnlockSurface(tempSurface);
        } else {
            SDL_UpdateTexture(texture, rect, tempSurface->pixels, tempSurface->pitch);
        }
        SDL_FreeSurface(tempSurface);
    } else {
        if (SDL_MUSTLOCK(surface)) {
            SDL_LockSurface(surface);
            SDL_UpdateTexture(texture, rect, surface->pixels, surface->pitch);
            SDL_UnlockSurface(surface);
        } else {
            SDL_UpdateTexture(texture, rect, surface->pixels, surface->pitch);
        }
    }
    
    return 0;
}
Пример #3
0
int Dx_FileRead_eof(int fileHandle) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        return (SDL_RWsize(rwops) == SDL_RWtell(rwops)) ? DXTRUE : DXFALSE;
    }
    return DXFALSE;
}
Пример #4
0
int Dx_FileRead_read(void *data, int size, int fileHandle) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        return (int)SDL_RWread(rwops, data, (size_t)size, 1) * size;
    }
    return 0;
}
Пример #5
0
int64_t Dx_FileRead_tell(int fileHandle) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        return SDL_RWtell(rwops);
    }
    return 0;
}
Пример #6
0
void LunaFontSprite::GetHeight(LFONTSPRITE lFontSpr, Sint32 *pHeight)
{
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        *pHeight = fontspr->lfdHeader->fontSize;
    } else {
        *pHeight = -1;
    }
}
Пример #7
0
void LunaFontSprite::Rendering(LFONTSPRITE lFontSpr) {
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        int i;
        for (i = 0; i < fontspr->sheetCount; ++i) {
            LunaSprite::Rendering(fontspr->sheetSprites[i]);
        }
    }
}
int PL_Texture_AddRef(int textureID) {
    TextureRef *textureref = (TextureRef*)PL_Handle_GetData(textureID, DXHANDLE_TEXTURE);
    if (textureref == NULL) {
        return -1;
    }
    
    textureref->refCount += 1;
    return 0;
}
int PL_Texture_RenderGetGraphTexture(int graphID, SDL_Texture **texture, SDL_Rect *rect) {
    int textureRefID = PL_Graph_GetTextureID(graphID, rect);
    TextureRef *textureref = (TextureRef*)PL_Handle_GetData(textureRefID, DXHANDLE_TEXTURE);
    
    if (textureref == NULL) {
        return -1;
    }
    *texture = textureref->texture;
    
    return 0;
}
Пример #10
0
void LunaFontSprite::ResetBuffer(LFONTSPRITE lFontSpr, Sint32 Space) {
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        int i;
        for (i = 0; i < fontspr->sheetCount; ++i) {
            LunaSprite::ResetBuffer(fontspr->sheetSprites[i]);
        }
        
        fontspr->space = Space;
    }
}
Пример #11
0
int Dx_FileRead_close(int fileHandle) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        SDL_RWclose(rwops);
        
        PL_Handle_ReleaseID(fileHandle, DXTRUE);
        
        return 0;
    }
    return -1;
}
Пример #12
0
void LunaFontSprite::DrawString(LFONTSPRITE lFontSpr, const char *pStr,
                          Sint32 Px, Sint32 Py, Float Pz, D3DCOLOR Color) {
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        unsigned int ch;
        unsigned int charMax = fontspr->charMax;
        float x = F(Px);
        float y = F(Py);
        float z = F(Pz);
        float fontSize = F(fontspr->lfdHeader->fontSize);
        float spacing = F(fontSize + fontspr->space);
        int sheetCount = fontspr->sheetCount;
        int charset = g_lunaUseCharSet;
        while ((ch = PL_Text_ReadChar(&pStr, charset)) != 0) {
            if (ch == '\n' || ch == '\r') {
                x = F(Px);
                y += fontSize;
            } else if (ch == '\t') {
                x += spacing * 4;
            } else if (ch == '\b') {
                x -= spacing;
            } else if (ch == ' ') {
                x += spacing * 0.5f;
            } else {
                unsigned int index = s_CharToIndex(fontspr, ch);
                if (index < charMax) {
                    const LFDCharEntry *entry = &fontspr->lfdCharEntries[index];
                    if (entry->sheetNo >= 0 && entry->sheetNo < sheetCount) {
                        CLunaRect dst, src;
                        float w = F(entry->x2 - entry->x1);
                        float h = F(entry->y2 - entry->y1);
                        dst.Px = x + F(entry->xOffset); dst.Py = y;
                        dst.Sx = w; dst.Sy = h;
                        src.Px = F(entry->x1); src.Py = F(entry->y1);
                        src.Sx = w; src.Sy = h;
                    
                        LunaSprite::DrawSquare(
                            fontspr->sheetSprites[entry->sheetNo],
                            &dst, z, &src, Color, 1);
                        
                        if (ch < 0xff) {
                            x += spacing * 0.5f;
                        } else {
                            x += spacing;
                        }
                    } else {
                        x += fontspr->space;
                    }
                }
            }
        }
    }
}
Пример #13
0
int Dx_FileRead_seek(int fileHandle, int64_t position, int origin) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        switch(origin) {
            case 0: SDL_RWseek(rwops, position, RW_SEEK_SET); break;
            case 1: SDL_RWseek(rwops, position, RW_SEEK_CUR); break;
            case 2: SDL_RWseek(rwops, position, RW_SEEK_END); break;
        }
    }
    return 0;
}
Пример #14
0
wchar_t Dx_FileRead_getcW(int fileHandle) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        wchar_t ch;
        if (SDL_RWread(rwops, &ch, sizeof(wchar_t), 1) < 1) {
            return (wchar_t)-1;
        }
        
        return (wchar_t)ch;
    }
    return (wchar_t)-1;
}
Пример #15
0
int PL_Texture_Release(int textureID) {
    TextureRef *textureref = (TextureRef*)PL_Handle_GetData(textureID, DXHANDLE_TEXTURE);
    if (textureref == NULL) {
        return -1;
    }
    
    textureref->refCount -= 1;
    if (textureref->refCount <= 0) {
        SDL_DestroyTexture(textureref->texture);
        PL_Handle_ReleaseID(textureID, DXTRUE);
    }
    return 0;
}
Пример #16
0
POINT LunaFontSprite::GetStringLastPos(LFONTSPRITE lFontSpr, const char *pStr, Sint32 Px, Sint32 Py)
{
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    POINT p;
    p.x = Px;
    p.y = Py;
    
    if (fontspr != NULL) {
        unsigned int ch;
        unsigned int charMax = fontspr->charMax;
        float x = F(Px);
        float y = F(Py);
        float fontSize = F(fontspr->lfdHeader->fontSize);
        float spacing = F(fontSize + fontspr->space);
        int sheetCount = fontspr->sheetCount;
        int charset = g_lunaUseCharSet;
        while ((ch = PL_Text_ReadChar(&pStr, charset)) != 0) {
            if (ch == '\n' || ch == '\r') {
                x = F(Px);
                y += fontSize;
            } else if (ch == '\t') {
                x += spacing * 4;
            } else if (ch == '\b') {
                x -= spacing;
            } else if (ch == ' ') {
                x += spacing * 0.5f;
            } else {
                unsigned int index = s_CharToIndex(fontspr, ch);
                if (index < charMax) {
                    const LFDCharEntry *entry = &fontspr->lfdCharEntries[index];
                    if (entry->sheetNo >= 0 && entry->sheetNo < sheetCount) {
                        if (ch < 0xff) {
                            x += spacing * 0.5f;
                        } else {
                            x += spacing;
                        }
                    } else {
                        x += fontSize * 0.5f;
                    }
                }
            }
        }
        
        p.x = (int)x;
        p.y = (int)y;
    }
    
    return p;
}
Пример #17
0
Sint32 LunaFontSprite::EXTGetCharaRect(LFONTSPRITE lFontSpr, const char *pStr,
    Sint32 *x1, Sint32 *y1, Sint32 *x2, Sint32 *y2, Sint32 *advance, Sint32 *xOffset)
{
    // barf
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr == NULL) {
        return 0;
    }
    
    int ch = PL_Text_ReadChar(&pStr, g_lunaUseCharSet);
    if (ch == 0) {
        return 0;
    }
    
    unsigned int index = s_CharToIndex(fontspr, ch);
    if (index >= fontspr->charMax) {
        return 0;
    }
    
    const LFDCharEntry *entry = &fontspr->lfdCharEntries[index];
    if (x1 != 0) {
        *x1 = entry->x1;
    }
    if (y1 != 0) {
        *y1 = entry->y1;
    }
    if (x2 != 0) {
        *x2 = entry->x2;
    }
    if (y2 != 0) {
        *y2 = entry->y2;
    }
    if (advance != 0) {
        *advance = entry->pAdvance;
    }
    if (xOffset != 0) {
        *xOffset = entry->xOffset;
    }
    
    if (ch < 256 || (ch >= 0xff00 && ch < 0xffff)) {
        return 1; // Half-width
    }
    return 2; // Full-width
}
Пример #18
0
static int Dx_FileRead_getWholeChar(int fileHandle) {
    FileHandle *handle = (FileHandle *)PL_Handle_GetData(fileHandle, DXHANDLE_FILE);
    if (handle != NULL) {
        SDL_RWops *rwops = handle->rwops;
        char buffer[8];
        const char *reader = buffer;
        int pos = 0;
        
        do {
            if (SDL_RWread(rwops, buffer + pos, sizeof(char), 1) < 1) {
                return -1;
            }
            pos += 1;
        } while (pos < 7 && PL_Text_IsIncompleteMultibyte(buffer, pos, s_fileUseCharset));
        buffer[pos] = '\0';
        
        return PL_Text_ReadChar(&reader, s_fileUseCharset);
    }
    return -1;
}
Пример #19
0
void LunaFontSprite::Release(LFONTSPRITE lFontSpr) {
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        int i;
        if (fontspr->sheetGraphs != NULL) {
            for (i = 0; i < fontspr->sheetCount; ++i) {
                PLG.Texture_Release(fontspr->sheetGraphs[i]);
            }
            DXFREE(fontspr->sheetGraphs);
        }
        if (fontspr->sheetSprites != NULL) {
            for (i = 0; i < fontspr->sheetCount; ++i) {
                LunaSprite::Release(fontspr->sheetSprites[i]);
            }
            DXFREE(fontspr->sheetSprites);
        }
        DXFREE(fontspr->lfdData);
        
        PL_Handle_ReleaseID(lFontSpr, DXTRUE);
    }
}
Пример #20
0
Bool LunaFontSprite::GetWidth(LFONTSPRITE lFontSpr, const char *pStr,
                         Sint32 *pLeft, Sint32 *pCenter, Sint32 *pRight) {
    LunaFontSprData *fontspr = (LunaFontSprData *)PL_Handle_GetData((int)lFontSpr, DXHANDLE_LUNAFONTSPRITE);
    if (fontspr != NULL) {
        int ch = PL_Text_ReadChar(&pStr, g_lunaUseCharSet);
        if (ch != 0) {
            unsigned int index = s_CharToIndex(fontspr, ch);
            if (index < fontspr->charMax) {
                const LFDCharEntry *entry = &fontspr->lfdCharEntries[index];
                if (pLeft != NULL) {
                    *pLeft = entry->xOffset;
                }
                if (pCenter != NULL) {
                    *pCenter = entry->pAdvance;
                }
                if (pRight != NULL) {
                    *pRight = entry->unused;
                }
                return true;
            }
        }
    }
    return false;
}
Пример #21
0
static Graph *s_GetGraph(int graphID) {
    return (Graph *)PL_Handle_GetData(graphID, DXHANDLE_GRAPH);
}