Ejemplo n.º 1
0
void MSOptionMenu::showMenu(unsigned long eventTime_)
{
  if (optionMenu()!=0)
   {
     // If option menu has never been mapped, call calculateNaturalSize & placeMenuItems
     // to compute its size and positions of individual items.
     int w,h;
     if (optionMenu()->firstMap()==MSFalse)
       {
	 optionMenu()->calculateNaturalSize(w,h);
	 optionMenu()->placeMenuItems();
       }
     else
      {
        w=optionMenu()->width();
        h=optionMenu()->height();
      }
     int rootx,rooty,xx,yy;
     rootXY(rootx,rooty);
     yy=rooty+fieldValue()->y()-optionMenu()->menuItemYOffset(selectedItem());
     if (yy<0) yy=0;
     else if (yy+h>server()->height())
      {
	yy=server()->height()-h;
      }
     xx=rootx+fieldValue()->x()-optionMenu()->menuItemXOffset(selectedItem());
     if (xx<0) xx=0;
     else if (xx+w>server()->width())
      {
        xx=server()->width()-w;
      }
     optionMenu()->moveTo(xx,yy);
     optionMenu()->popup(MSTrue,eventTime_);  // Always warp the pointer
   }
}
Ejemplo n.º 2
0
void MSOptionPopupMenu::init(void)
{
  _lastShowTime=0;
  _threshold=500;
  foreground(optionMenu()->foreground());
  background(optionMenu()->background());
  font(optionMenu()->font());
}
Ejemplo n.º 3
0
void MSOptionMenu::optionsModel(MSStringVector& options_) 
{
  if (optionMenu()!=0) optionMenu()->model(options_);
  else
   {
     _optionMenu=new MSOptionPopupMenu(this,options_);
     optionMenu()->columns(columns());
   }
}
Ejemplo n.º 4
0
void MSOptionPopupMenu::update(const MSIndexVector& index_)
{
  if (MSView::model()!=0)
   {
     if (index_.length()==0)
      {
	if (optionsModel().length()==itemCount())
	 {
	   MSMenuItem *mi;
           int i,n=itemCount();
           for(i=0;i<n;i++)
	    {
	      mi=(MSMenuItem *)itemVector()(i);
	      mi->label(optionsModel()(i));
	    }
	   computeSize();
	   optionMenu()->setSelectedItem(0);
	   optionMenu()->computeSize();
	 }
	else rebuildMenu();
      }
     else 
      {
	MSIndexVector iv(index_);
	iv.sortUp();
	if (iv(0)==itemCount())
	 {
	   for (unsigned i=0,j=itemCount();i<iv.length();i++,j++)
	    {
	      MSMenuItem *pMenuItem=new MSMenuItem(this,optionsModel()(j),0,j);
	      setItem(pMenuItem,j);
	    }
	 }
	else
	 {
	   for (unsigned i=0;i<iv.length();i++)
	    {
	      unsigned index=iv(i);
	      MSMenuItem *mi=menuItem(index);
	      if (mi!=0) mi->label(optionsModel()(index));
	    }
	 }
      }
     computeSize();
     optionMenu()->computeSize();
   }
}
Ejemplo n.º 5
0
void MSOptionPopupMenu::rebuildMenu(void)
{
  removeAllItems();
  if (MSView::model()!=0)
   {
     unsigned n=optionsModel().length();
     if (n>0)
      {
	for (unsigned i=0;i<n;i++)
	 {
	   MSMenuItem *pMenuItem=new MSMenuItem(this,optionsModel()(i),0,i);
	   setItem(pMenuItem,i);
	 }
      }
   }
  computeSize();
  optionMenu()->setSelectedItem(0);
  optionMenu()->computeSize();
}
Ejemplo n.º 6
0
void MSOptionPopupMenu::popup(MSBoolean warp_,unsigned long eventTime_)
{
   if (warp_==MSTrue)
   {
      selectedItem(optionMenu()->selectedItem());
      MSMenuItem *item=menuItem(selectedItem());
      if (item!=0)
	 XWarpPointer(display(),None,window(),0,0,0,0,
		      item->x()+item->width()/2,item->y()+item->height()/2);
   }
   show();
   lastShowTime(eventTime_);
}
Ejemplo n.º 7
0
MapArea *
follow_map_menu(Buffer *buf, char *name, Anchor *a_img, int x, int y)
{
    MapList *ml;
    ListItem *al;
    int i, selected = -1;
    int initial = 0;
#ifdef MENU_MAP
    MapArea *a;
    char **label;
#endif

    ml = searchMapList(buf, name);
    if (ml == NULL || ml->area == NULL || ml->area->nitem == 0)
	return NULL;

#ifdef USE_IMAGE
    initial = searchMapArea(buf, ml, a_img);
    if (initial < 0)
	initial = 0;
    else if (!image_map_list) {
	selected = initial;
	goto map_end;
    }
#endif

#ifdef MENU_MAP
    label = New_N(char *, ml->area->nitem + 1);
    for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
	a = (MapArea *) al->ptr;
	if (a)
	    label[i] = *a->alt ? a->alt : a->url;
	else
	    label[i] = "";
    }
    label[ml->area->nitem] = NULL;

    optionMenu(x, y, label, &selected, initial, NULL);
