applicat.cpp Spostata gestione evento E_FONT

config.cpp     Aggiunti metodi per convertire i colori
controls.cpp   Gestito meglio il font dell'interfaccia
window.cpp     Aggiunto metodo per cambiare il colore dello sfondo


git-svn-id: svn://10.65.10.50/trunk@3248 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-07-26 15:41:29 +00:00
parent e4884eb6f9
commit 4f621ab513
8 changed files with 133 additions and 78 deletions

View File

@ -178,16 +178,6 @@ long XVT_CALLCONV1 TApplication::task_eh(WINDOW win, EVENT *ep)
backdrop_eh(win, ep); backdrop_eh(win, ep);
break; break;
#endif #endif
case E_FONT:
{
XVT_FNTID new_font = ep->v.font.font_id;
char font_ser_desc[512];
TConfig font(CONFIG_USER, "Font");
xvt_font_serialize(new_font, font_ser_desc, sizeof(font_ser_desc));
font.set("FontDesc", font_ser_desc);
}
break;
default: default:
break; break;
} }
@ -251,6 +241,19 @@ long TApplication::handler(WINDOW win, EVENT* ep)
if (can_close()) if (can_close())
stop_run(); stop_run();
break; break;
case E_FONT:
{
XVT_FNTID new_font = ep->v.font.font_id;
char font_ser_desc[512];
TConfig font(CONFIG_USER, "Font");
xvt_font_serialize(new_font, font_ser_desc, sizeof(font_ser_desc));
font.set("FontDesc", font_ser_desc);
font.set_paragraph("Colors"); // Forza la scrittura del paragrafo
xvt_load_default_font();
}
break;
case E_QUIT: case E_QUIT:
if (ep->v.query) if (ep->v.query)
{ {

View File

@ -130,7 +130,7 @@ public:
TObject* get(); TObject* get();
// @cmember Ritorna l'oggetto e la relativa chiave // @cmember Ritorna l'oggetto e la relativa chiave
THash_object* get_hashobj(); THash_object* get_hashobj();
// @cmember Azzera il numero di righe e colonne della tabella hash // @cmember Azzera il numero di riga e colonna corrente della tabella hash
void restart() void restart()
{ _row = 0; _col = 0; } { _row = 0; _col = 0; }

View File

@ -337,6 +337,30 @@ HIDDEN void RGB_COLOR(COLOR c, int& r, int& g, int& b)
b = int(c) & 0xFF; b = int(c) & 0xFF;
} }
COLOR RGB2COLOR(unsigned char red, unsigned char green, unsigned char blue)
{
COLOR def = MAKE_COLOR(red, green, blue);
// Se nel colore non compare l'indice cerca di calcolarlo
const byte color_index = byte(def >> 12);
if (color_index < 0x1 || color_index > 0xF)
{
const COLOR native_color[11] = { COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_CYAN,
COLOR_MAGENTA, COLOR_YELLOW, COLOR_BLACK, COLOR_DKGRAY,
COLOR_GRAY, COLOR_LTGRAY, COLOR_WHITE };
for (int c = 0; c < 11; c++)
{
if (def == (native_color[c] & 0x00FFFFFF)) // Confronta solo la terna R,G,B
{
def = native_color[c];
break;
}
}
}
return def;
}
// @doc EXTERNAL // @doc EXTERNAL
// @mfunc Ritorna il valore del colore settato nella variabile nella // @mfunc Ritorna il valore del colore settato nella variabile nella
@ -358,36 +382,18 @@ COLOR TConfig::get_color(
if (*c) if (*c)
{ {
TToken_string s(c, ','); TToken_string s(c, ',');
const int r = s.get_int(); const byte r = (byte)s.get_int();
const int g = s.get_int(); const byte g = (byte)s.get_int();
const int b = s.get_int(); const byte b = (byte)s.get_int();
def = MAKE_COLOR(r, g, b); def = RGB2COLOR(r, g, b);
} }
else else
{ {
int r, g, b; RGB_COLOR(def, r, g, b); int r, g, b; RGB_COLOR(def, r, g, b);
TString16 d; d << r << ',' << g << ',' << b; TString16 d; d.format("%d,%d,%d", r, g, b);
set(var, d, section, TRUE, index); set(var, d, section, TRUE, index);
} }
// Se nel colore non compare l'indice cerca di calcolarlo
const byte color_index = byte(def >> 12);
if (color_index < 0x1 || color_index > 0xF)
{
const COLOR native_color[11] = { COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_CYAN,
COLOR_MAGENTA, COLOR_YELLOW, COLOR_BLACK, COLOR_DKGRAY,
COLOR_GRAY, COLOR_LTGRAY, COLOR_WHITE };
for (int c = 0; c < 11; c++)
{
if (def == (native_color[c] & 0x00FFFFFF)) // Confronta solo la terna R,G,B
{
def = native_color[c];
break;
}
}
}
return def; return def;
} }

View File

@ -143,4 +143,6 @@ public:
virtual ~TConfig(); virtual ~TConfig();
}; };
COLOR RGB2COLOR(unsigned char red, unsigned char green, unsigned char blue);
#endif #endif

View File

