Files correlati : ca1.exe Ricompilazione Demo : [ ] Commento : Evitato di uscire da programma di stampa anialitica dopo ogni stampa git-svn-id: svn://10.65.10.50/branches/R_10_00@22568 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			258 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			258 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <colmask.h>
 | 
						|
#include <config.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <diction.h>
 | 
						|
#include <treectrl.h>
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Utilities
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
inline int Y601(int r, int g, int b)
 | 
						|
{ return int(0.299*r + 0.587*g + 0.114*b); }
 | 
						|
 | 
						|
 | 
						|
COLOR RGB2COLOR(unsigned char red, unsigned char green, unsigned char blue)
 | 
						|
{
 | 
						|
  COLOR def = XVT_MAKE_COLOR(red, green, blue);
 | 
						|
  if (def == 0) def = COLOR_BLACK; // Per non confonderlo col colore 0, default per XI
 | 
						|
  return def;
 | 
						|
}
 | 
						|
 | 
						|
COLOR choose_color(COLOR col, WINDOW win)
 | 
						|
{ 
 | 
						|
  xvt_dm_post_color_sel(&col, win);
 | 
						|
  if (col == 0) col = COLOR_BLACK; // Per non confonderlo col colore 0, default per XI
 | 
						|
  return col;
 | 
						|
}
 | 
						|
 | 
						|
COLOR blend_colors(COLOR col1, COLOR col2, double perc)
 | 
						|
{
 | 
						|
  const unsigned int r1 = XVT_COLOR_GET_RED(col1);
 | 
						|
  const unsigned int g1 = XVT_COLOR_GET_GREEN(col1);
 | 
						|
  const unsigned int b1 = XVT_COLOR_GET_BLUE(col1);
 | 
						|
  const unsigned int r2 = XVT_COLOR_GET_RED(col2);
 | 
						|
  const unsigned int g2 = XVT_COLOR_GET_GREEN(col2);
 | 
						|
  const unsigned int b2 = XVT_COLOR_GET_BLUE(col2);
 | 
						|
  const double inv_perc = 1.0 - perc;
 | 
						|
	const byte r = byte(r1 * perc + r2*(inv_perc));
 | 
						|
	const byte g = byte(g1 * perc + g2*(inv_perc));
 | 
						|
	const byte b = byte(b1 * perc + b2*(inv_perc));
 | 
						|
	return RGB2COLOR(r, g, b);
 | 
						|
}
 | 
						|
 | 
						|
COLOR grayed_color(COLOR col)
 | 
						|
{
 | 
						|
  const int luma = Y601(XVT_COLOR_GET_RED(col), XVT_COLOR_GET_GREEN(col), XVT_COLOR_GET_BLUE(col));
 | 
						|
  return RGB2COLOR(luma, luma, luma);
 | 
						|
}
 | 
						|
 | 
						|
inline int rgb_clamp(double c)
 | 
						|
{
 | 
						|
  if (c <= 0) return 0;
 | 
						|
  if (c >= 255) return 255;
 | 
						|
  return int(c+0.5);
 | 
						|
}
 | 
						|
 | 
						|
// -1.0 = Black; 0.0 = Same Color; +1.0 = white
 | 
						|