#endif

#ifdef USE_IMAGE
  map_end:
#endif
    if (selected >= 0) {
	for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
	    if (al->ptr && i == selected)
		return (MapArea *) al->ptr;
	}
    }
    return NULL;
}
Ejemplo n.º 8
0
void MSOptionMenu::setSelectedItem(int item_)
{
  _selectedItem=item_;
  if(hasModel()==MSTrue)
   {
     if(optionMenu()!=0)
       {
	 _internalEvent=MSTrue;
	 if(_selectedItem<optionsModel().length())
	   {
	     viewModel()=optionsModel()(_selectedItem);
	   }
	 else viewModel().removeAll();
	 _internalEvent=MSFalse;
       }
   }
}
Ejemplo n.º 9
0
void MSOptionMenu::keyPress(const XEvent *pEvent_,KeySym keysym_,unsigned int state_,const char *)
{
  MSKeyPress keyPress(keysym_, state_);
  
  if (isProtected()==MSFalse&&optionMenu()!=0&& keyTranslate(keyPress)==MSFalse)
   {
     switch (keysym_)
      {
      case XK_Return:
      case XK_Up:      	
      case XK_Down:
	showMenu(pEvent_->xkey.time);
	break;
      default:
	break;
      }
   }
}
Ejemplo n.º 10
0
void MSOptionMenu::updateData(void)
{
  if(hasModel() == MSTrue && _internalEvent == MSFalse)
    {
      _internalEvent=MSTrue;
      unsigned index;

      if(optionMenu()==0)
	{
	  if(viewModel().length()!=0)
	    {
	      MSStringVector sv(viewModel());
	      options(sv);
	      _selectedItem=0;
	    }
	}
      else
	{
	  if(viewModel().length()!=0)
	    {
	      index = optionsModel().indexOf(viewModel());
	      
	      if(index == optionsModel().length())
		{
		  //append the new value to the list.
		  optionsModel().appendSingle(viewModel());
		}
	      _selectedItem=index;
	      drawFieldValue();
	    }
	  else
	    {
	      if(_selectedItem<optionsModel().length())
		{
		  viewModel()=optionsModel()(_selectedItem);
		}
	      else viewModel().removeAll();
	    }
	}
      _internalEvent=MSFalse;
    }
}
Ejemplo n.º 11
0
void MSOptionMenu::buttonRelease(const XEvent *)
{ if (optionMenu()!=0&&optionMenu()->mapped()==MSTrue) optionMenu()->grab(); }  
Ejemplo n.º 12
0
void MSOptionMenu::motionNotify(const XEvent *)
{ if (optionMenu()!=0&&optionMenu()->mapped()==MSTrue) optionMenu()->grab(); }
Ejemplo n.º 13
0
void MSOptionMenu::options(const MSStringVector& options_) 
{
  if (optionMenu()==0) _optionMenu=new MSOptionPopupMenu(this);
  optionMenu()->columns(columns());
  optionMenu()->options(options_);  
}
Ejemplo n.º 14
0
MSOptionMenu::~MSOptionMenu(void)
{ if (optionMenu()!=0) safeDestroy(optionMenu()); }
Ejemplo n.º 15
0
void MSOptionPopupMenu::activate(void)
{
  optionMenu()->activate(activeMenuItem()->tag());
  done();
}
Ejemplo n.º 16
0
/**
 *\fn int main(int argc, char *argv[])
 * Main
 *\param[in,out] argc argc
 *\param[in,out] argv argv
 */
