示例#1
0
void ChatBox::mouseClicked(gcn::MouseEvent& mouseEvent){
    if( mouseEvent.isConsumed() ){ return; }

    InfraellyWindow::mouseClicked(mouseEvent);

    //click from the chat area
    if( mouseEvent.getSource() == chatArea ){
        chatArea->requestFocus();
        typing = 0;
    }

    //click from the input field
    if( mouseEvent.getSource() == inputField ){
        typing = 1;
    }

    //if click was from send button
    if( mouseEvent.getSource() == sendButton ){
        // add the text from the text field into the chat area
        push_back( inputField->getText(), DO_CALLBACK|PUT_USERNAME );
        //clear off the text field
        inputField->setText("");
        //--------------------------
        //          play sound
        //------------------------
    }
}
示例#2
0
void ItemMakerBox::mouseClicked(gcn::MouseEvent& mouseEvent){
    if( mouseEvent.isConsumed() ){ return; };

    //  Save Button
    if( mouseEvent.getSource() == saveBtn ){
        mouseEvent.consume();
        save( filenameFld->getText() );
    } else
    //  Load Button
    if( mouseEvent.getSource() == loadBtn ){
        mouseEvent.consume();
        load( filenameFld->getText() );
    } else {
        setCaption(caption_);
    }
}
示例#3
0
void TabbedArea::mousePressed(gcn::MouseEvent &mouseEvent)
{
    if (mouseEvent.isConsumed())
        return;

    if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
    {
        gcn::Widget *widget = mTabContainer->getWidgetAt(mouseEvent.getX(),
                                                         mouseEvent.getY());
        gcn::Tab *tab = dynamic_cast<gcn::Tab*>(widget);

        if (tab)
        {
            setSelectedTab(tab);
            requestFocus();
        }
    }
}
示例#4
0
void PlayControlPanel::mouseClicked(gcn::MouseEvent &mouseEvent)
{
  if (mouseEvent.isConsumed()) {
    return;
  }

  gcn::Widget* sourceWidget = mouseEvent.getSource();
  if (sourceWidget == dynamic_cast<gcn::Widget*>(playButton)) {
    std::cout << "Click on PLAY button" << std::endl;
    changeState(PLAYING);
  } else if (sourceWidget == dynamic_cast<gcn::Widget*>(pauseButton)) {
    std::cout << "Click on PAUSE button" << std::endl;
    changeState(PAUSED);
  } else if (sourceWidget == dynamic_cast<gcn::Widget*>(stopButton)) {
    std::cout << "Click on STOP button" << std::endl;
    changeState(STOPPED);
  }

  mouseEvent.consume();
}
void Console::mouseClicked(gcn::MouseEvent& mouseEvent){
    if( mouseEvent.isConsumed() ){ return; };

    //click from the text area
    if( mouseEvent.getSource() == textArea ){
        inputField->requestFocus();
    };

    //if click was from send button
    if( mouseEvent.getSource() == sendButton ){
        // add the text from the text field into the text area
        push_back( inputField->getText(), DO_CALLBACK|PUT_USERNAME);
        //store command entered
        lastCommand = inputField->getText();
        //clear off the text field
        inputField->setText("");
        //--------------------------
        //          play sound
        //------------------------
        inputField->requestFocus();
    }
}
示例#6
0
void MapperGui::mouseClicked(gcn::MouseEvent& mouseEvent){
    if( mouseEvent.isConsumed() ){ return; };

    //click from the map image ( worldImagePlaceHolder )
    if( mouseEvent.getSource() == worldImagePlaceHolder ){
        //consume mouse event
        mouseEvent.consume();
        //click from the tilesetImage
        if( world != NULL ){
            if( world->empty() ){ return; };

            int layerNum = layerToggleBox->getWorkingLayer();
            Layer& workingLayer = world->getLayer(layerNum);

            // tileset select
            int tileWidth = workingLayer.getTileWidth();
            int tileHeight = workingLayer.getTileHeight();

            // get the x-y co-ords reletive to the tileset region
            int col = mouseEvent.getX() - worldImagePlaceHolder->getX();
            int row = mouseEvent.getY() - worldImagePlaceHolder->getY();

            // if its a multiple of tilewidth/height (ie in the barrier between)
            if( col % tileWidth == 0){ ++col; };
            if( row % tileHeight == 0){ ++row; };

            // turn co-ords into row/col
            col = col/tileWidth;
            row = row/tileHeight;


            // calculate the amount of tiles off the screen
            int trueCol = worldImagePlaceHolder->getX();
            int trueRow = worldImagePlaceHolder->getY();

            //  if its a multiple of tilewidth/height (ie in the barrier between)
            if( trueCol % tileWidth == 0){ ++col; };
            if( trueRow % tileHeight == 0){ ++row; };
            // turn co-ords into row/col
            trueCol = trueCol/tileWidth;
            trueRow = trueRow/tileHeight;
            //add the on screen offset to the offsecreen tiles
            trueCol += col-1;
            trueRow += row-1;

            //check if within range
            if( (trueCol < workingLayer.getWidth()) &&
                (trueRow < workingLayer.getHeight()) ){
                //if left click
                if( mouseEvent.getButton() == gcn::MouseEvent::LEFT ){
                    //set the tile wher mouse is on map, to selected tile on ts
                    //if the attrib ts is on
                    if( tilesetBox->getSelectedTileset() == tilesetBox->getAttribTileset() ){
                        //only replace the attibute
                        workingLayer.at(trueCol, trueRow).setAttribute( tilesetBox->getSelectedTile().getAttribute() );
                    } else {
                        //replace old tile
                        workingLayer.at(trueCol, trueRow) = tilesetBox->getSelectedTile();
                    }
                } else if( mouseEvent.getButton() == gcn::MouseEvent::MIDDLE ){
                    //fill layer, to selected tile on ts
                    //if the attrib ts is on
                    if( tilesetBox->getSelectedTileset() == tilesetBox->getAttribTileset() ){
                        //only replace the attibute
                        for(int i = 0; i < workingLayer.getHeight(); ++i){
                            for(int j = 0; j < workingLayer.getWidth(); ++j){
                                workingLayer.at(j, i).setAttribute( tilesetBox->getSelectedTile().getAttribute() );
                            }
                        }
                    } else {
                        //replace old tile
                        for(int i = 0; i < workingLayer.getHeight(); ++i){
                            for(int j = 0; j < workingLayer.getWidth(); ++j){
                                workingLayer.at(j, i) = tilesetBox->getSelectedTile();
                            }
                        }
                    }
                } else if ( mouseEvent.getButton() == gcn::MouseEvent::RIGHT ){
                    //if the attrib ts is on
                    if( tilesetBox->getSelectedTileset() == tilesetBox->getAttribTileset() ){
                        //clear attrib
                        workingLayer.at(trueCol, trueRow).setAttribute( MapTile::REGULAR );
                    } else {
                        //clear the tileset (delete tile)
                        workingLayer.at(trueCol, trueRow).setSource( NULL, 0, 0 );
                    }
                }
                mapTouched = 1;
            }
        }//end if event from drop down
    } else




    //click from the tilset panel
    //load tileset button
    if( mouseEvent.getSource() == tilesetBox->getLoadTilesetButton() ){
        mouseEvent.consume();
        loadTilesetBox->setVisible( true );
        loadTilesetBox->requestFocus();
    } else

    //make tileset button
    if( mouseEvent.getSource() == tilesetBox->getMakeTilesetButton() ){
        mouseEvent.consume();
        makeTilesetBox->setVisible( true );
        makeTilesetBox->requestFocus();
    } else

    //close tileset button
    if( mouseEvent.getSource() == tilesetBox->getCloseTilesetButton() ){
        mouseEvent.consume();
        tilesetDetailsBox->setInfoSource( NULL );
    } else

    //display tileset info
    if( mouseEvent.getSource() == tilesetBox->getTilesetDetailsButton() ){
        mouseEvent.consume();
        tilesetDetailsBox->setInfoSource( tilesetBox->getSelectedTileset() );
        tilesetDetailsBox->setVisible( true );
        tilesetDetailsBox->requestFocus();
    } else




    // from file tool bar
    //new doc
    if( mouseEvent.getSource() == fileToolBar->getNewDocButton() ){
        mouseEvent.consume();
        loadMapBox->setVisible( true );
        loadMapBox->requestFocus();
    } else

    //save document
    if( mouseEvent.getSource() == fileToolBar->getSaveDocButton() ){
        mouseEvent.consume();
        if( world == NULL ){
            alert("Theres no map to save (try the new map button =P)");
            return;
        }
        if( world->size() == 0 ){
            alert("Theres no map to save (try the new map button =P)");
            return;
        }
        std::string a =  world->getFilename() ;
        if( world->getFilename() == "NULL" || world->getFilename().empty() ||
            isSpace(world->getFilename())  || world->getFilename() == "" ){
            filenameBox->setFilename("data/maps/");
            filenameBox->setVisible( true );
            action = SAVEAS;
        } else {
            if( !world->saveMap(world->getFilename()) ){
                alert( ("Cant save file: " + world->getFilename()) );
                return;
            } else {
                alert("Saved");
            }
        }
    } else

    // save as
    if( mouseEvent.getSource() == fileToolBar->getSaveAsButton() ){
        mouseEvent.consume();
        if( world == NULL ){
            alert("Theres no map to save (try the new map button =P)");
            return;
        }
        if( world->size() == 0 ){
            alert("Theres no map to save (try the new map button =P)");
            return;
        }
        action = SAVEAS;
        filenameBox->setFilename("data/maps/");
        filenameBox->setVisible( true );
    } else

    //open new doc (close current 1st)
    if( mouseEvent.getSource() == fileToolBar->getOpenDocButton() ){
        mouseEvent.consume();
        action = OPEN;
        filenameBox->setFilename("data/maps/");
        filenameBox->setVisible( true );
    } else









    //close (no save) and reOpen
    if( mouseEvent.getSource() == fileToolBar->getReopenDocButton() ){
        mouseEvent.consume();
        if( world != NULL ){
            std::string filename = correctFilepath(world->getFilename());
            //delete map
            notify("Releasing old world from memory");
            world->unload();
            //clear the tileset array
            notify("Releasing tilesets");
            tilesetBox->freeTilesets();
            //reopen
            notify("Reopening file");
            if( !world->loadMap(filename) ){
                alert( ("Cant open file: " + filename) );
            }
            unNotify();
            mapDetailsBox->setInfoSource( world );
            //  free old worldImage
            if( worldImage != NULL ){
                SDL_FreeSurface(worldImage);
                worldImage = NULL;
            };
            mapTouched = 1;
            action = NOTHING;
        }
    } else

    //close
    if( mouseEvent.getSource() == fileToolBar->getCloseDocButton() ){
        mouseEvent.consume();
        //delete map
        notify("Releasing old world from memory");
        if( world != NULL ){
            //delete worlds
            world->unload();
            //clear the tileset array
            notify("Releasing tilesets");
            tilesetBox->freeTilesets();
            unNotify();
            mapDetailsBox->setInfoSource( world );
            //  free old worldImage
            if( worldImage != NULL ){
                SDL_FreeSurface(worldImage);
                worldImage = NULL;
            }
            mapTouched = 1;
            action = NOTHING;
        }
    } else

    //get details
    if( mouseEvent.getSource() == fileToolBar->getDetailsButton() ){
        mouseEvent.consume();
        mapDetailsBox->setVisible( true );
    }
}
示例#7
0
void MapperTilesetBox::mouseClicked(gcn::MouseEvent& mouseEvent){
    InfraellyWindow::mouseClicked(mouseEvent);

    if( mouseEvent.isConsumed() ){ return; };

    //if click was from closeTilesetButton
    if( mouseEvent.getSource() == closeTilesetButton ){
        //consume mouse event
        mouseEvent.consume();
        //get the pointer to the tileset to remove
        Tileset *toRemove = tilesetList->at( tilesetDropDown->getSelected() );

        //check if the user is trying to dlete teh nullTS
        if( toRemove != tilesetList->at(0) ){
            //store number to remove
            int removeIndex = tilesetDropDown->getSelected();
            //change the selected ts to the nullTS
            tilesetDropDown->setSelected(0);
            //delete the entry from teh list
            tilesetList->removeElementAt( removeIndex );


            //if there is a map activley associated
            if( world != NULL ){
                //stip dependency from map working on
                //if there IS dependency
                if( !world->empty() ){
                    //cycle through layers
                    for( size_t i = 0; i < world->size(); ++i ){
                        //cycle thru tiles
                        for( size_t j = 0; j < world->getLayer(i).getHeight() * world->getLayer(i).getWidth(); ++j){
                            if( world->getLayer(i).index(j).getTileset() == toRemove ){
                                world->getLayer(i).index(j).setTileset(NULL);
                            }
                        }
                    }
                }
            }
            //dependency of tileset stripped
            //delete the tileset
            cache::tilesets.erase(toRemove);

            //remove from selected tile
            selectedTile.setSource(NULL,0,0);
        }
    }


    //click from the tilesetImage
    if( mouseEvent.getSource() == tilesetImage ){
        //consume mouse event
        mouseEvent.consume();
        if( !tilesetList->empty() ){
            Tileset *selectedTs = selectedTile.getTileset();
            if( selectedTs != NULL ){
                // tileset select
                int tileWidth = selectedTs->getTileWidth();
                int tileHeight = selectedTs->getTileHeight();

                // get the x-y co-ords reletive to the tileset region
                int col = mouseEvent.getX() - (tilesetImage->getX()+selectedTs->getXOffset());
                int row = mouseEvent.getY() - (tilesetImage->getY()+selectedTs->getYOffset());

                // if its a multiple of tilewidth/height (ie in the barrier between)
                if( col % tileWidth == 0){ ++col; };
                if( row % tileHeight == 0){ ++row; };

                // turn co-ords into row/col
                col = col/tileWidth;
                row = row/tileHeight;


                // calculate the amount of tiles off the screen
                int trueCol = tilesetImage->getX();
                int trueRow = tilesetImage->getY();

                //  if its a multiple of tilewidth/height (ie in the barrier between)
                if( trueCol % tileWidth == 0){ ++col; };
                if( trueRow % tileHeight == 0){ ++row; };
                // turn co-ords into row/col
                trueCol = trueCol/tileWidth;
                trueRow = trueRow/tileHeight;
                //add the on screen offset to the offsecreen tiles
                trueCol += col-1;
                trueRow += row-1;

                //store the tile's new row-col
                selectedTile.setSource( selectedTs, trueCol, trueRow);
                //store attribute if on atrib ts
                if( selectedTile.getTileset() == attribTs ){
                    selectedTile.setAttribute(attribGrid[trueCol][trueRow]);
                }
            }// end if null
        }//end if empty list
    }//end if event from drop down*/
}