COLOR modulate_color(COLOR col, double perc)
 | 
						|
{
 | 
						|
  int r = XVT_COLOR_GET_RED(col);
 | 
						|
  int g = XVT_COLOR_GET_GREEN(col);
 | 
						|
  int b = XVT_COLOR_GET_BLUE(col);
 | 
						|
  const int luma = rgb_clamp(Y601(r, g, b) + perc * 255);
 | 
						|
  if (luma >= 255) return COLOR_WHITE;
 | 
						|
  if (luma <= 0)   return COLOR_BLACK;
 | 
						|
 | 
						|
  r = rgb_clamp(r * (1+perc));
 | 
						|
  g = rgb_clamp(g * (1+perc));
 | 
						|
  b = rgb_clamp(b * (1+perc));
 | 
						|
  return RGB2COLOR(r, g, b);
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TColor_object_props
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TColor_object_props : public TObject
 | 
						|
{         
 | 
						|
  COLOR _back, _fore, _back_def, _fore_def;
 | 
						|
  
 | 
						|
public:   
 | 
						|
  void set_back(COLOR back) { _back = back; }
 | 
						|
  void set_fore(COLOR fore) { _fore = fore; }
 | 
						|
  void set(COLOR back, COLOR fore) { set_back(back); set_fore(fore); }
 | 
						|
 | 
						|
  void set_back_def(COLOR back) { _back_def = back; }
 | 
						|
  void set_fore_def(COLOR fore) { _fore_def = fore; }
 | 
						|
  void set_def(COLOR back, COLOR fore) { set_back_def(back); set_fore_def(fore); }
 | 
						|
  
 | 
						|
  COLOR get_back() const { return _back; }
 | 
						|
  COLOR get_fore() const { return _fore; }
 | 
						|
  COLOR get_back_def() const { return _back_def; }
 | 
						|
  COLOR get_fore_def() const { return _fore_def; }
 | 
						|
 | 
						|
  TColor_object_props(COLOR back, COLOR fore);
 | 
						|
};
 | 
						|
 | 
						|
TColor_object_props::TColor_object_props(COLOR back, COLOR fore) 
 | 
						|
                   : _back(back), _fore(fore), _back_def(back), _fore_def(fore)
 | 
						|
{ }
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TSelect_color_mask
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
bool TSelect_color_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case DLG_DELREC:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TProp_field& g = (TProp_field&)field(DLG_USER);
 | 
						|
      g.freeze(true);
 | 
						|
      TString name;
 | 
						|
      FOR_EACH_ASSOC_OBJECT(_color_defs, h, k, o)
 | 
						|
      {
 | 
						|
        const TColor_object_props& p = *(const TColor_object_props*)o;
 | 
						|
        name = k; name << "_Bg";
 | 
						|
        g.set_property(name, p.get_back_def());
 | 
						|
        name.rtrim(3); name << "_Fg";
 | 
						|
        g.set_property(name, p.get_fore_def());
 | 
						|
      }
 | 
						|
      g.freeze(false);
 | 
						|
      return false;
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case DLG_USER:
 | 
						|
    if (e == fe_init)
 | 
						|
    {
 | 
						|
      TProp_field& g = (TProp_field&)o;
 | 
						|
      g.freeze(true);
 | 
						|
      xvt_vobj_maximize(g.win().win());
 | 
						|
      g.freeze(false);
 | 
						|
    } else
 | 
						|
    if (e == fe_close)
 | 
						|
    {
 | 
						|
      TProp_field& g = (TProp_field&)o;
 | 
						|
      TString name;
 | 
						|
      FOR_EACH_ASSOC_OBJECT(_color_defs, h, k, o)
 | 
						|
      {
 | 
						|
        TColor_object_props& p = *(TColor_object_props*)o;
 | 
						|
        name = k; name << "_Bg";
 | 
						|
        p.set_back(g.get_color_property(name));
 | 
						|
        name.rtrim(3); name << "_Fg";
 | 
						|
        p.set_fore(g.get_color_property(name));
 | 
						|
      }
 | 
						|
      save();
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default: break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_color_mask::add_color(const char* key, const char* prompt, COLOR back, COLOR fore, COLOR def_back, COLOR def_fore)
 | 
						|
{
 | 
						|
  TString80 name = key;
 | 
						|
  if (name.find(' ')>=0)
 | 
						|
  {
 | 
						|
    CHECKS(FALSE, "Lamentati con Guy se la variabile viene rifiutata ", key);
 | 
						|
    name.strip_double_spaces();
 | 
						|
    name.replace(' ', '_');
 | 
						|
  }
 | 
						|
 | 
						|
  TProp_field& g = (TProp_field&)field(DLG_USER);
 | 
						|
 | 
						|
  TColor_object_props* p = (TColor_object_props*)_color_defs.objptr(name);
 | 
						|
  if (p == NULL)
 | 
						|
  {
 | 
						|
    p = new TColor_object_props(def_back, def_fore);
 | 
						|
    _color_defs.add(name, p, true);
 | 
						|
  
 | 
						|
    g.set_property(name, (char*)NULL, prompt); // Categoria
 | 
						|
  }
 | 
						|
  else
 | 
						|
    p->set_def(back, fore);
 | 
						|
  p->set(back, fore);
 | 
						|
 | 
						|
  name << "_Bg";
 | 
						|
  g.set_property(name, back, TR("Sfondo"));  // Sfondo
 | 
						|
  name.rtrim(3); name << "_Fg";
 | 
						|
  g.set_property(name, fore, TR("Testo"));   // Testo
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_color_mask::add_color_def(const char* key, const char* prompt, COLOR def_back, COLOR def_fore)
 | 
						|
{
 | 
						|
  COLOR back = def_back;
 | 
						|
  COLOR fore = def_fore;
 | 
						|
 | 
						|
  TConfig conf(CONFIG_GUI, _paragraph);      // Ha una possibile personalizzazione?
 | 
						|
  conf.write_protect();
 | 
						|
  if (!conf.new_paragraph())
 | 
						|
  {
 | 
						|
    TString80 name = key;
 | 
						|
    fore = conf.get_color(name, NULL, -1, def_fore);
 | 
						|
	  name << "_Bg";
 | 
						|
    back = conf.get_color(name, NULL, -1, def_back);
 | 
						|
  }
 | 
						|
 | 
						|
  add_color(key, prompt, back, fore, def_back, def_fore);
 | 
						|
}   
 | 
						|
 | 
						|
bool TSelect_color_mask::get_color(const char* key, COLOR & back, COLOR & fore) const 
 | 
						|
{          
 | 
						|
  const TColor_object_props* p = (const TColor_object_props*)_color_defs.objptr(key);
 | 
						|
  if (p != NULL)
 | 
						|
  {
 | 
						|
    back = p->get_back();
 | 
						|
    fore = p->get_fore();
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    back = NORMAL_BACK_COLOR;
 | 
						|
    fore = NORMAL_COLOR;
 | 
						|
  }
 | 
						|
  return p != NULL;
 | 
						|
} 
 | 
						|
 | 
						|
void TSelect_color_mask::init(const char* mask_name, const char* para) 
 | 
						|
{              
 | 
						|
  const TFilename fn(mask_name);
 | 
						|
  _paragraph << fn.name_only();
 | 
						|
  if (para && *para)
 | 
						|
    _paragraph << '_' << para;
 | 
						|
  _paragraph.lower();
 | 
						|
}
 | 
						|
 | 
						|
void TSelect_color_mask::save() const
 | 
						|
{              
 | 
						|
  TConfig conf(CONFIG_GUI, _paragraph);
 | 
						|
  TString tmp;
 | 
						|
 | 
						|
  TAssoc_array& ass = (TAssoc_array&)_color_defs; // Fool const
 | 
						|
  FOR_EACH_ASSOC_OBJECT(ass, h, k, o)
 | 
						|
  {
 | 
						|
    const TColor_object_props& p = *(const TColor_object_props*)o;
 | 
						|
    
 | 
						|
    tmp = k; // tmp = p.get_key(); 
 | 
						|
    if (same_color(p.get_fore(), p.get_fore_def()))
 | 
						|
      conf.remove(tmp);
 | 
						|
    else
 | 
						|
      conf.set_color(tmp, p.get_fore());
 | 
						|
 | 
						|
    tmp << "_Bg";
 | 
						|
    if (same_color(p.get_back(), p.get_back_def()))
 | 
						|
      conf.remove(tmp);
 | 
						|
    else
 | 
						|
      conf.set_color(tmp, p.get_back());
 | 
						|
  }
 | 
						|
}              
 | 
						|
 | 
						|
TSelect_color_mask::TSelect_color_mask(const char* mask_name, const char* para) 
 | 
						|
                  : TAutomask("bagn007")
 | 
						|
{              
 | 
						|
  init(mask_name, para);
 | 
						|
}
 |