mapselector.cc
author hegyi
Wed, 25 Oct 2006 13:21:24 +0000
changeset 172 fc1e478697d3
parent 122 96bfa82264c3
child 174 95872af46fc4
permissions -rw-r--r--
Currently visualized map can be saved and loaded from file.
hegyi@112
     1
#include "mapselector.h"
hegyi@112
     2
hegyi@114
     3
MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false)
hegyi@112
     4
{
hegyi@112
     5
  update_list(ml);
hegyi@112
     6
hegyi@112
     7
  if(act=="")
hegyi@112
     8
    {
hegyi@112
     9
      cbt.set_active(0);
hegyi@112
    10
      default_state=true;
hegyi@112
    11
    }
hegyi@112
    12
  else
hegyi@112
    13
    {
hegyi@112
    14
      cbt.set_active_text((Glib::ustring)act);
hegyi@112
    15
      default_state=false;
hegyi@112
    16
    }
hegyi@112
    17
hegyi@112
    18
  //binding signal to the actual entry
hegyi@112
    19
  cbt.signal_changed().connect
hegyi@112
    20
    (
hegyi@112
    21
     sigc::mem_fun((*this), &MapSelector::comboChanged),
hegyi@112
    22
     false
hegyi@112
    23
     );
hegyi@112
    24
  
hegyi@114
    25
  label=new Gtk::Label(labeltext);
hegyi@112
    26
hegyi@112
    27
  label->set_width_chars(longest_property_string_length);
hegyi@112
    28
hegyi@122
    29
  defbut=NULL;
hegyi@122
    30
  if(def)
hegyi@122
    31
    {
hegyi@122
    32
      defbut=new Gtk::Button();
hegyi@122
    33
      defbut->set_label("Reset");
hegyi@122
    34
      
hegyi@122
    35
      defbut->signal_pressed().connect
hegyi@122
    36
	(
hegyi@122
    37
	 sigc::mem_fun(*this, &MapSelector::reset)
hegyi@122
    38
	 );
hegyi@122
    39
    }
hegyi@112
    40
hegyi@112
    41
  newbut=new Gtk::Button(Gtk::Stock::NEW);
hegyi@112
    42
hegyi@112
    43
  newbut->signal_pressed().connect
hegyi@112
    44
    (
hegyi@112
    45
     sigc::mem_fun(*this, &MapSelector::new_but_pressed)
hegyi@112
    46
     );
hegyi@112
    47
hegyi@112
    48
  add(*label);
hegyi@112
    49
hegyi@112
    50
  add(cbt);
hegyi@112
    51
hegyi@122
    52
  if(def)
hegyi@122
    53
    {
hegyi@122
    54
      add(*defbut);
hegyi@122
    55
    }
hegyi@122
    56
hegyi@112
    57
  add(*newbut);
hegyi@112
    58
}
hegyi@112
    59
hegyi@112
    60
void MapSelector::new_but_pressed()
hegyi@112
    61
{
hegyi@112
    62
  set_new_map=true;
hegyi@112
    63
  signal_newmapwin.emit(itisedge);
hegyi@112
    64
}
hegyi@112
    65
hegyi@112
    66
void MapSelector::update_list( std::vector< std::string > ml )
hegyi@112
    67
{
hegyi@112
    68
  int prev_act=cbt.get_active_row_number();
hegyi@112
    69
  cbt.clear();
hegyi@172
    70
  cbt_content.clear();
hegyi@112
    71
  std::vector< std::string >::iterator emsi=ml.begin();
hegyi@112
    72
  for(;emsi!=ml.end();emsi++)
hegyi@112
    73
    {
hegyi@112
    74
      cbt.append_text(*emsi);
hegyi@172
    75
      cbt_content.push_back(*emsi);
hegyi@112
    76
    }
hegyi@114
    77
  if(def)
hegyi@114
    78
    {
hegyi@114
    79
      cbt.prepend_text("Default values");
hegyi@172
    80
      cbt_content.push_back("Default values");
hegyi@114
    81
    }
hegyi@112
    82
  if(prev_act!=-1)
hegyi@112
    83
    {
hegyi@112
    84
      cbt.set_active(prev_act);
hegyi@112
    85
    }
hegyi@112
    86
}
hegyi@112
    87
hegyi@112
    88
void MapSelector::comboChanged()
hegyi@112
    89
{
hegyi@122
    90
  if(cbt.get_active_row_number()!=0 || !def)
hegyi@112
    91
    {
hegyi@112
    92
      default_state=false;
hegyi@112
    93
      Glib::ustring mapname = cbt.get_active_text();
hegyi@112
    94
      if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@112
    95
	{
hegyi@112
    96
	  signal_cbt.emit(mapname);
hegyi@112
    97
	}
hegyi@112
    98
    }
hegyi@112
    99
  else if((!default_state)&&(cbt.get_active_row_number()==0))
hegyi@112
   100
    {
hegyi@112
   101
      reset();
hegyi@112
   102
    }
hegyi@112
   103
}
hegyi@112
   104
hegyi@112
   105
void MapSelector::reset()
hegyi@112
   106
{
hegyi@112
   107
  default_state=true;
hegyi@112
   108
hegyi@112
   109
  cbt.set_active(0);
hegyi@112
   110
hegyi@112
   111
  signal_cbt.emit("");
hegyi@112
   112
}
hegyi@112
   113
hegyi@112
   114
hegyi@112
   115
Glib::ustring MapSelector::get_active_text()
hegyi@112
   116
{
hegyi@112
   117
  return cbt.get_active_text();
hegyi@112
   118
}
hegyi@112
   119
hegyi@112
   120
void MapSelector::set_active_text(Glib::ustring text)
hegyi@112
   121
{
hegyi@172
   122
  if(text.compare(""))
hegyi@172
   123
    {
hegyi@172
   124
      cbt.set_active_text(text);
hegyi@172
   125
    }
hegyi@172
   126
  else
hegyi@172
   127
    { 
hegyi@172
   128
      cbt.set_active_text("Default values");
hegyi@172
   129
    }
hegyi@112
   130
}
hegyi@112
   131
hegyi@112
   132
void MapSelector::append_text(Glib::ustring text)
hegyi@112
   133
{
hegyi@112
   134
  cbt.append_text(text);
hegyi@172
   135
  cbt_content.push_back(text);
hegyi@172
   136
hegyi@112
   137
  if(set_new_map)
hegyi@112
   138
    {
hegyi@112
   139
      set_active_text(text);
hegyi@112
   140
      set_new_map=false;
hegyi@112
   141
    }
hegyi@112
   142
}
hegyi@112
   143
hegyi@112
   144
sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
hegyi@112
   145
{
hegyi@112
   146
  return signal_cbt;
hegyi@112
   147
}
hegyi@112
   148
hegyi@112
   149
sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
hegyi@112
   150
{
hegyi@112
   151
  return signal_newmapwin;
hegyi@112
   152
}