Browse Source

Preliminary version of GTRANS

remotes/origin_old/ugfx_release_2.6
Joel Bodenmann 6 years ago
parent
commit
7b60003461
  1. 2
      demos/modules/gtrans/basic/gfxconf.h
  2. 39
      demos/modules/gtrans/basic/main.c
  3. 10
      gfx.h
  4. 51
      src/gtrans/gtrans.c
  5. 10
      src/gtrans/gtrans.h

2
demos/modules/gtrans/basic/gfxconf.h

@ -42,7 +42,7 @@
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_ANTIALIAS TRUE
#define GDISP_NEED_ANTIALIAS FALSE
#define GDISP_INCLUDE_USER_FONTS FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE

39
demos/modules/gtrans/basic/main.c

@ -28,10 +28,47 @@
*/
#include "gfx.h"
static const char* EnglishStrings[] = {
"Welcome",
"The number %s has the value %d",
"Goodbye"
};
static const transTable EnglishTranslation = { sizeof(EnglishStrings)/sizeof(EnglishStrings[0]), EnglishStrings };
static const char* GermanStrings[] = {
"Herzlich Willkommen",
"Die Zahl %s hat den Wert %d",
"Auf Wiedersehen"
};
static const transTable GermanTranslation = { sizeof(GermanStrings)/sizeof(GermanStrings[0]), GermanStrings };
int main(void)
{
size_t i, j;
font_t font;
gfxInit();
gdispClear(Silver);
font = gdispOpenFont("*");
gtransSetBaseLanguage(&EnglishTranslation);
gtransSetLanguage(&GermanTranslation);
gtransSetLanguage(&EnglishTranslation);
i = 0;
for (j = 0; j < EnglishTranslation.numEntries; j++) {
gdispFillStringBox(20+300*i, 35*j, 300, 35, gtransIndex(j), font, Black, Silver, justifyLeft);
}
gtransSetLanguage(&GermanTranslation);
i = 1;
for (j = 0; j < EnglishTranslation.numEntries; j++) {
gdispFillStringBox(20+300*i, 35*j, 300, 35, gtransIndex(j), font, Black, Silver, justifyLeft);
}
gdispFillStringBox(20, 300, 300, 25, gtransString("Welcome"), font, Black, Silver, justifyLeft);
while (TRUE) {
gfxSleepMilliseconds(500);

10
gfx.h

@ -145,6 +145,13 @@
#ifndef GFX_USE_GFILE
#define GFX_USE_GFILE FALSE
#endif
/**
* @brief GFX Translation Support API
* @details Defaults to FALSE
*/
#ifndef GFX_USE_GTRANS
#define GFX_USE_GTRANS FALSE
#endif
/** @} */
/**
@ -155,6 +162,7 @@
#include "src/gdriver/gdriver_options.h"
#include "src/gfile/gfile_options.h"
#include "src/gmisc/gmisc_options.h"
#include "src/gtrans/gtrans_options.h"
#include "src/gqueue/gqueue_options.h"
#include "src/gevent/gevent_options.h"
#include "src/gtimer/gtimer_options.h"
@ -181,6 +189,7 @@
#include "src/gtimer/gtimer_rules.h"
#include "src/gqueue/gqueue_rules.h"
#include "src/gmisc/gmisc_rules.h"
#include "src/gtrans/gtrans_rules.h"
#include "src/gfile/gfile_rules.h"
#include "src/gdriver/gdriver_rules.h"
#include "src/gos/gos_rules.h"
@ -192,6 +201,7 @@
//#include "src/gdriver/gdriver.h" // This module is only included by source that needs it.
#include "src/gfile/gfile.h"
#include "src/gmisc/gmisc.h"
#include "src/gtrans/gtrans.h"
#include "src/gqueue/gqueue.h"
#include "src/gevent/gevent.h"
#include "src/gtimer/gtimer.h"

51
src/gtrans/gtrans.c

@ -5,16 +5,67 @@
* http://ugfx.org/license.html
*/
#include <string.h>
#include "../../gfx.h"
#if GFX_USE_GTRANS
static const transTable* _languageBase;
static const transTable* _languageCurrent;
void _gtransInit(void)
{
_languageBase = 0;
_languageCurrent = 0;
}
void _gtransDeinit(void)
{
}
const char* gtransString(const char* string)
{
size_t i = 0;
while (1) {
if (i >= _languageBase->numEntries-1) {
return 0;
}
if (strcmp(string, _languageBase->strings[i]) == 0) {
break;
}
i++;
}
if (i >= _languageCurrent->numEntries-1) {
return 0;
}
return _languageCurrent->strings[i];
}
const char* gtransIndex(unsigned index)
{
if (!_languageCurrent) {
return 0;
}
if (index >= _languageCurrent->numEntries) {
return 0;
}
return _languageCurrent->strings[index];
}
void gtransSetBaseLanguage(const transTable* const translation)
{
_languageBase = translation;
}
void gtransSetLanguage(const transTable* const translation)
{
_languageCurrent = translation;
}
#endif /* GFX_USE_GTRANS */

10
src/gtrans/gtrans.h

@ -22,11 +22,19 @@
#if GFX_USE_GTRANS || defined(__DOXYGEN__)
typedef struct transTable {
unsigned numEntries;
const char** strings;
} transTable;
#ifdef __cplusplus
extern "C" {
#endif
const char* gtransString(const char* string);
const char* gtransIndex(unsigned index);
void gtransSetBaseLanguage(const transTable* const translation);
void gtransSetLanguage(const transTable* const translation);
#ifdef __cplusplus
}

Loading…
Cancel
Save