@ -84,6 +84,7 @@ public:
const TImage& image(short id) const { return (const TImage&)operator[](id); } const TImage& image(short id) const { return (const TImage&)operator[](id); }
bool exist(short id) const { return objptr(id) != NULL; } bool exist(short id) const { return objptr(id) != NULL; }
void reload();
TPicture_array() : TArray(128) {} TPicture_array() : TArray(128) {}
virtual ~TPicture_array() {} virtual ~TPicture_array() {}
@ -103,6 +104,19 @@ TImage& TPicture_array::add(short id)
return *i; return *i;
} }
void TPicture_array::reload()
{
for (int id = last(); id >= 0; id--)
{
TImage* i = (TImage*)objptr(id);
if (i)
{
i->load(id);
i->convert_transparent_color();
}
}
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Utility functions // Utility functions
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -152,6 +166,21 @@ XVT_FNTID xvt_default_font(bool bold)
return bold ? FAT_FONT : DEF_FONT; return bold ? FAT_FONT : DEF_FONT;
} }
XVT_FNTID xvt_load_default_font()
{
if (DEF_FONT)
{
xvt_font_destroy(DEF_FONT);
DEF_FONT = NULL;
}
if (FAT_FONT)
{
xvt_font_destroy(FAT_FONT);
FAT_FONT = NULL;
}
return xvt_default_font(FALSE);
}
static byte event_map[XIE_POST_NAVIGATION+1]; static byte event_map[XIE_POST_NAVIGATION+1];
enum event_action { a_ignore, a_xvt, a_xvt_post, a_obj, a_child, a_update, a_select, a_post, a_debug }; enum event_action { a_ignore, a_xvt, a_xvt_post, a_obj, a_child, a_update, a_select, a_post, a_debug };
@ -198,12 +227,12 @@ void customize_colors()
aga_set_pref(AGA_PREF_BTN_COLOR_DARK, BTN_DARK_COLOR); aga_set_pref(AGA_PREF_BTN_COLOR_DARK, BTN_DARK_COLOR);
if (_picture) if (_picture)
_picture->destroy(); _picture->reload();
} }
void init_controls() void init_controls()
{ {
xi_set_font_id(xvt_default_font()); xi_set_font_id(xvt_load_default_font());
xi_set_pref(XI_PREF_CARET_WIDTH, 2); xi_set_pref(XI_PREF_CARET_WIDTH, 2);
@ -328,6 +357,7 @@ WINDOW create_interface(WINDOW parent, short x, short y, short dx, short dy,
def->v.itf->automatic_back_color = FALSE; def->v.itf->automatic_back_color = FALSE;
def->v.itf->back_color = MASK_BACK_COLOR; def->v.itf->back_color = MASK_BACK_COLOR;
def->v.itf->font_id = xvt_default_font(FALSE);
def->v.itf->tab_on_enter = TRUE; def->v.itf->tab_on_enter = TRUE;
def->v.itf->win = win; def->v.itf->win = win;
@ -1354,6 +1384,7 @@ void TPushbutton_control::update()
else else
{ {
RCT& r = _obj->v.btn->rct; RCT& r = _obj->v.btn->rct;
xvt_dwin_set_font(win, xvt_default_font());
int ascent, descent; int ascent, descent;
xvt_dwin_get_font_metrics(win, NULL, &ascent, &descent); xvt_dwin_get_font_metrics(win, NULL, &ascent, &descent);

View File

@ -16,6 +16,7 @@ class TMask_field; // __MASKFLD_H
void init_controls(); void init_controls();
void free_controls(); void free_controls();
XVT_FNTID xvt_default_font(bool bold = FALSE); XVT_FNTID xvt_default_font(bool bold = FALSE);
XVT_FNTID xvt_load_default_font();
WINDOW create_interface(WINDOW parent, short x, short y, short dx, short dy, WINDOW create_interface(WINDOW parent, short x, short y, short dx, short dy,
const char* caption, TWindow* mask, bool tags); const char* caption, TWindow* mask, bool tags);

View File

@ -1,4 +1,8 @@
#define STRICT #define STRICT
#define XI_INTERNAL
#include <xi.h>
#define XVT_INCL_NATIVE #define XVT_INCL_NATIVE
#include <applicat.h> #include <applicat.h>
#include <checks.h> #include <checks.h>
@ -10,7 +14,6 @@
#include <colors.h> #include <colors.h>
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_NT #if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_NT
#define STRICT
#include <windows.h> #include <windows.h>
#endif #endif
@ -753,6 +756,14 @@ void TWindow::maximize() const
#endif #endif
} }
void TWindow::set_background_color(COLOR col)
{
XI_OBJ* itf = xi_get_itf(win());
itf->v.itf->back_color = col;
force_update();
}
// @doc EXTERNAL // @doc EXTERNAL
// @mfunc Attiva/disattiva la finestra // @mfunc Attiva/disattiva la finestra

View File

@ -259,7 +259,8 @@ public:
virtual bool stop_run(KEY key); virtual bool stop_run(KEY key);
// @cmember Forza ridisegno della finestra // @cmember Forza ridisegno della finestra
void force_update(); void force_update();
// @cmember Cambia il colore dello sfondo
void set_background_color(COLOR col);
// @cmember Mostra la finestra // @cmember Mostra la finestra
virtual void open(); virtual void open();
// @cmember Nasconde la finestra // @cmember Nasconde la finestra