int main(int argc, char *argv[])
{
    SDL_Surface *screen = NULL;

    int go = 1;
    int ret,ret1, ret2 = 0, ret3, ret4;

    char level_name[MAX_SIZE_FILE_NAME];
    char player_name[MAX_SIZE_FILE_NAME];
    int nb_lvl;
    /*sound*/
    Sound *sound_system;
    sound_system = createSound();

    /*keyboard config*/
    SDLKey kc[NB_KEY-1];

    /*input*/
    Input in;

    SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK);

    Player *current_player;

    current_player = (Player *)malloc(sizeof(Player));

    /*screen initialization*/
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);

    initInput(&in);

    /*configurations loading */
    loadSoundOptions("configuration/sound.conf",sound_system);


    SDL_WM_SetCaption("Super Martin", NULL); //window name

    SDL_ShowCursor(SDL_DISABLE); //delete the mouse

    while (go) //main loop
    {
        if(titleMenu(screen,&go,sound_system, &in))
        {

            while( (ret3 = menuPlayers(screen, player_name, &go, sound_system, &in)) != -1 && go)
            {
                switch(ret3)
                {
                    case -1:
                        break;
                    case 2  :
                        ret2 = newPlayer(screen, player_name, sound_system, &go);
                        if(ret2 == 1)
                        {
                            current_player->levelMax = 1;
                            current_player->nbCoins = 0;
                            current_player->nbLifes = 3;
                            current_player->nbProjectile = 5;
                            savePlayer("save/.save", player_name, current_player);
                            loadInputOptions("default",kc,&in);
                            saveInputOptions(player_name, kc, &in);
                        }
                        else
                            break;

                    case 1  :
                        loadPlayer("save/.save", player_name, current_player);
                        loadInputOptions(player_name,kc,&in);
                        while(go && (ret1 = mainMenu(screen,&go,sound_system, player_name, &in)) != -1)
                        {
                            switch(ret1)
                            {
                                case -1:
                                    break;
                                case 0:

                                    while( (ret4 = menuLevel(screen,level_name,sound_system, player_name, current_player, &go, &nb_lvl, &in)) != -1 && go)
                                    {
                                        while(play(screen,level_name,sound_system,&go,kc, &in, current_player, player_name, ret4+1, nb_lvl) && go);
                                    }
                                    break;

                                case 1 :
                                    save(screen, "save/.save", player_name, current_player, &go);
                                    loadPlayer("save/.save", player_name, current_player);
                                    break;

                                case 2 :
                                    while((ret = optionMenu(screen,&go,sound_system,kc, &in)) != -1 && go)
                                    {
                                        switch(ret)
                                        {
                                            case -1:
                                                break;
                                            case 0:
                                                soundOptions(screen,&go,sound_system, &in);
                                                break;
                                            case 1:
                                                keyBoardOptions(screen,&go,kc,&in,player_name);
                                                break;
                                            default:;
                                        }
                                    }
                                    break;

                                case 3 :
                                    deletePlayer(screen, "save/players", player_name);
                                    go = 0;
                                    break;

                                default: ;
                            }
                        }
                        go = 1;
                        break;

                    default : ;

                }
            }

        }

        SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,255,255,255)); //clear screen

        SDL_Flip(screen);
    }


    freeSound(sound_system);
    free((void*)current_player);
    freeInput(&in);
    SDL_Quit();

    return EXIT_SUCCESS;
}