Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3156 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Dec 11, 2004, 10:45:18 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk/gui: setting keys is really sexy now

Location:
orxonox/trunk/gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/gui/orxonox_gui.h

    r3147 r3156  
    11/*!
    22 \file orxonox_gui.h
    3  \brief Contains all Widgets and the Creation of the Gui
     3 \brief Creation of the Gui
    44*/
    55
  • orxonox/trunk/gui/orxonox_gui_gtk.cc

    r3154 r3156  
    102102    \brief Connect any signal to any given Sub-widget
    103103*/
    104 void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *))
    105 {
    106   g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
     104gulong Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *))
     105{
     106  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
    107107}
    108108
     
    110110   \brief Connect a signal with additionally passing the whole Object
    111111*/
    112 void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *))
    113 {
    114 g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
     112gulong Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *))
     113{
     114  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
    115115}
    116116
     
    118118   \brief Connect a signal with additionally passing a whole external Object
    119119*/
    120 void Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *))
    121 {
    122   g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
     120gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *))
     121{
     122  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
    123123}
    124124
     
    126126   \brief Connect a signal with additionally passing a whole external Object
    127127*/
    128 void Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *))
    129 {
    130   g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
     128gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *))
     129{
     130  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
     131}
     132
     133void Widget::disconnectSignal (gulong signalID)
     134{
     135  g_signal_handler_disconnect (G_OBJECT (this->widget), signalID);
    131136}
    132137
     
    374379{
    375380  static_cast<Window*>(window)->close();
    376  
    377 }
     381}
     382
    378383/**
    379384 * Quits the orxonox_GUI.
     
    852857   \brief Redraws the widget
    853858   Example: see void CheckButton::redraw ()
    854  */
     859*/
    855860void Menu::redraw ()
    856861{
    857862  gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value);
     863}
     864
     865OptionLabel::OptionLabel(char* text)
     866{
     867  init();
     868  setTitle(text);
     869}
     870
     871void OptionLabel::init(void)
     872{
     873  isOption = 4;
     874
     875  static_cast<Option*>(this)->init();
     876
     877  widget = gtk_label_new ("");
     878}
     879
     880void OptionLabel::setTitle(char* title)
     881{
     882  gtk_label_set_text (GTK_LABEL (widget), title);
     883}
     884
     885void OptionLabel::redraw(void)
     886{
     887 
    858888}
    859889
     
    862892   You migth consider adding Label::setTitle with this.
    863893*/
    864 Label:: Label ()
     894Label::Label ()
    865895{
    866896  this->init();
  • orxonox/trunk/gui/orxonox_gui_gtk.h

    r3153 r3156  
     1/*!
     2 \file orxonox_gui_gtk.h
     3 \brief Contains all th different Widgets.
     4*/
    15
    26#ifndef _ORXONOX_GUI_GTK_H
     
    3438  enum option { containerType = -2, boxType = -1, nothingType = 0, boolType = 1, intType = 2};
    3539  char* label; //!< The name of the Widget. Some do display it, Options need it to save;
    36   void connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *));
    37   void connectSignal (char* event, gint (*signal)(GtkWidget*, Widget *));
    38   void connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *));
    39   void connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *));
     40  gulong connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *));
     41  gulong connectSignal (char* event, gint (*signal)(GtkWidget*, Widget *));
     42  gulong connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *));
     43  gulong connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *));
     44  void disconnectSignal (gulong signalID);
    4045  void show ();
    4146  void hide ();
     
    178183  char* flag_name_short; //!< like flag_name but shorter
    179184  int default_value; //!< A default value is good, for hiding a option if it is not needed. (hidden if value == default_value)
    180   bool saveable;
     185  bool saveable;  //! Options can be Saved.
    181186
    182187  void setFlagName (char* flagname, int defaultvalue);
     
    252257};
    253258
     259//! A CharLabel is a simple Label, that holds a char*, and will be updated, if changed.
     260class OptionLabel : public Option
     261{
     262 public:
     263  OptionLabel(char* text);
     264  void init(void);
     265
     266  void setTitle(char* title);
     267  void redraw();
     268};
     269
    254270//! A label is a Widget, that displays a text
    255271class Label : public Widget
     
    264280};
    265281
     282
    266283//gint orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data);
    267284
  • orxonox/trunk/gui/orxonox_gui_keys.cc

    r3154 r3156  
    8080  openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen);
    8181
     82  inputWindow = new Window("inputWindow");
     83
     84  inputButton = new Button ("test");
     85  inputButton->connectSignal ("button_press_event", inputWindow, Window::windowClose);
     86  inputWindow->fill (inputButton);
     87  inputWindow->connectSignal("destroy", inputWindow, Window::windowClose);
     88  inputWindow->connectSignal("delete_event", inputWindow, Window::windowClose);
     89
    8290}
    8391
    8492Widget* Player::addKey (KEYS key, char* name)
    8593{
    86   pKeyBox[key] = new Box();
    87   pKeyLabel[key] = new Label (name);
    88   pKeyButton[key] = new Button(name);
    89   pKeyButton[key]->saveable = true;
     94  inputKey[key] = new InputKey;
     95  inputKey[key]->pKeyBox = new Box();
     96  inputKey[key]->pKeyButton = new Button(name);
     97  inputKey[key]->pKeyOLabel = new OptionLabel (name);
     98  inputKey[key]->pKeyOLabel->saveable = true;
    9099 
    91   pKeyButton[key]->connectSignal("key_press_event", pKeyButton[key], key_cb);
    92  
    93   pKeyBox[key]->fill(pKeyLabel[key]);
    94   pKeyBox[key]->fill(pKeyButton[key]);
    95   return pKeyBox[key];
     100  //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb);
     101  inputKey[key]->pKeyButton->connectSignal("button_press_event", inputKey[key], inputWindowEvent);
     102
     103  inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyButton);
     104  inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyOLabel);
     105  return inputKey[key]->pKeyBox;
    96106}
    97107
     
    105115{
    106116  cout << "setting up Key: "<< key <<endl;
     117}
     118
     119Window* Player::inputWindow = NULL;
     120Button* Player::inputButton = NULL;
     121long Player::keySignal = 0;
     122
     123gint Player::inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
     124{
     125  inputButton->setTitle("teste");
     126  keySignal = inputButton->connectSignal("key_press_event", inputKey, key_cb);
     127  inputWindow->open();
    107128}
    108129
     
    114135   \returns Nothing
    115136*/
    116 gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* widget)
    117 {
    118   Button* button = static_cast<Button*>(widget);
    119 
    120   switch(event->keyval) {
    121   case GDK_Up:
    122     printf("Up arrow key!\n");
    123     button->setTitle("up");
    124     break;
    125   case GDK_Down:
    126     printf("Down arrow key!\n");
    127     button->setTitle("down");
    128     break;
    129   case GDK_Left:
    130     printf("Left arrow key!\n");
    131     button->setTitle("left");
    132     break;
    133   case GDK_Right:
    134     printf("Right arrow key!\n");
    135     button->setTitle("right");
    136     break;
    137 
    138   case GDK_space:
    139     printf("Space Pressed.\n");
    140     button->setTitle("space");
    141     break;
    142 
    143   case 65293:
    144     printf("Enter Pressed\n");
    145     button->setTitle("enter");
    146     break;
    147 
    148     // Special Keys //
    149   case GDK_Shift_L:
    150     printf("Left Shift!\n");
    151     button->setTitle("l_shift");
    152     break;
    153   case GDK_Shift_R:
    154     printf("Right Shift!\n");
    155     button->setTitle("r_shift");
    156     break;
    157   case GDK_Control_L:
    158     printf("Left Control!\n");
    159     button->setTitle("l_ctrl");
    160     break;
    161   case GDK_Control_R:
    162     printf("Right Control!\n");
    163     button->setTitle("r_ctrl");
    164     break;
    165   case GDK_Alt_L:
    166     printf("Left Alt!\n");
    167     button->setTitle("l_alt");
    168     break;
    169   case GDK_Alt_R:
    170     printf("Rigth Alt!\n");
    171     button->setTitle("r_alt");
    172     break;
    173     // FXX KEYS //
    174   case GDK_F1:
    175     printf("F1!\n");
    176     button->setTitle("f1");
    177     break;
    178   case GDK_F2:
    179     printf("F2!\n");
    180     button->setTitle("f2");
    181     break;
    182   case GDK_F3:
    183     printf("F3!\n");
    184     button->setTitle("f3");
    185     break;
    186   case GDK_F4:
    187     printf("F4!\n");
    188     button->setTitle("f4");
    189     break;
    190   case GDK_F5:
    191     printf("F5!\n");
    192     button->setTitle("f5");
    193     break;
    194   case GDK_F6:
    195     printf("F6!\n");
    196     button->setTitle("f6");
    197     break;
    198   case GDK_F7:
    199     printf("F7!\n");
    200     button->setTitle("f7");
    201     break;
    202   case GDK_F8:
    203     printf("F8!\n");
    204     button->setTitle("f8");
    205     break;
    206   case GDK_F9:
    207     printf("F9\n");
    208     button->setTitle("f9");
    209     break;
    210   case GDK_F10:
    211     printf("F10!\n");
    212     button->setTitle("f10");
    213     break;
    214   case GDK_F11:
    215     printf("F11!\n");
    216     button->setTitle("f11");
    217     break;
    218   case GDK_F12:
    219     printf("F12!\n");
    220     button->setTitle("f12");
    221     break;
    222 
    223 
    224   default:
    225     char* tmp;
    226     sprintf(tmp, "%c", event->keyval);
    227     printf ("other key %s \n", tmp);
    228     button->setTitle(tmp);
    229     break;
    230   }
    231 }
     137gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
     138{
     139  InputKey* inputkey = (InputKey*) inputKey;
     140  char title [20];
     141
     142  switch(event->keyval)
     143    {
     144    case GDK_Up:
     145      printf("Up arrow key!\n");
     146      sprintf(title, "%s", "up");
     147      break;
     148    case GDK_Down:
     149      printf("Down arrow key!\n");
     150      sprintf(title, "%s", "down");
     151      break;
     152    case GDK_Left:
     153      printf("Left arrow key!\n");
     154      sprintf(title, "%s", "left");
     155      break;
     156    case GDK_Right:
     157      printf("Right arrow key!\n");
     158      sprintf(title, "%s", "right");
     159      break;
     160     
     161    case GDK_space:
     162      printf("Space Pressed.\n");
     163      sprintf(title, "%s", "space");
     164      break;
     165     
     166      /*  case GDK_escape:
     167          printf("Esc Pressed.\n");
     168          sprintf(title, "%s", "esc");
     169      */
     170    case 65293:
     171      printf("Enter Pressed\n");
     172      sprintf(title, "%s", "enter");
     173      break;
     174     
     175      // Special Keys //
     176    case GDK_Shift_L:
     177      printf("Left Shift!\n");
     178      sprintf(title, "%s", "l_shift");
     179      break;
     180    case GDK_Shift_R:
     181      printf("Right Shift!\n");
     182      sprintf(title, "%s", "r_shift");
     183      break;
     184    case GDK_Control_L:
     185      printf("Left Control!\n");
     186      sprintf(title, "%s", "l_ctrl");
     187      break;
     188    case GDK_Control_R:
     189      printf("Right Control!\n");
     190      sprintf(title, "%s", "r_ctrl");
     191      break;
     192    case GDK_Alt_L:
     193      printf("Left Alt!\n");
     194      sprintf(title, "%s", "l_alt");
     195      break;
     196    case GDK_Alt_R:
     197      printf("Rigth Alt!\n");
     198      sprintf(title, "%s", "r_alt");
     199      break;
     200      // FXX KEYS //
     201    case GDK_F1:
     202      printf("F1!\n");
     203      sprintf(title, "%s", "f1");
     204      break;
     205    case GDK_F2:
     206      printf("F2!\n");
     207      sprintf(title, "%s", "f2");
     208      break;
     209    case GDK_F3:
     210      printf("F3!\n");
     211      sprintf(title, "%s", "f3");
     212      break;
     213    case GDK_F4:
     214      printf("F4!\n");
     215      sprintf(title, "%s", "f4");
     216      break;
     217    case GDK_F5:
     218      printf("F5!\n");
     219      sprintf(title, "%s", "f5");
     220      break;
     221    case GDK_F6:
     222      printf("F6!\n");
     223      sprintf(title, "%s", "f6");
     224      break;
     225    case GDK_F7:
     226      printf("F7!\n");
     227      sprintf(title, "%s", "f7");
     228      break;
     229    case GDK_F8:
     230      printf("F8!\n");
     231      sprintf(title, "%s", "f8");
     232      break;
     233    case GDK_F9:
     234      printf("F9\n");
     235      sprintf(title, "%s", "f9");
     236      break;
     237    case GDK_F10:
     238      printf("F10!\n");
     239      sprintf(title, "%s", "f10");
     240      break;
     241    case GDK_F11:
     242      printf("F11!\n");
     243      sprintf(title, "%s", "f11");
     244      break;
     245    case GDK_F12:
     246      printf("F12!\n");
     247      sprintf(title, "%s", "f12");
     248      break;
     249     
     250     
     251    default:
     252      char* tmp;
     253      sprintf(tmp, "%c", event->keyval);
     254      printf ("other key %s \n", tmp);
     255      sprintf(title, "%s", tmp);
     256      break;
     257    }
     258  inputkey->pKeyOLabel->setTitle (title);
     259  inputButton->disconnectSignal(keySignal);
     260  inputWindow->close();
     261}
  • orxonox/trunk/gui/orxonox_gui_keys.h

    r3154 r3156  
    4343  Box* pKeysBox;
    4444 
    45   Box* pKeyBox[10];
    46   Button* pKeyButton[10];
    47   Label* pKeyLabel[10];
     45  struct InputKey
     46  {
     47    Box* pKeyBox;
     48    Button* pKeyButton;
     49    OptionLabel* pKeyOLabel;
     50  };
    4851
     52  InputKey* inputKey[10];
    4953
     54  static Window* inputWindow;
     55  static Button* inputButton;
     56  static long keySignal;
    5057 public:
    5158  Player(char* player);
     
    5562  Button* getOpenButton();
    5663
    57   static gint key_cb(GtkWidget* w, GdkEventKey* event, void* widget);
     64  static gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* widget);
     65  static gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey);
    5866  void setkey(KEYS key);
    5967 
Note: See TracChangeset for help on using the changeset viewer.