src/global/gui/registerObject.h

00001 /*
00002     SAL - Simple Application Library
00003     Copyright (C) 2006-2006 Kronon
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019     Kronon
00020     kronon88@users.sourceforge.net
00021 */
00022 
00023 //SAL register gui objects
00024 //Created by Kronon
00025 
00026 //If there are no free position in the array, add one at the end of the array
00027 if(container->free.isEmpty())
00028 {
00029         object->std.id = container->last_id;                                            //Button's id nr
00030         container->objects[container->last_id%1000] = &object->std;
00031         container->last_id++;                                   //Create a new id nr for this object
00032 }
00033 else
00034 {
00035         int freeId;
00036         container->free.top(freeId);
00037         object->std.id = freeId;                                                                        //Button's id nr
00038         container->objects[freeId] = &object->std;
00039         container->free.pop();
00040 }
00041 
00042 //Add gui object to select matrix
00043 int sW = SAL_struct.internal.render.display->w / 5;                     //Width of 1 square in the matrix
00044 int sH = SAL_struct.internal.render.display->h / 5;                     //Height of 1 square in the matrix
00045 
00046 //Add gui object to every square in the matrix where it's positioned in
00047 for(int i = (x / sW); i <= ((x + w) / sW) && i < 5; i++)
00048         for(int j = (y / sH); j <= ((y + h) / sH) && j < 5; j++)
00049                 SAL_struct.internal.event.select_matrix[i][j].append(&object->std);
00050