Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 5:43 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Jul 06, 2012 9:16 pm 
Offline

Joined: Thu Aug 11, 2011 7:24 pm
Posts: 17
Hi all,

I have a toolbox for a map editor with cursors inside (hand, pencil ...). They are placed like a grid in a DialogLayout.

But when I call getWidgetAt method, it always returns the DialogLayout, and not the cursors.


This is my code :
Code:
      pointeurs = new ArrayList<ArrayList<PointeurGUI>>();
      pointeurs.add(new ArrayList<PointeurGUI>());
      pointeurs.get(0).add(new PointeurGUI(new Image("data/main.png"), Pointeur.MAIN));
      pointeurs.get(0).add(new PointeurGUI(new Image("data/plus.png"), Pointeur.PLUS));

          DialogLayout pointeursLayout = new DialogLayout();
          pointeursLayout.setTheme("/dialoglayout");
          int x = 0, y = 0;
           for(int i =0; i < pointeurs.size(); i++)
           {
              x = 0;
              for(int j = 0; j < pointeurs.get(i).size(); j++)
              {
                   pointeurs.get(i).get(j).adjustSize();
                   pointeurs.get(i).get(j).setPosition(x, y);
                   x += pointeurs.get(i).get(j).getImg().getWidth() + 15;
                   pointeursLayout.add(pointeurs.get(i).get(j));
               }
               y += 30;
           }
           this.add(pointeursLayout);

   @Override
    protected boolean handleEvent(Event evt)
   {
      Widget w = getWidgetAt(evt.getMouseX(), evt.getMouseY());

      if(w instanceof PointeurGUI)
      {
         over = (PointeurGUI) w;
         over.setSelected(true);
         System.out.println("Pointeur selectionné : "+over.getPointeur());
      }
      else
      {
         over = null;
      }

      
      return super.handleEvent(evt);
   }

class PointeurGUI extends Widget
   {
      Image img, selec;
      Pointeur pointeur;
      boolean selected;
      public PointeurGUI(Image img, Pointeur pointeur)
      {
         this.img = img;
         try {
            this.selec = new Image("data/GUI/Images/selected.png");
         } catch (SlickException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         this.pointeur = pointeur;
      }
      @Override
      public void paintWidget(GUI gui)
      {
         img.draw(this.getX(), this.getY());
         if(selected)
         {
            
         }
      }
      
      @Override
       protected boolean handleEvent(Event evt)
      {
           if(evt.isMouseEventNoWheel())
           {
               if(evt.getMouseButton() == evt.MOUSE_LBUTTON)
               {
                  /*current_mouse_cursor = img;
               try {
                  test_gc.setMouseCursor(current_mouse_cursor, 0, 0);
               } catch (SlickException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }*/
               }
               return true;
           }
          
          
           return super.handleEvent(evt);
       }
      public Image getImg() {
         return img;
      }
      public void setImg(Image img) {
         this.img = img;
      }
      public Pointeur getPointeur() {
         return pointeur;
      }
      public void setPointeur(Pointeur pointeur) {
         this.pointeur = pointeur;
      }
      public boolean isSelected() {
         return selected;
      }
      public void setSelected(boolean selected) {
         this.selected = selected;
      }
      
      
   };


Hope that you can help me,

FaZeGA


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 10:16 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
The DialogLayout subclass handleEvent() doesn't receive mouse events while the mouse is over your PointeurGUI widgets as these handle the mouse events.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group