First commit

This commit is contained in:
2025-03-26 09:05:12 +01:00
parent 0edc031313
commit a39fd44d3a
68 changed files with 27611 additions and 0 deletions

199
MLV/MLV_all.h Normal file
View File

@@ -0,0 +1,199 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_all.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Fichier d'entête principal incluant tous les autres fichiers entêtes
* de la bibliothèque MLV.
*
* Vous trouverez tous les prototypes des fonctions proprées par la bibliothèque
* MLV dans les fichiers entêtes (.h) suivants :
*
* MLV_animation.h : permet de mettre en oeuvre des animations.
*
*
* MLV_audio.h : permet de jouer de la musique.
*
*
* MLV_color.h : definit les différentes couleurs de la bibliothèque MLV.
*
*
* MLV_event.h : propose une gestion avancée des évènements. Avec les fonctions
* proposées par MLV_evenement.h, il est possible de traiter les évènements
* sans intérrompre l'exécution du programme.
*
*
* MLV_image.h : charger, modifier et afficher des images.
*
*
* MLV_information.h : permet d'obtenir quelques informations concernant la
* bibliothèque MLV (web, auteurs, version).
*
*
* MLV_input_box.h : définit différents outils pour créer et utiliser des
* boîtes de saisies.
*
*
* MLV_keyboard.h : définit les types concerant le clavier et définit la
* fonction MLV_keyboard_wait pour récuperer des évènements
* provenant du clavier.
*
*
* MLV_mouse.h : définit les types concerant la souris ainsi que la fonction
* MLV_mouse_wait pour récuperer des évènements provenant de la
* souris.
*
*
* MLV_path.h : définit différents outils pour utiliser des chemins d'accès aux
* fichiers.
*
*
* MLV_random.h : propose des outils pour engendrer des nombres aléatoires.
*
*
* MLV_shape.h : permet de créer des figures ( cercle, ellipse, polygone,
* courbe de bezier, rectangle, ligne , point).
*
*
* MLV_text.h : définit differents outils permettant d'afficher du texte seul ou
* dans une boîte.
*
* MLV_text_va.h : définit les même outils que MLV_text.h mais en prenant une
* comme argument suplémentaire une liste d'arguments.
*
* MLV_time.h : propose des outils pour gérer le temps.
*
* MLV_xml.h : propose des outils pour lire des fichiers XML.
*
* MLV_xml_va.h : définit les même outils que MLV_xml.h mais en prenant une
* comme argument suplémentaire une liste d'arguments.
*
* MLV_window.h : propose des fonctions pour
* - initialiser, créer et fermer une fenêtre
* - actualiser l'affichage de la fenêtre
* - exécuter du code à la fermeture de la fenêtre
*
* \see MLV_animation.h MLV_audio.h MLV_color.h MLV_event.h MLV_image.h
* MLV_information.h MLV_input_box.h MLV_keyboard.h MLV_mouse.h
* MLV_path.h MLV_random.h MLV_shape.h MLV_text.h MLV_text_va.h MLV_time.h
* MLV_xml.h MLV_xml_va.h MLV_window.h
*/
/** \~spanish
* \file MLV_all.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Archivo principal de cabecera incluyendo todos los otros archivos de
* cabecera de la biblioteca informática MLV.
*
* Puede encontrar todos los prototipos des las subrutinas propuestas para la
* biblioteca MLV en los archivos de cabecera (.h) suiquiente :
*
* MLV_animation.h : permite de añadir animaciónes.
*
* MLV_audio.h : permite de tocar música.
*
*
* MLV_color.h : défine los differentes colores de la biblioteca MLV.
*
*
* MLV_event.h : proppone una gestión advencada des los eventos. Con las
* subrutinas propuestas para MLV_evenment.h, es possible de
* tratar los eventos sin interrumpir la ejecución del programa
* informático.
*
*
* MLV_shape.h : permite de creer figuras geométricas (círculo, elipse,
* polígono, Curva de Bézier, rectángulo, linea recta, punto).
*
*
* MLV_image.h : modificar and fijara las imagenes.
*
*
* MLV_information.h : permite de obtener algunas noticias concerniendo la
* biblioteca MLV. concernant la
*
*
* MLV_keyboard.h : define los tipos de dato por el teclado y la subrutina
* MLV_keyboard_wait para obtener los eventos del teclado.
*
*
* MLV_mouse.h : define los tipos de dato por el ratón y la subrutina
* MLV_mouse_wait para obtener eventos des ratón.
*
*
* MLV_input_box.h : define algunas herramientas para creer y utilisar caja de
* texto
*
*
* MLV_text.h : define algunas herramientas para fijar textos.
*
* MLV_text_va.h : TODO
*
* MLV_time.h : propone herramientas para utilisar el tiempo.
*
* MLV_xml.h : TODO
*
* MLV_xml_va.h : TODO
*
* MLV_random.h : propone herramientas para generar números aleatorios.
*
*
* MLV_window.h : propone las subrutina para
* - creer, inicializar, cerrar ventanas
* - actualizar la visualización de una ventana
* - ejecutar código al fin del programa
*
*
* \see MLV_animation.h MLV_audio.h MLV_color.h MLV_event.h MLV_shape.h
* MLV_image.h MLV_keyboard.h MLV_mouse.h MLV_input_box.h MLV_random.h
* MLV_text.h MLV_text_va.h MLV_time.h MLV_xml.h MLV_xml_va.h MLV_window.h
*/
#ifndef __MLV__MLV_ALL_H__
#define __MLV__MLV_ALL_H__
#include "MLV_animation.h"
#include "MLV_audio.h"
#include "MLV_color.h"
#include "MLV_event.h"
#include "MLV_shape.h"
#include "MLV_image.h"
#include "MLV_information.h"
#include "MLV_keyboard.h"
#include "MLV_mouse.h"
#include "MLV_path.h"
#include "MLV_playlist.h"
#include "MLV_input_box.h"
#include "MLV_random.h"
#include "MLV_text.h"
#include "MLV_text_va.h"
#include "MLV_time.h"
#include "MLV_xml.h"
#include "MLV_xml_va.h"
#include "MLV_window.h"
#endif

655
MLV/MLV_animation.h Normal file
View File

@@ -0,0 +1,655 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_animation.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* Cette interface est inspiré du tutoriel :
* http://www.gnurou.org/writing/linuxmag/sdl/partie3
*
* \brief Ce fichier définit les prototypes des fonctions permettant de mettre
* en oeuvre des animations.
*/
#ifndef __MLV__MLV_ANIMATION_H__
#define __MLV__MLV_ANIMATION_H__
#include "MLV_image.h"
#include "MLV_audio.h"
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////
// Animation data
///////////////////////////////////////////////
/** \~french
* \brief Ce type code une animation.
*
* Une animation est une succéssion de k+l+1 uplets.
* Chaque uplet contient :
* - k images,
* - l sons,
* - 1 temps d'affichage
* Les k images correspondent à k représentations différentes d'une
* même scène animée.
* Les l sons correspondent à l différents fonds sonores pour la
* même scène animée.
* Le temps d'affichage est le temps d'affichage des images dans
* l'animation.
*
* On appelle "couche graphique i", l'ensemble des images situées à la
* position i du k+l+1-uplet.
* On appelle "couche sonore j", l'ensemble des sons situées à la
* position k+j du k+l+1-uplet.
*
* Voici la Structure d'une animatione représentée à l'aide d'un tableau :
*
* \verbatim
|-------------------------------------------------------------|
| MLV_Animation |
|-------------------------------------------------------------|
| |
| Couche graphique 0 | Image Image Image ... |
| Couche graphique 1 | Image Image Image ... |
| ... | ... ... ... ... |
| Couche graphique k-1 | Image Image Image ... |
| ------------------------------------------------------- |
| Couche sonore 0 | Son Son Son ... |
| Couche sonore 1 | Son Son Son ... |
| ... | ... ... ... ... |
| Couche sonore k-1 | Son Son Son ... |
| ------------------------------------------------------- |
| Temps d'affichage | 1 3 1 ... |
| |
|-------------------------------------------------------------|
\endverbatim
*
*/
typedef struct _MLV_Animation MLV_Animation;
/** \~french
* \brief Créé une animation comportant un nombre d'image donné
*
* Une animationV est une succession d'image où à chaque image est
* associé un temps. Ce temps code le temps d'affichage de chaque image,
* lors du rendu de de l'animation.
* Pour des raisons de commodité, nos séquence d'animations sont composés de
* plusieurs couches. Elles sont donc des successions de couches contenant
* chacunes une image.
*
* Une sequence d'animation (à ne pas confondre avec une animation) est une
* pure structure de donnée. Elle peut donc pas s'animer, ni s'afficher à
* l'ecran.
* Pour afficher une séquence d'animation, il faut utiliser une animation,
* qui s'aidera de la séquence d'animation pour s'afficher ou pour mettre en
* mouvement les images de la séquence d'animation.
*
* Le temps d'une s'quence d'animation n'est pas codée en secondes. Il s'agit
* d'un entier. Lorsque vous utilisez une animation, l'animateur à un temps qui
* lui est propre et qui est codé à l'aide d'un entier qui croit. Les duree que
* vous ajouterez dans l'animation sont donc définit par rapport au temps de
* l'animation qui utilise la séquence d'animation.
*
* \param nb_frames Le nombre d'image que doit contenir l'animation
* \param nb_layers Nombre de couches graphique de l'animation.
* \param nb_channels Nombre de canaux sonore de l'animation.
* \return Un pointeur vers une animation.
*/
MLV_Animation* MLV_create_animation(
unsigned int nb_frames, unsigned int nb_layers, unsigned int nb_channels
);
/** \~french
* \brief Cette fonction libère les données allouées pour l'animation
*
* \param animation L'animation à fermer.
*/
void MLV_free_animation( MLV_Animation* animation );
/** \~french
* \brief Change un animation en remplacant une image et son temps d'affichage
* associé. L'image concerné est repéré à l'aide de son index et de
* l'index de la couche où elle appartient.
*
* \param array_of_images Un tableau d'adresse contenant les addresses de images
* correspondat aux différentes couches d'une animation.
* \param array_of_sounds Un tableau d'adresse contenant les addresses de sons
* correspondant aux différentes canaux d'une animation.
* \param delay temps d'affichage de l'image
* \param animation Animation à modifier
* \param position position de l'image dans l'animation
*/
void MLV_change_frame_in_animation(
MLV_Image** array_of_images, MLV_Sound** array_of_sounds, unsigned int delay,
MLV_Animation* animation, unsigned int position
);
/** \~french
* \brief Change un animation en remplacant uniquement une image.
* L'image concerné est repéré à l'aide de son index et de
* de l'index de sa couche.
*
* \param image image a ajouter dans l'animation
* \param animation Animation à modifier
* \param position position de l'image dans l'animation
* \param layer Couche de l'image.
*/
void MLV_change_frame_image_in_animation(
MLV_Image* image, MLV_Animation* animation, unsigned int position,
unsigned int layer
);
/** \~french
* \brief Change un animation en remplacant uniquement un bruitage.
* Le son image concerné est repéré à l'aide de son index et de
* de l'index de son canaul.
*
* \param sound son a ajouter dans l'animation
* \param animation Animation à modifier
* \param position position de l'image dans l'animation
* \param channel Canal du son.
*/
void MLV_change_frame_sound_in_animation(
MLV_Sound* sound, MLV_Animation* animation, unsigned int position,
unsigned int channel
);
/** \~french
* \brief Change le temps d'affichage d'une image donnée d'une animation.
*
* \param delay temps d'affichage de l'image
* \param animation Animation à modifier
* \param position position de l'image dans l'animation
*/
void MLV_change_frame_delay_in_animation(
unsigned int delay, MLV_Animation* animation, unsigned int position
);
/** \~french
* \brief Recupère l'image et le temps présents à une position et une couche
* donnée d'une animation.
*
* \param animation Animation à modifier
* \param layer Couche de l'image.
* \param position position de l'image dans l'animation
* \param image image a ajouter dans l'animation
* \param delay temps d'affichage de l'image
*/
void MLV_get_frame_from_animation(
MLV_Animation* animation, unsigned int position,
unsigned int layer,
MLV_Image** image, unsigned int* delay
);
/** \~french
* \brief Renvoie le temps d'affichage de l'image présente à une position
* donnée d'une animation donnée.
*
* \param animation Animation à modifier
* \param position position de l'image dans l'animation
*
* \return le temps d'affichage de l'image
*/
int MLV_get_frame_delay_from_animation(
MLV_Animation* animation, unsigned int position
);
/** \~french
* \brief Renvoie l'image présente à une position et une couche donnée d'une
* animation donnée.
*
* \param animation Animation à modifier
* \param position position de l'image dans l'animation
* \param layer Couche de l'image.
*
* \return l'image extraite.
*/
MLV_Image* MLV_get_frame_image_from_animation(
MLV_Animation* animation, unsigned int position,
unsigned int layer
);
////////////////////////////////////////////////
// Animation engine
///////////////////////////////////////////////
/** \~french
* \brief Ce type code un lecteur d'animation.
*
* Un lecteur d'animation est une structure qui permet d'animer une animation.
* Cette structure contient :
* - un pointeur vers une animation
* - la position de l'image courante de l'animation
* - une horloge interne ( dont le temps est discret et indépendant du temps courant )
*
*
*
* L'aiguille de l'horologe interne d'une animation avance d'une unité
* à chaque appel de la fonction MLV_update_animation_player().
* Les animations sont alors jouée en fonction de l'évolution du temps de chaque
* animateur. Ainsi, deux lecteurs différents peuvent avoir une courbe du
* temps différente.
*
* La bonne façon d'utiliser des lecteurs est de mettre a jour tous les
* lecteurs en même temps à un intervalle de temps régulier.
* Pour cela vous pouvez utiliser la fonction framerate qui endort le programme
* de façon a assurer l'execution d'un tour de boucle à une fréquence donnée
*
* Voici un exemple d'utilisation du lecteur :
* \code
* MLV_Image* creature1 = MLV_load_image("creature1.png");
* MLV_Image* creature2 = MLV_load_image("creature2.png");
* int time_per_image = 1;
*
* MLV_Animation* animation;
* animation = MLV_create_animation( 2 );
* MLV_change_frame_in_animation( creature1, time_per_image, animation, 0 );
* MLV_change_frame_in_animation( creature2, time_per_image, animation, 0 );
*
* MLV_Animation_player* animation_player;
* animation_player = MLV_create_animation_player( animation );
*
* int frequence = 24; // nombre d'images par secondes
* MLV_change_frame_rate( frequence );
* while( 1 ){
* MLV_update_animation_player( animation_player );
* MLV_draw_image_from_animation_player(0, 0, 0, animation_player);
* MLV_frame_rate_delay();
* }
* \endcode
*
*/
typedef struct _MLV_Animation_player MLV_Animation_player;
/** \~french
* \brief Cree un lecteur d'animation et l'initialise avec une animation donnée en
* paramètre.
*
* \param animation L'animation que devra animer l'animateur.
*
* \return L'animateur créé.
*/
MLV_Animation_player* MLV_create_animation_player( MLV_Animation* animation );
/** \~french
* \brief Libère l'espace mémoire alloué pour un animateur donné.
*
* \param animation_player Le lecteur d'animation à suprimer
*/
void MLV_free_animation_player( MLV_Animation_player* animation_player );
/** \~french
* \brief Demare la lecture de l'animation lu par le lecteur d'animation.
*
* \param animation_player Le lecteur d'animation
*/
void MLV_play_animation_player( MLV_Animation_player* animation_player );
/** \~french
* \brief Demande à un lecteur d'animation donné de jouer l'animation à l'envers.
*
* \param animation_player Le lecteur d'animation
*/
void MLV_play_revert_animation_player( MLV_Animation_player* animation_player );
/** \~french
* \brief Met en pause la lecture d'un lecteur d'animation donné.
*
* \param animation_player Le lecteur d'animation
*/
void MLV_stop_animation_player( MLV_Animation_player* animation_player );
/** \~french
* \brief Demande à l'animateur de reprendre la lecture de l'animation depuis le
* début.
*
* \param animation_player Le lecteur d'animation
*/
void MLV_rewind_animation_player( MLV_Animation_player* animation_player );
/** \~french
* \brief Force le lecteur d'animation à passer à l'image suivante.
*
* \param animation_player Le lecteur d'animation
*/
void MLV_next_frame( MLV_Animation_player* animation_player );
/** \~french
* \brief Force l'animateur à revenir sur l'image précédente.
*
* \param animation_player Le lecteur d'animation
*/
void MLV_previous_frame( MLV_Animation_player* animation_player );
/** \~french
* \brief Met a jour un lecteur d'animation.
*
* L'horloge interne du lecteur voit son temps incrémenter de 1 unité
* exactement.
*
* La position de lecture de l'animation est mis a jour en conséquence de la
* mis à jour de l'horloge interne.
*
* \param animation_player Le lecteur d'animation à mettre à jour
*/
void MLV_update_animation_player( MLV_Animation_player* animation_player );
/** \~french
* \brief Change le volume sonore d'un bruitage.
*
* \param animation_player L'animateur dans lequel se trouve le son.
* \param channel Le canal concerné.
* \param volume le nouveau volume sonore.
*/
void MLV_change_sound_volume_of_animation_player(
MLV_Animation_player* animation_player, unsigned int channel, float volume
);
/** \~french
* \brief Active le son du canal d'un lecteur d'animation donnée.
*
* \param animation_player L'animateur concerné.
* \param channel Le canal concerné.
*/
void MLV_turn_on_sound_of_animation_player(
MLV_Animation_player* animation_player, unsigned int channel
);
/** \~french
* \brief Désactive le son du canal d'une animation donnée.
*
* \param animation_player L'animateur concerné.
* \param channel Le canal concerné.
*/
void MLV_turn_off_sound_of_animation_player(
MLV_Animation_player* animation_player, unsigned int channel
);
////////////////////////////////////////////////
// Drawing animation
///////////////////////////////////////////////
/** \~french
* \brief Dessine à une position donnée l'image actuellement lue par
* l'animateur. Cette image est situè à une couche donnée en paramètre.
*
* \param animation_player Le lecteur de l'animation à aficher
* \param layer Couche de l'image.
* \param x Coordonnée en X de la position du sommet Nord-Ouest de
* l'image à afficher.
* \param y Coordonnée en Y de la position du sommet Nord-Ouest de
* l'image à afficher.
*/
void MLV_draw_image_from_animation_player(
MLV_Animation_player* animation_player, unsigned int layer,
int x, int y
);
/** \~french
* \brief Joue le son d'une couche sonore donnée correspondant à l'image en
* cours de lecture dans l'animation.
*
* Si le son a déjà été joué, cette fonction ne fait rien.
*
* \param animation_player Le lecteur de l'animation à aficher.
* \param layer Couche du son.
*/
void MLV_play_sound_from_animation_player(
MLV_Animation_player* animation_player, unsigned int layer
);
/** \~french
* \brief Même chose que MLV_play_sound_from_animation_player() sauf que cette
* fonction permet de lancer plusieurs sons en même temps.
*
* La liste des couches sonores à jouer doivent être passé en paramètre
* (un paramètre par couche), et le dernier paramètre doit valoir -1 pour
* dire à la fonction quand il doit s'arrêter.
*
* Par exemple, pour jouer les couches 2, 3 et 5 d'une animation,
* il suffit d'écrire:
*
* \code
* MLV_play_sounds_from_animation_player(
* animation,
* 2, 3, 5,
* -1
* );
* \endcode
*
* \param animation_player Le lecteur de l'animation à aficher.
* \param ... la liste des couches sonores, dont la veleure finale doit toujours être -1.
*/
void MLV_play_sounds_from_animation_player(
MLV_Animation_player* animation_player,
...
);
/** \~french
* \brief Même chose que MLV_play_sound_from_animation_player() sauf que cette
* fonction permet de lancer plusieurs sons en même temps.
*
* \param animation_player Le lecteur de l'animation à aficher.
* \param layers Tableau contenant les couches du son à jouer.
* \param nb_layers Nombre de couches dans le tableau.
* \
*/
void MLV_play_list_of_sounds_from_animation_player(
MLV_Animation_player* animation_player, unsigned int* layers,
unsigned int nb_layers
);
/** \~french
* \brief Dessine à l'écran à une position donnée, une portion de
* l'image actuellement lue par l'animateur et extraite de la
* couche spécifiée en paramètre.
*
* \param animation_player Le lecteur de l'animation à aficher
* \param layer Couche de l'image.
* \param image image sur laquel il faut dessiner l'animation
* \param source_x Coordonnée en X de la position de la portion à recopier
* \param source_y Coordonnée en Y de la position de la portion à recopier
* \param source_width Largeur de la portion à recopier
* \param source_height Hauteur de la portion à recopier
* \param x Coordonnée en X de la position du sommet Nord-Ouest de
* l'image à afficher.
* \param y Coordonnée en Y de la position du sommet Nord-Ouest de
* l'image à afficher.
*/
void MLV_draw_partial_image_from_animation_player(
MLV_Animation_player* animation_player, unsigned int layer,
int source_x, int source_y, int source_width, int source_height,
MLV_Image* image,
int x, int y
);
/** \~french
* \brief Dessine sur une image donnée à une position donnée l'image
* actuellement lue par l'animateur et située à une couche donnée.
*
* \param animation_player Le lecteur de l'animation à aficher
* \param layer Couche de l'image.
* \param image image sur laquel il faut dessiner l'animation
* \param x Coordonnée en X de la position du sommet Nord-Ouest de
* l'image à afficher.
* \param y Coordonnée en Y de la position du sommet Nord-Ouest de
* l'image à afficher.
*/
void MLV_draw_image_from_animation_player_on_image(
MLV_Animation_player* animation_player, unsigned int layer,
MLV_Image* image,
int x, int y
);
/** \~french
* \brief Dessine sur une image donnée à une position donnée une portion de
* l'image actuellement lue par l'animateur et située à une couche
* donnée.
*
* \param animation_player Le lecteru de l'animation à aficher
* \param layer Couche de l'image.
* \param image image sur laquel il faut dessiner l'animation
* \param source_x Coordonnée en X de la position de la portion à recopier
* \param source_y Coordonnée en Y de la position de la portion à recopier
* \param source_width Largeur de la portion à recopier
* \param source_height Hauteur de la portion à recopier
* \param x Coordonnée en X de la position du sommet Nord-Ouest de
* l'image à afficher.
* \param y Coordonnée en Y de la position du sommet Nord-Ouest de
* l'image à afficher.
*/
void MLV_draw_partial_image_from_animation_player_on_image(
MLV_Animation_player* animation_player, unsigned int layer,
int source_x, int source_y, int source_width, int source_height,
MLV_Image* image,
int x, int y
);
////////////////////////////////////////////////
// Loading animations from files
///////////////////////////////////////////////
/** \~french
* \brief Ce type correspond à un livre contenant de nombreuses animations.
*
* Un livre d'animations est un fichier XML qui code des animations.
* Le type MLV_Animation_book code le contenu d'un live d'animation.
*
*/
typedef struct _MLV_Animation_book MLV_Animation_book;
/** \~french
* \brief Charge en memoire un livre contenant une multitude d'animations.
*
* \param xml_file Fichiers xml.
* \param image_directory Le dossier ou se trouve toutes les images du livre
* d'animation. Si NULL est passe en parametre, alors le programme
* cherche dans le repertoire du fichier de configuration du livre
* d'animation.
* \param sound_directory Le dossier ou se trouve toutes les échantillons
* sonore du livre d'animation. Si NULL est passe en parametre,
* alors le programme cherche dans le repertoire du fichier de
* configuration du livre d'animation.
* \return L'adresse de la sructure de données contenant toutes les animations.
*/
MLV_Animation_book* MLV_load_animation_book(
const char* xml_file,
const char* image_directory,
const char* sound_directory
);
/** \~french
* \brief Libère la memoire contenue par le livre d'animation.
*
* \param animation_book Le livre d'animation.
*/
void MLV_free_animation_book(
MLV_Animation_book* animation_book
);
/** \~french
* \brief Détermine le nombre d'animations contenus par le livre d'animation.
*
* \param animation_book Le livre d'animation.
* \return le nombre d'animations contenus par le livre d'animation.
*/
int MLV_get_number_of_animations(
MLV_Animation_book* animation_book
);
/** \~french
* \brief Renvoie une animation donnée contenue dans le livre d'animation.
*
* \param animation_book Le livre d'animation.
* \param id L'identifiant
* \return La séquence d'animation.
*/
MLV_Animation* MLV_get_animation_from_id(
MLV_Animation_book* animation_book,
int id
);
/** \~french
* \brief Renvoie une animation donnée contenue dans le livre d'animation.
*
* \param animation_book Le livre d'animation.
* \param name Le nom de l'animation
* \return La séquence d'animation.
*/
MLV_Animation* MLV_get_animation_from_name(
MLV_Animation_book* animation_book,
const char* name
);
/** \~french
* \brief Renvoie le nom d'un animation à partir de son identifiant dans le
* livre d'animation.
*
* \param animation_book Le livre d'animation.
* \param id_animation L'identifiant de l'animation dans le livre.
* \return Le nom de l'animation.
*/
const char* MLV_get_name_from_id_animation(
MLV_Animation_book* animation_book, int id_animation
);
/** \~french
* \brief Ajoute un image dans la séquence d'animation.
* Cette fonction ne peux pas augmenter le nombre d'image d'une
* animation.
*
* \param array_of_images Liste d'image à ajouter. Il s'agit de toutes les
* images assiciée à toutes les couches correspondnant de
* l'animation.
* \param array_of_sounds Liste de sons à ajouter. Il s'agit de toutes les
* sons assiciées à tous les cannaux correspondnant de
* l'animation.
* \param delay le temps d'afficahge d'une image.
* \param animation La sequence d'animation à moifier.
*/
void MLV_add_frame_in_animation(
MLV_Image** array_of_images, MLV_Sound** array_of_sounds, unsigned int delay,
MLV_Animation* animation
);
#ifdef __cplusplus
}
#endif
#endif

187
MLV/MLV_audio.h Normal file
View File

@@ -0,0 +1,187 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_audio.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant de faire
* jouer de la musique et des échantillons sonores à l'aide de la bibliothèque
* MLV.
*/
#ifndef __MLV__MLV_AUDIO_H__
#define __MLV__MLV_AUDIO_H__
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Ce type code un morceau de musique.
*/
typedef struct _MLV_Music MLV_Music;
/** \~french
* \brief Ce type code un échantillon sonore.
*/
typedef struct _MLV_Sound MLV_Sound;
/** \~french
* \brief Cette fonction initialise la bibliothèque MLV pour pouvoir jouer de la
* musique et des sons.
*
* \return Renvoie 0 si l'infrastructure audio a été correctement initialisé,
* renvoie -1 sinon.
*/
int MLV_init_audio();
/** \~french
* \brief Ferme proprement les différents périphériques audios.
*/
void MLV_free_audio();
/** \~french
* \brief Change la taille du buffer audio. La taille doit être une puissance
* de 2.
*
* Le porgramme rempli périodiquement un buffer audio à faire jouer par la
* carte son. Plus la taille du buffer audio est grande, plus le programme
* à le temps de remplir le buffer avant qu'il se vide. Plus le buffer est
* grand, plus le programme met du temps à le remplir.
*
* Ainsi, si il y a un temps de latence entre une action et l'execution sonore
* du son correspondant, c'est que vous devez réduire la taille du buffer audio.
*
* Si le son est coupé et crépite, c'est que le buffer est trop petit et que le
* processeur est trop lent pour remplir le buffer avant qu'il se vide.
* Vous devez donc agrandir la taille du buffer.
*
* MLV_change_buffer_size vous permet d'ajuster la taille de ce buffer.
* par default la taille du buffer est mis à 1024.
*
* Si vous utilisez le programme uniquement pour jouer de la musique, nous vous
* vous conseillons de configurer la taille du buffer à 4096.
*
* \param buffer_size Taille du buffer audio ( une puissance de 2 )
*
* \return Renvoie 0 si l'infrastructure audio a été correctement initialisé,
* renvoie -1 sinon.
*/
int MLV_change_audio_buffer_size( int buffer_size );
/** \~french
* \brief Change le nombre d'écahantillons sonores qui peuvent être joués en
* même temps.
*
* \param n Le nombre d'échantillons sonores.
*/
void MLV_change_number_of_parallel_sounds( unsigned int n );
/** \~french
* \brief Charge un ficher contenant de la musique en mémoire.
*
* Cette fonction prends en paramètre le chemin d'accès du
* fichier contenant la musique et renvoie un pointeur vers l'espace mémoire où
* a été chargé la musique.
*
* Les formats de fichier acceptés sont les suivants .ogg, .mp3, .wav, etc ...
*
* \param file_music Chemin d'accès vers un fichier contenant de la musique
* codée en format .wav.
* \return Un pointeur vers la musique chargée en mémoire, ou NULL si la
* bibliothèque n'a pas réussi à charger la musique en mémoire.
*/
MLV_Music* MLV_load_music( const char* file_music );
/** \~french
* \brief Ferme un morceau de musique chargé en mémoire.
*
* \param music Le morceau de musique à fermer
*/
void MLV_free_music( MLV_Music* music );
/** \~french
* \brief Joue un morceau de musique qui est chargée en mémoire.
*
* \param music Le morceau de musique à jouer.
* \param volume Le volume sonore.
* \param loop Le nombre de fois que le morceau doit être joué. Si loop est
* strictement négatif, le morceau sera joué indéfiniment.
*/
void MLV_play_music( const MLV_Music* music, float volume, int loop );
/** \~french
* \brief Arrête toutes les musiques.
*/
void MLV_stop_music();
/** \~french
* \brief Charge un ficher contenant un échantillon sonore en mémoire.
*
* Cette fonction prends en paramètre le chemin d'accès du
* fichier contenant l'échantillon sonore et renvoie un pointeur vers l'espace
* mémoire où a été chargé l'échantillon sonore.
*
* Les formats de fichier acceptés sont les suivants : WAVE, AIFF, RIFF, OGG, and
* VOC.
*
* \param file_sound Chemin d'accès vers un fichier contenant un échantillon
* sonore.
* \return Null si le fichier n'a pas pu être chargé en mémoire. Un pointeur vers
* l'échantllon sonore sinon.
*/
MLV_Sound* MLV_load_sound( const char* file_sound );
/** \~french
* \brief Ferme un échantillon sonore chargé en mémoire.
*
* \param sound L'échantillon sonore à fermer
*/
void MLV_free_sound( MLV_Sound* sound );
/** \~french
* \brief Joue un échantillon sonore chargé en mémoire.
*
* \param sound L'échantillon sonore à jouer.
* \param volume Le volume sonore.
*/
void MLV_play_sound( const MLV_Sound* sound, float volume );
/** \~french
* \brief Arrête tous les échantillons sonores.
*/
void MLV_stop_all_sounds();
#ifdef __cplusplus
}
#endif
#endif

4652
MLV/MLV_color.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_device_with_buttons.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit des énumérations et des prototypes de fonctions pour
* manipuler des boutons de différents matériels (bouttons de souris,
* boutons de claviers, etc ...)
*
*/
#ifndef __MLV__MLV_DEVICE_WITH_BUTTONS_H__
#define __MLV__MLV_DEVICE_WITH_BUTTONS_H__
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Énumère les différents états possibles d'un bouton.
*/
typedef enum {
MLV_PRESSED, /**< \~french Le bouton est en position appuyée */
MLV_RELEASED /**< \~french Le bouton est en position relachée */
} MLV_Button_state;
#ifdef __cplusplus
}
#endif
#endif

361
MLV/MLV_event.h Normal file
View File

@@ -0,0 +1,361 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_event.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant d'utiliser
* les évènements dans la bibliothèque MLV.
*/
#ifndef __MLV__MLV_EVENT_H__
#define __MLV__MLV_EVENT_H__
#include "MLV_device_with_buttons.h"
#include "MLV_keyboard.h"
#include "MLV_mouse.h"
#include "MLV_input_box.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Énumère les différents types d'évènement de la bibliothèque MLV.
*/
typedef enum {
MLV_NONE = 0, /**< \~french Aucun évènement */
MLV_KEY = 1, /**< \~french Evnènement provenant du clavier */
MLV_INPUT_BOX = 2, /**< \~french Évènement provenant de la validation d'un texte dans
* une boîte de saisie. */
MLV_MOUSE_BUTTON = 3, /**< \~french Évènement provenant d'un clique de souris. */
MLV_MOUSE_MOTION = 4 /**< \~french Évènement provenant du déplacement de la souris.*/
} MLV_Event;
/** \~french
* \brief Cette fonction récupère un évènement dans la file d'attente, remplit
* en fonction de l'évènement récupéré une partie des paramètres de la
* fonction et renvoie un entier codant le type de l'évènement qui a été
* récupéré.
*
* Le type des évènements est défini par :
*
* MLV_Event
*
* et peut valoir les valeurs suivantes:
*
* Valeur ........... Signification
*
* ----------------------------------
*
* MLV_NONE .......... Aucun évènement récupéré
*
* MLV_KEY ........... Une touche du clavier a été appuyée ou
* relachée.
*
* MLV_INPUT_BOX ..... L'utilisateur a écrit une chaîne de
* caractères et validé cette chaîne par
* la touche entrée.
*
* MLV_MOUSE_BUTTON .. Un des boutons de la souris a été
* appuyé.
*
* MLV_MOUS_MOTION ... La souris a été déplacée.
*
*
*
* Voici un tableau qui donne les champs modifiés en fonction
* de l'évènement qui a été récupéré.
*
* Type Évènement .... Paramètres modifiés
*
* ---------------------------------------
*
* MLV_NONE .......... AUCUN
*
* MLV_KEY ........... key_sym, key_mod, state
*
* MLV_INPUT_BOX ..... texte, input_box
*
* MLV_MOUSE_BUTTON .. mouse_x, mouse_y, mouse_button, state
*
* MLV_MOUSE_MOTION .. mouse_x, mouse_y
*
*
* L'utilisateur n'est pas obligé d'utiliser un champs s'il
* n'en a pas l'utilité. Dans ce cas, il peut mettre la valeur
* NULL. Le champs est alors ignoré.
*
* \bug Il est possible que la récuperation du caractère unicode sous Windows
* ne fonctionne pas bien. En effet, aucun code de portage spécifique n'a été
* fait à ce sujet.
*
* \bug Sous WINDOWS, le clavier est configuré en "qwerty".
*
* \return La fonction renvoie un entier codant le type de l'évènement qui a
* été récupéré.
*
* \param key_sym Code de la touche qui a été appuyée ou relachée. La valeur de
* ce champs est définie par l'énumération : MLV_Keyboard_button.
* \param key_mod Mode dans lequel se trouve le clavier lorsqu'une touche est
* appuyée ou relachée. La valeur de ce champs est définie par
* l'énumération : MLV_Keyboard_modifier.
* \param unicode Caractère codé en unicode de la lettre obtenue en combinant
* le code et le mode précédent
* \param texte Texte récupéré par la boîte de saisie. L'allocation est
* affectée par la fonction elle-même. La désallocation est à
* la charge de l'utilisateur.
* \param input_box La boîte de saisie qui a récupérée le texte
* \param mouse_x Coordonnée en X de la position de la souris
* \param mouse_y Coordonnée en Y de la position de la souris
* \param mouse_button Bouton de la souris qui a été appuyé ou relaché.
* Ce champs est défini par l'énumération MLV_Mouse_button.
* \param state Etat de la touche concernée par l'évènement. La valeur de ce
* champs est défini par l'énumération: MLV_Button_state.
*/
MLV_Event MLV_get_event(
MLV_Keyboard_button* key_sym, MLV_Keyboard_modifier* key_mod, int* unicode,
char** texte, MLV_Input_box** input_box,
int* mouse_x, int* mouse_y, MLV_Mouse_button* mouse_button,
MLV_Button_state* state
);
/** \~french
* \brief Cette fonction suspends l'éxecution du programme jusqu'à ce qu'un
* évènement apparaît dans la file d'attente. Lorsqu'un nouvel
* évènement apparaît, la fonction
* - remplit ses paramètres et renvoie un entier codant le type de
* l'évènement qui a été récupéré, si les paramètres passés en
* argument concernent l'évènement récupéré.
* - se rendort en l'attente d'un nouvel évènement, dans le cas
* contraire.
*
* Pour plus d'informations sur les différents types d'évènements et leurs
* liens avec les paramètres de la fonction, veuillez consulter la
* documentation de la fonction MLV_get_event().
*
* L'utilisateur n'est pas obligé d'utiliser un champs s'il
* n'en a pas l'utilité. Dans ce cas, il peut mettre la valeur
* NULL et le paramètre est ignoré.
*
* \bug Voir les bugs de la fonction MLV_get_event().
*
* \param key_sym Code de la touche qui a été appuyée ou relachée. La valeur de
* ce champs est définie par l'énumération : MLV_Keyboard_button.
* \param key_mod Mode dans lequel se trouve le clavier lorsqu'une touche est
* appuyée ou relachée. La valeur de ce champs est définie par
* l'énumération : MLV_Keyboard_modifier.
* \param unicode Caractère codé en unicode de la lettre obtenue en combinant
* le code et le mode précédent
* \param texte Texte récupéré par la boîte de saisie. L'allocation est affecté par la
* la fonction elle même. La désallocation est à la charge de
* l'utilisateur.
* \param input_box La boîte de saisie qui a récupérée le texte
* \param mouse_x Coordonnée en X de la position de la souris
* \param mouse_y Coordonnée en Y de la position de la souris
* \param mouse_button Bouton de la souris qui a été appuyé ou relaché.
* Ce champs est défini par l'énumération MLV_Mouse_button.
* \param state Etat de la touche concernée par l'évènement. La valeur de ce
* champs est défini par l'énumération: MLV_Button_state.
*
* \return La fonction renvoie un entier codant le type de l'évènement qui
* a été récupéré.
*/
MLV_Event MLV_wait_event(
MLV_Keyboard_button* key_sym, MLV_Keyboard_modifier* key_mod, int* unicode,
char** texte, MLV_Input_box** input_box,
int* mouse_x, int* mouse_y, MLV_Mouse_button* mouse_button,
MLV_Button_state* state
);
/** \~french
* \brief Cette fonction suspends l'éxecution du programme jusqu'à ce qu'un
* évènement apparaît dans la file d'attente ou jusqu'à ce qu'un certain
* nombre de secondes se soient écoulées.
* Si le temps s'est complètement écoulé, la fonction renvoie MLV_NONE.
* Si un nouvel évènement apparaît et que les paramètres passés en arguments
* sont en rapport avec l'évènement récupéré, alors la fonction
* remplit les paramètres et renvoie un entier codant le type de
* l'évènement qui a été récupéré.
* Si un nouvel évènement apparaît et qu'il n'est pas en rapport
* avec les paramètres de la fonction, alors il se rendort dans
* l'attente d'un nouvel évènement ou de la fin du temps.
*
* Pour plus d'informations sur les différents types d'évènements et leurs
* liens avec les paramètres de la fonction, veuillez consulter la
* documentation de la fonction MLV_get_event().
*
* L'utilisateur n'est pas obligé d'utiliser un champs s'il
* n'en a pas l'utilité. Dans ce cas, il peut mettre la valeur
* NULL. Le champs est alors ignoré.
*
* \bug Voir les bugs de la fonction MLV_get_event().
*
* \param key_sym Code de la touche qui a été appuyée ou relachée. La valeur de
* ce champs est définie par l'énumération : MLV_Keyboard_button.
* \param key_mod Mode dans lequel se trouve le clavier lorsqu'une touche est
* appuyée ou relachée. La valeur de ce champs est définie par
* l'énumération : MLV_Keyboard_modifier.
* \param unicode Caractère codé en unicode de la lettre obtenue en combinant
* le code et le mode précédent
* \param texte Texte récupéré par la boîte de saisie. L'allocation est affecté par la
* la fonction elle même. La désallocation est à la charge de
* l'utilisateur.
* \param input_box La boîte de saisie qui a récupérée le texte
* \param mouse_x Coordonnée en X de la position de la souris
* \param mouse_y Coordonnée en Y de la position de la souris
* \param mouse_button Bouton de la souris qui a été appuyé ou relaché.
* Ce champs est défini par l'énumération MLV_Mouse_button.
* \param state Etat de la touche concernée par l'évènement. La valeur de ce
* champs est défini par l'énumération: MLV_Button_state.
* \param seconds Nombre de secondes à attendre avant de terminer l'execution de
* la fonction en renvoyant MLV_NONE.
* \return La fonction renvoie un entier codant le type de l'évènement qui
* a été récupéré ou MLV_NONE si le temps s'est écoulé.
*/
MLV_Event MLV_wait_event_or_seconds(
MLV_Keyboard_button* key_sym, MLV_Keyboard_modifier* key_mod, int* unicode,
char** texte, MLV_Input_box** input_box,
int* mouse_x, int* mouse_y, MLV_Mouse_button* mouse_button,
MLV_Button_state* state, int seconds
);
/** \~french
* \brief Cette fonction vide la file d'évènements.
*
*/
void MLV_flush_event_queue();
/** \~french
* \brief Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche
* du clavier ou sur le bouton gauche de la souris.
*
* Cette fonction renvoie un entier codant le type de l'évènement qui a été
* récupéré ( clavier ou souris )
*
* Lorsque l'utilisateur appuie sur une touche, la fonction retourne trois
* valeurs ( sym, mod et unicode ) correspondant respectivement au code de la
* touche, au mode dans lequel se trouve le clavier (majuscule etc ...) et au
* caractère unicode correspondnant obtenu en combinant le mode du clavier et le
* code de la touche appuyée.
*
* Lorsque l'utilisateur appuie sur le bouton gauche de la souris, la fonction
* remplit les parametres correspondant aux coordonnées en X et Y de la position
* de la souris sur l'écran.
*
* \bug Voir les bugs de la fonction MLV_get_event().
*
* \param sym Code de la touche qui a été appuyée ou relachée. La valeur de ce
* champs est définie par l'énumération : MLV_Keyboard_button.
* \param mod Mode dans lequel se trouve le clavier lorsqu'une touche est
* appuyée ou relachée. La valeur de ce champs est définie par
* l'énumération : MLV_Keyboard_modifier.
* \param unicode Caractère codé en unicode de la lettre obtenue en combinant
* le code et le mode précédent
* \param mouse_x Coordonnée en X de la position de la souris
* \param mouse_y Coordonnée en Y de la position de la souris
* \return un entier codant le type de l'évènement qui a été récupéré ( MLV_KEY
* ou MLV_MOUSE_BUTTON )
*/
MLV_Event MLV_wait_keyboard_or_mouse(
MLV_Keyboard_button* sym, MLV_Keyboard_modifier* mod, int* unicode,
int* mouse_x, int* mouse_y
);
/** \~french
* \brief Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche
* du clavier, sur le bouton gauche de la souris ou qu'un certain nombre
* de secondes passées en paramètres se soient écoulées.
*
* Cette fonction renvoie un entier codant le type de l'évènement qui a été
* récupéré ( clavier, souris ou aucun des deux ).
*
* Voir les fonctions MLV_wait_keyboard_seconds() et MLV_wait_mouse_seconds()
* pour plus d'informations.
*
* \bug Voir les bugs de la fonction MLV_get_event().
*
* \param sym Code de la touche qui a été appuyée ou relachée. La valeur de ce
* champs est définie par l'énumération : MLV_Keyboard_button.
* \param mod Mode dans lequel se trouve le clavier lorsqu'une touche est
* appuyée ou relachée. La valeur de ce champs est définie par
* l'énumération : MLV_Keyboard_modifier.
* \param unicode Caractère codé en unicode de la lettre obtenue en combinant le
* code et le mode précédent
* \param mouse_x Coordonnée en X de la position de la souris
* \param mouse_y Coordonnée en Y de la position de la souris
* \param seconds Le nombre de seconde à attendre avant d'arrêter la fonction
* \return un entier codant le type de l'évènement qui a été récupéré ( MLV_KEY
* ou MLV_MOUSE_BUTTON ), ou MLV_NONE si le temps s'est écoulé.
*/
MLV_Event MLV_wait_keyboard_or_mouse_or_seconds(
MLV_Keyboard_button* sym, MLV_Keyboard_modifier* mod, int* unicode,
int* mouse_x, int* mouse_y,
int seconds
);
/** \~french
* \brief Convertit le code d'un évènement en une chaîne de caractères.
*
* \param event_code le code de l'évènement
* \return La chaîne de caractères associée au code de l'évènement.
*/
const char* MLV_convert_event_to_string( MLV_Event event_code );
/** \~french
* \brief Convertit le nom d'un évènement en son code associé.
*
* \param event_string le nom de l'évènement.
* \return Le code de l'évènement associé à la chaîne de caractères.
*/
MLV_Event MLV_convert_string_to_event( const char* event_string );
/** \~french
* \brief Convertit le code d'un état en une chaîne de caractères.
*
* \param state_code le code de l'état
* \return La chaîne de caractères associée au code de l'état.
*/
const char* MLV_convert_button_state_to_string( MLV_Button_state state_code );
/** \~french
* \brief Convertit le nom d'un état en son code associé.
*
* \param state_string le nom de l'état.
* \return Le code de l'état associé à la chaîne de caractères.
*/
MLV_Button_state MLV_convert_string_to_button_state( const char* state_string );
#ifdef __cplusplus
}
#endif
#endif

623
MLV/MLV_image.h Normal file
View File

@@ -0,0 +1,623 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_image.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit tous les prototypes concernant les fonctions
* permettant d'insérer des images.
*/
#ifndef __MLV__MLV_IMAGE_H__
#define __MLV__MLV_IMAGE_H__
#include "MLV_color.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Définit le type Image dans la bibliothèque MLV.
*
* Une image dans la bibliothèque MLV est un tableau à deux dimentions
* dont chaque entée contient une couleur (voir MLV_Color).
* Nous rapellons que dans MLV les couleurs sont définies à l'aide de 4
* entiers compris entre 0 et 256 exclu, que l'on appelle composantes :
* - la composante Rouge ( R );
* - la composante Verte ( G );
* - la composant Blue ( B );
* - la composante Alpha, c'est la transparence ( A ).
*
*/
typedef struct _MLV_Image MLV_Image;
/** \~french
* \brief Charge en mémoire une image contenue dans un fichier.
*
* Cette fonction permet de charger les images des formats suivants:
* ICO(Icon)/CUR(Cursor)/BMP, PNM (PPM/PGM/PBM), XPM, LBM(IFF ILBM), PCX, GIF,
* JPEG, PNG, TGA, TIFF, and XV.
*
* \bug Cette fonction provoque une erreur de segmentation si elle est utilisée
* avant MLV_create_window(). Pour l'instant, nous vous conseillons
* d'utiliser cette fonction apres MLV_create_window().
*
* \bug Il est possible que cette fonction n'arrive pas à charger correctement
* les images qui ne sont pas en 32 bits (RGBA) - bug à tester.
*
* \bug BUG PRESENT SOUS WINDOWS ET MACOS X : Lorsque la composante alpha d'un
* pixel est à 0, MLV_load_image met à 0 les composantes Rouge, Verte
* et bleue du pixel associé. Ce bug provient de la bibliothèque SDL_image.
*
* \param file_image Chemin d'accès du fichier contenant l'image.
* \return L'image chargée.
*/
MLV_Image* MLV_load_image( const char* file_image );
/** \~french
* \brief Sauvegarde une image dans une fichier BMP.
*
* \bug Cette fonction ne sauvegarde pas la composante alpha.
*
* \param image Image à sauvegarder
* \param file_image Chemin d'accès du fichier contenant l'image.
* \return 0 si c'est un succés, -1 s'il y a eut une erreur.
*/
int MLV_save_image_as_bmp( const MLV_Image* image, const char* file_image );
/** \~french
* \brief Créer une image de composante alpha opaque.
*
* \param width Largeur de l'image
* \param height Hauteur de l'image
* \return L'image créé.
*/
MLV_Image* MLV_create_image( int width, int height );
/** \~french
* \brief Libère la mémoire utilisée par l'image.
*
* \param image Image à supprimer de la mémoire
*/
void MLV_free_image( MLV_Image *image );
/** \~french
* \brief Copie une image.
*
* Cette fonction créé une nouvelle image qui est la copie conforme de l'image
* passée en paramètre.
* La gestion de la mémoire de l'image créée est laissée à l'utilisateur.
*
* \param image L'image à copier.
* \return La copie de l'image.
*/
MLV_Image* MLV_copy_image( const MLV_Image* image );
/** \~french
* \brief Copie une partie de l'image.
*
* Cette fonction créé une nouvelle image qui est la copie conforme d'une partie
* de l'image passée en paramètre.
* La gestion de la mémoire de l'image créée est laissée à l'utilisateur.
*
* \param image L'image à copier.
* \param x Abscisse du sommet Nord-Ouest de la partie de l'image à copier
* \param y Ordonnée du sommet Nord-Ouest de la partie de l'image à copier
* \param width Largeur de la partie de l'image à copier
* \param height Hauteur de la partie de l'image à copier
* \return La copie de l'image.
*/
MLV_Image* MLV_copy_partial_image(
const MLV_Image* image, int x, int y, int width, int height
);
/** \~french
* \brief Retourne la taille d'une image donnée.
*
* \param image L'image pour laquelle la fonction doit retourner sa taille.
* \param width La largeur de l'image.
* \param height La hauteur de l'image.
*/
void MLV_get_image_size( const MLV_Image* image, int* width, int* height );
/** \~french
* \brief Retourne la largeur d'une image donnée.
*
* \param image L'image à analyser.
* \return La largeur de l'image.
*/
int MLV_get_image_width( const MLV_Image* image );
/** \~french
* \brief Retourne la hauteur d'une image donnée.
*
* \param image L'image à analyser.
* \return La hauteur de l'image
*/
int MLV_get_image_height( const MLV_Image* image );
/** \~french
* \brief Redimensionne l'image en ne respectant pas les proportions de l'image
* originale.
*
* La hauteur et la largeur de la nouvelle image deviennent respectivement la
* hauteur et la largeur passées en paramètres.
*
* \param image L'image à redimentionner.
* \param width La largeur de l'image.
* \param height La hauteur de l'image.
*/
void MLV_resize_image( MLV_Image* image, int width, int height );
/** \~french
* \brief Modifie l'image en réalisant une réflexion verticale.
*
* \param image L'image à modifier.
*/
void MLV_vertical_image_mirror( MLV_Image* image );
/** \~french
* \brief Modifie l'image en réalisant une réflexion horizontale.
*
* \param image L'image à modifier.
*/
void MLV_horizontal_image_mirror( MLV_Image* image );
/** \~french
* \brief Cette fonction redimensionne l'image en repsectant les proportions
* de l'image originale.
*
* L'image résultat est la plus grande image possible incluse dans le rectangle
* de largeur width et de hauteur height.
*
* L'utilisateur peut entrer un entier négatif pour les champs width et height.
* Ces champs ne sont alors pas pris en compte dans le redimensionnement de
* l'image. Dans ce cas, si le paramètre width (resp. height) est
* négatif, alors l'image finale aura pour largeur (resp. hauteur) la taille
* spécifiée dans le paramètre width (resp. height).
*
* \param image L'image à redimentionner.
* \param width La nouvelle largeur de l'image.
* \param height La nouvlle hauteur de l'image.
*/
void MLV_resize_image_with_proportions(
MLV_Image* image, int width, int height
);
/** \~french
* \brief Modifie l'image à l'aide d'une homotétie ( Étire l'image )
*
* \param image L'image à modifier.
* \param scalar Coefficient de proportionalité de l'homotétie ( >1 l'image est
* agrandie, <1 l'image est rétrécie ).
*/
void MLV_scale_image( MLV_Image* image, double scalar );
/** \~french
* \brief Éffectue une rotation sur une image donnée.
*
* \param image L'image à modifier.
* \param rotation L'angle de la rotation.
*/
void MLV_rotate_image( MLV_Image* image, double rotation );
/** \~french
* \brief Éffectue une rotation suivie d'une homotétie
*
* \param image L'image à modifier.
* \param rotation L'angle de la rotation.
* \param scalar Le coéfficient de proportionnalité de l'homotétie.
*/
void MLV_rotate_and_scale_image( MLV_Image* image, double rotation, double scalar );
/** \~french
* \brief Étire l'image suivant l'axe X et l'axe Y avec des coefficients de
* proportionnalité différents pour les deux axes.
*
* \param image L'image à modifier.
* \param scalar_x Le coéfficient de proportionnalité de l'axe X.
* \param scalar_y Le coéfficient de proportionnalité de l'axe Y.
*/
void MLV_scale_xy_image( MLV_Image* image, double scalar_x, double scalar_y );
/** \~french
* \brief Éffectue une rotation, puis étire l'image suivant l'axe X et l'axe Y
* avec des coefficients de proportionnalité différents pour les deux
* axes.
*
* \param image L'image à modifier.
* \param rotation L'angle de la rotaiton.
* \param scalar_x Le coéfficient de proportionnalité de l'axe X.
* \param scalar_y Le coéfficient de proportionnalité de l'axe Y.
*
*/
void MLV_rotate_and_scale_xy_image(
MLV_Image* image, double rotation, double scalar_x, double scalar_y
);
/** \~french
* \brief Dessine une image donnée à une position donnée de la fenêtre.
*
* \param image Image à dessiner.
* \param x Coordonnée en X de la position dans la fenêtre de sommet Nord-Ouest
* de l'image.
* \param y Coordonnée en Y de la position dans la fenêtre du sommet Nord-Ouest
* de l'image.
*/
void MLV_draw_image( const MLV_Image *image, int x, int y );
/** \~french
* \brief Dessine une partie d'une image donnée à une position donnée sur la
* fenêtre.
* \param image L'image à afficher sur la fenêtre
* \param x_source La coordonnée en X du sommet Nord-Ouest de la partie de
* l'image à afficher.
* \param y_source La coordonnée en Y du sommet Nord-Ouest de la partie de
* l'image à afficher.
* \param width_source La largeur de la partie de l'image à afficher.
* \param height_source La hauteur de la partie de l'image à afficher.
* \param x Coordonnée en X de la position dans la fenêtre du sommet Nord-Ouest
* de la partie de l'image à afficher.
* \param y Coordonnée en Y de la position dans la fenêtre du sommet Nord-Ouest
* de la partie de l'image à afficher.
*/
void MLV_draw_partial_image(
const MLV_Image *image, int x_source, int y_source,
int width_source, int height_source,
int x, int y
);
/** \~french
* \brief La composante alpha de l'image est remplacée par une composante
* alpha homogène dont la valeur est donnée en paramètre.
*
* La transparence joue un role lorsqu'une image est dessinée à l'écran, ou
* lorsqu'une image est recopiée à l'intérieure d'une autre image.
* Lorsque l'on recopie une image, les pixels du résultat final sont obtenus en
* faisant un barycentre entre le pixel de l'image source avec celui de l'image
* destination. Les poids des barycentres sont définis par la composante
* transparente ( composante alpha ) de l'image source.
* La transparence de l'image destination reste inchangée.
*
* Par exemple,
* \verbatim
couleur pixel source : RGBA( 60,80,100,128 )
couleur destination : RGBA( 0,20,40,30 )
couleur final après recopie :
RGBA(
barycentre( 60, 128, 0, 256-128 ),
barycentre( 80, 128, 20, 256-128 ),
barycentre( 100, 128, 40, 256-128 ),
30
) =
RGBA(
( 60 * 128 + 0 * (256-128) ) / 256,
( 80 * 128 + 20 * (256-128) ) / 256,
( 100 * 128 + 40 * (256-128) ) / 256,
30
) =
RGBA( 30, 50, 70, 30 )
\endverbatim
*
* \param image L'image à modifier.
* \param alpha La nouvelle composante alpha de l'image.
*/
void MLV_set_alpha_on_image( MLV_Alpha alpha, MLV_Image *image );
/** \~french
*
* \brief Écrase les composantes rouge, bleue, vert et alpha d'un pixel par
* celles passées en paramètre de la fonction.
*
* \param x La coordonnée en x du pixel à modifier.
* \param y La coordonnée en y du pixel à modifier.
* \param color La nouvelle couleur du pixel.
* \param image L'image à modifier.
*/
void MLV_set_pixel_on_image(
int x, int y,
MLV_Color color,
MLV_Image *image
);
/** \~french
* \brief Renvoie la couleur du pixel de l'écran pour une position donnée.
*
* Les paramètres red, blue, green et alpha peuvent être égaux à 0. Dans ce
* cas, ils sont ignorés.
*
* \param x Coordonnée en X de la position du pixel.
* \param y Coordonnée en Y de la position du pixel.
* \param red Composante rouge du pixel.
* \param green Composante verte du pixel.
* \param blue Composante bleue du pixel.
* \param alpha Composante alpha (transparence) du pixel.
*/
void MLV_get_pixel(
int x, int y, int* red, int* green, int* blue, int* alpha
);
/** \~french
* \brief Renvoie la couleur du pixel présent à une position donnée d'une image
* donnée.
*
* Les paramètres red, blue, green et alpha peuvent être égaux à NULL. Dans ce
* cas, ils sont ignorés.
*
* \param image Image à inspecter.
* \param x Coordonnée en X de la position du pixel à inspecter.
* \param y Coordonnée en Y de la position du pixel à inspecter.
* \param red Composante rouge du pixel.
* \param green Composante verte du pixel.
* \param blue Composante bleue du pixel.
* \param alpha Composante alpha (transparence) du pixel.
*/
void MLV_get_pixel_on_image(
const MLV_Image* image, int x, int y,
int* red, int* green, int* blue, int* alpha
);
/** \~french
* \brief Dessine une image dans une image destination
*
* \param source_image Image source
* \param source_x Abscisse du sommet nord-Ouest de la position de la portion
* d'image à recopier
* \param source_y Ordonné du sommet nord-Ouest de la position de la portion
* d'image à recopier
* \param width Largeur de la position à recopier
* \param height Hauteur de la position à recopier
* \param destination_image Image destination
* \param destination_x Abscisse de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
* \param destination_y Ordonnée de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
*/
void MLV_draw_partial_image_on_image(
const MLV_Image* source_image,
int source_x, int source_y,
int width, int height,
MLV_Image* destination_image,
int destination_x, int destination_y
);
/** \~french
* \brief Dessine une image dans une image destination
*
* \param source_image Image source
* \param destination_image Image destination
* \param destination_x Abscisse de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
* \param destination_y Ordonnée de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
*/
void MLV_draw_image_on_image(
const MLV_Image* source_image,
MLV_Image* destination_image,
int destination_x, int destination_y
);
/** \~french
* \brief Renvoie les données internes de l'image.
*
* Cette fonction renvoie un pointeur vers la structure de donnée
* de la libriaire SDL codant une image.
*
* N'utilisez cette fonction que si vous souhaitez effectuer une opération
* sur une image qui n'existe pas dans la bibliothèque MLV.
* En effet, modifier les données internes d'une image de type MLV_Image
* peut corrompre le fonctionnement de la bibliothèque MLV.
*
* Vous pouvez alors utiliser les routines de la lirairie SDL pour
* modifier l'image. (http://libsdl.org)
*
* Voici un exemple de code montrant comment il est possible de récupérer les
* composantes rouge, vert, bleu et alpha du pixel (3,4) de l'image.
*
* \code
* int x=3, y=4;
*
* SDL_Surface* surface = MLV_get_image_data( image );
* Uint32 red, blue, green, alpha;
*
* // Extracting color components from a 32-bit color value
* SDL_PixelFormat *fmt;
* Uint32 pixel;
*
* SDL_LockSurface(surface);
* fmt = surface->format;
* pixel = *(((Uint32*) surface->pixels)+ y*surface->pitch/4 + x );
*
* // Get Red component
* red = pixel & fmt->Rmask; // Isolate red component
* red = red >> fmt->Rshift; // Shift it down to 8-bit
* red = red << fmt->Rloss; // Expand to a full 8-bit number
*
* // Get Green component
* green = pixel & fmt->Gmask; // Isolate green component
* green = green >> fmt->Gshift; // Shift it down to 8-bit
* green = green << fmt->Gloss; // Expand to a full 8-bit number
*
* // Get Blue component
* blue = pixel & fmt->Bmask; // Isolate blue component
* blue = blue >> fmt->Bshift; // Shift it down to 8-bit
* blue = blue << fmt->Bloss; // Expand to a full 8-bit number
*
* // Get Alpha component
* alpha = pixel & fmt->Amask; // Isolate alpha component
* alpha = alpha >> fmt->Ashift; // Shift it down to 8-bit
* alpha = alpha << fmt->Aloss; // Expand to a full 8-bit number
*
* MLV_unlock_image( image );
* \endcode
*
* \param image L'image dont vous souhaitez récuperer les données internes.
* \return un pointeur vers une image de la bibliothèque SDL.
*/
SDL_Surface* MLV_get_image_data( MLV_Image* image );
/** \~french
* \brief Enregistre l'image de l'écran dans un presse papier interne à la
* bibliothèque MLV..
*
*/
void MLV_save_screen();
/** \~french
* \brief Charge l'image présent dans le presse papier interne de la bibliothèque
* MLV.
*
*/
void MLV_load_screen();
// TODO
#if 0
/** \~french
* \brief Enmére différents types d'opérations mathématiques.
*
*/
typedef enum {
MLV_NONE,
MLV_REPLACE,
MLV_MAX,
MLV_MIN,
MLV_BARYCENTER
} MLV_Mathematic_operations;
/** \~french
* \brief Dessine une image dans une image destination
*
* Cette fonction offre diférentes façon de dessiner une image
* dans une autre.
* Ces différentes façon concerne d'une part les couveh RGB
* ( rouge-vert-bleue) de l'image et d'autre part la couche alpha
* Les différentes façons sont décrites par les paramètres : rgb_treatment
* et alpha_treatment
* Voici un tableau récapitulatif des effets obtenus
* Opération ........ Éffet
* MLV_NONE ........ Les composante destination sont laissée intactes
* MLV_REPLACE ..... Les composantes contenues dans l'image destinatiion sont
* remplacées par celle de l'image source
* MLV_MAX ......... La composante maximale entre source et destination est
* stocké dans l'image destination
* MLV_MIN ......... La composante minimale entre source et destination est
* stocké dans l'image destination
* MLV_BARYCENTER .. Cette opération n'est définit que pour les composantes
* RGB. La composane destination est obtenu en faisant un
* barycentre entre l'image source et l'image destination
* en utilisant la composante alpha de l'image source.
*
*
* \param source_image Image source
* \param source_x Abscisse du sommet nord-Ouest de la position de la portion
* d'image à recopier
* \param source_y Ordonné du sommet nord-Ouest de la position de la portion
* d'image à recopier
* \param with Largeur de la position à recopier
* \param height Hauteur de la position à recopier
* \param destination_image Image destination
* \param destination_x Abscisse de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
* \param destination_y Ordonnée de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
* \param rgb_treatment Opération mathématique à appliquer pour traiter les
* composantes RGB de l'image
* \param alpha_treatment Opération mathématique à appliquer pour traiter la
* composante alpha de l'image
*/
void MLV_draw_partial_image_on_image(
const MLV_Image* source_image,
int source_x, int source_y,
int with, int height,
MLV_Image* destination_image,
int destination_x, int destination_y,
MLV_Mathematic_operations rgb_treatment,
MLV_Mathematic_operations alpha_treatment
);
/** \~french
* \brief Dessine une image dans une image destination en utilisant
* l'accélération de la carte graphique.
*
* Les couleurs RGB des images sources et destinations sont mélangé suivant
* les proportions préssentes dans la couches alpha de l'image" source.
* Par exemple, si pour un pixel de l'image, la composant alpha
* vaut 200, alors le pixal final sera composé à 200/255 de la couleur de
* l'image source et de 255-200/255 = 55/200 de l'image destination.
* La composant alpha de l'image destination reste inchangée.
*
* Cette opération est identique à
* MLV_draw_partial_image_on_image(
* X,X,X,X,X,X,X,X,
* MLV_BARYCENTER,
* MLV_NONE,
* );
* Cependant, MLV_draw_partial_image_on_image_FAST est un opération
* qui bénéficie d'optimisation par la carte graphique.
*
* \param source_image Image source
* \param source_x Abscisse du sommet nord-Ouest de la position de la portion
* d'image à recopier
* \param source_y Ordonné du sommet nord-Ouest de la position de la portion
* d'image à recopier
* \param with Largeur de la position à recopier
* \param height Hauteur de la position à recopier
* \param destination_image Image destination
* \param destination_x Abscisse de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
* \param destination_y Ordonnée de la position où devra être recopier l'image.
* Il s'agit de la futur position du sommet nord-Ouest de
* la portion d'image à recopier.
*/
void MLV_draw_partial_image_on_image_FAST(
const MLV_Image* source_image,
int source_x, int source_y,
int with, int height,
const MLV_Image* destination_image,
int destination_x, int destination_y
);
#endif
/* TODO : A Vérifier !
void MLV_draw_rotated_image( MLV_Image *image, int x, int y, double rotation );
void MLV_draw_scaled_image( MLV_Image *image, int x, int y, double scalar );
void MLV_draw_scaled_rotated_image( MLV_Image *image, int x, int y, double roation, double scalar );
*/
#ifdef __cplusplus
}
#endif
#endif

98
MLV/MLV_information.h Normal file
View File

@@ -0,0 +1,98 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_information.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant de récupérer
* des informations sur la bibliothèque.
*/
#ifndef __MLV__MLV_INFORMATIONS_H__
#define __MLV__MLV_INFORMATIONS_H__
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Renvoie le nom de la bibliothèque.
*
* \return Le nom de la bibliothèque.
*/
const char* MLV_get_package_name( );
/** \~french
* \brief Renvoie la version de la bibliothèque
*
* \return La version de la bibliothèque.
*/
const char* MLV_get_version( );
/** \~french
* \brief Renvoie la révision du dépot du logiciel de gestion de version de
* mlv.
*
* \return La révision du dépot du logiciel de gestion de version de mlv.
*/
const char* MLV_get_revision_of_revision_control_software( );
/** \~french
* \brief Renvoie l'adresse du dépot de code source où se trouve la
* bibliothèque.
*
* \return Le dépôt de la bibliothèque.
*/
const char* MLV_get_repository( );
/** \~french
* \brief Renvoie l'addresse mail à laquelle vous pouvez envoyer les bugs que
* vous rencontrez.
*
* \return L'addresse mail.
*/
const char* MLV_get_bug_report_address( );
/** \~french
* \brief Renvoie le nom de la licence de la bibliothèque.
*
* \return Le nom de la licence de la bibliothèque.
*/
const char* MLV_get_licence( );
/** \~french
* \brief Renvoie l'addresse internet où l'on peut trouver le code source de la
* bibliothèque.
*
* \return L'addresse internet où l'on peut trouver le code source de la
* bibliothèque.
*/
const char* MLV_get_web_distribution( );
#ifdef __cplusplus
}
#endif
#endif

317
MLV/MLV_input_box.h Normal file
View File

@@ -0,0 +1,317 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_input_box.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant de
* demander à l'utilisateur du texte par l'intermédiaire de boîtes
* de saisie.
*
*/
#ifndef __MLV__MLV_INPUT_BOX_H__
#define __MLV__MLV_INPUT_BOX_H__
#include "MLV_color.h"
#include "MLV_text.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Définition du type des boîtes de saisies
*
*/
typedef struct _MLV_Input_box MLV_Input_box;
/** \~french
*
* \brief Cette fonction suspend l'exécution du programme, affiche une boîte
* de saisie et attends que l'utilisateur rentre une phrase dans le
* champs de la boîte.
*
* La boîte de saisie contient deux zones de textes.
* La première zone ne peut pas être éditée par l'utilisateur et sert à
* afficher un message d'information.
* La deuxième est vide et peut être éditée par l'utilisateur.
* Lorsque l'utilisateur appuie sur la touche entrée, le texte qui
* se trouve dans la zone de texte est renvoyé par la fonction
* grâce au paramètre text.
* Le texte, la taille et les couleurs de la boîte de saisie sont
* paramétrables.
*
* MLV_wait_input_box() alloue lui même la mémoire associée au paramètre "text".
* Par contre, après utilisation, vous devez libérer l'espace mémoire qui a été
* alloué.
*
* \param sommetHautGaucheX La coordonnée en X du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetHautGaucheY La coordonnée en Y du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetBasDroitX La coordonnée en X du coin Sud-Est de la
* boîte de saisie.
* \param sommetBasDroitY La coordonnée en Y du coin Sud-Est de la
* boîte de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte de la boîte de saisie.
* \param backgroundColor La couleur de fond de la boîte de saisie.
* \param informativeMessage Le message à afficher devant la boîte de saisie.
* \param text L'addresse où sera placé la réponse donnée par
* l'utilisateur.
*/
void MLV_wait_input_box(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text, ...
);
/** \~french
*
* \brief Même chose que MLV_wait_input_box(), mais il est possible de
* changer la fonte du du texte.
*
* MLV_wait_input_box_with_font() alloue lui même la mémoire associée au
* paramètre "text".
* Par contre, après utilisation, vous devez libérer l'espace mémoire qui a
* été alloué.
*
* \param sommetHautGaucheX La coordonnée en X du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetHautGaucheY La coordonnée en Y du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetBasDroitX La coordonnée en X du coin Sud-Est de la boîte
* de saisie.
* \param sommetBasDroitY La coordonnée en Y du coin Sud-Est de la boîte
* de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte de la boîte de saisie.
* \param backgroundColor La couleur de fond de la boîte de saisie.
* \param informativeMessage Le message à afficher devant la boîte de saisie.
* \param text L'addresse où sera placé la réponse donnée par
* l'utilisateur.
* \param font La font du texte à utiliser.
*/
void MLV_wait_input_box_with_font(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text,
const MLV_Font* font, ...
);
/** \~french
* \brief Cette fonction suspend l'exécution du programme jusqu'à ce que
* l'utilisateur écrive une phrase dans le champs de la boîte de
* saisie passée en paramètre de la fonction.
*
* \param input_box La boîte de saisie qui doit être observée.
* \param text Le texte récupéré par la boîte de saisie.
*/
void MLV_wait_particular_input_box( MLV_Input_box* input_box, char** text);
/** \~french
* \brief Cette fonction créé une boîte de saisie.
*
* Une fois la boîte de saisie créé, si l'utilisateur clique sur la boîte
* de saisie, la boîte de saisie devient active.
* Cela veux dire que tout les évènements clavier sont récupérés par la
* boîte de saisie qui s'en sert pour enregistrer le texte tapé par
* l'utilisateur.
* De même, tout clique de souris réalisé sur la boîte de saisie est
* acaparé par la boîte de saisie.
*
* Pour dessiner une ou toutes les boîtes de saisies, dans la zone où vous
* les avez créées, vous devez utiliser les fonctions :
* - MLV_draw_input_box()
* - MLV_draw_all_input_boxes()
*
* \param sommetHautGaucheX La coordonnée en X du sommet Nord-Ouest de la boîte
* de saisie.
* \param sommetHautGaucheY La coordonnée en Y du sommet Nord-Ouest de la boîte
* de saisie.
* \param width La largeur de la boîte de saisie.
* \param height La hauteur de la boîte de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond.
* \param informativeMessage La message d'entête de la boîte de saisie.
*/
MLV_Input_box* MLV_create_input_box(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage, ...
);
/** \~french
* \brief Cette fonction créé une boîte de saisie avec une font spécifique.
*
* \param sommetHautGaucheX La coordonnée en X du sommet Nord-Ouest de la boîte de saisie.
* \param sommetHautGaucheY La coordonnée en Y du sommet Nord-Ouest de la boîte de saisie.
* \param width La largeur de la boîte de saisie.
* \param height La hauteur de la boîte de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond.
* \param informativeMessage Le message d'entête de la boîte de saisie.
* \param font La font à utiliser pour le texte.
*/
MLV_Input_box* MLV_create_input_box_with_font(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
const MLV_Font* font, ...
);
/** \~french
* \brief Cette fonction ferme une boîte de saisie précédement créée.
*
* L'espace mémoire allouée à la boîte de saisie est libéré.
*
* \param input_box La boîte de saisie à fermer.
*/
void MLV_free_input_box( MLV_Input_box* input_box );
/** \~french
* \brief Cette fonction change le message d'entête d'une boîte de saisie.
*
* \param input_box La boîte de saisie à modifier.
* \param message Le message d'entête.
*/
void MLV_change_informative_message_of_input_box(
MLV_Input_box* input_box, const char* message, ...
);
/** \~french
* \brief Cette fonction dessine une boîte de saisie particulière.
*
* \param input_box La boîte de saisie à dessiner.
*/
void MLV_draw_input_box( MLV_Input_box* input_box );
/** \~french
* \brief Cette fonction dessine tous les boîtes de saisies.
*
*/
void MLV_draw_all_input_boxes();
/** \~french
* \brief Cette fonction supprime l'historique d'une boîte de saisie.
*
* \param input_box La boîte de saisie dont l'histoirque doit être supprimé
*/
void MLV_suppress_history( MLV_Input_box* input_box );
/** \~french
* \brief Cette fonction change la taille et la position d'une boîte de saisie donnée en paramètre.
*
* \param input_box La boîte de saisie à modifier.
* \param sommetHautGaucheX La nouvelle coordonnée en X de la position du sommet
* Nord-Ouest de la boîte de saisie.
* \param sommetHautGaucheY La nouvelle coordonnée en Y de la position du sommet
* Nord-Ouest de la boîte de saisie.
* \param width La nouvelle largeur de la boîte de saisie.
* \param height La nouvelle hauteur de la boîte de saisie.
*/
void MLV_change_input_box_geometry(
MLV_Input_box* input_box, int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height
);
/** \~french
* \brief Cette fonction change la taille d'une boîte de saisie.
*
* \param input_box La boîte de saisie à modifier.
* \param width La nouvelle largeur de la boîte de saisie.
* \param height La nouvelle hauteur de la boîte de saisie.
*/
void MLV_change_input_box_size(MLV_Input_box* input_box, int width, int height);
/** \~french
* \brief Cette fonction change la position d'une boîte de saisie donnée en paramètre.
*
* \param input_box La boîte de saisie à modifier.
* \param sommetHautGaucheX La nouvelle coordonnée en X de la position du sommet
* Nord-Ouest de la boîte de saisie.
* \param sommetHautGaucheY La nouvelle coordonnée en Y de la position du sommet
* Nord-Ouest de la boîte de saisie.
*/
void MLV_change_input_box_position(
MLV_Input_box* input_box, int sommetHautGaucheX, int sommetHautGaucheY
);
/** \~french
* \brief Cette fonction change les différentes couleurs d'une boîte de saisie donnée
*
* \param input_box La boîte de saisie à modifier.
* \param borderColor La nouvelle couleur du bord de la boîte de saisie.
* \param textColor La nouvelle couleur du texte de la boîte de saisie.
* \param backgroundColor La nouvelle couleur de fond de la boîte de saisie.
*/
void MLV_change_input_box_colors(
MLV_Input_box* input_box, MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor
);
/** \~french
* \brief Cette fonction active une boîte de saisie.
*
* Cette opération agit comme si l'utilisateur avait cliqué sur la boîte de
* saisie en question (action qui rend active une boîte de saisie).
*
* Lorsque une boîte de saisie est active, les évènements du clavier sont
* récupérés par la boîte de saisie et sont utilisés pour enregistrer le
* texte tapé par l'utilisateur.
* Les cliques de souris sur la boîte de saisie sont aussi récupérés par
* la boîte de saisie.
*
* \param input_box La boîte de saisie à activer.
*/
void MLV_activate_input_box( MLV_Input_box* input_box );
/** \~french
* \brief Cette fonction désactive la boîte de saisie qui est active.
*
* Si il n'y a pas de boîte de saisie active, cette fonction ne fait rien.
*/
void MLV_desactivate_input_box( );
#ifdef __cplusplus
}
#endif
#endif

204
MLV/MLV_input_box_va.h Normal file
View File

@@ -0,0 +1,204 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2013-2014 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_input_box_va.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant de
* demander à l'utilisateur du texte par l'intermédiaire de boîtes
* de saisie.
*
*/
#ifndef __MLV__MLV_INPUT_BOX_VA_H__
#define __MLV__MLV_INPUT_BOX_VA_H__
#include "MLV_color.h"
#include "MLV_text.h"
#include "MLV_input_box.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
*
* \brief Cette fonction suspend l'exécution du programme, affiche une boîte
* de saisie et attends que l'utilisateur rentre une phrase dans le
* champs de la boîte.
*
* La boîte de saisie contient deux zones de textes.
* La première zone ne peut pas être éditée par l'utilisateur et sert à
* afficher un message d'information.
* La deuxième est vide et peut être éditée par l'utilisateur.
* Lorsque l'utilisateur appuie sur la touche entrée, le texte qui
* se trouve dans la zone de texte est renvoyé par la fonction
* grâce au paramètre text.
* Le texte, la taille et les couleurs de la boîte de saisie sont
* paramétrables.
*
* MLV_wait_input_box() alloue lui même la mémoire associée au paramètre "text".
* Par contre, après utilisation, vous devez libérer l'espace mémoire qui a été
* alloué.
*
* \param sommetHautGaucheX La coordonnée en X du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetHautGaucheY La coordonnée en Y du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetBasDroitX La coordonnée en X du coin Sud-Est de la
* boîte de saisie.
* \param sommetBasDroitY La coordonnée en Y du coin Sud-Est de la
* boîte de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte de la boîte de saisie.
* \param backgroundColor La couleur de fond de la boîte de saisie.
* \param informativeMessage Le message à afficher devant la boîte de saisie.
* \param text L'addresse où sera placé la réponse donnée par
* l'utilisateur.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*/
void MLV_wait_input_box_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text,
va_list pile
);
/** \~french
*
* \brief Même chose que MLV_wait_input_box(), mais il est possible de
* changer la fonte du du texte.
*
* MLV_wait_input_box_with_font() alloue lui même la mémoire associée au
* paramètre "text".
* Par contre, après utilisation, vous devez libérer l'espace mémoire qui a
* été alloué.
*
* \param sommetHautGaucheX La coordonnée en X du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetHautGaucheY La coordonnée en Y du coin Nord-Ouest de la
* boîte de saisie.
* \param sommetBasDroitX La coordonnée en X du coin Sud-Est de la boîte
* de saisie.
* \param sommetBasDroitY La coordonnée en Y du coin Sud-Est de la boîte
* de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte de la boîte de saisie.
* \param backgroundColor La couleur de fond de la boîte de saisie.
* \param informativeMessage Le message à afficher devant la boîte de saisie.
* \param text L'addresse où sera placé la réponse donnée par
* l'utilisateur.
* \param font La font du texte à utiliser.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*/
void MLV_wait_input_box_with_font_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text,
const MLV_Font* font,
va_list pile
);
/** \~french
* \brief Cette fonction créé une boîte de saisie.
*
* Une fois la boîte de saisie créé, si l'utilisateur clique sur la boîte
* de saisie, la boîte de saisie devient active.
* Cela veux dire que tout les évènements clavier sont récupérés par la
* boîte de saisie qui s'en sert pour enregistrer le texte tapé par
* l'utilisateur.
* De même, tout clique de souris réalisé sur la boîte de saisie est
* acaparé par la boîte de saisie.
*
* Pour dessiner une ou toutes les boîtes de saisies, dans la zone où vous
* les avez créées, vous devez utiliser les fonctions :
* - MLV_draw_input_box()
* - MLV_draw_all_input_boxes()
*
* \param sommetHautGaucheX La coordonnée en X du sommet Nord-Ouest de la boîte
* de saisie.
* \param sommetHautGaucheY La coordonnée en Y du sommet Nord-Ouest de la boîte
* de saisie.
* \param width La largeur de la boîte de saisie.
* \param height La hauteur de la boîte de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond.
* \param informativeMessage La message d'entête de la boîte de saisie.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*/
MLV_Input_box* MLV_create_input_box_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
va_list pile
);
/** \~french
* \brief Cette fonction créé une boîte de saisie avec une font spécifique.
*
* \param sommetHautGaucheX La coordonnée en X du sommet Nord-Ouest de la boîte de saisie.
* \param sommetHautGaucheY La coordonnée en Y du sommet Nord-Ouest de la boîte de saisie.
* \param width La largeur de la boîte de saisie.
* \param height La hauteur de la boîte de saisie.
* \param borderColor La couleur de la bordure de la boîte de saisie.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond.
* \param informativeMessage Le message d'entête de la boîte de saisie.
* \param font La font à utiliser pour le texte.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*/
MLV_Input_box* MLV_create_input_box_with_font_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
const MLV_Font* font,
va_list pile
);
/** \~french
* \brief Cette fonction change le message d'entête d'une boîte de saisie.
*
* \param input_box La boîte de saisie à modifier.
* \param message Le message d'entête.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*/
void MLV_change_informative_message_of_input_box_va(
MLV_Input_box* input_box, const char* message, va_list pile
);
#ifdef __cplusplus
}
#endif
#endif

545
MLV/MLV_keyboard.h Normal file
View File

@@ -0,0 +1,545 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_keyboard.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant
* d'utiliser le clavier.
*
*/
#ifndef __MLV__MLV_KEYBOARD_H__
#define __MLV__MLV_KEYBOARD_H__
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
#include "MLV_device_with_buttons.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Énumère l'ensemble des codes des touches du clavier
*/
typedef enum {
MLV_KEYBOARD_NONE = SDLK_UNKNOWN,
MLV_KEYBOARD_UNKNOWN = SDLK_UNKNOWN,
MLV_KEYBOARD_FIRST = SDLK_FIRST,
MLV_KEYBOARD_BACKSPACE = SDLK_BACKSPACE,
MLV_KEYBOARD_TAB = SDLK_TAB,
MLV_KEYBOARD_CLEAR = SDLK_CLEAR,
MLV_KEYBOARD_RETURN = SDLK_RETURN,
MLV_KEYBOARD_PAUSE = SDLK_PAUSE,
MLV_KEYBOARD_ESCAPE = SDLK_ESCAPE,
MLV_KEYBOARD_SPACE = SDLK_SPACE,
MLV_KEYBOARD_EXCLAIM = SDLK_EXCLAIM,
MLV_KEYBOARD_QUOTEDBL = SDLK_QUOTEDBL,
MLV_KEYBOARD_HASH = SDLK_HASH,
MLV_KEYBOARD_DOLLAR = SDLK_DOLLAR,
MLV_KEYBOARD_AMPERSAND = SDLK_AMPERSAND,
MLV_KEYBOARD_QUOTE = SDLK_QUOTE,
MLV_KEYBOARD_LEFTPAREN = SDLK_LEFTPAREN,
MLV_KEYBOARD_RIGHTPAREN = SDLK_RIGHTPAREN,
MLV_KEYBOARD_ASTERISK = SDLK_ASTERISK,
MLV_KEYBOARD_PLUS = SDLK_PLUS,
MLV_KEYBOARD_COMMA = SDLK_COMMA,
MLV_KEYBOARD_MINUS = SDLK_MINUS,
MLV_KEYBOARD_PERIOD = SDLK_PERIOD,
MLV_KEYBOARD_SLASH = SDLK_SLASH,
MLV_KEYBOARD_0 = SDLK_0,
MLV_KEYBOARD_1 = SDLK_1,
MLV_KEYBOARD_2 = SDLK_2,
MLV_KEYBOARD_3 = SDLK_3,
MLV_KEYBOARD_4 = SDLK_4,
MLV_KEYBOARD_5 = SDLK_5,
MLV_KEYBOARD_6 = SDLK_6,
MLV_KEYBOARD_7 = SDLK_7,
MLV_KEYBOARD_8 = SDLK_8,
MLV_KEYBOARD_9 = SDLK_9,
MLV_KEYBOARD_COLON = SDLK_COLON,
MLV_KEYBOARD_SEMICOLON = SDLK_SEMICOLON,
MLV_KEYBOARD_LESS = SDLK_LESS,
MLV_KEYBOARD_EQUALS = SDLK_EQUALS,
MLV_KEYBOARD_GREATER = SDLK_GREATER,
MLV_KEYBOARD_QUESTION = SDLK_QUESTION,
MLV_KEYBOARD_AT = SDLK_AT,
MLV_KEYBOARD_LEFTBRACKET = SDLK_LEFTBRACKET,
MLV_KEYBOARD_BACKSLASH = SDLK_BACKSLASH,
MLV_KEYBOARD_RIGHTBRACKET = SDLK_RIGHTBRACKET,
MLV_KEYBOARD_CARET = SDLK_CARET,
MLV_KEYBOARD_UNDERSCORE = SDLK_UNDERSCORE,
MLV_KEYBOARD_BACKQUOTE = SDLK_BACKQUOTE,
MLV_KEYBOARD_a = SDLK_a,
MLV_KEYBOARD_b = SDLK_b,
MLV_KEYBOARD_c = SDLK_c,
MLV_KEYBOARD_d = SDLK_d,
MLV_KEYBOARD_e = SDLK_e,
MLV_KEYBOARD_f = SDLK_f,
MLV_KEYBOARD_g = SDLK_g,
MLV_KEYBOARD_h = SDLK_h,
MLV_KEYBOARD_i = SDLK_i,
MLV_KEYBOARD_j = SDLK_j,
MLV_KEYBOARD_k = SDLK_k,
MLV_KEYBOARD_l = SDLK_l,
MLV_KEYBOARD_m = SDLK_m,
MLV_KEYBOARD_n = SDLK_n,
MLV_KEYBOARD_o = SDLK_o,
MLV_KEYBOARD_p = SDLK_p,
MLV_KEYBOARD_q = SDLK_q,
MLV_KEYBOARD_r = SDLK_r,
MLV_KEYBOARD_s = SDLK_s,
MLV_KEYBOARD_t = SDLK_t,
MLV_KEYBOARD_u = SDLK_u,
MLV_KEYBOARD_v = SDLK_v,
MLV_KEYBOARD_w = SDLK_w,
MLV_KEYBOARD_x = SDLK_x,
MLV_KEYBOARD_y = SDLK_y,
MLV_KEYBOARD_z = SDLK_z,
MLV_KEYBOARD_DELETE = SDLK_DELETE,
MLV_KEYBOARD_WORLD_0 = SDLK_WORLD_0,
MLV_KEYBOARD_WORLD_1 = SDLK_WORLD_1,
MLV_KEYBOARD_WORLD_2 = SDLK_WORLD_2,
MLV_KEYBOARD_WORLD_3 = SDLK_WORLD_3,
MLV_KEYBOARD_WORLD_4 = SDLK_WORLD_4,
MLV_KEYBOARD_WORLD_5 = SDLK_WORLD_5,
MLV_KEYBOARD_WORLD_6 = SDLK_WORLD_6,
MLV_KEYBOARD_WORLD_7 = SDLK_WORLD_7,
MLV_KEYBOARD_WORLD_8 = SDLK_WORLD_8,
MLV_KEYBOARD_WORLD_9 = SDLK_WORLD_9,
MLV_KEYBOARD_WORLD_10 = SDLK_WORLD_10,
MLV_KEYBOARD_WORLD_11 = SDLK_WORLD_11,
MLV_KEYBOARD_WORLD_12 = SDLK_WORLD_12,
MLV_KEYBOARD_WORLD_13 = SDLK_WORLD_13,
MLV_KEYBOARD_WORLD_14 = SDLK_WORLD_14,
MLV_KEYBOARD_WORLD_15 = SDLK_WORLD_15,
MLV_KEYBOARD_WORLD_16 = SDLK_WORLD_16,
MLV_KEYBOARD_WORLD_17 = SDLK_WORLD_17,
MLV_KEYBOARD_WORLD_18 = SDLK_WORLD_18,
MLV_KEYBOARD_WORLD_19 = SDLK_WORLD_19,
MLV_KEYBOARD_WORLD_20 = SDLK_WORLD_20,
MLV_KEYBOARD_WORLD_21 = SDLK_WORLD_21,
MLV_KEYBOARD_WORLD_22 = SDLK_WORLD_22,
MLV_KEYBOARD_WORLD_23 = SDLK_WORLD_23,
MLV_KEYBOARD_WORLD_24 = SDLK_WORLD_24,
MLV_KEYBOARD_WORLD_25 = SDLK_WORLD_25,
MLV_KEYBOARD_WORLD_26 = SDLK_WORLD_26,
MLV_KEYBOARD_WORLD_27 = SDLK_WORLD_27,
MLV_KEYBOARD_WORLD_28 = SDLK_WORLD_28,
MLV_KEYBOARD_WORLD_29 = SDLK_WORLD_29,
MLV_KEYBOARD_WORLD_30 = SDLK_WORLD_30,
MLV_KEYBOARD_WORLD_31 = SDLK_WORLD_31,
MLV_KEYBOARD_WORLD_32 = SDLK_WORLD_32,
MLV_KEYBOARD_WORLD_33 = SDLK_WORLD_33,
MLV_KEYBOARD_WORLD_34 = SDLK_WORLD_34,
MLV_KEYBOARD_WORLD_35 = SDLK_WORLD_35,
MLV_KEYBOARD_WORLD_36 = SDLK_WORLD_36,
MLV_KEYBOARD_WORLD_37 = SDLK_WORLD_37,
MLV_KEYBOARD_WORLD_38 = SDLK_WORLD_38,
MLV_KEYBOARD_WORLD_39 = SDLK_WORLD_39,
MLV_KEYBOARD_WORLD_40 = SDLK_WORLD_40,
MLV_KEYBOARD_WORLD_41 = SDLK_WORLD_41,
MLV_KEYBOARD_WORLD_42 = SDLK_WORLD_42,
MLV_KEYBOARD_WORLD_43 = SDLK_WORLD_43,
MLV_KEYBOARD_WORLD_44 = SDLK_WORLD_44,
MLV_KEYBOARD_WORLD_45 = SDLK_WORLD_45,
MLV_KEYBOARD_WORLD_46 = SDLK_WORLD_46,
MLV_KEYBOARD_WORLD_47 = SDLK_WORLD_47,
MLV_KEYBOARD_WORLD_48 = SDLK_WORLD_48,
MLV_KEYBOARD_WORLD_49 = SDLK_WORLD_49,
MLV_KEYBOARD_WORLD_50 = SDLK_WORLD_50,
MLV_KEYBOARD_WORLD_51 = SDLK_WORLD_51,
MLV_KEYBOARD_WORLD_52 = SDLK_WORLD_52,
MLV_KEYBOARD_WORLD_53 = SDLK_WORLD_53,
MLV_KEYBOARD_WORLD_54 = SDLK_WORLD_54,
MLV_KEYBOARD_WORLD_55 = SDLK_WORLD_55,
MLV_KEYBOARD_WORLD_56 = SDLK_WORLD_56,
MLV_KEYBOARD_WORLD_57 = SDLK_WORLD_57,
MLV_KEYBOARD_WORLD_58 = SDLK_WORLD_58,
MLV_KEYBOARD_WORLD_59 = SDLK_WORLD_59,
MLV_KEYBOARD_WORLD_60 = SDLK_WORLD_60,
MLV_KEYBOARD_WORLD_61 = SDLK_WORLD_61,
MLV_KEYBOARD_WORLD_62 = SDLK_WORLD_62,
MLV_KEYBOARD_WORLD_63 = SDLK_WORLD_63,
MLV_KEYBOARD_WORLD_64 = SDLK_WORLD_64,
MLV_KEYBOARD_WORLD_65 = SDLK_WORLD_65,
MLV_KEYBOARD_WORLD_66 = SDLK_WORLD_66,
MLV_KEYBOARD_WORLD_67 = SDLK_WORLD_67,
MLV_KEYBOARD_WORLD_68 = SDLK_WORLD_68,
MLV_KEYBOARD_WORLD_69 = SDLK_WORLD_69,
MLV_KEYBOARD_WORLD_70 = SDLK_WORLD_70,
MLV_KEYBOARD_WORLD_71 = SDLK_WORLD_71,
MLV_KEYBOARD_WORLD_72 = SDLK_WORLD_72,
MLV_KEYBOARD_WORLD_73 = SDLK_WORLD_73,
MLV_KEYBOARD_WORLD_74 = SDLK_WORLD_74,
MLV_KEYBOARD_WORLD_75 = SDLK_WORLD_75,
MLV_KEYBOARD_WORLD_76 = SDLK_WORLD_76,
MLV_KEYBOARD_WORLD_77 = SDLK_WORLD_77,
MLV_KEYBOARD_WORLD_78 = SDLK_WORLD_78,
MLV_KEYBOARD_WORLD_79 = SDLK_WORLD_79,
MLV_KEYBOARD_WORLD_80 = SDLK_WORLD_80,
MLV_KEYBOARD_WORLD_81 = SDLK_WORLD_81,
MLV_KEYBOARD_WORLD_82 = SDLK_WORLD_82,
MLV_KEYBOARD_WORLD_83 = SDLK_WORLD_83,
MLV_KEYBOARD_WORLD_84 = SDLK_WORLD_84,
MLV_KEYBOARD_WORLD_85 = SDLK_WORLD_85,
MLV_KEYBOARD_WORLD_86 = SDLK_WORLD_86,
MLV_KEYBOARD_WORLD_87 = SDLK_WORLD_87,
MLV_KEYBOARD_WORLD_88 = SDLK_WORLD_88,
MLV_KEYBOARD_WORLD_89 = SDLK_WORLD_89,
MLV_KEYBOARD_WORLD_90 = SDLK_WORLD_90,
MLV_KEYBOARD_WORLD_91 = SDLK_WORLD_91,
MLV_KEYBOARD_WORLD_92 = SDLK_WORLD_92,
MLV_KEYBOARD_WORLD_93 = SDLK_WORLD_93,
MLV_KEYBOARD_WORLD_94 = SDLK_WORLD_94,
MLV_KEYBOARD_WORLD_95 = SDLK_WORLD_95,
MLV_KEYBOARD_KP0 = SDLK_KP0,
MLV_KEYBOARD_KP1 = SDLK_KP1,
MLV_KEYBOARD_KP2 = SDLK_KP2,
MLV_KEYBOARD_KP3 = SDLK_KP3,
MLV_KEYBOARD_KP4 = SDLK_KP4,
MLV_KEYBOARD_KP5 = SDLK_KP5,
MLV_KEYBOARD_KP6 = SDLK_KP6,
MLV_KEYBOARD_KP7 = SDLK_KP7,
MLV_KEYBOARD_KP8 = SDLK_KP8,
MLV_KEYBOARD_KP9 = SDLK_KP9,
MLV_KEYBOARD_KP_PERIOD = SDLK_KP_PERIOD,
MLV_KEYBOARD_KP_DIVIDE = SDLK_KP_DIVIDE,
MLV_KEYBOARD_KP_MULTIPLY = SDLK_KP_MULTIPLY,
MLV_KEYBOARD_KP_MINUS = SDLK_KP_MINUS,
MLV_KEYBOARD_KP_PLUS = SDLK_KP_PLUS,
MLV_KEYBOARD_KP_ENTER = SDLK_KP_ENTER,
MLV_KEYBOARD_KP_EQUALS = SDLK_KP_EQUALS,
MLV_KEYBOARD_UP = SDLK_UP,
MLV_KEYBOARD_DOWN = SDLK_DOWN,
MLV_KEYBOARD_RIGHT = SDLK_RIGHT,
MLV_KEYBOARD_LEFT = SDLK_LEFT,
MLV_KEYBOARD_INSERT = SDLK_INSERT,
MLV_KEYBOARD_HOME = SDLK_HOME,
MLV_KEYBOARD_END = SDLK_END,
MLV_KEYBOARD_PAGEUP = SDLK_PAGEUP,
MLV_KEYBOARD_PAGEDOWN = SDLK_PAGEDOWN,
MLV_KEYBOARD_F1 = SDLK_F1,
MLV_KEYBOARD_F2 = SDLK_F2,
MLV_KEYBOARD_F3 = SDLK_F3,
MLV_KEYBOARD_F4 = SDLK_F4,
MLV_KEYBOARD_F5 = SDLK_F5,
MLV_KEYBOARD_F6 = SDLK_F6,
MLV_KEYBOARD_F7 = SDLK_F7,
MLV_KEYBOARD_F8 = SDLK_F8,
MLV_KEYBOARD_F9 = SDLK_F9,
MLV_KEYBOARD_F10 = SDLK_F10,
MLV_KEYBOARD_F11 = SDLK_F11,
MLV_KEYBOARD_F12 = SDLK_F12,
MLV_KEYBOARD_F13 = SDLK_F13,
MLV_KEYBOARD_F14 = SDLK_F14,
MLV_KEYBOARD_F15 = SDLK_F15,
MLV_KEYBOARD_NUMLOCK = SDLK_NUMLOCK,
MLV_KEYBOARD_CAPSLOCK = SDLK_CAPSLOCK,
MLV_KEYBOARD_SCROLLOCK = SDLK_SCROLLOCK,
MLV_KEYBOARD_RSHIFT = SDLK_RSHIFT,
MLV_KEYBOARD_LSHIFT = SDLK_LSHIFT,
MLV_KEYBOARD_RCTRL = SDLK_RCTRL,
MLV_KEYBOARD_LCTRL = SDLK_LCTRL,
MLV_KEYBOARD_RALT = SDLK_RALT,
MLV_KEYBOARD_LALT = SDLK_LALT,
MLV_KEYBOARD_RMETA = SDLK_RMETA,
MLV_KEYBOARD_LMETA = SDLK_LMETA,
MLV_KEYBOARD_LSUPER = SDLK_LSUPER,
MLV_KEYBOARD_RSUPER = SDLK_RSUPER,
MLV_KEYBOARD_MODE = SDLK_MODE,
MLV_KEYBOARD_COMPOSE = SDLK_COMPOSE,
MLV_KEYBOARD_HELP = SDLK_HELP,
MLV_KEYBOARD_PRINT = SDLK_PRINT,
MLV_KEYBOARD_SYSREQ = SDLK_SYSREQ,
MLV_KEYBOARD_BREAK = SDLK_BREAK,
MLV_KEYBOARD_MENU = SDLK_MENU,
MLV_KEYBOARD_POWER = SDLK_POWER,
MLV_KEYBOARD_EURO = SDLK_EURO,
MLV_KEYBOARD_UNDO = SDLK_UNDO,
MLV_KEYBOARD_LAST = SDLK_LAST
} MLV_Keyboard_button;
/** \~french
* \brief Énumère l'ensemble des codes associées aux différents modes du clavier
*/
typedef enum {
MLV_KEYBOARD_KMOD_NONE = KMOD_NONE,
MLV_KEYBOARD_KMOD_LSHIFT = KMOD_LSHIFT,
MLV_KEYBOARD_KMOD_RSHIFT = KMOD_RSHIFT,
MLV_KEYBOARD_KMOD_LCTRL = KMOD_LCTRL,
MLV_KEYBOARD_KMOD_RCTRL = KMOD_RCTRL,
MLV_KEYBOARD_KMOD_LALT = KMOD_LALT,
MLV_KEYBOARD_KMOD_RALT = KMOD_RALT,
MLV_KEYBOARD_KMOD_LMETA = KMOD_LMETA,
MLV_KEYBOARD_KMOD_RMETA = KMOD_RMETA,
MLV_KEYBOARD_KMOD_NUM = KMOD_NUM,
MLV_KEYBOARD_KMOD_CAPS = KMOD_CAPS,
MLV_KEYBOARD_KMOD_MODE = KMOD_MODE,
MLV_KEYBOARD_KMOD_RESERVED = KMOD_RESERVED
} MLV_Keyboard_modifier;
/** \~french
* \brief Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche
* du clavier.
*
* Lorsque l'utilisateur appuie sur une touche, la fonction remplit le contenu
* des trois paramètres sym, mod et unicode correspondant respectivement au
* code de la touche, au mode dans lequel se trouve le clavier
* (majuscule etc ...) et au caractère unicode obtenu en combinant le mode du
* clavier et le code de la touche appuyée.
*
* La fonction accepte des valeurs nulles pour les pointeurs sym, mod et
* unicode.
* Dans ce cas la fonction ignore les champs en questions.
*
* \bug Voir les bugs de la fonction MLV_get_event().
*
* \param sym Le code de la touche.
* \param mod Le mode dans lequel se trouve le clavier.
* \param unicode Le caractère codé en unicode de la lettre obtenue en combinant
* le code et le mode précédent.
*/
void MLV_wait_keyboard( MLV_Keyboard_button* sym, MLV_Keyboard_modifier* mod, int* unicode );
/** \~french
* \brief Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche
* du clavier ou jusq'à ce q'un nombre de secondes passées en paramètres
* soient écoulées.
*
* Pour plus d'informations sur le fonctionnement de cette fonction, veuillez
* vous reporter à la documentation de MLV_wait_keyboard().
*
* La fonction accepte des valeurs nulles pour les pointeurs sym, mod et
* unicode.
* Dans ce cas la fonction ignore les champs en questions.
*
* \bug Voir les bugs de la fonction MLV_get_event().
*
* \param sym Le code de la touche.
* \param mod Le mode dans lequel se trouve le clavier.
* \param unicode Le caractère codé en unicode de la lettre obtenue en combinant
* le code et le mode précédent.
* \param seconds Le nombre de secondes à attendre.
* \return Renvoie 1 si l'utilisateur a utilisé le calvier, 0 si le temps s'est
* écoulé.
*/
int MLV_wait_keyboard_or_seconds(
MLV_Keyboard_button* sym, MLV_Keyboard_modifier* mod, int* unicode, int seconds
);
/** \~french
* \brief Renvoie le code de la touche clavier correspondant au type clavier
* passé en paramètre.
*
* \param key_string La chaine de caractères codant le type de la touche.
*
* \return Le code de la touche clavier.
*/
MLV_Keyboard_button MLV_convert_string_to_keyboard_button( const char* key_string );
/** \~french
* \brief Renvoie la chaîne de caractères correspondant au code de la touche
* passé en paramètre.
*
* \param key_code Le code de la touche.
*
* \return La chaine de caractères codant le code de la touche.
*/
const char* MLV_convert_keyboard_button_to_string( MLV_Keyboard_button key_code );
/** \~french
* \brief Renvoie la chaîne de caractères correspondant au mode du clavier
* passé en paramètre.
*
* \param keymod_code Le code du mode.
*
* \return La chaine de caractères codant le mode du clavier.
*/
char* MLV_convert_keyboard_mod_to_string( MLV_Keyboard_modifier keymod_code );
/** \~french
*
* \brief Renvoie l'état (préssé ou relaché) d'une touche donnée d'un clavier.
*
* \param keyboard_code Le code de la touche dont il faut renvoyer l'état.
* \return L'état de la touche.
*/
MLV_Button_state MLV_get_keyboard_state( MLV_Keyboard_button keyboard_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison shift du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison shift a été appuyée.
*/
int MLV_shift_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison shift gauche du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison shift gauche a été appuyée.
*/
int MLV_left_shift_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison shift droit du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison shift droit a été appuyée.
*/
int MLV_right_shift_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison ctrl gauche du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison ctrl gauche a été appuyée.
*/
int MLV_left_ctrl_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison ctrl droit du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison ctrl droit a été appuyée.
*/
int MLV_right_ctrl_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison ctrl du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison ctrl a été appuyée.
*/
int MLV_ctrl_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison alt gauche du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison alt gauche a été appuyée.
*/
int MLV_left_alt_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison alt droit du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison alt droit a été appuyée.
*/
int MLV_right_alt_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison alt du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison alt a été appuyée.
*/
int MLV_alt_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison meta gauche du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison meta gauche a été appuyée.
*/
int MLV_left_meta_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison meta droit du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison meta droit a été appuyée.
*/
int MLV_right_meta_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison meta du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison meta a été appuyée.
*/
int MLV_meta_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison num du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison num a été appuyée.
*/
int MLV_num_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison cpas du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison caps a été appuyée.
*/
int MLV_caps_key_was_pressed( MLV_Keyboard_modifier modifier_code );
/** \~french
*
* \brief Renvoie vrai si le code, passé en paramètre, correspond à l'état appuyé de la touche de combinaison mode du clavier.
*
* \param modifier_code Le code de la touche de combinaison.
* \return Vrai, si la touche de cobinaison mode a été appuyée.
*/
int MLV_mode_key_was_pressed( MLV_Keyboard_modifier modifier_code );
#ifdef __cplusplus
}
#endif
#endif

127
MLV/MLV_mouse.h Normal file
View File

@@ -0,0 +1,127 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_mouse.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions qui permettent
* d'utiliser la souris.
*
*/
#ifndef __MLV__MLV_MOUSE_H__
#define __MLV__MLV_MOUSE_H__
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
#include "MLV_device_with_buttons.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Énumère les différents bouttons de la souris
*
*/
typedef enum{
MLV_BUTTON_LEFT = SDL_BUTTON_LEFT, /**< \~french Bouton gauche de la souris */
MLV_BUTTON_MIDDLE = SDL_BUTTON_MIDDLE, /**< \~french Bouton du milieu de la souris */
MLV_BUTTON_RIGHT = SDL_BUTTON_RIGHT /**< \~french Bouton droit de la souris */
} MLV_Mouse_button;
/** \~french
*
* \brief Suspend l'exécution jusqu'à ce que l'utilisateur clique sur le bouton
* gauche de la souris.
*
* Au moment où l'utilisateur clique, la fonction retourne les
* coordonnées de la position de la souris dans la fenêtre.
*
* \param x Coordonnée en X de la position de la souris dans la fenêtre.
* \param y Coordonnée en Y de la position de la souris dans la fenêtre.
*/
void MLV_wait_mouse(int *x, int *y);
/** \~french
*
* \brief Suspend l'exécution jusqu'à ce que l'utilisateur clique sur le bouton
* gauche de la souris où jusqu'à ce qu'un nombre de secondes, passé en
* paramètres, se soient écoulées.
*
* Au moment où l'utilisateur clique, la fonction retourne les
* coordonnées de la position de la souris dans la fenêtre.
*
* \param x Coordonnée en X de la position de la souris dans la fenêtre.
* \param y Coordonnée en Y de la position de la souris dans la fenêtre.
* \param seconds Le nombre de second à attendre avant de quitter la fonction.
* \return Renvoie 1 si l'utilisateur a cliqué avec le bouton gauche de la souris,
* et 0 si le temps s'est écoulé.
*/
int MLV_wait_mouse_or_seconds(int *x, int *y, int seconds);
/** \~french
* \brief Convertit le code associé à un boutton de la souris (MLV_Mouse_button) en
* chaîne de caratères.
*
* \param button_code Le code du bouton.
* \return La chaîne de caratères correspondant au code du boutton de la
* souris passé en paramètre.
*/
const char* MLV_convert_mouse_button_to_string( MLV_Mouse_button button_code );
/** \~french
* \brief Convertit une chaîne de caractères en un code bouton.
*
* \param button_string La chaîne de caractères à convertir.
* \return Le code bouton associé à la chaîne de caractères.
*/
MLV_Mouse_button MLV_convert_string_to_mouse_button( const char* button_string );
/** \~french
*
* \brief Renvoie la position courante de la souris.
*
* \param x Coordonnée en X de la position de la souris dans la fenêtre.
* \param y Coordonnée en Y de la position de la souris dans la fenêtre.
*/
void MLV_get_mouse_position( int* x, int* y );
/** \~french
*
* \brief Renvoie l'état (préssé ou relaché) d'un bouton de la souris.
*
* \param mouse_button Le code du bouton de la souris
* \return L'état du bouton.
*/
MLV_Button_state MLV_get_mouse_button_state( MLV_Mouse_button mouse_button );
#ifdef __cplusplus
}
#endif
#endif

172
MLV/MLV_path.h Normal file
View File

@@ -0,0 +1,172 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_path.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant de
* manipuler les chemins d'accès aux fichiers et répertoires.
*
*/
#ifndef __MLV__MLV_PATH_H__
#define __MLV__MLV_PATH_H__
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Renvoie la chaîne de caractères après le dernier séparteur / dans un
* chemin donné en paramètre.
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \param path Le chemin à analyser.
* \return Une chaîne de caractères.
*/
char* MLV_get_base_name( const char* path );
/** \~french
*
* \brief Renvoie la chaîne de caractères s'étendant jusqu'au dernier séparateur
* / du chemin donné en paramètre.
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \param path Le chemin à analyser.
* \return Une chaîne de caractères.
*/
char* MLV_get_directory_name( const char* path );
/** \~french
* \brief Teste si un chemin est absolu.
*
* \param path Le chemin
* \return Renvoie 1 si le chemin est absolue, 0 sinon.
*/
int MLV_path_is_absolute( const char* path );
/** \~french
* \brief Teste si un chemin est relatif.
*
* \param path Le chemin
* \return Renoie 1 si le chemin est relatif, 0 sinon.
*/
int MLV_path_is_relative( const char* path );
/** \~french
*
* \brief Teste si le chemin corespond au chemin d'un fichier ou dossier
* existant.
*
* \param path Le chemin
* \return Renvoie 1 si le chemin est associé à un dossier ou à un fichier
* existant, 0 sinon.
*/
int MLV_path_exists( const char* path );
/** \~french
* \brief Vérifie si un chemin est associé à un répertoire.
*
* \param path Le chemin
* \return Renvoie 1 si le chemin est associé à un dossier, 0 sinon.
*/
int MLV_path_is_a_directory( const char* path );
/** \~french
* \brief Vérifie si un chemin est associé à un fichier.
*
* \param path Le chemin
* \return Renvoie 1 si le chemin est associé à un fichier, 0 sinon.
*/
int MLV_path_is_a_file( const char* path );
/** \~french
* \brief Construit en concaténant différents textes, une chaîne de caractères
* représentant un chemin dont les séparateurs corespondent aux
* spécifications de la plateforme sur laquel s'exécute le programme.
*
* \bug Cette fonction ne fait que concaténer les differentes chaînes en
* mettant entre chaque chaîne un séparateur de répertoire compatible
* avec le système d'exploitation. Par contre, ce qui constitue le bug, il
* ne convertit pas chaque chaîne dans un format compatible avec celui du
* système d'exploitation.
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \param first_element La première chaîne à concaténer.
* \param ... Les autres éléments à concaténer.
* \return Le chemin vérifiant les normes de la plateforme hôte.
*/
char* MLV_build_path( const char* first_element, ... );
/** \~french
* \brief Même chose que MLV_build_path
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \param elements Les éléments à concaténer ensemble.
* \return Le chemin vérifiant les normes de la plateforme qui va exécuter
* le programme.
*/
char* MLV_build_path_v( char** elements );
/** \~french
* \brief Détermine le répertoire courant.
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \return Le chemin du répertoire courant.
*/
char * MLV_get_current_directory( );
/** \~french
* \brief Détermine le répertoire temporaire.
*
* Le répertoire temporaire est le répertoire dans lequel les applications
* ont le droit d'ajouter et de modifier des fichiers.
* Ce répertoire est génaralement vidé lorsque la machine est étteinte.
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \return Le chemin du répertoire temporaire.
*/
const char * MLV_get_temporary_directory( );
/** \~french
* \brief Détermine le répertoire personnel de l'utilisateur courant.
*
* La chaîne de caractères doit être désallouée après utilisation.
*
* \return Le chemin du répertoire personnel.
*/
const char * MLV_get_home_directory( );
#ifdef __cplusplus
}
#endif
#endif

58
MLV/MLV_playlist.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__MLV_PLAYLIST_H__
#define __MLV__MLV_PLAYLIST_H__
#include "MLV_audio.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _MLV_Playlist MLV_Playlist;
void MLV_init_playlists();
void MLV_close_playlists();
MLV_Playlist* MLV_create_playlist( int loop );
void MLV_close_playlist( MLV_Playlist* playlist );
void MLV_playlist_add( MLV_Playlist* playlist, const char* file_music );
void MLV_playlist_add_sheet_music( MLV_Playlist* playlist, MLV_Music* );
void MLV_playlist_remove( MLV_Playlist* playlist, int index );
void MLV_playlist_clear( MLV_Playlist* playlist );
void MLV_playlist_volume( MLV_Playlist* playlist, double volume );
void MLV_playlist_play( MLV_Playlist* playlist );
void MLV_playlist_pause( MLV_Playlist* playlist );
void MLV_playlist_stop( MLV_Playlist* playlist );
void MLV_playlist_next( MLV_Playlist* playlist );
void MLV_playlist_previous( MLV_Playlist* playlist );
void MLV_playlist_first( MLV_Playlist* playlist );
void MLV_playlist_last( MLV_Playlist* playlist );
void MLV_playlist_index( MLV_Playlist* playlist, int index);
#ifdef __cplusplus
}
#endif
#endif

70
MLV/MLV_random.h Executable file
View File

@@ -0,0 +1,70 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_random.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit tous les prototypes des fonctions concernant
* la manipulation des nombres aléatoires.
*
*/
#ifndef __MLV__MLV_RANDOM_H__
#define __MLV__MLV_RANDOM_H__
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Renvoie 0 ou 1 aléatoirement.
*
* \return 0 ou 1 aléatoirement.
*/
int MLV_get_random_boolean();
/** \~french
* \brief Renvoie un entier aléatoire choisi dans un intervalle donné en
* paramètre.
*
* \param begin Borne inférieur de l'intervalle ( inclusif )
* \param end Borne supérieur de l'intervalle ( inclusif )
* \return Un entier aléatoire choisi dans l'intervalle [begin, end].
*/
int MLV_get_random_integer(int begin, int end);
/** \~french
* \brief Renvoie un réel aléatoire choisi dans un intervalle donné en
* paramètre.
*
* \param begin Borne inférieur de l'intervalle ( inclusif )
* \param end Borne supérieur de l'intervalle ( inclusif )
* \return Un réel aléatoire choisi dans l'intervalle [begin, end].
*/
double MLV_get_random_double(double begin, double end);
#ifdef __cplusplus
}
#endif
#endif

414
MLV/MLV_shape.h Normal file
View File

@@ -0,0 +1,414 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_shape.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit tout les prototypes des fonctions permettant de
* dessiner des figures.
*
*
*/
#ifndef __MLV__MLV_FIGURES_H__
#define __MLV__MLV_FIGURES_H__
#include "MLV_color.h"
#include "MLV_image.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Dessine un cercle à une position et un rayon spécifiés en paramètres.
**
* \param x La coordonnée en X du centre.
* \param y La coordonnée en Y du centre.
* \param radius Le rayon du cercle.
* \param color La couleur du tracé.
*/
void MLV_draw_circle(int x, int y, int radius, MLV_Color color);
/** \~french
* \brief Dessine un disque plein dont le centre et le rayon sont passés en
* paramètres.
*
* \param x La coordonnée en X du centre.
* \param y La coordonnée en Y du centre.
* \param radius Le rayon du cercle.
* \param color La couleur du tracé.
*/
void MLV_draw_filled_circle(int x, int y, int radius, MLV_Color color);
/** \~french
* \brief Dessine une ellipse.
*
* \param x La coordonnée en X du centre de l'ellipse.
* \param y La coordonnée en Y du centre de l'ellipse.
* \param radius_x Le rayon en X de l'ellipse.
* \param radius_y Le rayon en Y de l'ellipse.
* \param color La couleur du tracé.
*/
void MLV_draw_ellipse(
int x, int y, int radius_x, int radius_y, MLV_Color color
);
/** \~french
* \brief Dessine une ellipse pleine.
*
* \param x La coordonnée en X du centre de l'ellipse.
* \param y La coordonnée en Y du centre de l'ellipse.
* \param radius_x Le rayon en X de l'ellipse.
* \param radius_y Le rayon en Y de l'ellipse.
* \param color La couleur du tracé.
*/
void MLV_draw_filled_ellipse(
int x, int y, int radius_x, int radius_y, MLV_Color color
);
/** \~french
* \brief Dessine un polygone à partir d'une liste de sommets.
*
* \param vx La liste des coordonnées en X des différents sommets du polygone.
* \param vy La liste des coordonnées en Y des différents sommets du polygone.
* \param nb_points Le nombre de sommets du polygone.
* \param color La couleur du tracé.
*/
void MLV_draw_polygon(
const int* vx, const int* vy, int nb_points, MLV_Color color
);
/** \~french
* \brief Dessine un polygone plein à partir d'une liste de sommets.
*
* \param vx La liste des coordonnées en X des différents sommets du polygone.
* \param vy La liste des coordonnées en Y des différents sommets du polygone.
* \param nb_points Le nombre de sommets du polygone.
* \param color La couleur du tracé.
*/
void MLV_draw_filled_polygon(
const int* vx, const int* vy, int nb_points, MLV_Color color
);
/** \~french
* \brief Dessine une courbe de Bézier à partir d'une liste de sommets.
*
* \param vx La liste des coordonnées en X des différents sommets de la courbe.
* \param vy La liste des coordonnées en Y des différents sommets de la courbe.
* \param nb_points Le nombre de sommets disponibles pour dessiner la courbe de
* Bézier.
* \param color La couleur du tracé.
*/
void MLV_draw_bezier_curve(
const int* vx, const int* vy, int nb_points, MLV_Color color
);
/** \~french
* \brief Dessine un polygone plein à partir d'une liste de sommets.
*
* \param vx La liste des coordonnées en X des différents sommets du polygone.
* \param vy La liste des coordonnées en Y des différents sommets du polygone.
* \param nb_points Le nombre de sommets du polygone.
* \param color La couleur du tracé.
*/
void MLV_draw_filled_polygon(
const int* vx, const int* vy, int nb_points, MLV_Color color
);
/** \~french
* \brief Dessine un rectangle dont la taille, la couleur et la position du
* sommet Nord-Ouest sont données en paramètres.
*
* \param x La coordonnée en X du sommet Nord-Ouest du rectangle.
* \param y La coordonnée en Y du sommet Nord-Ouest du rectangle.
* \param width La largeur du rectangle.
* \param height La hauteur du rectangle.
* \param color La couleur du tracé.
*/
void MLV_draw_rectangle(int x, int y, int width, int height, MLV_Color color);
/** \~french
* \brief Dessine un rectangle dont la taille, la couleur et la position du
* sommet Nord-Ouest sont données en paramètres.
*
* \param x La coordonnée en X du sommet Nord-Ouest du rectangle.
* \param y La coordonnée en Y du sommet Nord-Ouest du rectangle.
* \param width La largeur du rectangle.
* \param height La hauteur du rectangle.
* \param color La couleur du tracé.
*/
void MLV_draw_rectangle(int x, int y, int width, int height, MLV_Color color);
/** \~french
* \brief Dessine un rectangle plein dont la taille, la couleur et la position
* du sommet Nord-Ouest sont données en paramètres.
*
* \param x La coordonnée en X du sommet Nord-Ouest du rectangle.
* \param y La coordonnée en Y du sommet Nord-Ouest du rectangle.
* \param width La largeur du rectangle.
* \param height La hauteur du rectangle.
* \param color La couleur du tracé.
*/
void MLV_draw_filled_rectangle(
int x, int y, int width, int height, MLV_Color color
);
/** \~french
* \brief Dessine une ligne.
*
* \param x1 La coordonnée en X de la première extrémité de la ligne.
* \param y1 La coordonnée en Y de la première extrémité de la ligne.
* \param x2 La coordonnée en X de la deuxième extrémité de la ligne.
* \param y2 La coordonnée en Y de la deuxième extrémité de la ligne.
* \param color La couleur du tracé.
*/
void MLV_draw_line(int x1, int y1, int x2, int y2, MLV_Color color);
/** \~french
* \brief Dessine un pixel dont les coordonnées sont passées en paramètres.
*
* \param x La coordonnée en X du pixel.
* \param y La coordonnée en Y du pixel.
* \param color La couleur du tracé.
*/
void MLV_draw_pixel(int x, int y, MLV_Color color);
/** \~french
* \brief Dessine un point dont les coordonnées sont passées en paramètres.
* Cette fonction est identique à MLV_draw_pixel.
*
* \param x La coordonnée en X du point.
* \param y La coordonnée en Y du point.
* \param color La couleur du tracé.
*/
void MLV_draw_point(int x, int y, MLV_Color color);
///////////////////////////////////////////////////////////////////////////////
// Drawing operation on images //
///////////////////////////////////////////////////////////////////////////////
/** \~french
* \brief Dessine un cercle à une position et un rayon spécifiés en paramètres
* dans une image.
*
* \param x La coordonnée en X du centre.
* \param y La coordonnée en Y du centre.
* \param radius Le rayon du cercle.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_circle_on_image(
int x, int y, int radius, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un disque plein dont le centre et le rayon sont passés en
* parametres dans une image.
*
* \param x La coordonnée en X du centre.
* \param y La coordonnée en Y du centre.
* \param radius Le rayon du cercle.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_filled_circle_on_image(
int x, int y, int radius, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine une ellipse dans une image.
*
* \param x La coordonnée en X du centre de l'ellipse.
* \param y La coordonnée en Y du centre de l'ellipse.
* \param radius_x Le rayon en X de l'ellipse.
* \param radius_y Le rayon en Y de l'ellipse.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_ellipse_on_image(
int x, int y, int radius_x, int radius_y, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine une ellipse pleine dans une image.
*
* \param x La coordonnée en X du centre de l'ellipse.
* \param y La coordonnée en Y du centre de l'ellipse.
* \param radius_x Le rayon en X de l'ellipse.
* \param radius_y Le rayon en Y de l'ellipse.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_filled_ellipse_on_image(
int x, int y, int radius_x, int radius_y, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un polygone à partir d'une liste de sommets dans une image.
*
* \param vx La liste des coordonnées en X des différents sommets du polygone.
* \param vy La liste des coordonnées en Y des différents sommets du polygone.
* \param nb_points Le nombre de sommets du polygone.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_polygon_on_image(
const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un polygone plein à partir d'une liste de sommets dans une
* image.
*
* \param vx La liste des coordonnées en X des différents sommets du polygone.
* \param vy La liste des coordonnées en Y des différents sommets du polygone.
* \param nb_points Le nombre de sommets du polygone.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_filled_polygon_on_image(
const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine une courbe de Bézier à partir d'une liste de sommets dans une
* image.
*
* \param vx La liste des coordonnées en X des différents sommets de la courbe.
* \param vy La liste des coordonnées en Y des différents sommets de la courbe.
* \param nb_points Le nombre de sommets disponibles pour dessiner la courbe de
* Bézier.
* \param color La couleur du tracé.
* \param image image dans laquelle la figure est dessinée
*/
void MLV_draw_bezier_curve_on_image(
const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un polygone plein à partir d'une liste de sommets dans une
* image.
*
* \param vx La liste des coordonnées en X des différents sommets du polygone.
* \param vy La liste des coordonnées en Y des différents sommets du polygone.
* \param nb_points Le nombre de sommets du polygone.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée
*/
void MLV_draw_filled_polygon_on_image(
const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un rectangle dont la taille, la couleur et la position du
* sommet Nord-Ouest sont données en paramètres dans une image.
*
* \param x La coordonnée en X du sommet Nord-Ouest du rectangle.
* \param y La coordonnée en Y du sommet Nord-Ouest du rectangle.
* \param width La largeur du rectangle.
* \param height La hauteur du rectangle.
* \param color La couleur du rectangle.
* \param image L'image dans laquelle la figure est dessinée .
*/
void MLV_draw_rectangle_on_image(
int x, int y, int width, int height, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un rectangle dont la taille, la couleur et la position du
* sommet Nord-Ouest sont données en paramètres dans une image.
*
* \param x La coordonnée en X du sommet Nord-Ouest du rectangle.
* \param y La coordonnée en Y du sommet Nord-Ouest du rectangle.
* \param width La largeur du rectangle.
* \param height La hauteur du rectangle.
* \param color La couleur du rectangle.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_rectangle_on_image(
int x, int y, int width, int height, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un rectangle plein dont la taille, la couleur et la position
* du sommet Nord-Ouest sont données en paramètres dans une image.
*
* \param x La coordonnée en X du sommet Nord-Ouest du rectangle.
* \param y La coordonnée en Y du sommet Nord-Ouest du rectangle.
* \param width La largeur du rectangle.
* \param height La hauteur du rectangle.
* \param color La couleur du rectangle.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_filled_rectangle_on_image(
int x, int y, int width, int height, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine une ligne dans une image.
*
* \param x1 La coordonnée en X de la première extrémité de la ligne.
* \param y1 La coordonnée en Y de la première extrémité de la ligne.
* \param x2 La coordonnée en X de la deuxième extrémité de la ligne.
* \param y2 La coordonnée en Y de la deuxième extrémité de la ligne.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_line_on_image(
int x1, int y1, int x2, int y2, MLV_Color color, MLV_Image* image
);
/** \~french
* \brief Dessine un pixel dont les coordonnées sont passées en paramètres dans
* une image.
*
* \param x Coordonnée en X du pixel
* \param y Coordonnée en Y du pixel
* \param color Couleur du tracé
* \param image image dans laquelle la figure est dessinée
*/
void MLV_draw_pixel_on_image(int x, int y, MLV_Color color, MLV_Image* image);
/** \~french
* \brief Dessine un point dont les coordonnées sont passées en paramètres.
* Cette fonction est identique à MLV_draw_pixel dans une image.
*
* \param x La coordonnée en X du point.
* \param y La coordonnée en Y du point.
* \param color La couleur du tracé.
* \param image L'image dans laquelle la figure est dessinée.
*/
void MLV_draw_point_on_image(int x, int y, MLV_Color color, MLV_Image* image);
#ifdef __cplusplus
}
#endif
#endif

489
MLV/MLV_text.h Normal file
View File

@@ -0,0 +1,489 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_text.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les différents prototypes des fonctions permmettant
* d'afficher du texte et des boîtes de dialogues.
*/
#ifndef __MLV__MLV_TEXT_H__
#define __MLV__MLV_TEXT_H__
#include "MLV_color.h"
#include "MLV_image.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Énumère les différents types de justification du texte.
*/
typedef enum {
MLV_TEXT_CENTER, /**< \~french Le texte est justifié au centre. */
MLV_TEXT_LEFT, /**< \~french Le texte est justifié sur la gauche. */
MLV_TEXT_RIGHT /**< \~french Le texte est justifié sur la doite. */
} MLV_Text_justification;
/** \~french
* \brief Énumère les différents types de position horizontale du texte dans une boîte.
*/
typedef enum {
MLV_HORIZONTAL_CENTER, /**< \~french Le texte est centrée horizontalement
* dans la boîte. */
MLV_HORIZONTAL_LEFT, /**< \~french Le texte est positioné sur la droite de
* la boîte. */
MLV_HORIZONTAL_RIGHT /**< \~french Le texte est positioné sur la gauche de
* la boîte. */
} MLV_Horizontal_position;
/** \~french
* \brief Énumère les différents types de positions verticales du texte dans une boîte.
*/
typedef enum {
MLV_VERTICAL_CENTER, /**< \~french Le texte est centré horizonatalement
* dans la boîte. */
MLV_VERTICAL_TOP, /**< \~french Le texte est positionné en haut de la
* boîte. */
MLV_VERTICAL_BOTTOM /**< \~french Le texte est positionné en bas de la
* boîte. */
} MLV_Vertical_position;
/** \~french
* Ce type code une fonte de caractères.
*/
typedef struct _MLV_Font MLV_Font;
/** \~french
* \brief Cette fonction charge en mémoire une fonte de caractères de standard
* "TrueType" (fichiers ayant une extension .ttf).
*
* La fonte de caractères chargée est configurée avec une taille de fonte
* donnée en paramètre.
*
* \param file_font Le chemin d'accés où se trouve le fichier contenant la
* fonte de caractères.
* \param size La taille de la fonte de caractères.
* \return La structure de donnée MLV contenant la fonte de caractères.
*/
MLV_Font* MLV_load_font( const char* file_font, int size );
/** \~french
* \brief Cette fonction libère la mémoire d'une fonte de caractères
* précédement chargée.
*
* \param font L'adresse de la fonte de caractères à libérer.
*/
void MLV_free_font( MLV_Font* font );
/** \~french
* \brief Cette fonction calcule la taille du texte qui sera affiché sur
* l'écran à l'aide de la fonction MLV_draw_text().
*
* \param text Le texte qui doit être affiché.
* \param width La largeur du texte.
* \param height La hauteur du texte.
*/
void MLV_get_size_of_text( const char *text, int *width, int *height, ... );
/** \~french
* \brief Cette fonction calcule la taille du texte qui sera affiché sur
* l'écran à l'aide de la fonction MLV_draw_text_with_font().
*
* \param text Le texte qui doit être affiché.
* \param width La largeur du texte.
* \param height La hauteur du texte.
* \param font La fonte de caractères utilisée pour afficher le texte.
*/
void MLV_get_size_of_text_with_font(
const char *text, int *width, int *height, const MLV_Font* font, ...
);
/** \~french
* \brief Imprime un texte donné à une position et une couleur données.
*
* Le texte est imprimé à l'aide de la fonte de caractères par default de la
* bibliothèque MLV.
*
* \param x Coordonnée en X du coin Nord-Ouest du texte
* \param y Coordonnée en Y du coin Nord-Ouest du texte
* \param text texte à afficher
* \param color couleur du tracé
*/
void MLV_draw_text( int x, int y, const char *text, MLV_Color color, ... );
/** \~french
* \brief Écrit du texte sur l'écran en utilisant une couleur et une fonte de
* caractères données en paramètres.
*
* \param x La coordonnée en X du coin Nord-Ouest du texte.
* \param y La coordonnée en Y du coin Nord-Ouest du texte.
* \param text Le texte à afficher.
* \param color La couleur du tracé.
* \param font La fonte de caractères utilisée pour dessiner le texte.
*/
void MLV_draw_text_with_font(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color, ...
);
/** \~french
* \brief Écrit sur une image un texte donné à une position et une couleur
* données.
*
* Le texte est imprimé à l'aide de la fonte de caractères par default de la
* bibliothèque MLV.
*
* \param x La coordonnée en X du coin Nord-Ouest du texte.
* \param y La coordonnée en Y du coin Nord-Ouest du texte.
* \param text Le texte à afficher.
* \param color La couleur du tracé.
* \param image L'image sur laquel le texte doit être ecrit.
*/
void MLV_draw_text_on_image(
int x, int y, const char *text, MLV_Color color, MLV_Image* image, ...
);
/** \~french
* \brief Écrit du texte sur une image en utilisant une couleur et une fonte de
* caractères données en paramètres.
*
* \param x La coordonnée en X du coin Nord-Ouest du texte.
* \param y La coordonnée en Y du coin Nord-Ouest du texte.
* \param text Le texte à afficher.
* \param color La couleur du tracé.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param image L'image sur laquel le texte doit être ecrit.
*/
void MLV_draw_text_with_font_on_image(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color,
MLV_Image* image, ...
);
/** \~french
* \brief Dessine une boîte contenant du texte.
*
* La taille de la boîte dessinée s'adapte à la
* taille du texte.
* Les différentes couleurs de la boîte et du texte,
* ainsi que la taille de l'interligne du texte sont
* paramétrables.
*
* Il est possible de préciser la justification du texte à l'aide du
* paramètre "text_justification".
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param borderColor La couleur des bordures.
* \param sizeInterligne La taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
*/
void MLV_draw_adapted_text_box(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification, ...
);
/** \~french
* \brief Même chose que MLV_draw_adapted_text_box() mis à part que le texte est
* rendu avec une fonte de caractères donnée en paramètre.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param borderColor La couleur des bordures.
* \param sizeInterligne La taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param image L'image sur laquel le texte doit être ecrit.
*/
void MLV_draw_adapted_text_box_on_image(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, ...
);
/** \~french
* \brief Cette fonction calcule la taille de la boîte de texte qui serait
* obtenue si vous utilisez la fonction : MLV_draw_adapted_text_box().
*
* \param message Le texte qui sera affiché lorsque vous utiliserez
* MLV_draw_adapted_text_box().
* \param sizeInterligne La taille de l'interligne.
* \param result_width La largeur de la boîte que vous obtiendrez en
* utilisant MLV_draw_adapted_text_box().
* \param result_height La hauteur de la boîte que vous obtiendrez en
* utilisant MLV_draw_adapted_text_box().
*
* \return La fonction renvoie la taille de la boîte de texte.
*/
int MLV_get_size_of_adapted_text_box(
const char* message,
int sizeInterligne,
int *result_width, int *result_height,
...
);
/** \~french
* \brief Même chose que MLV_draw_adapted_text_box() mis à part que le texte est
* rendu avec une fonte de caractères donnée en paramètre.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param borderColor La couleur des bordures.
* \param sizeInterligne La taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
*/
void MLV_draw_adapted_text_box_with_font(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification, ...
);
/** \~french
* \brief Même chose que MLV_draw_adapted_text_box_with_font() mis à part que
* le texte est rendu sur une image et non directement à l'écran.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param borderColor La couleur des bordures.
* \param sizeInterligne Le taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param image L'image sur laquel le texte doit être ecrit.
*/
void MLV_draw_adapted_text_box_with_font_on_image(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, ...
);
/** \~french
* \brief Cette fonction calcule la taille de la boîte de texte qui serait
* obtenue si vous utilisez la fonction :
* MLV_draw_adapted_text_box_with_font().
*
* \param message Le texte qui sera affiché lorsque vous utiliserez
* MLV_draw_adapted_text_box_with_font().
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param sizeInterligne La taille de l'interligne.
* \param result_width La largeur de la boîte que vous obtiendrez en utilisant
* MLV_draw_adapted_text_box_with_font().
* \param result_height La hauteur de la boîte que vous obtiendrez en utilisant
* MLV_draw_adapted_text_box_with_font().
*
* \return La fonction renvoie la taille de la boîte de texte.
*/
int MLV_get_size_of_adapted_text_box_with_font(
const char* message,
const MLV_Font* font,
int sizeInterligne,
int *result_width, int *result_height,
...
);
/** \~french
* \brief Dessine une boîte de taille donnée par l'utilisateur et contenant un
* texte donné par l'utilisateur.
*
* Le texte est déssiné à l'interieur d'une boîte. Le texte est imprimé sur
* plusieurs lignes en respectant les retours à la ligne présents dans le texte.
*
* Les différentes couleurs de la boîte et du texte, ainsi que la taille de
* l'interligne du texte sont paramétrables.
*
* Il est possible de préciser la justification du texte contenu dans la boîte.
*
* De même , il est possible de préciser la position du texte à l'intérieur de
* la boîte.
*
* Cette fonction ne remet pas en forme le texte. Cela veux dire que si le texte
* est trop grand, alors il dépassera de la boîte et les parties qui depassent
* ne seront pas affichées.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
*/
void MLV_draw_text_box(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
...
);
/** \~french
* \brief Même chose que MLV_draw_text_box() mis à part que le texte n'est pas
* écrit directement sur l'écran, mais sur une image à la place.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
* \param image L'image sur laquel le texte doit être ecrit.
*/
void MLV_draw_text_box_on_image(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
...
);
/** \~french
* \brief Même chose que la fonction MLV_draw_text_box() mis à part que le texte
* est rendu avec une fonte de caractères donnée en paramètre par
* l'utilisateur.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
*/
void MLV_draw_text_box_with_font(
int x, int y,
int width, int height,
const char* message ,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
...
);
/** \~french
* \brief Même chose que la fonction MLV_draw_text_box_with_font() mis à part que
* le texte n'est pas dessinné directement sur l'ecran, mais sur une
* une image.
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param font La fonte caractères utilisée pour dessiner le texte.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
* \param image L'image sur laquel le texte doit être ecrit.
*/
void MLV_draw_text_box_with_font_on_image(
int x, int y,
int width, int height,
const char* message ,
MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
...
);
/** \~french
* \brief Transforme un caractère en format unicode en chaîne de caractères
* compatible avec le codage local (codage utilisé par la machine qui
* exécute le programme).
*
* Après utilisation, vous devez libérer l'espace mémoire de la chaîne de
* caractères renvoyée par la fonction.
*
* \param unicode Le caractère en format unicode.
* \return Un pointeur vers une nouvelle chaîne de caractères.
*/
char* MLV_convert_unicode_to_string( int unicode );
#ifdef __cplusplus
}
#endif
#endif

516
MLV/MLV_text_va.h Normal file
View File

@@ -0,0 +1,516 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2013-2014 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_text_va.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit différents prototypes des fonctions permmettant
* d'afficher du texte et des boîtes de dialogues.
*/
#ifndef __MLV__MLV_TEXT_VA_H__
#define __MLV__MLV_TEXT_VA_H__
#include "MLV_color.h"
#include "MLV_image.h"
#include "MLV_text.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Imprime un texte donné à une position et une couleur données.
*
* Cette fonction est équivalente à la fonction MLV_draw_text() à l'exception
* qu'elle est apellée avec un paramètre de type va_list à la place d'une
* nombre variable d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text()
*
* \param x Coordonnée en X du coin Nord-Ouest du texte
* \param y Coordonnée en Y du coin Nord-Ouest du texte
* \param text texte à afficher
* \param color couleur du tracé
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_va(
int x, int y, const char *text, MLV_Color color, va_list pile
);
/** \~french
* \brief Écrit du texte sur l'écran en utilisant une couleur et une fonte de
* caractères données en paramètres.
*
* Cette fonction est équivalente à la fonction MLV_draw_text_wih_font() à
* l'exception qu'elle est apellée avec un paramètre de type va_list à la
* place d'une nombre variable d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text_with_font()
*
* \param x La coordonnée en X du coin Nord-Ouest du texte.
* \param y La coordonnée en Y du coin Nord-Ouest du texte.
* \param text Le texte à afficher.
* \param color La couleur du tracé.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_with_font_va(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color,
va_list pile
);
/** \~french
* \brief Écrit du texte sur une image en utilisant une couleur et une fonte de
* caractères données en paramètres.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_text_with_font_on_image() à l'exception qu'elle est apellée
* avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text_with_font_on_image()
*
* \param x La coordonnée en X du coin Nord-Ouest du texte.
* \param y La coordonnée en Y du coin Nord-Ouest du texte.
* \param text Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param color La couleur du tracé.
* \param image L'image sur laquel le texte doit être ecrit.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_with_font_on_image_va(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color,
MLV_Image* image, va_list pile
);
/** \~french
* \brief Cette fonction calcule la taille du texte qui sera affiché sur
* l'écran à l'aide de la fonction MLV_draw_text().
*
* Cette fonction est équivalente à la fonction
* MLV_get_size_of_text() à l'exception qu'elle est apellée
* avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_get_size_of_text()
*
* \param text Le texte qui doit être affiché.
* \param width La largeur du texte.
* \param height La hauteur du texte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_get_size_of_text_va(
const char *text, int *width, int *height, va_list pile
);
/** \~french
* \brief Cette fonction calcule la taille du texte qui sera affiché sur
* l'écran à l'aide de la fonction MLV_draw_text_with_font().
*
* Cette fonction est équivalente à la fonction
* MLV_get_size_of_text_with_font() à l'exception qu'elle est apellée
* avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_get_size_of_text_with_font()
*
* \param text Le texte qui doit être affiché.
* \param width La largeur du texte.
* \param height La hauteur du texte.
* \param font La fonte de caractères utilisée pour afficher le texte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_get_size_of_text_with_font_va(
const char *text, int *width, int *height, const MLV_Font* font,
va_list pile
);
/** \~french
* \brief Même chose que MLV_draw_adapted_text_box() mis à part que le texte est
* rendu avec une fonte de caractères donnée en paramètre.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_adapted_text_box_with_font() à l'exception qu'elle est apellée
* avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_adapted_text_box_with_font()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param borderColor La couleur des bordures.
* \param sizeInterligne La taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_adapted_text_box_with_font_va(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
va_list pile
);
/** \~french
* \brief Dessine une boîte contenant du texte.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_adapted_text_box() à l'exception qu'elle est apellée
* avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_adapted_text_box()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param borderColor La couleur des bordures.
* \param sizeInterligne La taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_adapted_text_box_va(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification, va_list pile
);
/** \~french
* \brief Même chose que MLV_draw_adapted_text_box() mis à part que le texte est
* rendu avec une fonte de caractères donnée en paramètre.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_adapted_text_box_on_image() à l'exception qu'elle est apellée
* avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_adapted_text_box_on_image()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param borderColor La couleur des bordures.
* \param sizeInterligne La taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param image L'image sur laquel le texte doit être ecrit.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_adapted_text_box_on_image_va(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, va_list pile
);
/** \~french
* \brief Même chose que MLV_draw_adapted_text_box_with_font() mis à part que
* le texte est rendu sur une image et non directement à l'écran.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_adapted_text_box_with_font_on_image() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_adapted_text_box_with_font_on_image()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param message Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param borderColor La couleur des bordures.
* \param sizeInterligne Le taille de l'interligne.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param image L'image sur laquel le texte doit être ecrit.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_adapted_text_box_with_font_on_image_va(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, va_list pile
);
/** \~french
* \brief Cette fonction calcule la taille de la boîte de texte qui serait
* obtenue si vous utilisez la fonction : MLV_draw_adapted_text_box().
*
* Cette fonction est équivalente à la fonction
* MLV_get_size_of_adapted_text_box() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_get_size_of_adapted_text_box()
*
* \param message Le texte qui sera affiché lorsque vous utiliserez
* MLV_draw_adapted_text_box().
* \param sizeInterligne La taille de l'interligne.
* \param result_width La largeur de la boîte que vous obtiendrez en
* utilisant MLV_draw_adapted_text_box().
* \param result_height La hauteur de la boîte que vous obtiendrez en
* utilisant MLV_draw_adapted_text_box().
* \param pile Une liste d'arguments supplémentaires
*
* \return La fonction renvoie la taille de la boîte de texte.
*/
int MLV_get_size_of_adapted_text_box_va(
const char* message,
int sizeInterligne,
int *result_width, int *result_height,
va_list pile
);
/** \~french
* \brief Cette fonction calcule la taille de la boîte de texte qui serait
* obtenue si vous utilisez la fonction :
* MLV_draw_adapted_text_box_with_font().
*
* Cette fonction est équivalente à la fonction
* MLV_get_size_of_adapted_text_box_with_font() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_get_size_of_adapted_text_box_with_font()
*
* \param message Le texte qui sera affiché lorsque vous utiliserez
* MLV_draw_adapted_text_box_with_font().
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param sizeInterligne La taille de l'interligne.
* \param result_width La largeur de la boîte que vous obtiendrez en utilisant
* MLV_draw_adapted_text_box_with_font().
* \param result_height La hauteur de la boîte que vous obtiendrez en utilisant
* MLV_draw_adapted_text_box_with_font().
* \param pile Une liste d'arguments supplémentaires
*
* \return La fonction renvoie la taille de la boîte de texte.
*/
int MLV_get_size_of_adapted_text_box_with_font_va(
const char* message,
const MLV_Font* font,
int sizeInterligne,
int *result_width, int *result_height,
va_list pile
);
/** \~french
* \brief Même chose que la fonction MLV_draw_text_box() mis à part que le texte
* est rendu avec une fonte de caractères donnée en paramètre par
* l'utilisateur.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_text_box_with_font() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text_box_with_font()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param font La fonte de caractères utilisée pour dessiner le texte.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_box_with_font_va(
int x, int y,
int width, int height,
const char* message ,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
va_list pile
);
/** \~french
* \brief Dessine une boîte de taille donnée par l'utilisateur et contenant un
* texte donné par l'utilisateur.
*
*
* Cette fonction est équivalente à la fonction
* MLV_draw_text_box() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text_box()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_box_va(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
va_list pile
);
/** \~french
* \brief Même chose que la fonction MLV_draw_text_box_with_font() mis à part que
* le texte n'est pas dessinné directement sur l'ecran, mais sur une
* une image.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_text_box_with_font_on_image() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text_box_with_font_on_image()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param font La fonte caractères utilisée pour dessiner le texte.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
* \param image L'image sur laquel le texte doit être ecrit.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_box_with_font_on_image_va(
int x, int y,
int width, int height,
const char* message ,
MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
va_list pile
);
/** \~french
* \brief Même chose que MLV_draw_text_box() mis à part que le texte n'est pas
* écrit directement sur l'écran, mais sur une image à la place.
*
* Cette fonction est équivalente à la fonction
* MLV_draw_text_box_on_image() à l'exception qu'elle est
* apellée avec un paramètre de type va_list à la place d'une nombre variable
* d'arguments.
*
* Pour plus de détail sur la fonction, aller voir la documentation de
* MLV_draw_text_box_on_image()
*
* \param x La coordonnée en X de la position du coin Nord-Ouest de la boîte.
* \param y La coordonnée en Y de la position du coin Nord-Ouest de la boîte.
* \param width La largeur de la boîte.
* \param height La hauteur de la boîte.
* \param message Le texte à afficher.
* \param sizeInterligne La taille de l'interligne.
* \param borderColor La couleur des bordures.
* \param textColor La couleur du texte.
* \param backgroundColor La couleur du fond de la boîte.
* \param text_justification La justification du texte.
* \param horizontal_position La position horizontale du texte dans la boîte.
* \param vertical_position La position verticale du texte dans la boîte.
* \param image L'image sur laquel le texte doit être ecrit.
* \param pile Une liste d'arguments supplémentaires
*/
void MLV_draw_text_box_on_image_va(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
va_list pile
);
#ifdef __cplusplus
}
#endif
#endif

119
MLV/MLV_time.h Executable file
View File

@@ -0,0 +1,119 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_time.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit tous les prototypes des fonctions concernant la
* gestion du temps.
*
*/
#ifndef __MLV__MLV_TIME_H__
#define __MLV__MLV_TIME_H__
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Le programme s'intérompt pendant un nombre de milli-secondes donné
* en paramètre.
*
* \param milliseconds Le nombre de milli-secondes à attendre.
*/
void MLV_wait_milliseconds(int milliseconds);
/** \~french
* \brief Le programme s'intérompt pendant un nombre de secondes.
*
* \param seconds Le nombre de secondes à attendre.
*/
void MLV_wait_seconds(int seconds);
/** \~french
* \brief Renvoie le nombre de millisecondes écoulées depuis le début de
* l'initialisation de la bibliothèque MLV ( avec MLV_create_window ).
* \return Le temps écoulé depuis l'initialisation de la bibliothèque MLV.
*/
int MLV_get_time();
/** \~french
* \brief Donne la date du jour (seconde/heure/jour/mois/annee).
*
* L'année est donnée depuis l'an 0.
*
* Une valeur nulle peut être passée en paramètre de la fonction. Dans ce cas,
* le paramètre est ignoré par la fonction.
*
* \param seconds Le nombre de secondes écoulées depuis le dernier changement de
* minute.
* \param minutes Le nombre de minutes écoulées depuis le dernier changement
* d'heure
* \param hours Le nombre d'heures écoulées depuis minuit.
* \param day Le quantième du mois.
* \param month Le nombre de mois écoulés depuis le début de l'année.
* \param year Le nombre d'années depuis l'an 0.
* \param day_of_the_week Le jour de la semaine ( 0: Lundi, 1:Mardi, ...,
* 6:Dimanche).
* \return Renvoie 1 si le décalage heure d'hivers et heure d'été a été
* pris en compte, 0 si il ne l'a pas été et -1 si l'information
* n'est pas disponible.
*/
int MLV_get_date(
int* seconds, int* minutes, int* hours,
int* day, int* month, int* year,
int* day_of_the_week
);
/** \~french
* \brief Configure la fréquence de rafraichissement en Hz.
*
* La fréquence de rafraîchissement par defaut est de 100 Hz. Cela signifie
* que si l'on utilise MLV_delay_according_to_frame_rate() entre chaque
* rafraîchissement de la fenêtre graphique, on obtient un rafraichissement
* de 100 images par secondes.
*
* \param rate Fréquence de rafraîchissement.
*/
void MLV_change_frame_rate( int rate );
/** \~french
* \brief Donne la fréquence de rafraîchissement courante.
*
* \return La fréquence de rafraîchissement courante.
*/
int MLV_get_frame_rate( );
/** \~french
* \brief Suspend l'exécution du programme de façon à ce que le temps écoulé
* depuis le drenier appel à cette fonction, soit égale à la période de
* la fréquence de rafraîchissement configuré par MLV_change_frame_rate.
*/
void MLV_delay_according_to_frame_rate( );
#ifdef __cplusplus
}
#endif
#endif

306
MLV/MLV_window.h Normal file
View File

@@ -0,0 +1,306 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_window.h
* \brief Ce fichier définit les prototypes des fonctions permettant de créer,
* initialiser et fermer des fenêtres.
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
*/
#ifndef __MLV__MLV_WINDOW_H__
#define __MLV__MLV_WINDOW_H__
#include "MLV_color.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Créé une fenêtre dont la taille, et les différents noms sont passés en
* paramètres.
*
* Cette fonction initialise la bibliothèque MLV.
* Un programme donné ne peut pas ouvrir plus d'une fenêtre à la
* fois.
* Les paramètres largeur et hauteur peuvent éventuellement prendre des valeurs
* négatives. Dans ce cas, la fenêtre est dessinée en plein écran.
*
* \bug BOGUES WINDOWS ET MACOSX UNIQUEMENT\n\n
* Sous Windows uniquement, la fenêtre crée ne peut pas toujours être
* fermée à l'aide de la croix. En effet, la bibliothèque MLV implémente
* une fermeture automatique de la fenêtre lorsque l'utilisateur utilise
* la croix. Or, ce mécanisme utilise les threads SDL qui ne sont
* malheureusement pas bien supportés sous Windows et MacOSX.\n\n
* En fait, la bibliothèque MLV utilise un second thread pour
* récuperer en permanance tous les évènements SDL de la pile et pour les
* traiter au fur et à mesure de leurs apparitions. OR, sous Windos et
* Mac OS X, comme les threads ne fonctionnent pas, la bibliothèque ne peux
* pas lire les évènements systèmes comme ceux de la fermeture de la
* fenêtre.
* Elle n'est donc plus informée de ce qui ce passe.
* Pour permettre à la bibliothèque de récupérer ces informations, il vous
* suffit de demander un évènement à l'aide de la fonction :
* MLV_get_event().
* Cela obligera la bibliothèque MLV à dépiler et à traiter tous les
* évènements SDL de la pile. Cela aura pour conséquence de traiter
* l'évènement système de la fermeture de la fenêtre.
* Dans l'implémentation des fonctions : MLV_wait_keyboard(),
* MLV_wait_mouse(), etc ..., nous utilisons la fonction MLV_get_event().
* C'est pourquoi, la croix fonctionne correctement lorsque le programme
* est en attente d'une information provenant de l'utilisateur.
*
* \param window_name Le nom de la fenêtre.
* \param icone_name Le nom de l'icône de la fenêtre.
* \param width La largeur de la fenêtre.
* \param height La hauteur de la fenêtre.
*/
void MLV_create_window(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height
);
/** \~french
* \brief Même chose que MLV_create_window(), mais en utilisant une fonte
* de caractères particulière.
*
* \bug Même bogues que la fonction MLV_create_window().
*
* \param window_name Le nom de la fenêtre.
* \param icone_name Le nom de l'icône de la fenêtre.
* \param width La largeur de la fenêtre.
* \param height La hauteur de la fenêtre.
* \param path_to_font Le chemin d'accès vers une fonte de caratères au standard
* 'TrueType' (fichiers d'extension .ttf).
* \param size_font La taille de la fonte de caractères. la hauteur de la fenêtre.
*/
void MLV_create_window_with_default_font(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height,
const char* path_to_font, unsigned int size_font
);
/** \~french
* \brief Change la fonte de caractères par défault de la bibliothèque MLV.
*
* Cette fonction change la fonte de caractères par défault de la bibliothèque.
* Cette fonction ne peux s'exécuter qu'après avoir initialisé la bibliothèque
* MLV en créant une fenêtre à l'aide de la fonction MLV_create_window().
* Cette fonction n'a pas de sens si vous ne souhaitez pas changer de fontes
* plusieurs fois durant l'exécution de votre programme.
* Si vous n'utilisez qu'une seule fonte de caractères, il vaut mieux
* l'indiquer à la bibliothèque MLV lors de la création de la fenêtre en utilisant
* la fonction: MLV_create_window_with_default_font().
*
* \param path_to_font Le chemin d'accès vers une fonte de caratères au
* standard "TrueType" (fichiers d'extension .ttf).
* \param size_font La taille de la fonte de caractères.
*/
void MLV_change_default_font( const char* path_to_font, unsigned int size_font );
/** \~french
* \brief Même chose que MLV_create_window(), mais configure la fenêtre en
* mode plein écran.
*
* \bug Même bogues que MLV_create_window().
*
* \param window_name Le nom de la fenêtre.
* \param icone_name Le nom de l'icône de la fenêtre.
* \param width La largeur de la fenêtre ( en mode plein écran, cette valeur
* correspond à la coordonnée en X de la résolution de l'image ).
* \param height La hauteur de la fenêtre ( en mode plein écran, cela
* correspond à la coordonnée en Y de la résolution de l'image ).
*/
void MLV_create_full_screen_window(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height
);
/** \~french
* \brief Même chose que MLV_create_window(), mais configure la fenêtre en
* mode plein écran.
*
* \bug Même bogues que MLV_create_window().
*
* \param window_name Le nom de la fenêtre.
* \param icone_name Le nom de l'icône de la fenêtre.
* \param width La largeur de la fenêtre ( en mode plein écran, cette valeur
* correspond à la coordonnée en X de la résolution de l'image ).
* \param height La hauteur de la fenêtre ( en mode plein écran, cela
* correspond à la coordonnée en Y de la résolution de l'image ).
* \param path_to_font Le chemin d'accès vers une fonte de caratères au
* standard "TrueType" (fichiers d'extension .ttf).
* \param size_font La taille de la fonte de caractères.
*/
void MLV_create_full_screen_window_with_default_font(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height,
const char* path_to_font, unsigned int size_font
);
/** \~french
* \brief Affiche la fenêtre en plein ecran.
*
* La résolution de l'image est donnée alors par la taille de l'image.
* Pour que l'application soit en plein écran, il faut que la taille de la
* fenêtre soit compatible avec la résolution de l'écran.
*/
void MLV_enable_full_screen();
/** \~french
* \brief Désactve le mode plein écran de la fenêtre.
*/
void MLV_disable_full_screen();
/** \~french
* \brief Test si l'affichage est en mode plein écran ou en mode fenêtre.
*
* \return Renvoie 1 si l'affichage est en mode plein écran, 0 sinon.
*/
int MLV_is_full_screen();
/** \~french
* \brief Change la taille de la fenêtre.
*
* Si la fenêtre est configurée en mode plein ecran, l'application reste alors
* en mode plein écran.
* Pour que l'application soit en plein écran, il faut que la taille de la
* fenêtre soit compatible avec la résolution de l'écran.
* De plus, en mode plein écran, la taille de la fenêtre correspond à la
* résolution de l'image sur l'écran.
*
* \param width la largeur de la fenêtre
* \param height la hauteur de la fenêtre
*/
void MLV_change_window_size( unsigned int width, unsigned int height );
/** \~french
* \brief Change les intitulés de la fenêtre principale.
*
* \param window_name Intitulé apparaissaissant sur la barre de la fenêtre.
* \param icone_name Intitulé apparaissaissant dans la barre des tâches.
*/
void MLV_change_window_caption(
const char* window_name, const char* icone_name
);
/** \~french
* \brief Renvoie dans les paramètres, la hauteur et la largeur de la fentre.
*
* \param width La largeur de la fenêtre.
* \param height La hauteur de la fenêtre.
*/
void MLV_get_window_size( unsigned int* width, unsigned int* height );
/** \~french
* \brief Retourne la hauteur de la fenêtre.
*/
int MLV_get_window_height( );
/** \~french
* \brief Retourne la largeur de la fenêtre.
*/
int MLV_get_window_width( );
/** \~french
* \brief Éfface la fenêtre et la remplace par un monochrome de la couleur
* donnée en paramètre.
*
* \param color La couleur du fond de la fênetre.
*/
void MLV_clear_window( MLV_Color color );
/** \~french
* \brief Ferme la fenêtre de la bibliothèque MLV.
*
* Cette fonction libère correctement toutes les données qui ont été crées par la
* bibliothèque MLV
*
*/
void MLV_free_window();
/** \~french
* \brief Actualise l'affichage de la fenêtre.
*
* Vois La fonction MLV_update_window
*
* Lorsque vous utilisez des fonctions de dessins, les différents changements
* effectués ne sont pas visibles. Pour les afficher vous devez utiliser cette
* fonction.
*/
void MLV_actualise_window();
/** \~french
* \brief Met à jour l'affichage de la fenêtre.
*
* Lorsque vous utilisez des fonctions de dessins, les différents changements
* effectués ne sont pas visibles. Pour les afficher vous devez utiliser cette
* fonction.
*/
void MLV_update_window();
/** \~french
* \brief Exécute la fonction de call back donnée en paramètre lorsque le système
* envoie un signal d'arrêt, ou lorsque l'utilisateur clique sur la croix de la
* fenêtre.
*
* La fonction de call back est alors exécutée avec en
* paramêtre un pointeur vers une structure de donnée qui
* est aussi donné en paramètre à la fonction
* MLV_execute_at_exit().
*
* \param function Le pointeur de la fonction de call back qui doit être exécutée.
* \param data La Donnée à passer en paramètre à la fonction de call back lors de
* son exécution.
*/
void MLV_execute_at_exit( void (*function)(void*), void* data );
/** \~french
* \brief Renvoie dans les paramètres, la hauteur et la largeur de
* l'environement de bureau de l'ordinateur.
*
* \param width La largeur du bureau.
* \param height La hauteur du bureau.
*/
void MLV_get_desktop_size( unsigned int* width, unsigned int* height );
/** \~french
* \brief Renvoie la hauteur de l'environement de bureau de l'ordinateur.
*/
int MLV_get_desktop_height( );
/** \~french
* \brief Renvoie la largeur de l'environement de bureau de l'ordinateur.
*/
int MLV_get_desktop_width( );
#ifdef __cplusplus
}
#endif
#endif

217
MLV/MLV_xml.h Normal file
View File

@@ -0,0 +1,217 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_xml.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les prototypes des fonctions permettant de lire des
* fichiers xml.
*
* Les fichiers xml sont utilisés pour stocker les données nécessaires au
* fonctionnement d'un programme. Ils permettent de modifier facilement
* l'exécution du programme sans avoir à le modifier. En effet, ils sont
* lisibles par l'homme et par la machine en même temps.
* Ils constituent donc une interface pratique entre l'ordinateur et
* l'utilisateur.
*
*/
#ifndef __MLV__MLV_XML_H__
#define __MLV__MLV_XML_H__
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Définit le type de donnée stockée au format xml dans la bibliothèque MLV.
*/
typedef struct _MLV_Xml MLV_Xml;
/** \~french
* \brief Charge en mémoire un fichier au format xml.
*
* Cette fonction renvoi NULL, lorsque le fichier n'a pas pu être correctement
* chargé.
*
* \param xml_file_path Chemin d'accès du fichier xml.
* \return Le fichier xml lu, analysé et chargé.
*/
MLV_Xml* MLV_load_xml( const char* xml_file_path );
/** \~french
* \brief Libère la mémoire utilisée par les données du fichier xml.
*
* \param xml_data Les données xml a supprimer.
*/
void MLV_free_xml( MLV_Xml* xml_data );
/** \~french
* \brief Énumère les différents codes d'erreurs que l'on peut rencontrer
* lorsque l'ordinateur lit un document xml.
*/
typedef enum {
MLV_XML_NONE, /**< \~french Aucune erreur detectée. */
MLV_XML_THE_FIELD_DOESNT_EXIST, /**< \~french Le champs n'existe pas dans le document xml. */
MLV_XML_THE_FIELD_IS_NOT_A_REAL, /**< \~french Le champs ne contient pas une chaîne de caractères codant un reel. */
MLV_XML_THE_FIELD_IS_NOT_AN_INTEGER, /**< \~french Le champs ne contient pas un chaîne de caractères codant un entier. */
MLV_XML_THE_FIELD_IS_TOO_BIG /**< \~french La chaîne code un réel/entier trop long pour être stocké dans la variable. */
} MLV_Xml_error;
/** \~french
* \brief Permet d'accéder à l'interieur d'un champs donné du fichier xml.
*
* Cette fonction peut contenir un nombre variable de paramètres.
* Comme avec la fonction printf les paramètres suplémentaires,
* situées après le paramètre xpath, permettent de construire des
* requêtes xpath évolué.
*
* Par exemple,
* \code
* int id_batiment = 2;
* char * type_salle = "informatique"
* int id_salle = 4;
* char* nom_salle;
* MLV_get_string_value_from_xml(
* xml_data, &(nom_salle),
* "/batiment[%d]/salle[type=%s][%d]/nom",
* id_batiment, type_salle, id_salle
* )
* free( nom_salle ); // on oublie pas de libérer la mémoire après avoir
* // utilisé nom_salle
* \endcode
*
* permet de recupérer le contenu du champs "nom" situé dans la 4eme salle
* informatique du 2eme batiment.
*
* Attention: Il ne faut pas oublier de libérer la mémoire associée au champs
* result.
*
* \param xml_data Les données xml.
* \param result Un pointeur vers une addresse vide qui contiendra l'addresse de la chaîne de caractères correspondant au résultat de la fonction.
* \param xpath Le chemin d'accès.
* \return renvoie un code d'erreur si la fonction n'a pa reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_string_value_from_xml(
const MLV_Xml* xml_data, char** result , const char* xpath, ...
);
/** \~french
* \brief Permet de récupérer l'entier d'un champs donné du fichier xml.
*
* Tout comme la fonction MLV_get_string_value_from_xml(), cette fonction peut
* contenir un nombre variable de paramètres.
* Pour plus d'informations, veuillez lire la documentation de la fonction
* MLV_get_string_value_from_xml().
*
* \param xml_data Les données xml.
* \param result Un pointeur vers un entier dans lequel le résultat de la fonction sera enregistré.
* \param xpath Le chemin d'accès.
* \return renvoie un code d'erreur si la fonction n'a pa reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_integer_value_from_xml(
const MLV_Xml* xml_data, int* result, const char* xpath, ...
);
/** \~french
* \brief Permet de récupérer le reel d'un champs donné du fichier xml.
*
* Tout comme la fonction MLV_get_string_value_from_xml(), cette fonction peut
* contenir un nombre variable de paramètres.
* Pour plus d'informations, veuillez lire la documentation de la fonction
* MLV_get_string_value_from_xml().
*
* \param xml_data Les données xml.
* \param result Un pointeur vers un réel dans lequel le résultat de la fonction sera enregistré.
* \param xpath Le chemin d'accès.
* \return renvoie un code d'erreur (voir MLV_Xml_error) si la fonction n'a pas reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_double_value_from_xml(
const MLV_Xml* xml_data, double* result, const char* xpath, ...
);
/** \~french
* \brief Permet de récupérer le réel d'un champs donné du fichier xml.
*
* Tout comme la fonction MLV_get_string_value_from_xml(), cette fonction peut
* contenir un nombre variable de paramètres.
* Pour plus d'informations, veuillez lire la documentation de la fonction
* MLV_get_string_value_from_xml().
*
* \param xml_data Les données xml.
* \param result Un pointeur vers un réel dans lequel le résultat de la fonction sera enregistré.
* \param xpath Le chemin d'accès.
* \return renvoie un code d'erreur (voir MLV_Xml_error) si la fonction n'a pas reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_float_value_from_xml(
const MLV_Xml* xml_data, float* result, const char* xpath, ...
);
/** \~french
* \brief Compte le nombre d'objets présents dans le fichier xml verifiant
* un certain nombre de critères passés en paramètre de la fonction.
*
* \param xml_data Les données xml.
* \param xpath Le chemin d'accès.
* \param ... Les paramètres de la fonction.
*
* \return Cette fonction renvoie le nombre d'objet ayant pour chemin d'accès
* "xpath".
*/
int MLV_get_number_of_objects_from_xml(
const MLV_Xml* xml_data, const char* xpath, ...
);
/** \~french
* \brief Permet de récupérer un noeud interne de l'arbre représentant le
* fichier XML.
*
* Cette fonction n'est pas encore implémentée.
*
* \param xml_data Les données xml.
* \param xpath Le chemin d'accès.
* \param ... Les paramètres de la fonction.
*
* \return Un noeud interne de l'arbre XML.
*/
MLV_Xml* MLV_get_xml_object_of( const MLV_Xml* xml_data, const char* xpath, ... );
/** \~french
* \brief Écrit sur le terminal le contenu d'un fichier xml.
*
* Cette fonction n'est pas encore implémentée.
*
* \param xml_data Les données xml.
* \param ... Les paramètres de la fonction.
*/
void MLV_print_xml( const MLV_Xml* xml_data );
#ifdef __cplusplus
}
#endif
#endif

155
MLV/MLV_xml_va.h Normal file
View File

@@ -0,0 +1,155 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2013-2014 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
/** \~french
* \file MLV_xml_va.h
*
* \author Adrien Boussicault
* \author Marc Zipstein
*
* \brief Ce fichier définit les même prototypes des fonctions que MLV_xml.h
* mais en utilisant en argument sulémentaire une liste de type va_list.
*
* Les fichiers xml sont utilisés pour stocker les données nécessaires au
* fonctionnement d'un programme. Ils permettent de modifier facilement
* l'exécution du programme sans avoir à le modifier. En effet, ils sont
* lisibles par l'homme et par la machine en même temps.
* Ils constituent donc une interface pratique entre l'ordinateur et
* l'utilisateur.
*
*/
#ifndef __MLV__MLV_XML_VA_H__
#define __MLV__MLV_XML_VA_H__
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \~french
* \brief Permet d'accéder à l'interieur d'un champs donné du fichier xml.
*
* Attention: Il ne faut pas oublier de libérer la mémoire associée au
* champs result.
*
* \param xml_data Les données xml.
* \param result Un pointeur vers une addresse vide qui contiendra l'addresse de la chaîne de caractères correspondant au résultat de la fonction.
* \param xpath Le chemin d'accès.
* \param pile La pile des complements de paramètres comme dans vaprintf.
* \return renvoie un code d'erreur si la fonction n'a pa reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_string_value_from_xml_va(
const MLV_Xml* xml_data, char** result, const char* xpath, va_list pile
);
/** \~french
* \brief Permet de récupérer l'entier d'un champs donné du fichier xml.
*
* Tout comme la fonction MLV_get_string_value_from_xml(), cette fonction peut
* contenir un nombre variable de paramètres.
* Pour plus d'informations, veuillez lire la documentation de la fonction
* MLV_get_string_value_from_xml().
*
* \param xml_data Les données xml.
* \param result Un pointeur vers un entier dans lequel le résultat de la fonction sera enregistré.
* \param xpath Le chemin d'accès.
* \param pile La pile des complements de paramètres comme dans vaprintf.
* \return renvoie un code d'erreur si la fonction n'a pa reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_integer_value_from_xml_va(
const MLV_Xml* xml_data, int* result, const char* xpath, va_list pile
);
/** \~french
* \brief Permet de récupérer le reel d'un champs donné du fichier xml.
*
* Tout comme la fonction MLV_get_string_value_from_xml(), cette fonction peut
* contenir un nombre variable de paramètres.
* Pour plus d'informations, veuillez lire la documentation de la fonction
* MLV_get_string_value_from_xml().
*
* \param xml_data Les données xml.
* \param result Un pointeur vers un réel dans lequel le résultat de la fonction sera enregistré.
* \param xpath Le chemin d'accès.
* \param pile La pile des complements de paramètres comme dans vaprintf.
* \return renvoie un code d'erreur (voir MLV_Xml_error) si la fonction n'a pas reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_double_value_from_xml_va(
const MLV_Xml* xml_data, double* result, const char* xpath, va_list pile
);
/** \~french
* \brief Permet de récupérer le réel d'un champs donné du fichier xml.
*
* Tout comme la fonction MLV_get_string_value_from_xml(), cette fonction peut
* contenir un nombre variable de paramètres.
* Pour plus d'informations, veuillez lire la documentation de la fonction
* MLV_get_string_value_from_xml().
*
* \param xml_data Les données xml.
* \param result Un pointeur vers un réel dans lequel le résultat de la fonction sera enregistré.
* \param xpath Le chemin d'accès.
* \param pile La pile des complements de paramètres comme dans vaprintf.
* \return renvoie un code d'erreur (voir MLV_Xml_error) si la fonction n'a pas reussie à extraire la donnée souhaitée du document xml.
*/
MLV_Xml_error MLV_get_float_value_from_xml_va(
const MLV_Xml* xml_data, float* result, const char* xpath, va_list pile
);
/** \~french
* \brief Compte le nombre d'objets présents dans le fichier xml verifiant
* un certain nombre de critères passés en paramètre de la fonction.
*
* \param xml_data Les données xml.
* \param xpath Le chemin d'accès.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*
* \return Cette fonction renvoie le nombre d'objet ayant pour chemin d'accès
* "xpath".
*/
int MLV_get_number_of_objects_from_xml_va(
const MLV_Xml* xml_data, const char* xpath, va_list pile
);
/** \~french
* \brief Permet de récupérer un noeud interne de l'arbre représentant le
* fichier XML.
*
* Cette fonction n'est pas encore implémentée.
*
* \param xml_data Les données xml.
* \param xpath Le chemin d'accès.
* \param pile La pile des complements de paramètres comme dans vaprintf.
*
* \return Un noeud interne de l'arbre XML.
*/
MLV_Xml* MLV_get_xml_object_of_va(
const MLV_Xml* xml_data, const char* xpath, va_list pile
);
#ifdef __cplusplus
}
#endif
#endif

118
MLV/Makefile.am Normal file
View File

@@ -0,0 +1,118 @@
#
# This file is part of the MLV Library.
#
# Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
#
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this Library. If not, see <http://www.gnu.org/licenses/>.
#
mlv_includedir=${includedir}/MLV
if OS_IS_APPLE
lib_LTLIBRARIES = libMLV.la libMLVMain.la
else
lib_LTLIBRARIES = libMLV.la
endif
libMLV_la_SOURCES = \
animation.c \
audio.c \
color.c \
event.c \
shapes.c \
image.c \
informations.c \
keyboard.c \
mouse.c \
path.c \
playlist.c \
input_box.c \
input_box_wait.c \
random.c \
sdlkeyboardtochar.c \
text.c \
time.c \
xml.c \
list.c \
mathematics.c \
key.c \
tree_set.c \
tree_map.c \
window.c
if OS_IS_APPLE
libMLVMain_la_SOURCES = \
SDLMain.m
endif
if MEMORY_DEBUG
libMLV_la_SOURCES += memory_debug.c
endif
if MEMORY_DEBUG
libMLV_la_CFLAGS = ${libxml_CFLAGS} ${glib_CFLAGS} -DDATA_PATH=\"${DATA_PATH}\"
libMLV_la_LIBADD = ${libxml_LIBS} ${glib_LIBS}
else
libMLV_la_CFLAGS = ${sdl_CFLAGS} ${sdlttf_CFLAGS} ${sdlimage_CFLAGS} ${sdlmixer_CFLAGS} ${libxml_CFLAGS} ${glib_CFLAGS} -DDATA_PATH=\"${DATA_PATH}\"
libMLV_la_LIBADD = ${sdl_LIBS} ${libxml_LIBS} ${glib_LIBS} ${sdlttf_LIBS} ${sdlgfx_LIBS} ${sdlimage_LIBS} ${sdlmixer_LIBS}
endif
libMLV_la_LDFLAGS = -version-info $(MLV_CURRENT):$(MLV_REVISION):$(MLV_AGE)
# To Compile .DLL
if RELATIVEPATH
libMLV_la_LDFLAGS += -no-undefined
endif
mlv_include_HEADERS = \
MLV_audio.h \
MLV_all.h \
MLV_animation.h \
MLV_color.h \
MLV_device_with_buttons.h \
MLV_event.h \
MLV_shape.h \
MLV_image.h \
MLV_information.h \
MLV_input_box_va.h \
MLV_keyboard.h \
MLV_mouse.h \
MLV_path.h \
MLV_playlist.h \
MLV_input_box.h \
MLV_random.h \
MLV_text.h \
MLV_text_va.h \
MLV_time.h \
MLV_xml.h \
MLV_xml_va.h \
MLV_window.h
noinst_HEADERS = \
image.h \
data_structure.h \
memory_debug.h \
memory_management.h \
platform.h \
input_box.h \
sdlkeyboardtochar.h \
text.h \
warning_error.h \
mathematics.h \
list.h \
key.h \
tree_set.h \
tree_map.h \
SDLMain.h

1138
MLV/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

33
MLV/SDLMain.h Normal file
View File

@@ -0,0 +1,33 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
*
* Copyright (C)
* Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
* Non-NIB-Code & other changes: Max Horn <max@quendi.de>
* Change "Feel free to customize this file to suit your needs" to a
* GPL licence for the MLV Library : Adrien Boussicault (2013)
*
* This file is part of the MLV Library.
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SDLMain_h_
#define _SDLMain_h_
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end
#endif /* _SDLMain_h_ */

398
MLV/SDLMain.m Normal file
View File

@@ -0,0 +1,398 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
*
* Copyright (C)
* Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
* Non-NIB-Code & other changes: Max Horn <max@quendi.de>
* Change "Feel free to customize this file to suit your needs" to a
* GPL licence for the MLV Library : Adrien Boussicault (2013)
*
* This file is part of the MLV Library.
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SDL/SDL.h"
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
it ourselves here. */
@interface NSApplication(SDL_Missing_Methods)
- (void)setAppleMenu:(NSMenu *)menu;
@end
/* Use this flag to determine whether we use SDLMain.nib or not */
#define SDL_USE_NIB_FILE 0
/* Use this flag to determine whether we use CPS (docking) or not */
#define SDL_USE_CPS 1
#ifdef SDL_USE_CPS
/* Portions of CPS.h */
typedef struct CPSProcessSerNum
{
UInt32 lo;
UInt32 hi;
} CPSProcessSerNum;
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
#endif /* SDL_USE_CPS */
static int gArgc;
static char **gArgv;
static BOOL gFinderLaunch;
static BOOL gCalledAppMainline = FALSE;
static NSString *getApplicationName(void)
{
const NSDictionary *dict;
NSString *appName = 0;
/* Determine the application name */
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];
if (![appName length])
appName = [[NSProcessInfo processInfo] processName];
return appName;
}
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@end
#endif
@interface NSApplication (SDLApplication)
@end
@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
/* The main class of the application, the application's delegate */
@implementation SDLMain
/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
chdir(parentdir); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}
#if SDL_USE_NIB_FILE
/* Fix menu to contain the real app name instead of "SDL App" */
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
{
NSRange aRange;
NSEnumerator *enumerator;
NSMenuItem *menuItem;
aRange = [[aMenu title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
enumerator = [[aMenu itemArray] objectEnumerator];
while ((menuItem = [enumerator nextObject]))
{
aRange = [[menuItem title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
}
#else
static void setApplicationMenu(void)
{
/* warning: this code is very odd */
NSMenu *appleMenu;
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
appName = getApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
}
/* Create a window menu */
static void setupWindowMenu(void)
{
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[windowMenuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:windowMenuItem];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
}
/* Replacement for NSApplicationMain */
static void CustomApplicationMain (int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
/* Ensure the application object is initialised */
[NSApplication sharedApplication];
#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN))
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[NSApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setApplicationMenu();
setupWindowMenu();
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
/* Start the main event loop */
[NSApp run];
[sdlMain release];
[pool release];
}
#endif
/*
* Catch document open requests...this lets us notice files when the app
* was launched by double-clicking a document, or when a document was
* dragged/dropped on the app's icon. You need to have a
* CFBundleDocumentsType section in your Info.plist to get this message,
* apparently.
*
* Files are added to gArgv, so to the app, they'll look like command line
* arguments. Previously, apps launched from the finder had nothing but
* an argv[0].
*
* This message may be received multiple times to open several docs on launch.
*
* This message is ignored once the app's mainline has been called.
*/
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
const char *temparg;
size_t arglen;
char *arg;
char **newargv;
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
temparg = [filename UTF8String];
arglen = SDL_strlen(temparg) + 1;
arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
SDL_free(arg);
return FALSE;
}
gArgv = newargv;
SDL_strlcpy(arg, temparg, arglen);
gArgv[gArgc++] = arg;
gArgv[gArgc] = NULL;
return TRUE;
}
/* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
int status;
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
#endif
/* Hand off to main application code */
gCalledAppMainline = TRUE;
status = SDL_main (gArgc, gArgv);
/* We're done, thank you for playing */
exit(status);
}
@end
@implementation NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
{
unsigned int bufferSize;
unsigned int selfLen = [self length];
unsigned int aStringLen = [aString length];
unichar *buffer;
NSRange localRange;
NSString *result;
bufferSize = selfLen + aStringLen - aRange.length;
buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
/* Get first part into buffer */
localRange.location = 0;
localRange.length = aRange.location;
[self getCharacters:buffer range:localRange];
/* Get middle part into buffer */
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer+aRange.location) range:localRange];
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
/* Build output string */
result = [NSString stringWithCharacters:buffer length:bufferSize];
NSDeallocateMemoryPages(buffer, bufferSize);
return result;
}
@end
#ifdef main
# undef main
#endif
/* Main entry point to executable - should *not* be SDL_main! */
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
gArgv[0] = argv[0];
gArgv[1] = NULL;
gArgc = 1;
gFinderLaunch = YES;
} else {
int i;
gArgc = argc;
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
for (i = 0; i <= argc; i++)
gArgv[i] = argv[i];
gFinderLaunch = NO;
}
#if SDL_USE_NIB_FILE
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv);
#endif
return 0;
}

1116
MLV/animation.c Normal file

File diff suppressed because it is too large Load Diff

149
MLV/audio.c Normal file
View File

@@ -0,0 +1,149 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_audio.h"
#include "warning_error.h"
#include "memory_management.h"
#include "data_structure.h"
#include "platform.h"
#if defined( OS_WINDOWS )
# include <SDL/SDL_mixer.h>
#elif defined( OS_APPLE )
# include <SDL_mixer/SDL_mixer.h>
#else
# include <SDL/SDL_mixer.h>
#endif
#include <glib.h>
extern DataMLV* MLV_data;
struct _MLV_Music {
Mix_Music* music;
};
struct _MLV_Sound {
Mix_Chunk* sample;
};
struct _MLV_Playlist {
GList* list_music;
};
#define MLV_AUDIO_BUFFER_SIZE 1024
#define MLV_AUDIO_STEREO 2
#define MLV_AUDIO_NUMBER_OF_MIXING_CHANEL 16
int init_audio( int buffer_size ){
int result = Mix_OpenAudio(
MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MLV_AUDIO_STEREO, buffer_size
);
if( !result ){
Mix_AllocateChannels(MLV_AUDIO_NUMBER_OF_MIXING_CHANEL);
}
return result;
}
void MLV_change_number_of_parallel_sounds( unsigned int n ){
if( ! n ){
fprintf( stderr, "Incorrect parameter for MLV_change_number_playing_parallel_sounds. The number of parrallel sound can't be null." );
exit(1);
}
Mix_AllocateChannels( n );
}
int MLV_init_audio(){
return init_audio( MLV_AUDIO_BUFFER_SIZE ); // If the sound are not well
// former, increse this value.
// If the sound have some lags, the you have
// to decrease this value.
}
int MLV_change_audio_buffer_size( int buffer_size ){
MLV_free_audio();
return init_audio( buffer_size );
}
void MLV_free_audio(){
Mix_HaltChannel(-1);
Mix_HaltMusic();
Mix_CloseAudio();
}
MLV_Music* MLV_load_music( const char* file_music ){
MLV_Music* result = MLV_MALLOC( 1, MLV_Music );
result->music= Mix_LoadMUS( file_music );
if(! result->music) {
MLV_FREE( result, MLV_Music );
result = NULL;
}
return result;
}
void MLV_free_music( MLV_Music* music ){
if( music ){
Mix_FreeMusic( music->music );
MLV_FREE( music, MLV_Music );
}
}
void MLV_play_music( const MLV_Music* music, float volume, int loop ){
Mix_VolumeMusic( volume * MIX_MAX_VOLUME );
MLV_stop_music();
if( loop ) Mix_PlayMusic( music->music, loop-1 );
}
void MLV_stop_music(){
Mix_HaltMusic();
}
MLV_Sound* MLV_load_sound( const char* file_sound ){
MLV_Sound* result = MLV_MALLOC( 1, MLV_Sound );
result->sample = Mix_LoadWAV( file_sound );
if(! result->sample ){
MLV_FREE( result, MLV_Sound );
result = NULL;
}else{
Mix_VolumeChunk( result->sample, MIX_MAX_VOLUME );
}
return result;
}
void MLV_free_sound( MLV_Sound* sound ){
if( sound ){
Mix_FreeChunk( sound->sample );
MLV_FREE( sound, MLV_Sound );
}
}
void MLV_play_sound( const MLV_Sound* sound, float volume ){
int channel = Mix_PlayChannel( -1, sound->sample, 0 );
Mix_Volume(channel, volume * MIX_MAX_VOLUME);
}
void MLV_stop_all_sounds(){
Mix_HaltChannel(-1);
}

4589
MLV/color.c Normal file

File diff suppressed because it is too large Load Diff

77
MLV/config.h.in Normal file
View File

@@ -0,0 +1,77 @@
/* MLV/config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Define the revision in the source repository */
#undef MLV_RCS_REVISION
/* Define the revision control software */
#undef MLV_REPOSITORY
/* Define the address of the MLV repository */
#undef MLV_SOURCE_REPOSITORY
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Version number of package */
#undef VERSION
/* Define to empty if `const' does not conform to ANSI C. */
#undef const

72
MLV/data_structure.h Normal file
View File

@@ -0,0 +1,72 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__DATA_STRUCTURE_H_
#define __MLV__DATA_STRUCTURE_H_
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#endif
#else
#include "memory_management.h"
#endif
#include <glib.h>
#include "MLV_playlist.h"
#include "MLV_text.h"
#include "list.h"
typedef struct _DataMLV {
SDL_Surface *screen;
Uint32 width;
Uint32 height;
int full_screen_is_enable;
SDL_Rect rectangle;
SDL_Surface *save_screen;
SDL_sem* audio_semaphore;
SDL_AudioSpec audio_device_spec;
MLV_List* playing_streaming;
MLV_List* playlists;
MLV_List* active_playlists;
MLV_Font* defaultFont;
FPSmanager frame_rate_manager;
FPSmanager frame_rate_manager_for_MLV_wait_event;
} DataMLV;
struct _MLV_Image {
SDL_Surface * surface;
};
#endif

425
MLV/event.c Normal file
View File

@@ -0,0 +1,425 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_event.h"
#include "MLV_mouse.h"
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#endif
#else
#include "memory_debug.h"
#endif
#include <string.h>
#include "warning_error.h"
#include "memory_management.h"
#include "MLV_time.h"
#include "data_structure.h"
extern DataMLV* MLV_data;
MLV_Event MLV_get_event(
MLV_Keyboard_button* key_sym, MLV_Keyboard_modifier* key_mod, int* unicode,
char** texte, MLV_Input_box** input_box,
int* mouse_x, int* mouse_y, MLV_Mouse_button* mouse_button,
MLV_Button_state* state
){
SDL_Event event;
int invalidEvent = 1;
while( invalidEvent ){
if( SDL_PollEvent( &event ) ){
switch( event.type ){
case SDL_KEYDOWN: {
if( key_sym || key_mod || state ){
if( key_sym ){
(*key_sym) = (MLV_Keyboard_button)
event.key.keysym.sym;
}
if( key_mod ){
(*key_mod) = (MLV_Keyboard_modifier)
event.key.keysym.mod;
}
if( unicode ){
(*unicode) = event.key.keysym.unicode;
}
if( state ){
(*state) = MLV_PRESSED;
}
return MLV_KEY;
}
};
break;
case SDL_KEYUP:{
if( key_sym || key_mod || state ){
if( key_sym ){
(*key_sym) = (MLV_Keyboard_button)
event.key.keysym.sym;
}
if( key_mod ){
(*key_mod) = (MLV_Keyboard_modifier)
event.key.keysym.mod;
}
if( unicode ){
(*unicode) = event.key.keysym.unicode;
}
if( state ){
(*state) = MLV_RELEASED;
}
return MLV_KEY;
}
};
break;
case SDL_MOUSEMOTION:{
if( mouse_x || mouse_y ){
if( mouse_x ){
(*mouse_x) = event.motion.x;
}
if( mouse_y ){
(*mouse_y) = event.motion.y;
}
return MLV_MOUSE_MOTION;
}
}
break;
case SDL_MOUSEBUTTONUP: {
if( mouse_x || mouse_y || mouse_button || state ){
if( mouse_x ){
(*mouse_x) = event.button.x;
}
if( mouse_y ){
(*mouse_y) = event.button.y;
}
if( mouse_button ){
(*mouse_button) = (MLV_Mouse_button)
event.button.button;
}
if( state ){
(*state) = MLV_RELEASED;
}
return MLV_MOUSE_BUTTON;
}
}
break;
case SDL_MOUSEBUTTONDOWN: {
if( mouse_x || mouse_y || mouse_button || state ){
if( mouse_x ){
(*mouse_x) = event.button.x;
}
if( mouse_y ){
(*mouse_y) = event.button.y;
}
if( mouse_button ){
(*mouse_button) = (MLV_Mouse_button)
event.button.button;
}
if( state ){
(*state) = MLV_PRESSED;
}
return MLV_MOUSE_BUTTON;
}
}
break;
case SDL_QUIT:{
}
break;
case SDL_USEREVENT: {
if( event.user.code == MLV_INPUT_BOX ){
if( texte || input_box ){
if( input_box ){
(*input_box) = event.user.data1;
}
if( texte ){
int size = strlen(event.user.data2)+1;
(*texte) = MLV_MALLOC( size, char );
memcpy(
(*texte),
event.user.data2,
size
);
}
return MLV_INPUT_BOX;
}
}
}
break;
default:;
}
}else{
invalidEvent = 0;
}
}
return MLV_NONE;
}
MLV_Event MLV_wait_event(
MLV_Keyboard_button* key_sym, MLV_Keyboard_modifier* key_mod, int* unicode,
char** texte, MLV_Input_box** input_box,
int* mouse_x, int* mouse_y, MLV_Mouse_button* mouse_button,
MLV_Button_state* state
){
MLV_Event resultat;
while(
(
resultat = MLV_get_event(
key_sym, key_mod, unicode,
texte, input_box,
mouse_x, mouse_y, mouse_button,
state
)
) == MLV_NONE
) SDL_framerateDelay( &(MLV_data->frame_rate_manager_for_MLV_wait_event) );
return resultat;
}
MLV_Event MLV_wait_event_or_seconds(
MLV_Keyboard_button* key_sym, MLV_Keyboard_modifier* key_mod, int* unicode,
char** texte, MLV_Input_box** input_box,
int* mouse_x, int* mouse_y, MLV_Mouse_button* mouse_button,
MLV_Button_state* state, int seconds
){
MLV_Event resultat;
int time = MLV_get_time();
while(
(
(
resultat = MLV_get_event(
key_sym, key_mod, unicode,
texte, input_box,
mouse_x, mouse_y, mouse_button,
state
)
) == MLV_NONE
) && (
MLV_get_time() - time < seconds*1000
)
) SDL_framerateDelay( &(MLV_data->frame_rate_manager_for_MLV_wait_event) );
return resultat;
}
void MLV_flush_event_queue(){
MLV_get_event(
NULL, NULL, NULL,
NULL, NULL,
NULL, NULL, NULL,
NULL
);
}
MLV_Event MLV_wait_keyboard_or_mouse(
MLV_Keyboard_button* sym, MLV_Keyboard_modifier* mod, int* unicode,
int* mouse_x, int* mouse_y
){
MLV_Event resultat;
MLV_Button_state state;
MLV_Mouse_button mouse_button;
// We remove all existing event from the queue
MLV_flush_event_queue();
MLV_Keyboard_button tmp_sym;
MLV_Keyboard_modifier tmp_mod;
int tmp_unicode;
int tmp_mouse_x;
int tmp_mouse_y;
//We wait for a new keyboard or mouse event
while(
(
(
(
resultat = MLV_wait_event(
&tmp_sym, &tmp_mod, &tmp_unicode,
NULL, NULL,
&tmp_mouse_x, &tmp_mouse_y, &mouse_button,
&state
)
) != MLV_KEY
) && (
( resultat != MLV_MOUSE_BUTTON ) ||
( mouse_button != MLV_BUTTON_LEFT )
)
) || (
state != MLV_PRESSED
)
);
switch( resultat ){
case MLV_KEY:
if( sym ) *sym = tmp_sym;
if( mod ) *mod = tmp_mod;
if( unicode ) *unicode = tmp_unicode;
break;
case MLV_MOUSE_BUTTON:
if( mouse_x ) *mouse_x = tmp_mouse_x;
if( mouse_y ) *mouse_y = tmp_mouse_y;
break;
default:
ERROR("Valeur d'evenements innatendu.");
}
return resultat;
}
MLV_Event MLV_wait_keyboard_or_mouse_or_seconds(
MLV_Keyboard_button* sym, MLV_Keyboard_modifier* mod, int* unicode,
int* mouse_x, int* mouse_y,
int seconds
){
MLV_Event resultat;
MLV_Button_state state;
MLV_Mouse_button mouse_button;
// We remove all existing event from the queue
MLV_flush_event_queue();
int time = MLV_get_time();
MLV_Keyboard_button tmp_sym;
MLV_Keyboard_modifier tmp_mod;
int tmp_unicode;
int tmp_mouse_x;
int tmp_mouse_y;
int event_is_not_valid = 0;
//We wait for a new keyboard or mouse event
while(
(
event_is_not_valid = (
(
(
resultat = MLV_wait_event_or_seconds(
&tmp_sym, &tmp_mod, &tmp_unicode,
NULL, NULL,
&tmp_mouse_x, &tmp_mouse_y, &mouse_button,
&state,
seconds - (MLV_get_time() - time)/1000
)
) != MLV_KEY
) && (
( resultat != MLV_MOUSE_BUTTON ) ||
( mouse_button != MLV_BUTTON_LEFT )
)
) || (
state != MLV_PRESSED
)
) && (
(MLV_get_time() - time) < seconds*1000
)
);
if(event_is_not_valid) return MLV_NONE;
switch( resultat ){
case MLV_KEY:
if( sym ) *sym = tmp_sym;
if( mod ) *mod = tmp_mod;
if( unicode ) *unicode = tmp_unicode;
break;
case MLV_MOUSE_BUTTON:
if( mouse_x ) *mouse_x = tmp_mouse_x;
if( mouse_y ) *mouse_y = tmp_mouse_y;
break;
default:
ERROR("Valeur d'evenements innatendu.");
}
return resultat;
}
const char* MLV_convert_event_to_string( MLV_Event event_code ){
switch( event_code ){
case MLV_NONE:
return "MLV_NONE";
case MLV_KEY:
return "MLV_KEY";
case MLV_INPUT_BOX:
return "MLV_INPUT_BOX";
case MLV_MOUSE_BUTTON:
return "MLV_MOUSE_BUTTON";
case MLV_MOUSE_MOTION:
return "MLV_MOUSE_MOTION";
default:
ERROR( "Event code unexpected." );
}
return NULL;
}
MLV_Event MLV_convert_string_to_event( const char* event_string ){
if( strcmp( event_string, "MLV_NONE" )==0 ){
return MLV_NONE;
}
if( strcmp( event_string, "MLV_KEY" )==0 ){
return MLV_KEY;
}
if( strcmp( event_string, "MLV_INPUT_BOX" )==0 ){
return MLV_INPUT_BOX;
}
if( strcmp( event_string, "MLV_MOUSE_BUTTON" )==0 ){
return MLV_MOUSE_BUTTON;
}
if( strcmp( event_string, "MLV_MOUSE_MOTION" )==0 ){
return MLV_MOUSE_MOTION;
}
ERROR( "Event name unknown." );
return -1;
}
const char* MLV_convert_button_state_to_string( MLV_Button_state state_code ){
switch( state_code ){
case MLV_PRESSED :
return "MLV_PRESSED";
case MLV_RELEASED :
return "MLV_RELEASED";
default:
ERROR( "Unexpected state code." );
}
return NULL;
}
MLV_Button_state MLV_convert_string_to_button_state( const char* state_string ){
if( strcmp( state_string, "MLV_PRESSED" ) ){
return MLV_PRESSED;
}
if( strcmp( state_string, "MLV_RELEASED" ) ){
return MLV_RELEASED;
}
ERROR( "Unexpected state name." );
return -1;
}

521
MLV/image.c Normal file
View File

@@ -0,0 +1,521 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_image.h"
#include "data_structure.h"
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_image.h>
# include <SDL/SDL_rotozoom.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL_image/SDL_image.h>
# include <SDL/SDL_rotozoom.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_image.h>
# include <SDL/SDL_rotozoom.h>
#endif
#else
#include "memory_debug.h"
#endif
#include "warning_error.h"
#include "memory_management.h"
#include "data_structure.h"
#include "image.h"
extern DataMLV* MLV_data;
SDL_Surface* create_surface( int width, int height ){
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
#if defined( OS_ANDROID )
return SDL_CreateRGBSurface(
SDL_SWSURFACE|SDL_SRCALPHA,
width, height,
MLV_BPP, rmask, gmask, bmask, amask
);
#else
return SDL_CreateRGBSurface(
SDL_HWSURFACE|SDL_SRCALPHA,
width, height,
MLV_BPP, rmask, gmask, bmask, amask
);
#endif
}
MLV_Image* MLV_load_image( const char* file_image ){
if( MLV_data==NULL ){
ERROR("Before using MLV_load_image, you have to initialise the MLV library by calling MLV_create_windows.");
}
SDL_Surface* surface = IMG_Load( file_image );
if( surface==NULL ){
return NULL;
}
MLV_Image* image = MLV_MALLOC( 1, MLV_Image );
image->surface = SDL_DisplayFormatAlpha(
surface
);
SDL_FreeSurface( surface );
return image;
}
int MLV_save_image_as_bmp( const MLV_Image* image, const char* file_image ){
return SDL_SaveBMP( image->surface, file_image );
}
void MLV_resize_image( MLV_Image* image, int width, int height ){
double scalar_x = ((double) width) / ((double) image->surface->w);
double scalar_y = ((double) height) / ((double) image->surface->h);
MLV_scale_xy_image( image, scalar_x, scalar_y );
}
void MLV_vertical_image_mirror( MLV_Image* image ){
int width, height;
MLV_get_image_size( image, &width, &height );
Uint32 *pixel_src, *pixel_dst, tmp;
int i=0; int j=0;
for( i=0; i< width/2; i++ ){
for( j=0; j<height; j++ ){
pixel_src = ((Uint32*) image->surface->pixels) +
j*image->surface->pitch/4 + i;
pixel_dst = ((Uint32*) image->surface->pixels) +
j*image->surface->pitch/4 + width-1-i;
tmp = *pixel_dst;
*pixel_dst = *pixel_src;
*pixel_src = tmp;
}
}
}
void MLV_horizontal_image_mirror( MLV_Image* image ){
int width, height;
MLV_get_image_size( image, &width, &height );
Uint32 *pixel_src, *pixel_dst, tmp;
int i=0; int j=0;
for( i=0; i< width; i++ ){
for( j=0; j<height/2; j++ ){
pixel_src = ((Uint32*) image->surface->pixels) +
j*image->surface->pitch/4 + i;
pixel_dst = ((Uint32*) image->surface->pixels) +
(height-1-j)*image->surface->pitch/4 + i;
tmp = *pixel_dst;
*pixel_dst = *pixel_src;
*pixel_src = tmp;
}
}
}
void MLV_resize_image_with_proportions( MLV_Image* image, int width, int height ){
double scalar_x = -1.0;
double scalar_y = -1.0;
if( width<=0 && height<=0 ) return;
if( width > 0){
scalar_x = ((double) width) / ((double) image->surface->w);
}
if( height > 0){
scalar_y = ((double) height) / ((double) image->surface->h);
}
if( scalar_x < 0 ){
scalar_x = scalar_y;
}
if( scalar_y < 0 ){
scalar_y = scalar_x;
}
MLV_scale_image( image, ( scalar_x < scalar_y )? scalar_x : scalar_y );
}
void MLV_get_image_size( const MLV_Image* image, int* width, int* height ){
if( width ){
*width = image->surface->w;
}
if( height ){
*height = image->surface->h;
}
}
int MLV_get_image_width( const MLV_Image* image ){
return image->surface->w;
}
int MLV_get_image_height( const MLV_Image* image ){
return image->surface->h;
}
void MLV_scale_xy_image( MLV_Image* image, double scalar_x, double scalar_y ){
MLV_rotate_and_scale_xy_image( image, 0.0, scalar_x, scalar_y );
}
void MLV_rotate_and_scale_xy_image(
MLV_Image* image, double rotation, double scalar_x, double scalar_y
){
SDL_Surface* dst;
dst = rotozoomSurfaceXY( image->surface, rotation, scalar_x, scalar_y, 0);
SDL_FreeSurface( image->surface );
image->surface = dst;
}
void MLV_scale_image( MLV_Image* image, double scalar ){
MLV_rotate_and_scale_image( image, 0.0, scalar );
}
void MLV_rotate_image( MLV_Image* image, double rotation ){
MLV_rotate_and_scale_image( image, rotation, 1.0 );
}
void MLV_rotate_and_scale_image( MLV_Image* image, double rotation, double scalar ){
SDL_Surface* dst;
dst = rotozoomSurface( image->surface, rotation, scalar, 0);
SDL_FreeSurface( image->surface );
image->surface = dst;
}
MLV_Image* MLV_create_image( int width, int height ){
MLV_Image* result = MLV_MALLOC( 1, MLV_Image );
result->surface = create_surface( width, height );
int i,j;
for( i=0; i<width; i++ ){
for( j=0; j<height; j++ ){
MLV_set_pixel_on_image( i, j, MLV_rgba( 0,0,0,255 ), result );
}
}
return result;
}
void MLV_free_image( MLV_Image* image ){
if( image ){
SDL_FreeSurface( image->surface );
MLV_FREE( image, MLV_Image );
}
}
MLV_Image* MLV_copy_image( const MLV_Image* image ){
MLV_Image* result = MLV_MALLOC( 1, MLV_Image );
result->surface = SDL_ConvertSurface(
image->surface, image->surface->format, image->surface->flags
);
return result;
}
MLV_Image* MLV_copy_partial_image( const MLV_Image* image, int x, int y, int width, int height ){
MLV_Image* result = MLV_MALLOC( 1, MLV_Image );
SDL_Surface* tmp = create_surface( width, height );
result->surface = SDL_DisplayFormatAlpha( tmp );
SDL_FreeSurface( tmp );
SDL_LockSurface( image->surface );
SDL_LockSurface( result->surface );
Uint32 *pixel_src, *pixel_dst;
int i=0; int j=0;
for( i=0; i< width; i++ ){
for( j=0; j<height; j++ ){
pixel_src = ((Uint32*) image->surface->pixels) +
(y+j)*image->surface->pitch/4 + x+i;
pixel_dst = ((Uint32*) result->surface->pixels) +
j*result->surface->pitch/4 + i;
*pixel_dst = * pixel_src;
}
}
SDL_UnlockSurface( result->surface );
SDL_UnlockSurface( image->surface );
return result;
}
void MLV_draw_image( const MLV_Image* image, int x, int y ){
SDL_Rect rectangle;
rectangle.x = x;
rectangle.y = y;
rectangle.h = image->surface->h;
rectangle.w = image->surface->w;
SDL_BlitSurface( image->surface, NULL, MLV_data->screen, &rectangle);
}
void MLV_draw_partial_image(
const MLV_Image* image, int x_source, int y_source,
int width_source, int height_source,
int x, int y
){
SDL_Rect rectangle_source;
rectangle_source.x = x_source;
rectangle_source.y = y_source;
rectangle_source.h = height_source;
rectangle_source.w = width_source;
SDL_Rect rectangle_dest;
rectangle_dest.x = x;
rectangle_dest.y = y;
rectangle_dest.h = height_source;
rectangle_dest.w = width_source;
SDL_BlitSurface( image->surface, &rectangle_source, MLV_data->screen, &rectangle_dest);
}
void MLV_draw_scaled_rotated_image( MLV_Image* image, int centre_x, int centre_y, double rotation, double scalar ){
SDL_Surface* dst;
dst = rotozoomSurface( image->surface, rotation, scalar, 0);
SDL_Rect rectangle_dest;
rectangle_dest.x = centre_x;
rectangle_dest.y = centre_y;
rectangle_dest.h = dst->h;
rectangle_dest.w = dst->w;
SDL_BlitSurface( dst, NULL, MLV_data->screen, &rectangle_dest);
SDL_FreeSurface( dst );
}
void MLV_draw_rotated_image( MLV_Image* image, int centre_x, int centre_y, double roation ){
MLV_draw_scaled_rotated_image( image, centre_x, centre_y, roation, 1.0 );
}
void MLV_draw_scaled_image( MLV_Image* image, int centre_x, int centre_y, double scalar ){
MLV_draw_scaled_rotated_image( image, centre_x, centre_y, 0.0, scalar );
}
void MLV_set_alpha_on_image( MLV_Alpha alpha, MLV_Image *image ){
SDL_Surface* surface = image->surface;
SDL_LockSurface(surface);
SDL_PixelFormat *fmt;
Uint32 *pixel;
Uint32 alpha32;
fmt = surface->format;
int x,y;
int width, height;
MLV_get_image_size( image, &width, &height );
for( x=0; x<width; x++){
for( y=0; y<height; y++ ){
pixel = ((Uint32*) surface->pixels)+ y*surface->pitch/4 + x;
/* set the Alpha component */
alpha32 = alpha;
alpha32 = alpha32 >> fmt->Aloss;
alpha32 = alpha32 << fmt->Ashift;
*pixel = (
*pixel & ( fmt->Rmask | fmt->Gmask | fmt->Bmask )
) | alpha32;
}
}
SDL_UnlockSurface(surface);
}
void MLV_set_pixel_on_image(
int x, int y,
MLV_Color color,
MLV_Image *image
){
SDL_Surface* surface = image->surface;
SDL_LockSurface(surface);
SDL_PixelFormat *fmt;
Uint32 *pixel;
fmt = surface->format;
pixel = ((Uint32*) surface->pixels)+ y*surface->pitch/4 + x;
Uint8 red, blue, green, alpha;
MLV_convert_color_to_rgba( color, &red, &green, &blue, &alpha );
Uint32 red32 = red, blue32 = blue, green32 = green, alpha32 = alpha;
/* set the Red component */
red32 = red32 >> fmt->Rloss;
red32 = red32 << fmt->Rshift;
/* set the Green component */
green32 = green32 >> fmt->Gloss;
green32 = green32 << fmt->Gshift;
/* set the Blue component */
blue32 = blue32 >> fmt->Bloss;
blue32 = blue32 << fmt->Bshift;
/* set the Alpha component */
alpha32 = alpha32 >> fmt->Aloss;
alpha32 = alpha32 << fmt->Ashift;
*pixel = red32 | green32 | blue32 | alpha32;
SDL_UnlockSurface(surface);
}
SDL_Surface* MLV_get_image_data( MLV_Image* image ){
return image->surface;
}
void get_pixel_on_image_unsafe(
SDL_Surface* surface,
int x, int y,
int* red, int* green, int* blue, int* alpha
){
/* Extracting color components from a 32-bit color value */
SDL_PixelFormat *fmt;
Uint32 temp, pixel;
fmt = surface->format;
pixel = *(((Uint32*) surface->pixels)+ y*surface->pitch/4 + x );
/* Get Red component */
if( red ){
temp = pixel & fmt->Rmask; /* Isolate red component */
temp = temp >> fmt->Rshift; /* Shift it down to 8-bit */
temp = temp << fmt->Rloss; /* Expand to a full 8-bit number */
*red = temp;
}
/* Get Green component */
if( green ){
temp = pixel & fmt->Gmask; /* Isolate green component */
temp = temp >> fmt->Gshift; /* Shift it down to 8-bit */
temp = temp << fmt->Gloss; /* Expand to a full 8-bit number */
*green = temp;
}
/* Get Blue component */
if( blue ){
temp = pixel & fmt->Bmask; /* Isolate blue component */
temp = temp >> fmt->Bshift; /* Shift it down to 8-bit */
temp = temp << fmt->Bloss; /* Expand to a full 8-bit number */
*blue = temp;
}
/* Get Alpha component */
if( alpha ){
temp = pixel & fmt->Amask; /* Isolate alpha component */
temp = temp >> fmt->Ashift; /* Shift it down to 8-bit */
temp = temp << fmt->Aloss; /* Expand to a full 8-bit number */
*alpha = temp;
}
}
void get_pixel_on_image(
SDL_Surface* surface,
int x, int y,
int* red, int* green, int* blue, int* alpha
){
SDL_LockSurface(surface);
get_pixel_on_image_unsafe(
surface,
x, y,
red, green, blue, alpha
);
SDL_UnlockSurface(surface);
}
void MLV_get_pixel(
int x, int y, int* red, int* green, int* blue, int* alpha
){
get_pixel_on_image( MLV_data->screen, x, y, red, green, blue, alpha );
}
void MLV_get_pixel_on_image(
const MLV_Image* image, int x, int y,
int* red, int* green, int* blue, int* alpha
){
get_pixel_on_image( image->surface, x, y, red, green, blue, alpha );
}
void MLV_draw_image_on_image(
const MLV_Image* source_image,
MLV_Image* destination_image,
int destination_x, int destination_y
){
SDL_Rect rectangle;
rectangle.x = destination_x;
rectangle.y = destination_y;
rectangle.h = source_image->surface->h;
rectangle.w = source_image->surface->w;
SDL_BlitSurface( source_image->surface, NULL, destination_image->surface , &rectangle);
}
void MLV_draw_partial_image_on_image(
const MLV_Image* source_image,
int source_x, int source_y,
int width, int height,
MLV_Image* destination_image,
int destination_x, int destination_y
){
SDL_Rect rectangle_source,rectangle_destination;
rectangle_destination.x = destination_x;
rectangle_destination.y = destination_y;
rectangle_destination.w = destination_image->surface->w;
rectangle_destination.h = destination_image->surface->h;
rectangle_source.x = source_x;
rectangle_source.y = source_y;
rectangle_source.w = width;
rectangle_source.h = height;
SDL_BlitSurface(
source_image->surface, &rectangle_source,
destination_image->surface , &rectangle_destination
);
}
///////////////////////////////////////////////////////////////////////////////
// Save screen //
///////////////////////////////////////////////////////////////////////////////
void MLV_save_screen(){
SDL_BlitSurface( MLV_data->screen, NULL, MLV_data->save_screen, &(MLV_data->rectangle));
}
void MLV_load_screen(){
SDL_BlitSurface( MLV_data->save_screen, NULL, MLV_data->screen, &(MLV_data->rectangle));
}

55
MLV/image.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__IMAGE_H__
#define __MLV__IMAGE_H__
#include "platform.h"
#if defined( __MLV_ANDROID__ )
# define MLV_16_BPP 16
#else
# define MLV_32_BPP 32
#endif
#if defined( MLV_32_BPP )
# define MLV_BPP 32
#elif defined( MLV_16_BPP )
# define MLV_BPP 16
#endif
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
#else
# include <SDL/SDL.h>
#endif
#else
#include "memory_debug.h"
#endif
SDL_Surface* create_surface( int width, int height );
void get_pixel_on_image_unsafe( SDL_Surface* surface, int x, int y,
int* red, int* green, int* blue, int* alpha
);
#endif

50
MLV/informations.c Normal file
View File

@@ -0,0 +1,50 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_information.h"
#include "config.h"
const char* MLV_get_package_name( ){
return PACKAGE_NAME;
}
const char* MLV_get_version( ){
return VERSION;
}
const char* MLV_get_revision_of_revision_control_software( ){
return MLV_RCS_REVISION;
}
const char* MLV_get_repository( ){
return MLV_REPOSITORY;
}
const char* MLV_get_bug_report_address( ){
return PACKAGE_BUGREPORT;
}
const char* MLV_get_web_distribution( ){
return PACKAGE_URL;
}
const char* MLV_get_licence( ){
return "GPL V3";
}

935
MLV/input_box.c Normal file
View File

@@ -0,0 +1,935 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "platform.h"
#ifdef OS_WINDOWS
/* Get va_list. */
#if __STDC__ || defined __cplusplus || defined _MSC_VER
# include <stdarg.h>
#else
# include <varargs.h>
#endif
extern int vasprintf (char **, const char *, va_list);
#endif
#include "MLV_input_box.h"
#include "MLV_event.h"
#include "MLV_text.h"
#include "platform.h"
#include "image.h"
#include "input_box.h"
#include "text.h"
#include "list.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
#endif
#else
#include "memory_debug.h"
#endif
#include "sdlkeyboardtochar.h"
#include "glib.h"
#include <string.h>
#include "warning_error.h"
#include "memory_management.h"
#define SIZE_FONT 8
#define SIZE_BORD 1
#define TIME_CURSOR 1000 //Periode d'oscillation du curseur (ms)
//
// Les fonction avec le suffixe _NST veux dire : No Safe Thread.
// Cela veux dire qu'anvant d'utiliser de telle fonctions, il faut
// s'assurer la propriété entiere des objet qu'il va modifier.
//
#include "data_structure.h"
extern DataMLV* MLV_data;
struct _MLV_Input_box {
//Géométrie de la boîte de saisie
int sommetHautGauche[2];
int sommetBasDroit[2];
int width;
int height;
SDL_Rect rectangle;
//Taille de la font du texte
const MLV_Font* font;
//Positiononnement du texte
int bord[2];
int widthMessage;
int widthAnswer;
int heightMessAns;
//Couleurs de la boîtes de saisie
MLV_Color borderColor;
MLV_Color textColor;
MLV_Color backgroundColor;
//Rendu de la boîte de saisie
SDL_Surface* apparence;
SDL_Surface* answer;
SDL_Rect answerRectangle;
//Message d'information
char* informativeMessage;
//position du curseur dans la réponse courante
int positionCursor;
int lastTime;
int cursorIsVisible; //le curseur (qui clignote ) est dans son etat visible
//La boîte de saisie est active
int isListenning;
//Histroique - le premier élément de l'historique correspond à la
//reponse courante de la boîte de saisie
MLV_List* history;
MLV_List* positionHistory;
//Gestion concurentiel de l'accès à la boîte de saisie.
SDL_sem* semaphore;
};
/*
* bord[0] withMessage withAnswer bord[0]
* <---><-------------><---------------------------><-->
* _ ____________________________________________________
* bord[1] | | |
* |_ | _____________________________________________ |
* | | | | | |
* heightMessAns | | | I. Message | An|swer | |
* |_ | |_______________|___________________________| |
* | | |
* bord[1] |_ |___________________________________________________|
*
*
* */
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void recalculateTextPositions_NTS( MLV_Input_box* input_box ){
int width_message, height_message;
MLV_get_size_of_text_with_font(
input_box->informativeMessage,
&width_message, &height_message,
input_box->font
);
input_box->widthMessage = width_message;
input_box->widthAnswer = input_box->width - input_box->widthMessage - 2 * input_box->bord[0];
input_box->heightMessAns = ( input_box->font->size > height_message )?
input_box->font->size : height_message ;
// input_box->heightMessAns = height_message ;
input_box->bord[1] = (input_box->height - ( input_box->heightMessAns ) )/2;
if(input_box->answer){
// DEBUG("Free answer");
SDL_FreeSurface( input_box->answer );
}
if( input_box->widthAnswer > 0 ){
// DEBUG("Create answer");
input_box->answer = create_surface( input_box->widthAnswer, input_box->heightMessAns );
input_box->answerRectangle.x = input_box->bord[0] + input_box->widthMessage;
input_box->answerRectangle.y = input_box->bord[1];
input_box->answerRectangle.w = input_box->widthAnswer;
input_box->answerRectangle.h = input_box->heightMessAns;
}else{
input_box->answer = NULL;
}
}
void lock_input_box( MLV_Input_box* input_box ){
if( SDL_SemWait( input_box->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
void unlock_input_box( MLV_Input_box* input_box ){
if( SDL_SemPost( input_box->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
typedef struct _Input_box_information {
MLV_List* input_box_list;
MLV_Input_box* input_box_activated;
SDL_sem* semaphore;
} Input_box_information;
Input_box_information input_box_information;
void lock_input_box_information( ){
if( SDL_SemWait( input_box_information.semaphore ) ){
ERROR_FULL( "Probleme de semaphore" );
}
}
void unlock_input_box_information( ){
if( SDL_SemPost( input_box_information.semaphore ) ){
ERROR_FULL( "Probleme de semaphore" );
}
}
/*
input_box->history->data
0 m l-1
---------------------------------------------------------
| | | | | X | Y | | | | | | | | \0 |
---------------------------------------------------------
|
curseur
new
0 m l-1 l
---------------------------------------------------------
| | | | | X | c | Y | | | | | | | \0 |
---------------------------------------------------------
|
curseur
*/
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void add_carac_input_box_NTS( MLV_Input_box* input_box, char c ){
int l = strlen(input_box->history->data);
int m = input_box->positionCursor ;
// DEBUG("Add History Entry");
char* new = MLV_MALLOC( ( l + 2 ), char );
strncpy( new, input_box->history->data , m );
new[input_box->positionCursor] = c;
strncpy( new + m + 1 , input_box->history->data + m , l - m );
new[l + 1] = '\0';
// DEBUG("Free History Entry");
MLV_FREE( input_box->history->data, char );
input_box->history->data = new;
input_box->positionCursor++;
}
/*
input_box->history->data
0 m l-1
---------------------------------------------------------
| | | | | X | Y | Z | | | | | | | \0 |
---------------------------------------------------------
|
curseur
resultat
0 m l-1
------------------------------------------------------
| | | | | X | Z | | | | | | | \0 |
------------------------------------------------------
|
curseur
*/
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void suppress_carac_input_box_NTS( MLV_Input_box* input_box ){
int l = strlen(input_box->history->data);
int m = input_box->positionCursor ;
if( l == m ) return;
memmove( input_box->history->data + m, input_box->history->data + m + 1, l - m );
}
/*
input_box->history->data
0 m l-1
---------------------------------------------------------
| | | | X | Y | Z | | | | | | | | \0 |
---------------------------------------------------------
|
curseur
resulat
0 m-1 m l-1
------------------------------------------------------
| | | | X | Z | | | | | | | | \0 |
------------------------------------------------------
|
curseur
*/
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void return_deletion_carac_input_box_NTS( MLV_Input_box* input_box ){
int l = strlen(input_box->history->data);
int m = input_box->positionCursor ;
if( m != 0 ){
memmove( input_box->history->data + m-1, input_box->history->data + m , l - m + 1 );
input_box->positionCursor--;
}
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void recalculateSommetBas_NTS( MLV_Input_box* input_box ){
input_box->sommetBasDroit[0] = input_box->sommetHautGauche[0] + input_box->width;
input_box->sommetBasDroit[1] = input_box->sommetHautGauche[1] + input_box->height;
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void change_position_input_box_NTS(MLV_Input_box* input_box, int sommetHautGaucheX, int sommetHautGaucheY){
input_box->sommetHautGauche[0] = sommetHautGaucheX;
input_box->sommetHautGauche[1] = sommetHautGaucheY;
input_box->rectangle.x = sommetHautGaucheX;
input_box->rectangle.y = sommetHautGaucheY;
recalculateSommetBas_NTS( input_box );
recalculateTextPositions_NTS( input_box );
}
void MLV_change_position_input_box(MLV_Input_box* input_box, int sommetHautGaucheX, int sommetHautGaucheY){
lock_input_box( input_box );
change_position_input_box_NTS( input_box, sommetHautGaucheX, sommetHautGaucheY );
unlock_input_box( input_box );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void change_size_input_box_NTS(MLV_Input_box* input_box, int width, int height){
if( (width < 0) || (height < 0)){
ERROR_FULL( "Les tailles ne sont pas correctes." );
}
input_box->width = width;
input_box->height = height;
input_box->rectangle.w = width;
input_box->rectangle.h = height;
if( input_box->apparence ){
// DEBUG("Free apparence");
SDL_FreeSurface(input_box->apparence);
}
// DEBUG("Create apparence");
input_box->apparence = create_surface( input_box->width, input_box->height );
recalculateSommetBas_NTS( input_box );
recalculateTextPositions_NTS( input_box );
}
void MLV_change_input_box_size(MLV_Input_box* input_box, int width, int height){
lock_input_box( input_box );
change_size_input_box_NTS( input_box, width, height);
unlock_input_box( input_box );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void change_geometry_input_box_NTS(MLV_Input_box* input_box, int sommetHautGaucheX, int sommetHautGaucheY, int width, int height){
change_size_input_box_NTS( input_box, width, height );
change_position_input_box_NTS( input_box, sommetHautGaucheX, sommetHautGaucheY);
};
void MLV_change_input_box_geometry(MLV_Input_box* input_box, int sommetHautGaucheX, int sommetHautGaucheY, int width, int height){
lock_input_box( input_box );
change_geometry_input_box_NTS( input_box, sommetHautGaucheX, sommetHautGaucheY, width, height);
unlock_input_box( input_box );
};
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void change_colors_input_box_NTS( MLV_Input_box* input_box, MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor ){
input_box->borderColor = borderColor;
input_box->textColor = textColor;
input_box->backgroundColor = backgroundColor;
};
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void MLV_change_input_box_colors( MLV_Input_box* input_box, MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor ){
lock_input_box( input_box );
change_colors_input_box_NTS( input_box, borderColor, textColor, backgroundColor );
unlock_input_box( input_box );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void desactivate_input_box_NTS( ){
if( input_box_information.input_box_activated ){
input_box_information.input_box_activated->isListenning = 0;
input_box_information.input_box_activated = NULL;
}
}
void MLV_desactivate_input_box( ){
lock_input_box_information();
desactivate_input_box_NTS( );
unlock_input_box_information();
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void activate_imput_box_NTS( MLV_Input_box* input_box ){
desactivate_input_box_NTS( );
input_box->isListenning = 1;
input_box_information.input_box_activated = input_box;
}
void MLV_activate_input_box( MLV_Input_box* input_box ){
lock_input_box_information();
lock_input_box( input_box );
activate_imput_box_NTS( input_box );
unlock_input_box( input_box );
unlock_input_box_information();
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
int is_in_input_box_NTS( MLV_Input_box* input_box, int x, int y ){
int result = 0;
if( (x >= input_box->sommetHautGauche[0]) &&
(x <= input_box->sommetBasDroit[0]) &&
(y >= input_box->sommetHautGauche[1]) &&
(y <= input_box->sommetBasDroit[1])
) result = 1;
return result;
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
MLV_Input_box* is_in_an_input_box_NTS( int x, int y ){
MLV_Input_box* result = NULL;
MLV_List* list = input_box_information.input_box_list;
while( list ){
MLV_Input_box* input_box = (MLV_Input_box*) list->data;
if( is_in_input_box_NTS( input_box, x, y ) ){
result = input_box;
break;
}
list = list->next;
}
return result;
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void construct_input_box_NTS( MLV_Input_box* input_box ){
int width_message_before_input_box, height_message_before_input_box;
boxColor(
input_box->apparence,
0, 0, input_box->width-1, input_box->height-1,
input_box->backgroundColor
);
drawString(
input_box->apparence,
input_box->bord[0] , input_box->bord[1],
input_box->informativeMessage,
input_box->textColor, input_box->font->font
);
if( input_box->widthAnswer > 0 ){
boxColor(
input_box->answer,
0, 0, input_box->widthAnswer-1, input_box->heightMessAns -1,
input_box->backgroundColor
);
char * message = (char*) input_box->history->data ;
int decalage = 0;
char* message_before_input_box = MLV_MALLOC( input_box->positionCursor+1, char );
strncpy( message_before_input_box, message, input_box->positionCursor );
message_before_input_box[input_box->positionCursor] = '\0';
MLV_get_size_of_text_with_font(
message_before_input_box,
&width_message_before_input_box, &height_message_before_input_box,
input_box->font
);
if( width_message_before_input_box > (input_box->widthAnswer) ){
decalage = input_box->widthAnswer - width_message_before_input_box -1;
}
MLV_FREE( message_before_input_box, char );
drawString(
input_box->answer,
decalage , 0,
message,
input_box->textColor, input_box->font->font
);
SDL_BlitSurface(
input_box->answer, NULL,
input_box->apparence, &(input_box->answerRectangle)
);
}
int time = SDL_GetTicks();
if( ( time - input_box->lastTime > TIME_CURSOR ) ){
input_box->lastTime = time;
input_box->cursorIsVisible = ! input_box->cursorIsVisible;
};
if( (! input_box->isListenning) || input_box->cursorIsVisible ){
int abscisse;
if( width_message_before_input_box > input_box->widthAnswer ){
abscisse = input_box->bord[0] +
input_box->widthMessage +
input_box->widthAnswer -2;
}else{
abscisse = input_box->bord[0] +
input_box->widthMessage +
width_message_before_input_box;
}
lineColor(
input_box->apparence,
abscisse , input_box->bord[1],
abscisse, input_box->bord[1] + input_box->heightMessAns -1,
input_box->textColor
);
}
rectangleColor(
input_box->apparence,
0, 0,
input_box->width-1, input_box->height-1,
input_box->borderColor
);
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void input_box_register_NTS(MLV_Input_box* input_box){
input_box_information.input_box_list = MLV_prepend_list( input_box_information.input_box_list , input_box );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void input_box_unregister_NTS(MLV_Input_box* input_box){
if( input_box_information.input_box_activated == input_box ) desactivate_input_box_NTS();
input_box_information.input_box_list = MLV_remove_list( input_box_information.input_box_list, input_box );
}
MLV_Input_box* create_input_box_with_font(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
const MLV_Font* font
){
// DEBUG("Add input_box");
MLV_Input_box* input_box = MLV_MALLOC( 1, MLV_Input_box );
// DEBUG("Create semaphore");
input_box->semaphore = SDL_CreateSemaphore(1);
input_box->font = font;
input_box->bord[0] = SIZE_BORD;
// DEBUG("Add Informative message");
input_box->informativeMessage = MLV_MALLOC( (strlen(informativeMessage)+1), char );
strcpy( input_box->informativeMessage, informativeMessage );
input_box->apparence = NULL;
input_box->answer = NULL;
change_geometry_input_box_NTS(input_box, sommetHautGaucheX, sommetHautGaucheY, width, height);
MLV_change_input_box_colors(input_box, borderColor, textColor, backgroundColor );
// DEBUG("Add History Entry");
input_box->history = MLV_prepend_list( NULL, MLV_MALLOC( 1, char ) );
((char*) input_box->history->data)[0] = '\0';
input_box->positionHistory = input_box->history;
input_box->positionCursor = 0;
input_box->lastTime = SDL_GetTicks();
input_box->cursorIsVisible = 1;
input_box->isListenning = 0;
lock_input_box_information();
input_box_register_NTS( input_box );
unlock_input_box_information();
return input_box;
}
MLV_Input_box* MLV_create_input_box_with_font_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
const MLV_Font* font, va_list pile
){
char* complete_informative_message;
if(
vasprintf(
&complete_informative_message, informativeMessage, pile
)==-1
){
ERROR("Unexpected Error.");
}
MLV_Input_box* result = create_input_box_with_font(
sommetHautGaucheX, sommetHautGaucheY, width, height, borderColor,
textColor, backgroundColor, complete_informative_message, font
);
free( complete_informative_message );
return result;
}
MLV_Input_box* MLV_create_input_box_with_font(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
const MLV_Font* font, ...
){
va_list pile;
va_start( pile, font );
MLV_Input_box* result = MLV_create_input_box_with_font_va(
sommetHautGaucheX, sommetHautGaucheY,
width, height,
borderColor, textColor,
backgroundColor,
informativeMessage,
font, pile
);
va_end( pile );
return result;
}
MLV_Input_box* MLV_create_input_box_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
va_list pile
){
return MLV_create_input_box_with_font_va(
sommetHautGaucheX, sommetHautGaucheY,
width, height,
borderColor, textColor,
backgroundColor,
informativeMessage,
MLV_data->defaultFont, pile
);
}
MLV_Input_box* MLV_create_input_box(
int sommetHautGaucheX, int sommetHautGaucheY,
int width, int height,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage, ...
){
va_list pile;
va_start( pile, informativeMessage );
MLV_Input_box* result = MLV_create_input_box_va(
sommetHautGaucheX, sommetHautGaucheY,
width, height,
borderColor, textColor,
backgroundColor,
informativeMessage, pile
);
va_end( pile );
return result;
}
void free_NTS( void* data, void* useless ){
// DEBUG("Free Entry Hystory");
MLV_FREE( data, char );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void suppressHistory_NTS( MLV_Input_box* input_box ){
MLV_foreach_list( input_box->history, free_NTS, NULL );
// DEBUG("Free history");
MLV_free_list( input_box->history );
}
void MLV_suppress_history( MLV_Input_box* input_box ){
lock_input_box( input_box );
suppressHistory_NTS( input_box );
unlock_input_box( input_box );
}
void MLV_free_input_box( MLV_Input_box* input_box ){
lock_input_box_information( );
lock_input_box( input_box );
input_box_unregister_NTS( input_box );
// DEBUG("Free apparence");
SDL_FreeSurface(input_box->apparence);
// DEBUG("Free answer");
SDL_FreeSurface( input_box->answer );
// DEBUG("Free Informative message");
MLV_FREE( input_box->informativeMessage, char );
// MLV_FREE( input_box->history->data, char );
suppressHistory_NTS( input_box );
// DEBUG("Free semaphore");
SDL_DestroySemaphore( input_box->semaphore );
unlock_input_box_information( );
// DEBUG("Free input_box");
MLV_FREE( input_box, MLV_Input_box );
}
void change_informative_message_of_input_box(
MLV_Input_box* input_box, const char* message
){
lock_input_box(input_box);
if( input_box->informativeMessage ){
// DEBUG("Free Informative message");
MLV_FREE( input_box->informativeMessage, char );
}
// DEBUG("Add Informative message");
input_box->informativeMessage = MLV_MALLOC( (strlen(message)+1), char );
strcpy( input_box->informativeMessage, message );
recalculateTextPositions_NTS( input_box );
unlock_input_box(input_box);
}
void MLV_change_informative_message_of_input_box_va(
MLV_Input_box* input_box, const char* message, va_list pile
){
char* complete_message;
if( vasprintf( &complete_message, message, pile )==-1 ){
ERROR("Unexpected Error.");
}
change_informative_message_of_input_box(
input_box, complete_message
);
free( complete_message );
}
void MLV_change_informative_message_of_input_box(
MLV_Input_box* input_box, const char* message, ...
){
va_list pile;
va_start( pile, message );
MLV_change_informative_message_of_input_box_va(
input_box, message, pile
);
va_end( pile );
}
void MLV_draw_input_box( MLV_Input_box* input_box ){
lock_input_box( input_box );
construct_input_box_NTS( input_box );
SDL_BlitSurface( input_box->apparence, NULL, MLV_data->screen, &(input_box->rectangle));
unlock_input_box( input_box );
}
void MLV_draw_all_input_boxes(){
lock_input_box_information( );
MLV_foreach_list( input_box_information.input_box_list, (void (*)(void*,void*)) MLV_draw_input_box , MLV_data->screen);
unlock_input_box_information( );
}
void init_input_box_mechanism(){
SDL_EnableUNICODE(SDL_ENABLE);
input_box_information.semaphore = SDL_CreateSemaphore(1);
lock_input_box_information();
input_box_information.input_box_list = NULL;
input_box_information.input_box_activated=NULL;
unlock_input_box_information();
}
void quit_input_box_mechanism(){
SDL_DestroySemaphore(input_box_information.semaphore);
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void replaceEntreeByHistory_NTS( MLV_Input_box* input_box ){
char* dst = input_box->history->data;
if( input_box->positionHistory != input_box->history ){
char* src = (char*) input_box->positionHistory->data;
if( strlen(dst) >= strlen(src) ){
strcpy( dst, src );
}else{
// DEBUG("Add Hystory Entry");
input_box->history->data = MLV_MALLOC( (strlen(src) + 1), char );
strcpy( input_box->history->data, src );
// DEBUG("Suppress Hystory Entry");
MLV_FREE( dst, char );
}
}else{
if(dst){
dst[0] = '\0';
}
}
input_box->positionCursor = strlen(input_box->history->data);
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void goDownInHistory_NTS( MLV_Input_box* input_box ){
if( input_box->positionHistory->previous ){
input_box->positionHistory = input_box->positionHistory->previous;
}else{
return;
}
replaceEntreeByHistory_NTS( input_box );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void goUpInHistory_NTS( MLV_Input_box* input_box ){
if( input_box->positionHistory->next ){
input_box->positionHistory = input_box->positionHistory->next;
}else{
return;
}
replaceEntreeByHistory_NTS( input_box );
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void make_the_input_box_visible_NTS( MLV_Input_box* input_box ){
input_box->lastTime = SDL_GetTicks();
input_box->cursorIsVisible = 1;
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void input_box_move_left_answer_NTS( MLV_Input_box* input_box ){
if( input_box->positionCursor > 0 ){
input_box->positionCursor--;
}
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void input_box_move_right_answer_NTS( MLV_Input_box* input_box ){
if( input_box->positionCursor < strlen( input_box->history->data ) ){
input_box->positionCursor++;
}
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void validate_input_box_NTS( MLV_Input_box* input_box ){
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = MLV_INPUT_BOX;
event.user.data1 = input_box;
event.user.data2 = input_box->history->data;
SDL_PushEvent(&event);
input_box->history = MLV_prepend_list( input_box->history, input_box->history->data );
input_box->positionHistory = input_box->history;
// DEBUG("Add Hystory Entry");
input_box->history->data = MLV_MALLOC( 1, char );
((char*)input_box->history->data)[0] = '\0';
input_box->positionCursor = 0;
}
int input_box_events_filter(const SDL_Event *event) {
int result = 1;
lock_input_box_information();
switch(event->type){
case SDL_KEYUP :
{ //Une touche a ete appuyee
if( input_box_information.input_box_activated ) result = 0;
}
break;
case SDL_KEYDOWN :
{ //Une touche a ete appuyee
// Si la touche echap a ete appuye, on laisse passe l'evenement
if ( event->key.keysym.sym == SDLK_ESCAPE ) break;
if( input_box_information.input_box_activated ){
lock_input_box( input_box_information.input_box_activated );
make_the_input_box_visible_NTS( input_box_information.input_box_activated);
//Si la touche est une fleche gauche ou droite on deplace le curseu
if( event->key.keysym.sym == SDLK_LEFT ){
input_box_move_left_answer_NTS( input_box_information.input_box_activated );
}else if( event->key.keysym.sym == SDLK_RIGHT ){
input_box_move_right_answer_NTS( input_box_information.input_box_activated );
}else if( event->key.keysym.sym == SDLK_UP ){//Si la touche est une fleche bas ou haut on se deplace dans l'historique
goUpInHistory_NTS( input_box_information.input_box_activated );
}else if( event->key.keysym.sym == SDLK_DOWN ){
goDownInHistory_NTS( input_box_information.input_box_activated );
}else if( event->key.keysym.sym == SDLK_DELETE ){//Si la touche est une suppession on supprime une lettre
suppress_carac_input_box_NTS( input_box_information.input_box_activated );
}else if( event->key.keysym.sym == SDLK_BACKSPACE ){
return_deletion_carac_input_box_NTS( input_box_information.input_box_activated );
}else if( (event->key.keysym.sym == SDLK_RETURN) || (event->key.keysym.sym == SDLK_KP_ENTER) ){
validate_input_box_NTS(input_box_information.input_box_activated);
}else if( event->key.keysym.unicode != 0 ){
//Si la lettre n'est pas \n On ajoute la lettre au mot courant
//Sinon on vide le mot et on cree un evenement du mot qui
//a ete attrappee par la boite de saisie
char* character = MLV_convert_unicode_to_string(
event->key.keysym.unicode
);
int i=0;
while( character[i] != '\0' ){
add_carac_input_box_NTS(
input_box_information.input_box_activated,
character[i]
);
i++;
}
MLV_FREE( character, char );
}
unlock_input_box( input_box_information.input_box_activated );
result = 0;
}
}
break;
case SDL_MOUSEBUTTONDOWN :
{ //Si on est dans une zone de boîte de saisie on active
// l'enregistrement des données.
MLV_Input_box* tmp = is_in_an_input_box_NTS(
event->button.x, event->button.y
);
if( tmp ){
lock_input_box( tmp );
activate_imput_box_NTS( tmp );
unlock_input_box( tmp );
result=0;
}else{
desactivate_input_box_NTS( );
}
}
break;
default :;
}
unlock_input_box_information();
return result;
}

34
MLV/input_box.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__INPUT_BOX_H__
#define __MLV__INPUT_BOX_H__
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
void init_input_box_mechanism();
void quit_input_box_mechanism();
int input_box_events_filter(const SDL_Event *event);
#endif

187
MLV/input_box_wait.c Normal file
View File

@@ -0,0 +1,187 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "platform.h"
#ifdef OS_WINDOWS
/* Get va_list. */
#if __STDC__ || defined __cplusplus || defined _MSC_VER
# include <stdarg.h>
#else
# include <varargs.h>
#endif
extern int vasprintf (char **, const char *, va_list);
#endif
#include "MLV_input_box.h"
#include "MLV_shape.h"
#include "MLV_color.h"
#include "MLV_window.h"
#include "MLV_event.h"
#include "data_structure.h"
#include "warning_error.h"
#include <stdlib.h>
#include "memory_management.h"
#include "image.h"
extern DataMLV* MLV_data;
void MLV_wait_particular_input_box( MLV_Input_box* input_box, char** text){
MLV_Input_box* tmp_input_box = NULL;
(*text) = NULL;
//We activate the input_box
MLV_activate_input_box( input_box );
// We first flush the event queue
MLV_flush_event_queue();
// We wait for a input_box event
while( ! (*text) ){
MLV_Event event_type = MLV_get_event(
NULL, NULL, NULL,
text, &tmp_input_box,
NULL, NULL, NULL,
NULL
);
if( (event_type==MLV_INPUT_BOX ) && input_box != tmp_input_box ){
MLV_FREE( (*text), char );
(*text) = NULL;
}
MLV_draw_all_input_boxes();
MLV_actualise_window();
}
}
void wait_input_box_with_font(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text,
const MLV_Font* font
){
MLV_Input_box* input_box = MLV_create_input_box_with_font(
sommetHautGaucheX, sommetHautGaucheY,
sommetBasDroitX, sommetBasDroitY,
borderColor, textColor,
backgroundColor,
informativeMessage,
font
);
SDL_Surface *save_screen = create_surface( MLV_data->width, MLV_data->height );
SDL_BlitSurface( MLV_data->screen, NULL, save_screen, &(MLV_data->rectangle));
MLV_wait_particular_input_box( input_box, text);
MLV_free_input_box( input_box );
SDL_BlitSurface( save_screen, NULL, MLV_data->screen, &(MLV_data->rectangle));
SDL_FreeSurface( save_screen );
MLV_actualise_window();
}
void MLV_wait_input_box_with_font_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text,
const MLV_Font* font, va_list pile
){
char* complete_informative_message;
if(
vasprintf(
&complete_informative_message, informativeMessage, pile
)==-1
){
ERROR("Unexpected Error.");
}
wait_input_box_with_font(
sommetHautGaucheX, sommetHautGaucheY, sommetBasDroitX, sommetBasDroitY,
borderColor, textColor, backgroundColor, complete_informative_message,
text, font
);
free( complete_informative_message );
}
void MLV_wait_input_box_with_font(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text,
const MLV_Font* font, ...
){
va_list pile;
va_start( pile, font );
MLV_wait_input_box_with_font_va(
sommetHautGaucheX, sommetHautGaucheY, sommetBasDroitX, sommetBasDroitY,
borderColor, textColor, backgroundColor, informativeMessage,
text, font, pile
);
va_end( pile );
}
void MLV_wait_input_box_va(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text, va_list pile
){
MLV_wait_input_box_with_font_va(
sommetHautGaucheX, sommetHautGaucheY,
sommetBasDroitX, sommetBasDroitY,
borderColor, textColor,
backgroundColor,
informativeMessage,
text, MLV_data->defaultFont, pile
);
}
void MLV_wait_input_box(
int sommetHautGaucheX, int sommetHautGaucheY,
int sommetBasDroitX, int sommetBasDroitY,
MLV_Color borderColor, MLV_Color textColor,
MLV_Color backgroundColor,
const char* informativeMessage,
char** text, ...
){
va_list pile;
va_start( pile, text );
MLV_wait_input_box_va(
sommetHautGaucheX, sommetHautGaucheY, sommetBasDroitX, sommetBasDroitY,
borderColor, textColor, backgroundColor, informativeMessage, text, pile
);
va_end( pile );
}

97
MLV/key.c Normal file
View File

@@ -0,0 +1,97 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "key.h"
#include "warning_error.h"
#include "memory_management.h"
#include <string.h>
struct _MLV_Key {
void* value;
void (* value_destroying_function )( void* value );
int (* compare_values )( void* value1, void* value2 );
};
MLV_Key* MLV_create_key(
void* value,
void (* value_destroying_function )( void* data ),
int (* compare_values )( void* value1, void* value2 )
){
MLV_Key* key = MLV_MALLOC( 1, MLV_Key );
key->value = value;
key->value_destroying_function = value_destroying_function;
key->compare_values = compare_values;
return key;
}
void MLV_free_key( MLV_Key* key ){
if( key ){
if( key->value_destroying_function ){
key->value_destroying_function( key->value );
}
MLV_FREE( key, MLV_Key );
}
}
int MLV_compare_keys( MLV_Key* key1, MLV_Key* key2 ){
return key1->compare_values( key1->value, key2->value );
}
void free_string( char* text ){
MLV_FREE( text, char );
}
int compare_strings( char* text1, char* text2 ){
return strcmp( text1, text2 );
}
MLV_Key* MLV_string_to_key( const char* text ){
size_t l = strlen( text );
char* text_copy = MLV_MALLOC( ( l + 1 ), char );
strncpy( text_copy, text, l+1);
return MLV_create_key(
text_copy,
( void (*)( void* ) ) free_string,
( int (*)( void*, void* ) ) compare_strings
);
}
void free_integer( int* integer ){
MLV_FREE( integer, int );
}
int compare_integers( int* int1, int* int2 ){
return (*int1) - (*int2);
}
MLV_Key* MLV_integer_to_key( int integer ){
int* value = MLV_MALLOC( 1, int );
*value = integer;
return MLV_create_key(
value,
( void (*)( void* ) ) free_integer,
(int (*)( void*, void* )) compare_integers
);
}
void* MLV_get_value_from_key( MLV_Key* key ){
return key->value;
}

42
MLV/key.h Normal file
View File

@@ -0,0 +1,42 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__KEY_H__
#define __MLV__KEY_H__
typedef struct _MLV_Key MLV_Key;
MLV_Key* MLV_create_key(
void* value,
void (* value_destroying_function )( void* value ),
int (* compare_values )( void* value1, void* value2 )
);
void MLV_free_key( MLV_Key* key );
int MLV_compare_keys( MLV_Key* key1, MLV_Key* key2 );
MLV_Key* MLV_string_to_key( const char* text );
MLV_Key* MLV_integer_to_key( int integer );
void* MLV_get_value_from_key( MLV_Key* key );
#endif

1678
MLV/keyboard.c Normal file

File diff suppressed because it is too large Load Diff

79
MLV/list.c Normal file
View File

@@ -0,0 +1,79 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "list.h"
#include "memory_management.h"
MLV_List* MLV_prepend_list( MLV_List* list, void* data ){
MLV_List* result = MLV_MALLOC( 1, MLV_List );
if( list ){
list->previous = result;
}
result->previous = NULL;
result->next = list;
result->data = data;
return result;
}
void MLV_free_list( MLV_List* list ){
if( list ){
MLV_free_list( list->next );
MLV_FREE( list, MLV_List );
}
}
void MLV_foreach_list(
MLV_List* list,
void (* function )( void* data, void* user_data ),
void* user_data
){
while( list ){
function( list->data, user_data );
list = list->next;
}
}
MLV_List* MLV_find_list( MLV_List* list, void* data ){
while( list ){
if( list->data == data ){
break;
}
list = list->next;
}
return list;
}
MLV_List* MLV_remove_list( MLV_List* list, void* data ){
MLV_List* result;
MLV_List* elem = MLV_find_list( list, data );
if( elem->previous ){
elem->previous->next = elem->next;
}
if( elem->next ){
elem->next->previous = elem->previous;
}
if( elem==list ){
result = elem->next;
}else{
result = list;
}
return result;
}

46
MLV/list.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__LIST_H__
#define __MLV__LIST_H__
typedef struct _MLV_List MLV_List;
struct _MLV_List {
MLV_List* previous;
MLV_List* next;
void* data;
};
MLV_List* MLV_prepend_list( MLV_List* list, void* data );
void MLV_free_list( MLV_List* list );
void MLV_foreach_list(
MLV_List* list,
void (* function )( void* data, void* user_data ),
void* user_data
);
MLV_List* MLV_find_list( MLV_List* list, void* data );
MLV_List* MLV_remove_list( MLV_List* list, void* data );
#endif

26
MLV/mathematics.c Normal file
View File

@@ -0,0 +1,26 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mathematics.h"
int max( int a, int b ){
return (a>b)?a:b;
}

27
MLV/mathematics.h Normal file
View File

@@ -0,0 +1,27 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__MATHEMATICS_H__
#define __MLV__MATHEMATICS_H__
int max( int a, int b );
#endif

575
MLV/memory_debug.c Normal file
View File

@@ -0,0 +1,575 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "memory_debug.h"
#include <stdlib.h>
#include <stdio.h>
#define DEBUG_MEMORY_MSG(x) { fprintf(stderr,"Memory Debug : %s \n",(x)); }
#include "memory_management.h"
int memory_debug_n;
SDL_EventFilter memory_debug_filter;
SDL_Event memory_debug_event;
Memory_debug_statistics memory_debug_statistics;
void init_memory_debug(){
memory_debug_statistics.nb_create_surface = 0;
memory_debug_statistics.nb_free_surface = 0;
memory_debug_statistics.nb_init_sdl = 0;
memory_debug_statistics.nb_close_sdl = 0;
memory_debug_statistics.nb_create_semaphore = 0;
memory_debug_statistics.nb_free_semaphore = 0;
memory_debug_statistics.nb_malloc = 0;
memory_debug_statistics.nb_free = 0;
memory_debug_statistics.nb_free_wave = 0;
memory_debug_statistics.nb_load_wave = 0;
memory_debug_statistics.nb_open_font = 0;
memory_debug_statistics.nb_close_font = 0;
memory_debug_statistics.nb_init_ttf = 0;
memory_debug_statistics.nb_quit_ttf = 0;
}
void print_memory_statistics(){
fprintf(stderr,"--------------------------STATISTICS---------------------\n");
fprintf(stderr,"Memory Debug : nb_create_surface : %i \n", memory_debug_statistics.nb_create_surface);
fprintf(stderr,"Memory Debug : nb_free_surface : %i \n", memory_debug_statistics.nb_free_surface);
fprintf(stderr,"Memory Debug : nb_init_sdl : %i \n", memory_debug_statistics.nb_init_sdl);
fprintf(stderr,"Memory Debug : nb_close_sdl : %i \n", memory_debug_statistics.nb_close_sdl);
fprintf(stderr,"Memory Debug : nb_create_semaphore : %i \n", memory_debug_statistics.nb_create_semaphore);
fprintf(stderr,"Memory Debug : nb_free_semaphore : %i \n", memory_debug_statistics.nb_free_semaphore);
fprintf(stderr,"Memory Debug : nb_malloc : %i \n", memory_debug_statistics.nb_malloc);
fprintf(stderr,"Memory Debug : nb_calloc : %i \n", memory_debug_statistics.nb_calloc);
fprintf(stderr,"Memory Debug : nb_free : %i \n", memory_debug_statistics.nb_free);
fprintf(stderr,"Memory Debug : nb_free_wave : %i \n", memory_debug_statistics.nb_free_wave);
fprintf(stderr,"Memory Debug : nb_load_wave : %i \n", memory_debug_statistics.nb_load_wave);
fprintf(stderr,"Memory Debug : nb_open_font : %i \n", memory_debug_statistics.nb_open_font);
fprintf(stderr,"Memory Debug : nb_close_font : %i \n", memory_debug_statistics.nb_close_font);
fprintf(stderr,"Memory Debug : nb_init_ttf : %i \n", memory_debug_statistics.nb_init_ttf);
fprintf(stderr,"Memory Debug : nb_quit_ttf : %i \n", memory_debug_statistics.nb_quit_ttf);
fprintf(stderr,"----------------------END-STATISTICS---------------------\n");
}
typedef enum {
MEMORY_DEBUG_CREATE_SURFACE,
MEMORY_DEBUG_FREE_SURFACE,
MEMORY_DEBUG_INIT_SDL,
MEMORY_DEBUG_CLOSE_SDL,
MEMORY_DEBUG_CREATE_SEMAPHORE,
MEMORY_DEBUG_FREE_SEMAPHORE,
MEMORY_DEBUG_MALLOC,
MEMORY_DEBUG_CALLOC,
MEMORY_DEBUG_FREE,
MEMORY_DEBUG_FREE_WAVE,
MEMORY_DEBUG_LOAD_WAVE,
MEMORY_DEBUG_OPEN_FONT,
MEMORY_DEBUG_CLOSE_FONT,
MEMORY_DEBUG_QUIT_TTF,
MEMORY_DEBUG_INIT_TTF
} Memory_debug_statistics_type;
void update_memory_statistics( Memory_debug_statistics_type type ){
switch( type ){
case MEMORY_DEBUG_CREATE_SURFACE :
{
memory_debug_statistics.nb_create_surface++;
}
break;
case MEMORY_DEBUG_FREE_SURFACE :
{
memory_debug_statistics.nb_free_surface++;
}
break;
case MEMORY_DEBUG_INIT_SDL :
{
memory_debug_statistics.nb_init_sdl++;
}
break;
case MEMORY_DEBUG_CLOSE_SDL :
{
memory_debug_statistics.nb_close_sdl++;
}
break;
case MEMORY_DEBUG_CREATE_SEMAPHORE :
{
memory_debug_statistics.nb_create_semaphore++;
}
break;
case MEMORY_DEBUG_FREE_SEMAPHORE :
{
memory_debug_statistics.nb_free_semaphore ++;
}
break;
case MEMORY_DEBUG_MALLOC :
{
memory_debug_statistics.nb_malloc ++;
}
break;
case MEMORY_DEBUG_CALLOC :
{
memory_debug_statistics.nb_calloc ++;
}
break;
case MEMORY_DEBUG_FREE :
{
memory_debug_statistics.nb_free ++;
}
break;
case MEMORY_DEBUG_FREE_WAVE :
{
memory_debug_statistics.nb_free_wave ++;
}
break;
case MEMORY_DEBUG_LOAD_WAVE :
{
memory_debug_statistics.nb_load_wave ++;
}
break;
case MEMORY_DEBUG_OPEN_FONT :
{
memory_debug_statistics.nb_open_font ++;
}
break;
case MEMORY_DEBUG_CLOSE_FONT :
{
memory_debug_statistics.nb_close_font ++;
}
break;
case MEMORY_DEBUG_QUIT_TTF :
{
memory_debug_statistics.nb_quit_ttf ++;
}
break;
case MEMORY_DEBUG_INIT_TTF :
{
memory_debug_statistics.nb_init_ttf ++;
}
break;
default:;
}
}
void close_memory_debug(){
}
void filledCircleColor( SDL_Surface* screen, int x, int y, int radius, Uint32 color){
}
void circleColor( SDL_Surface* screen, int x, int y, int radius, Uint32 color){
}
void ellipseColor( SDL_Surface* screen, int x, int y, int radius_x, int radius_y, Uint32 color ){
}
void filledEllipseColor( SDL_Surface* screen, int x, int y, int radius_x, int radius_y, Uint32 color){
}
void polygonColor( SDL_Surface* screen, Sint16* vx, Sint16* vy, int npoints, Uint32 color){
}
void filledPolygonColor( SDL_Surface* screen, Sint16* vx, Sint16* vy, int npoints, Uint32 color){
}
void rectangleColor( SDL_Surface* screen, int x, int y, int width, int height, Uint32 color){
}
void boxColor( SDL_Surface* screen, int x, int y, int width, int height, Uint32 color){
}
void lineColor( SDL_Surface* screen, int x1, int y1, int x2, int y2, Uint32 color){
}
void pixelColor( SDL_Surface* screen, int x, int y, Uint32 color){
}
void stringColor( SDL_Surface* screen, int x, int y, const char *text, Uint32 color){
}
int SDL_BlitSurface( SDL_Surface* src, SDL_Rect* rectangle_src, SDL_Surface* dst, SDL_Rect* rectangle_dest){
return 0;
}
int memory_debug_modulo;
int SDL_PollEvent( SDL_Event* event ){
memory_debug_n = (memory_debug_n+1)%memory_debug_modulo;
switch( memory_debug_n ){
case 0:
{
DEBUG_MEMORY_MSG("Pas d'evenement")
return 0;
}
case 1: ;
{
DEBUG_MEMORY_MSG("souris deplace 10 10")
event->type=SDL_MOUSEMOTION;
event->motion.which = 0;
event->motion.state = SDL_RELEASED;
event->motion.x = 10;
event->motion.y = 10;
event->motion.xrel = -90;
event->motion.yrel = -90;
};
break;
case 2: ;
{
DEBUG_MEMORY_MSG("bouton gauche souris tape")
event->type=SDL_MOUSEBUTTONDOWN;
event->button.which = 0;
event->button.button = SDL_BUTTON_LEFT;
event->button.state = SDL_PRESSED;
event->button.x = 10;
event->button.y = 10;
};
break;
case 3: ;
{
DEBUG_MEMORY_MSG("bouton gauche souris relache")
event->type=SDL_MOUSEBUTTONUP;
event->button.which = 0;
event->button.button = SDL_BUTTON_LEFT;
event->button.state = SDL_RELEASED;
event->button.x = 10;
event->button.y = 10;
};
break;
case 4: ;
{
DEBUG_MEMORY_MSG("souris deplace 100")
event->type=SDL_MOUSEMOTION;
event->motion.which = 0;
event->motion.state = SDL_RELEASED;
event->motion.x = 100;
event->motion.y = 100;
event->motion.xrel = 90;
event->motion.yrel = 90;
};
break;
case 5: ;
{
DEBUG_MEMORY_MSG("bouton gauche souris tape")
event->type=SDL_MOUSEBUTTONDOWN;
event->button.which = 0;
event->button.button = SDL_BUTTON_LEFT;
event->button.state = SDL_PRESSED;
event->button.x = 100;
event->button.y = 100;
};
break;
case 6: ;
{
DEBUG_MEMORY_MSG("bouton gausche souris relache")
event->type=SDL_MOUSEBUTTONUP;
event->button.which = 0;
event->button.button = SDL_BUTTON_LEFT;
event->button.state = SDL_RELEASED;
event->button.x = 100;
event->button.y = 100;
};
break;
case 7:
{
DEBUG_MEMORY_MSG("a tape")
event->type=SDL_KEYDOWN;
event->key.type=SDL_KEYDOWN;
event->key.which=0;
event->key.state=SDL_PRESSED;
event->key.keysym.scancode = 0;
event->key.keysym.sym=SDLK_a;
event->key.keysym.mod=KMOD_NONE;
event->key.keysym.unicode=97;
};
break;
case 8: ;
{
DEBUG_MEMORY_MSG("a relache")
event->type=SDL_KEYUP;
event->key.type=SDL_KEYUP;
event->key.which=0;
event->key.state=SDL_RELEASED;
event->key.keysym.scancode = 0;
event->key.keysym.sym=SDLK_a;
event->key.keysym.mod=KMOD_NONE;
event->key.keysym.unicode=97;
};
break;
case 9: ;
{
DEBUG_MEMORY_MSG("b tape")
event->type=SDL_KEYDOWN;
event->key.type=SDL_KEYDOWN;
event->key.which=0;
event->key.state=SDL_PRESSED;
event->key.keysym.scancode = 0;
event->key.keysym.sym=SDLK_b;
event->key.keysym.mod=KMOD_NONE;
event->key.keysym.unicode=98;
};
break;
case 10: ;
{
DEBUG_MEMORY_MSG("b relache")
event->type=SDL_KEYUP;
event->key.type=SDL_KEYUP;
event->key.which=0;
event->key.state=SDL_RELEASED;
event->key.keysym.scancode = 0;
event->key.keysym.sym=SDLK_b;
event->key.keysym.mod=KMOD_NONE;
event->key.keysym.unicode=98;
};
break;
case 11: ;
{
DEBUG_MEMORY_MSG("return tape")
event->type=SDL_KEYDOWN;
event->key.type=SDL_KEYDOWN;
event->key.which=0;
event->key.state=SDL_PRESSED;
event->key.keysym.scancode = 0;
event->key.keysym.sym=SDLK_RETURN;
event->key.keysym.mod=KMOD_NONE;
event->key.keysym.unicode=13;
};
break;
case 12: ;
{
DEBUG_MEMORY_MSG("Return relache")
event->type=SDL_KEYUP;
event->key.type=SDL_KEYUP;
event->key.which=0;
event->key.state=SDL_RELEASED;
event->key.keysym.scancode = 0;
event->key.keysym.sym=SDLK_RETURN;
event->key.keysym.mod=KMOD_NONE;
event->key.keysym.unicode=13;
};
break;
case 13:
{
DEBUG_MEMORY_MSG("Evenement User")
(*event)=memory_debug_event;
};
break;
default: ;
}
return memory_debug_filter( event );
}
void SDL_SetAlpha(SDL_Surface* surface, int prop1, int prop2){
}
SDL_Surface* SDL_LoadBMP( const char* path ){
update_memory_statistics( MEMORY_DEBUG_CREATE_SURFACE );
return (SDL_Surface*) malloc( sizeof(SDL_Surface) );
}
SDL_Surface* SDL_CreateRGBSurface( int prop1, int w, int h, int resol, int r, int g, int b, int prop2 ){
update_memory_statistics( MEMORY_DEBUG_CREATE_SURFACE );
return (SDL_Surface*) malloc( sizeof(SDL_Surface) );
}
void SDL_FreeSurface( SDL_Surface* surface ){
update_memory_statistics( MEMORY_DEBUG_FREE_SURFACE );
free( surface );
}
SDL_Surface* rotozoomSurface( SDL_Surface* surface, double rotation, double zoom, int antialias){
update_memory_statistics( MEMORY_DEBUG_CREATE_SURFACE );
return (SDL_Surface*) malloc( sizeof(SDL_Surface) );
}
SDL_Surface* rotozoomSurfaceXY( SDL_Surface* surface, double rotation, double zoomx, double zoomy, int antialias){
update_memory_statistics( MEMORY_DEBUG_CREATE_SURFACE );
return (SDL_Surface*) malloc( sizeof(SDL_Surface) );
}
char* memory_debug_sdl_init;
int SDL_Init( int flags ){
memory_debug_n = 0;
memory_debug_modulo = 14;
update_memory_statistics( MEMORY_DEBUG_INIT_SDL );
memory_debug_sdl_init = (char*) malloc( sizeof(char) );
return 0;
}
void SDL_Quit(){
update_memory_statistics( MEMORY_DEBUG_CLOSE_SDL );
free(memory_debug_sdl_init);
}
char* SDL_GetError(){
return "TOTO";
}
SDL_Surface* SDL_SetVideoMode( int w, int h, int bits, int flags ){
update_memory_statistics( MEMORY_DEBUG_CREATE_SURFACE );
return (SDL_Surface*) malloc( sizeof( SDL_Surface ) );
}
void SDL_WM_SetCaption( const char* wind, const char* icon ){
}
void SDL_SetEventFilter( SDL_EventFilter filter ){
memory_debug_filter = filter;
}
void SDL_Flip( SDL_Surface* surface ){
}
int SDL_SemWait( SDL_sem* semaphore ){
return 0;
}
int SDL_SemPost( SDL_sem* semaphore ){
return 0;
}
SDL_sem* SDL_CreateSemaphore( int valeur ){
update_memory_statistics( MEMORY_DEBUG_CREATE_SEMAPHORE );
return (SDL_sem*) malloc( sizeof( SDL_sem ) );
}
void SDL_DestroySemaphore( SDL_sem* semaphore ){
update_memory_statistics( MEMORY_DEBUG_FREE_SEMAPHORE );
free(semaphore);
}
void SDL_EnableUNICODE( int flags ){
}
int SDL_PushEvent( SDL_Event* event ){
memory_debug_event = (*event);
memory_debug_n = memory_debug_modulo - 2 ;
return 0;
}
int SDL_GetTicks(){
return 1;
}
void SDL_Delay( int milliseconds ){
}
void* memory_debug_malloc(size_t size, int line, char* file ){
update_memory_statistics( MEMORY_DEBUG_MALLOC );
fprintf(stderr, "Memory Debug : malloc ligne : %i, fichier : %s \n", line, file );
return malloc( size );
}
void* memory_debug_calloc( size_t nmemb, size_t size, int line, char* file ){
update_memory_statistics( MEMORY_DEBUG_CALLOC );
fprintf(stderr, "Memory Debug : calloc ligne : %i, fichier : %s \n", line, file );
return calloc( nmemb, size );
}
void memory_debug_free( void* ptr, int line, char* file ){
update_memory_statistics( MEMORY_DEBUG_FREE );
fprintf(stderr, "Memory Debug : free ligne : %i, fichier : %s \n", line, file );
free( ptr );
}
void SDL_LockAudio(){
}
void SDL_UnlockAudio(){
}
void SDL_MixAudio(Uint8 *dst, Uint8 *src, Uint32 len, int volume){
}
SDL_AudioSpec* SDL_LoadWAV(const char *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len){
update_memory_statistics( MEMORY_DEBUG_LOAD_WAVE );
(*audio_buf) = (Uint8*) malloc( 10000 * sizeof( Uint8 ) );
(*audio_len) = 10000 * sizeof(Uint8);
return spec;
}
void SDL_FreeWAV(Uint8 *audio_buf){
update_memory_statistics( MEMORY_DEBUG_FREE_WAVE );
free( audio_buf );
}
void SDL_PauseAudio(int pause_on){
}
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained){
return 0;
}
void SDL_CloseAudio(){
}
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key){
return 0;
}
int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h){
return 0;
}
char* memory_debug_ttf_init;
int TTF_Init(void){
update_memory_statistics( MEMORY_DEBUG_INIT_TTF );
memory_debug_ttf_init = (char*) malloc( sizeof(char) );
return 0;
}
void TTF_Quit(void){
update_memory_statistics( MEMORY_DEBUG_QUIT_TTF );
free( memory_debug_ttf_init );
}
TTF_Font * TTF_OpenFont(const char *file, int ptsize){
update_memory_statistics( MEMORY_DEBUG_OPEN_FONT );
return (TTF_Font*) malloc( sizeof(TTF_Font) );
}
void TTF_SetFontStyle(TTF_Font *font, int style){
}
void TTF_CloseFont(TTF_Font *font){
update_memory_statistics( MEMORY_DEBUG_CLOSE_FONT );
free( font );
}
SDL_Surface * TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg){
update_memory_statistics( MEMORY_DEBUG_CREATE_SURFACE );
return (SDL_Surface*) malloc( sizeof(SDL_Surface) );
}

556
MLV/memory_debug.h Normal file
View File

@@ -0,0 +1,556 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__MEMMORY_DEBUG_H__
#define __MLV__MEMMORY_DEBUG_H__
#include <stdlib.h>
void init_memory_debug();
void print_memory_statistics();
void close_memory_debug();
typedef struct _Memory_debug_statistics {
int nb_create_surface;
int nb_free_surface;
int nb_init_sdl;
int nb_close_sdl;
int nb_create_semaphore;
int nb_free_semaphore;
int nb_malloc;
int nb_calloc;
int nb_free;
int nb_free_wave;
int nb_load_wave;
int nb_open_font;
int nb_close_font;
int nb_init_ttf;
int nb_quit_ttf;
} Memory_debug_statistics;
typedef int Uint32;
typedef int Uint16;
typedef int Uint8;
typedef int Sint32;
typedef int Sint16;
typedef struct SDL_Rect {
Sint16 x, y;
Uint16 w, h;
} SDL_Rect;
typedef struct _SDL_Screen {
int h;
int w;
} SDL_Surface;
typedef enum {
SDLK_UNKNOWN,
SDLK_FIRST,
SDLK_BACKSPACE,
SDLK_TAB,
SDLK_CLEAR,
SDLK_RETURN,
SDLK_PAUSE,
SDLK_ESCAPE,
SDLK_SPACE,
SDLK_EXCLAIM,
SDLK_QUOTEDBL,
SDLK_HASH,
SDLK_DOLLAR,
SDLK_AMPERSAND,
SDLK_QUOTE,
SDLK_LEFTPAREN,
SDLK_RIGHTPAREN,
SDLK_ASTERISK,
SDLK_PLUS,
SDLK_COMMA,
SDLK_MINUS,
SDLK_PERIOD,
SDLK_SLASH,
SDLK_0,
SDLK_1,
SDLK_2,
SDLK_3,
SDLK_4,
SDLK_5,
SDLK_6,
SDLK_7,
SDLK_8,
SDLK_9,
SDLK_COLON,
SDLK_SEMICOLON,
SDLK_LESS,
SDLK_EQUALS,
SDLK_GREATER,
SDLK_QUESTION,
SDLK_AT,
SDLK_LEFTBRACKET,
SDLK_BACKSLASH,
SDLK_RIGHTBRACKET,
SDLK_CARET,
SDLK_UNDERSCORE,
SDLK_BACKQUOTE,
SDLK_a,
SDLK_b,
SDLK_c,
SDLK_d,
SDLK_e,
SDLK_f,
SDLK_g,
SDLK_h,
SDLK_i,
SDLK_j,
SDLK_k,
SDLK_l,
SDLK_m,
SDLK_n,
SDLK_o,
SDLK_p,
SDLK_q,
SDLK_r,
SDLK_s,
SDLK_t,
SDLK_u,
SDLK_v,
SDLK_w,
SDLK_x,
SDLK_y,
SDLK_z,
SDLK_DELETE,
SDLK_KP0,
SDLK_KP1,
SDLK_KP2,
SDLK_KP3,
SDLK_KP4,
SDLK_KP5,
SDLK_KP6,
SDLK_KP7,
SDLK_KP8,
SDLK_KP9,
SDLK_KP_PERIOD,
SDLK_KP_DIVIDE,
SDLK_KP_MULTIPLY,
SDLK_KP_MINUS,
SDLK_KP_PLUS,
SDLK_KP_ENTER,
SDLK_KP_EQUALS,
SDLK_UP,
SDLK_DOWN,
SDLK_RIGHT,
SDLK_LEFT,
SDLK_INSERT,
SDLK_HOME,
SDLK_END,
SDLK_PAGEUP,
SDLK_PAGEDOWN,
SDLK_F1,
SDLK_F2,
SDLK_F3,
SDLK_F4,
SDLK_F5,
SDLK_F6,
SDLK_F7,
SDLK_F8,
SDLK_F9,
SDLK_F10,
SDLK_F11,
SDLK_F12,
SDLK_F13,
SDLK_F14,
SDLK_F15,
SDLK_NUMLOCK,
SDLK_CAPSLOCK,
SDLK_SCROLLOCK,
SDLK_RSHIFT,
SDLK_LSHIFT,
SDLK_RCTRL,
SDLK_LCTRL,
SDLK_RALT,
SDLK_LALT,
SDLK_RMETA,
SDLK_LMETA,
SDLK_LSUPER,
SDLK_RSUPER,
SDLK_MODE,
SDLK_COMPOSE,
SDLK_HELP,
SDLK_PRINT,
SDLK_SYSREQ,
SDLK_BREAK,
SDLK_MENU,
SDLK_POWER,
SDLK_EURO,
SDLK_UNDO,
SDLK_LAST
} SDLKey;
typedef enum {
KMOD_NONE,
KMOD_LSHIFT,
KMOD_RSHIFT,
KMOD_LCTRL,
KMOD_RCTRL,
KMOD_LALT,
KMOD_RALT,
KMOD_LMETA,
KMOD_RMETA,
KMOD_NUM,
KMOD_CAPS,
KMOD_MODE,
KMOD_RESERVED
} SDLMod;
typedef struct SDL_keysym {
Uint8 scancode; /* hardware specific scancode */
SDLKey sym; /* SDL virtual keysym */
SDLMod mod; /* current key modifiers */
Uint16 unicode; /* translated character */
} SDL_keysym;
/* Event enumerations */
typedef enum SDL_Events {
SDL_NOEVENT = 0, /* Unused (do not remove) */
SDL_ACTIVEEVENT, /* Application loses/gains visibility */
SDL_KEYDOWN, /* Keys pressed */
SDL_KEYUP, /* Keys released */
SDL_MOUSEMOTION, /* Mouse moved */
SDL_MOUSEBUTTONDOWN, /* Mouse button pressed */
SDL_MOUSEBUTTONUP, /* Mouse button released */
SDL_JOYAXISMOTION, /* Joystick axis motion */
SDL_JOYBALLMOTION, /* Joystick trackball motion */
SDL_JOYHATMOTION, /* Joystick hat position change */
SDL_JOYBUTTONDOWN, /* Joystick button pressed */
SDL_JOYBUTTONUP, /* Joystick button released */
SDL_QUIT, /* User-requested quit */
SDL_SYSWMEVENT, /* System specific event */
SDL_EVENT_RESERVEDA, /* Reserved for future use.. */
SDL_EVENT_RESERVEDB, /* Reserved for future use.. */
SDL_VIDEORESIZE, /* User resized video mode */
SDL_VIDEOEXPOSE, /* Screen needs to be redrawn */
SDL_EVENT_RESERVED2, /* Reserved for future use.. */
SDL_EVENT_RESERVED3, /* Reserved for future use.. */
SDL_EVENT_RESERVED4, /* Reserved for future use.. */
SDL_EVENT_RESERVED5, /* Reserved for future use.. */
SDL_EVENT_RESERVED6, /* Reserved for future use.. */
SDL_EVENT_RESERVED7, /* Reserved for future use.. */
/* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
SDL_USEREVENT = 24,
/* This last event is only for bounding internal arrays
It is the number of bits in the event mask datatype -- Uint32
*/
SDL_NUMEVENTS = 32
} SDL_EventType;
/* Application visibility event structure */
typedef struct SDL_ActiveEvent {
Uint8 type; /* SDL_ACTIVEEVENT */
Uint8 gain; /* Whether given states were gained or lost (1/0) */
Uint8 state; /* A mask of the focus states */
} SDL_ActiveEvent;
/* Keyboard event structure */
typedef struct SDL_KeyboardEvent {
Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */
Uint8 which; /* The keyboard device index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
SDL_keysym keysym;
} SDL_KeyboardEvent;
/* Mouse motion event structure */
typedef struct SDL_MouseMotionEvent {
Uint8 type; /* SDL_MOUSEMOTION */
Uint8 which; /* The mouse device index */
Uint8 state; /* The current button state */
Uint16 x, y; /* The X/Y coordinates of the mouse */
Sint16 xrel; /* The relative motion in the X direction */
Sint16 yrel; /* The relative motion in the Y direction */
} SDL_MouseMotionEvent;
/* Mouse button event structure */
typedef struct SDL_MouseButtonEvent {
Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
Uint8 which; /* The mouse device index */
Uint8 button; /* The mouse button index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
Uint16 x, y; /* The X/Y coordinates of the mouse at press time */
} SDL_MouseButtonEvent;
/* Joystick axis motion event structure */
typedef struct SDL_JoyAxisEvent {
Uint8 type; /* SDL_JOYAXISMOTION */
Uint8 which; /* The joystick device index */
Uint8 axis; /* The joystick axis index */
Sint16 value; /* The axis value (range: -32768 to 32767) */
} SDL_JoyAxisEvent;
/* Joystick trackball motion event structure */
typedef struct SDL_JoyBallEvent {
Uint8 type; /* SDL_JOYBALLMOTION */
Uint8 which; /* The joystick device index */
Uint8 ball; /* The joystick trackball index */
Sint16 xrel; /* The relative motion in the X direction */
Sint16 yrel; /* The relative motion in the Y direction */
} SDL_JoyBallEvent;
/* Joystick hat position change event structure */
typedef struct SDL_JoyHatEvent {
Uint8 type; /* SDL_JOYHATMOTION */
Uint8 which; /* The joystick device index */
Uint8 hat; /* The joystick hat index */
Uint8 value; /* The hat position value:
SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP
SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT
SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN
Note that zero means the POV is centered.
*/
} SDL_JoyHatEvent;
/* Joystick button event structure */
typedef struct SDL_JoyButtonEvent {
Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
Uint8 which; /* The joystick device index */
Uint8 button; /* The joystick button index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
} SDL_JoyButtonEvent;
/* The "window resized" event
When you get this event, you are responsible for setting a new video
mode with the new width and height.
*/
typedef struct SDL_ResizeEvent {
Uint8 type; /* SDL_VIDEORESIZE */
int w; /* New width */
int h; /* New height */
} SDL_ResizeEvent;
/* The "screen redraw" event */
typedef struct SDL_ExposeEvent {
Uint8 type; /* SDL_VIDEOEXPOSE */
} SDL_ExposeEvent;
/* The "quit requested" event */
typedef struct SDL_QuitEvent {
Uint8 type; /* SDL_QUIT */
} SDL_QuitEvent;
/* A user-defined event type */
typedef struct SDL_UserEvent {
Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */
int code; /* User defined event code */
void *data1; /* User defined data pointer */
void *data2; /* User defined data pointer */
} SDL_UserEvent;
/* If you want to use this event, you should include SDL_syswm.h */
struct SDL_SysWMmsg;
typedef struct SDL_SysWMmsg SDL_SysWMmsg;
typedef struct SDL_SysWMEvent {
Uint8 type;
SDL_SysWMmsg *msg;
} SDL_SysWMEvent;
/* General event structure */
typedef union SDL_Event {
Uint8 type;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_ExposeEvent expose;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
} SDL_Event;
#define SDL_BUTTON_LEFT 1
#define SDL_BUTTON_MIDDLE 2
#define SDL_BUTTON_RIGHT 3
void filledCircleColor( SDL_Surface* screen, int x, int y, int radius, Uint32 color);
void circleColor( SDL_Surface* screen, int x, int y, int radius, Uint32 color);
void ellipseColor( SDL_Surface* screen, int x, int y, int radius_x, int radius_y, Uint32 color );
void filledEllipseColor( SDL_Surface* screen, int x, int y, int radius_x, int radius_y, Uint32 color);
void polygonColor( SDL_Surface* screen, Sint16* vx, Sint16* vy, int npoints, Uint32 color);
void filledPolygonColor( SDL_Surface* screen, Sint16* vx, Sint16* vy, int npoints, Uint32 color);
void rectangleColor( SDL_Surface* screen, int x, int y, int width, int height, Uint32 color);
void boxColor( SDL_Surface* screen, int x, int y, int width, int height, Uint32 color);
void lineColor( SDL_Surface* screen, int x1, int y1, int x2, int y2, Uint32 color);
void pixelColor( SDL_Surface* screen, int x, int y, Uint32 color);
void stringColor( SDL_Surface* screen, int x, int y, const char *text, Uint32 color);
int SDL_BlitSurface( SDL_Surface* src, SDL_Rect* rectangle_src, SDL_Surface* dst, SDL_Rect* rectangle_dest);
int SDL_PollEvent( SDL_Event* event );
#define SDL_HWSURFACE 1
#define SDL_SRCALPHA 1
#define SDL_ALPHA_TRANSPARENT 1
#define SDL_RLEACCEL 1
#define SDL_ALPHA_OPAQUE 1
void SDL_SetAlpha(SDL_Surface* surface, int prop1, int prop2);
SDL_Surface* SDL_LoadBMP( const char* path );
SDL_Surface* SDL_CreateRGBSurface( int prop1, int w, int h, int resol, int r, int g, int b, int prop2 );
void SDL_FreeSurface( SDL_Surface* surface );
SDL_Surface* rotozoomSurface( SDL_Surface* surface, double rotation, double zoom, int antialias);
SDL_Surface* rotozoomSurfaceXY( SDL_Surface* surface, double rotation, double zoomx, double zoomy, int antialias);
#define SDL_INIT_VIDEO 1
#define SDL_INIT_TIMER 1
#define SDL_INIT_AUDIO 1
#define SDL_DOUBLEBUF 1
#define SDL_INIT_EVENTTHREAD 1
typedef int (*SDL_EventFilter)(const SDL_Event *event);
int SDL_Init( int flags );
void SDL_Quit();
char* SDL_GetError();
SDL_Surface* SDL_SetVideoMode( int w, int h, int bits, int flags );
void SDL_WM_SetCaption( const char* wind, const char* icon );
void SDL_SetEventFilter( SDL_EventFilter filter );
void SDL_Flip( SDL_Surface* surface );
#define SDL_PRESSED 0
#define SDL_RELEASED 1
#define SDL_ENABLE 1
typedef struct _SDL_sem {
} SDL_sem;
int SDL_SemWait( SDL_sem* semaphore );
int SDL_SemPost( SDL_sem* semaphore );
SDL_sem* SDL_CreateSemaphore( int );
void SDL_DestroySemaphore( SDL_sem* semaphore );
void SDL_EnableUNICODE( int flags );
int SDL_PushEvent( SDL_Event* event );
int SDL_GetTicks();
void SDL_Delay( int milliseconds );
void* memory_debug_malloc( size_t size, int line, char* file );
void* memory_debug_calloc( size_t nmemb, size_t size, int line, char* file );
void memory_debug_free( void* ptr, int line, char* file );
typedef struct{
int freq;
Uint16 format;
Uint8 channels;
Uint8 silence;
Uint16 samples;
Uint32 size;
void (*callback)(void *userdata, Uint8 *stream, int len);
void *userdata;
} SDL_AudioSpec;
void SDL_LockAudio();
void SDL_UnlockAudio();
void SDL_MixAudio(Uint8 *dst, Uint8 *src, Uint32 len, int volume);
SDL_AudioSpec* SDL_LoadWAV(const char *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
void SDL_FreeWAV(Uint8 *audio_buf);
void SDL_PauseAudio(int pause_on);
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained);
void SDL_CloseAudio();
/* Audio format flags (defaults to LSB byte order) */
#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */
#define AUDIO_S8 0x8008 /* Signed 8-bit samples */
#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */
#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */
#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */
#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */
#define AUDIO_U16 AUDIO_U16LSB
#define AUDIO_S16 AUDIO_S16LSB
#define SDL_MIX_MAXVOLUME 128
typedef struct {
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 unused;
} SDL_Color;
#define SDL_SRCCOLORKEY 0x00001000 /* Blit uses a source color key */
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
/*
typedef struct {
} GList;
*/
typedef struct {
} TTF_Font;
int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
int TTF_Init(void);
void TTF_Quit(void);
TTF_Font * TTF_OpenFont(const char *file, int ptsize);
#define TTF_GetError SDL_GetError
void TTF_SetFontStyle(TTF_Font *font, int style);
#define TTF_STYLE_NORMAL 0x00
void TTF_CloseFont(TTF_Font *font);
SDL_Surface * TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg);
#endif

38
MLV/memory_management.h Normal file
View File

@@ -0,0 +1,38 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__MEMORY_MANAGEMENT_H__
#define __MLV__MEMORY_MANAGEMENT_H__
#include <stdlib.h>
#ifndef MEMORY_DEBUG
#define MLV_MALLOC( size, type ) (type *) malloc( (size) * sizeof( type ) )
#define MLV_CALLOC( nmemb, size, type ) (type *) calloc( nmemb, (size) * sizeof( type ) )
#define MLV_FREE( ptr, type ) free( (ptr) )
#else
#include "memory_debug.h"
#define MLV_MALLOC( size, type ) (type *) memory_debug_malloc( (size) * sizeof( type ), __LINE__, __FILE__ )
#define MLV_CALLOC( size, type ) (type *) memory_debug_calloc( (size) * sizeof( type ), __LINE__ , __FILE__ )
#define MLV_FREE( ptr, type ) memory_debug_free( (ptr), __LINE__, __FILE__ )
#endif
#endif

139
MLV/mouse.c Normal file
View File

@@ -0,0 +1,139 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_mouse.h"
#include "MLV_event.h"
#include "MLV_time.h"
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
#include "warning_error.h"
#include "memory_management.h"
void MLV_wait_mouse(int *x, int *y){
MLV_Button_state state;
MLV_Mouse_button mouse_button;
// We remove all existing event from the queue
MLV_flush_event_queue();
//We wait for a new mouse event
while(
(
MLV_wait_event(
NULL, NULL, NULL,
NULL, NULL,
x, y, &mouse_button,
&state
) != MLV_MOUSE_BUTTON
) ||
( mouse_button != MLV_BUTTON_LEFT ) ||
( state != MLV_PRESSED )
);
};
int MLV_wait_mouse_or_seconds(int *x, int *y, int seconds){
MLV_Button_state state;
MLV_Mouse_button mouse_button;
// We remove all existing event from the queue
MLV_flush_event_queue();
int time = MLV_get_time();
//We wait for a new mouse event
int resultat = 0;
int tmp_x, tmp_y;
while(
(
resultat =
(
MLV_wait_event_or_seconds(
NULL, NULL, NULL,
NULL, NULL,
&tmp_x, &tmp_y, &mouse_button,
&state,
seconds - ( MLV_get_time() - time )/1000
) != MLV_MOUSE_BUTTON
) ||
( mouse_button != MLV_BUTTON_LEFT ) ||
( state != MLV_PRESSED )
) && (
(MLV_get_time() - time) < seconds*1000
)
);
if(
! resultat &&
mouse_button == MLV_BUTTON_LEFT &&
state == MLV_PRESSED
){
if( x ) *x = tmp_x;
if( y ) *y = tmp_y;
}
return !resultat;
}
const char* MLV_convert_mouse_button_to_string( MLV_Mouse_button button_code ){
switch( button_code ){
case MLV_BUTTON_LEFT:
return "MLV_BUTTON_LEFT";
case MLV_BUTTON_MIDDLE:
return "MLV_BUTTON_MIDDLE";
case MLV_BUTTON_RIGHT:
return "MLV_BUTTON_RIGHT";
default:
ERROR("Button code unexpected");
}
return NULL;
}
MLV_Mouse_button MLV_convert_string_to_mouse_button( const char* button_string ){
if( strcmp( button_string, "MLV_BUTTON_LEFT" )==0 ){
return MLV_BUTTON_LEFT;
}
if( strcmp( button_string, "MLV_BUTTON_MIDDLE" )==0 ){
return MLV_BUTTON_MIDDLE;
}
if( strcmp( button_string, "MLV_BUTTON_RIGHT" )==0 ){
return MLV_BUTTON_RIGHT;
}
ERROR("Button name unexpected");
return -1;
}
void MLV_get_mouse_position( int* x, int* y ){
SDL_PumpEvents();
SDL_GetMouseState(x,y);
}
MLV_Button_state MLV_get_mouse_button_state( MLV_Mouse_button mouse_button ){
SDL_PumpEvents();
if( SDL_GetMouseState(NULL,NULL) & SDL_BUTTON( mouse_button ) ){
return MLV_PRESSED;
}
return MLV_RELEASED;
}

122
MLV/path.c Normal file
View File

@@ -0,0 +1,122 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_path.h"
#include "warning_error.h"
#include "memory_management.h"
#include "data_structure.h"
#include <glib.h>
#include <stdarg.h>
char* MLV_get_base_name( const char* path ){
return g_path_get_basename( path );
}
char* MLV_get_directory_name( const char* path ){
return g_path_get_dirname( path );
}
int MLV_path_is_absolute( const char* path ){
return g_path_is_absolute( path );
}
int MLV_path_is_relative( const char* path ){
return ! MLV_path_is_absolute( path );
}
char* MLV_build_path_v( char** elements ){
gchar* tmp_res = g_build_filenamev( elements );
char* result = strdup( tmp_res );
g_free( tmp_res ); // tmp_res have to be freed with g_free (
// see glib documentation
// )
return result;
}
char* MLV_build_path( const char* first_element, ...){
char *result;
if( !first_element ) return NULL;
va_list pile;
const char* type;
int compteur;
va_start( pile, first_element );
compteur = 2;
while(
(
type = va_arg( pile, char* )
) != NULL
){
compteur ++;
}
va_end( pile );
char** elements = MLV_MALLOC( compteur, char* );
elements[0] = strdup( first_element );
va_start( pile, first_element );
int i;
for( i=1; i<compteur; i++ ){
type = va_arg( pile, const char*);
if( type ){
elements[i] = strdup( (const char*) type );
}else{
elements[i] = NULL;
}
}
va_end( pile );
result = MLV_build_path_v( elements );
for( i=0; i<compteur-1; i++ ){
MLV_FREE( elements[i], char );
}
MLV_FREE( elements, char* );
return result;
}
int MLV_path_is_a_directory( const char* path ){
return g_file_test( path, G_FILE_TEST_IS_DIR );
}
int MLV_path_is_a_file( const char* path ){
return g_file_test( path, G_FILE_TEST_IS_REGULAR );
}
int MLV_path_exists( const char* path ){
return g_file_test( path, G_FILE_TEST_EXISTS );
}
char * MLV_get_current_directory( ){
return g_get_current_dir();
}
const char * MLV_get_temporary_directory( ){
return g_get_tmp_dir();
}
const char * MLV_get_home_directory( ){
return g_get_home_dir();
}

34
MLV/platform.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__PLATFORM_H__
#define __MLV__PLATFORM_H__
#if defined( __WIN32__ ) || defined( _WIN32 ) || defined( __CYGWIN__ )
# define OS_WINDOWS
#elif defined( __APPLE_CC__)
# define OS_APPLE
#elif defined( __MLV_ANDROID__ )
# define OS_ANDROID
#else
# define OS_LINUX
#endif
#endif

205
MLV/playlist.c Normal file
View File

@@ -0,0 +1,205 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_playlist.h"
#include "MLV_audio.h"
#include "data_structure.h"
#include "list.h"
#include "memory_management.h"
#include "warning_error.h"
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
extern DataMLV* MLV_data;
typedef struct _Music_item {
int interne;
MLV_Music* music;
} Music_item;
struct _MLV_Playlist {
MLV_List* music_items;
int playing;
int current;
int size;
SDL_sem* semaphore;
double volume;
int loop;
};
void MLV_init_playlists(){
MLV_data->playlists = NULL;
MLV_data->active_playlists = NULL;
}
void MLV_close_playlists(){
MLV_List* playlists = NULL;
MLV_List* tmp = MLV_data->playlists;
while(tmp){
playlists = MLV_prepend_list(
playlists,
tmp->data
);
tmp = tmp->next;
}
MLV_foreach_list(
playlists,
(void (*)(void*,void*)) MLV_close_playlist
, NULL
);
MLV_free_list( MLV_data->playlists );
MLV_free_list( MLV_data->active_playlists );
}
MLV_Playlist* MLV_create_playlist( int loop ){
MLV_Playlist* playlist = MLV_MALLOC( 1, MLV_Playlist );
playlist->music_items = NULL;
playlist->semaphore = SDL_CreateSemaphore(1);
playlist->volume = 1.0;
playlist->size = 0;
playlist->loop = loop;
if( SDL_SemWait( MLV_data->audio_semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
MLV_data->playlists = MLV_prepend_list(
MLV_data->playlists,
playlist
);
if( SDL_SemPost( MLV_data->audio_semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
return playlist;
}
void MLV_close_playlist( MLV_Playlist* playlist ){
if( SDL_SemWait( MLV_data->audio_semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
MLV_data->playlists = MLV_remove_list( MLV_data->playlists, playlist );
if( SDL_SemPost( MLV_data->audio_semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
MLV_playlist_clear( playlist );
MLV_free_list( playlist->music_items );
SDL_DestroySemaphore( playlist->semaphore );
}
void MLV_playlist_add( MLV_Playlist* playlist, const char* file_music ){
Music_item* item = MLV_MALLOC(1, Music_item);
item->interne = 1;
item->music = MLV_load_music( file_music );
if( SDL_SemWait( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
playlist->music_items = MLV_prepend_list(
playlist->music_items,
item
);
playlist->size ++;
if( SDL_SemPost( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
void MLV_playlist_add_sheet_music( MLV_Playlist* playlist, MLV_Music* music ){
Music_item* item = MLV_MALLOC(1, Music_item);
item->interne = 0;
item->music = music;
if( SDL_SemWait( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
playlist->music_items = MLV_prepend_list(
playlist->music_items,
item
);
if( SDL_SemPost( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
void MLV_playlist_remove( MLV_Playlist* playlist, int index ){
TODO
}
void MLV_playlist_clear( MLV_Playlist* playlist ){
TODO
}
void MLV_playlist_volume( MLV_Playlist* playlist, double volume ){
if( SDL_SemWait( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
playlist->volume = volume;
if( SDL_SemPost( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
void MLV_playlist_play( MLV_Playlist* playlist ){
if( SDL_SemWait( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
playlist->playing = 1;
if( SDL_SemPost( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
void MLV_playlist_pause( MLV_Playlist* playlist ){
if( SDL_SemWait( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
playlist->playing = 0;
if( SDL_SemPost( playlist->semaphore ) ){
ERROR_FULL("Probleme de semaphore");
}
}
void MLV_playlist_stop( MLV_Playlist* playlist ){
TODO
}
void MLV_playlist_next( MLV_Playlist* playlist ){
TODO
}
void MLV_playlist_previous( MLV_Playlist* playlist ){
TODO
}
void MLV_playlist_first( MLV_Playlist* playlist ){
TODO
}
void MLV_playlist_last( MLV_Playlist* playlist ){
TODO
}
void MLV_playlist_index( MLV_Playlist* playlist, int index){
TODO
}

44
MLV/random.c Normal file
View File

@@ -0,0 +1,44 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_random.h"
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
#include <glib.h>
#include "warning_error.h"
#include "memory_management.h"
int MLV_get_random_boolean(int begin, int end){
return g_random_boolean( );
}
int MLV_get_random_integer(int begin, int end){
return g_random_int_range( begin, end );
}
double MLV_get_random_double(double begin, double end){
return g_random_double_range( begin, end );
}

198
MLV/sdlkeyboardtochar.c Normal file
View File

@@ -0,0 +1,198 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sdlkeyboardtochar.h"
#include "memory_management.h"
int sldKeyIsACharacter( SDLKey key){
int result = 1;
switch( key ) {
case SDLK_TAB : result = 1; break;
case SDLK_SPACE : result = 1; break;
case SDLK_EXCLAIM : result = 1; break;
case SDLK_QUOTEDBL : result = 1; break;
case SDLK_HASH : result = 1; break;
case SDLK_DOLLAR : result = 1; break;
case SDLK_AMPERSAND : result = 1; break;
case SDLK_QUOTE : result = 1; break;
case SDLK_LEFTPAREN : result = 1; break;
case SDLK_RIGHTPAREN : result = 1; break;
case SDLK_ASTERISK : result = 1; break;
case SDLK_PLUS : result = 1; break;
case SDLK_COMMA : result = 1; break;
case SDLK_MINUS : result = 1; break;
case SDLK_PERIOD : result = 1; break;
case SDLK_SLASH : result = 1; break;
case SDLK_0 : result = 1; break;
case SDLK_1 : result = 1; break;
case SDLK_2 : result = 1; break;
case SDLK_3 : result = 1; break;
case SDLK_4 : result = 1; break;
case SDLK_5 : result = 1; break;
case SDLK_6 : result = 1; break;
case SDLK_7 : result = 1; break;
case SDLK_8 : result = 1; break;
case SDLK_9 : result = 1; break;
case SDLK_COLON : result = 1; break;
case SDLK_SEMICOLON : result = 1; break;
case SDLK_LESS : result = 1; break;
case SDLK_EQUALS : result = 1; break;
case SDLK_GREATER : result = 1; break;
case SDLK_QUESTION : result = 1; break;
case SDLK_AT : result = 1; break;
case SDLK_LEFTBRACKET : result = 1; break;
case SDLK_BACKSLASH : result = 1; break;
case SDLK_RIGHTBRACKET : result = 1; break;
case SDLK_CARET : result = 1; break;
case SDLK_UNDERSCORE : result = 1; break;
case SDLK_BACKQUOTE : result = 1; break;
case SDLK_a : result = 1; break;
case SDLK_b : result = 1; break;
case SDLK_c : result = 1; break;
case SDLK_d : result = 1; break;
case SDLK_e : result = 1; break;
case SDLK_f : result = 1; break;
case SDLK_g : result = 1; break;
case SDLK_h : result = 1; break;
case SDLK_i : result = 1; break;
case SDLK_j : result = 1; break;
case SDLK_k : result = 1; break;
case SDLK_l : result = 1; break;
case SDLK_m : result = 1; break;
case SDLK_n : result = 1; break;
case SDLK_o : result = 1; break;
case SDLK_p : result = 1; break;
case SDLK_q : result = 1; break;
case SDLK_r : result = 1; break;
case SDLK_s : result = 1; break;
case SDLK_t : result = 1; break;
case SDLK_u : result = 1; break;
case SDLK_v : result = 1; break;
case SDLK_w : result = 1; break;
case SDLK_x : result = 1; break;
case SDLK_y : result = 1; break;
case SDLK_z : result = 1; break;
case SDLK_KP_PERIOD : result = 1; break;
case SDLK_KP_DIVIDE : result = 1; break;
case SDLK_KP_MULTIPLY : result = 1; break;
case SDLK_KP_MINUS : result = 1; break;
case SDLK_KP_PLUS : result = 1; break;
case SDLK_KP_EQUALS : result = 1; break;
default: result = 0;
}
return result;
}
int converSdlKeyToChar( SDLKey key, SDLMod mod, char* character ){
int result = 0;
/*
* if( mod & KMOD_NUM ) printf( "NUMLOCK " );
* if( mod & KMOD_CAPS ) printf( "CAPSLOCK " );
* if( mod & KMOD_LCTRL ) printf( "LCTRL " );
* if( mod & KMOD_RCTRL ) printf( "RCTRL " );
* if( mod & KMOD_RSHIFT ) printf( "RSHIFT " );
* if( mod & KMOD_LSHIFT ) printf( "LSHIFT " );
* if( mod & KMOD_RALT ) printf( "RALT " );
* if( mod & KMOD_LALT ) printf( "LALT " );
* if( mod & KMOD_CTRL ) printf( "CTRL " );
* if( mod & KMOD_SHIFT ) printf( "SHIFT " );
* if( mod & KMOD_ALT ) printf( "ALT " );
* */
switch( key ) {
case SDLK_TAB : (*character) = '\t'; break;
case SDLK_SPACE : (*character) = ' '; break;
case SDLK_EXCLAIM : (*character) = '!'; break;
case SDLK_QUOTEDBL : (*character) = '"'; break;
case SDLK_HASH : (*character) = '#'; break;
case SDLK_DOLLAR : (*character) = '$'; break;
case SDLK_AMPERSAND : (*character) = '&'; break;
case SDLK_QUOTE : (*character) = '\''; break;
case SDLK_LEFTPAREN : (*character) = '('; break;
case SDLK_RIGHTPAREN : (*character) = ')'; break;
case SDLK_ASTERISK : (*character) = '*'; break;
case SDLK_PLUS : (*character) = '+'; break;
case SDLK_COMMA : (*character) = ','; break;
case SDLK_MINUS : (*character) = '-'; break;
case SDLK_PERIOD : (*character) = '.'; break;
case SDLK_SLASH : (*character) = '/'; break;
case SDLK_0 : (*character) = '0'; break;
case SDLK_1 : (*character) = '1'; break;
case SDLK_2 : (*character) = '2'; break;
case SDLK_3 : (*character) = '3'; break;
case SDLK_4 : (*character) = '4'; break;
case SDLK_5 : (*character) = '5'; break;
case SDLK_6 : (*character) = '6'; break;
case SDLK_7 : (*character) = '7'; break;
case SDLK_8 : (*character) = '8'; break;
case SDLK_9 : (*character) = '9'; break;
case SDLK_COLON : (*character) = ':'; break;
case SDLK_SEMICOLON : (*character) = ';'; break;
case SDLK_LESS : (*character) = '<'; break;
case SDLK_EQUALS : (*character) = '='; break;
case SDLK_GREATER : (*character) = '>'; break;
case SDLK_QUESTION : (*character) = '?'; break;
case SDLK_AT : (*character) = '@'; break;
case SDLK_LEFTBRACKET : (*character) = '['; break;
case SDLK_BACKSLASH : (*character) = '\\'; break;
case SDLK_RIGHTBRACKET : (*character) = ']'; break;
case SDLK_CARET : (*character) = '^'; break;
case SDLK_UNDERSCORE : (*character) = '_'; break;
case SDLK_BACKQUOTE : (*character) = '`'; break;
case SDLK_a : (*character) = 'a'; break;
case SDLK_b : (*character) = 'b'; break;
case SDLK_c : (*character) = 'c'; break;
case SDLK_d : (*character) = 'd'; break;
case SDLK_e : (*character) = 'e'; break;
case SDLK_f : (*character) = 'f'; break;
case SDLK_g : (*character) = 'g'; break;
case SDLK_h : (*character) = 'h'; break;
case SDLK_i : (*character) = 'i'; break;
case SDLK_j : (*character) = 'j'; break;
case SDLK_k : (*character) = 'k'; break;
case SDLK_l : (*character) = 'l'; break;
case SDLK_m : (*character) = 'm'; break;
case SDLK_n : (*character) = 'n'; break;
case SDLK_o : (*character) = 'o'; break;
case SDLK_p : (*character) = 'p'; break;
case SDLK_q : (*character) = 'q'; break;
case SDLK_r : (*character) = 'r'; break;
case SDLK_s : (*character) = 's'; break;
case SDLK_t : (*character) = 't'; break;
case SDLK_u : (*character) = 'u'; break;
case SDLK_v : (*character) = 'v'; break;
case SDLK_w : (*character) = 'w'; break;
case SDLK_x : (*character) = 'x'; break;
case SDLK_y : (*character) = 'y'; break;
case SDLK_z : (*character) = 'z'; break;
case SDLK_KP_PERIOD : (*character) = '.'; break;
case SDLK_KP_DIVIDE : (*character) = '/'; break;
case SDLK_KP_MULTIPLY : (*character) = '*'; break;
case SDLK_KP_MINUS : (*character) = '-'; break;
case SDLK_KP_PLUS : (*character) = '+'; break;
case SDLK_KP_EQUALS : (*character) = '='; break;
default: result = 1;
}
return result;
}

34
MLV/sdlkeyboardtochar.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__SDLKEYBOARDTOCHAR_H__
#define __MLV__SDLKEYBOARDTOCHAR_H__
#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif
int converSdlKeyToChar( SDLKey key, SDLMod mod, char* character );
int sldKeyIsACharacter( SDLKey key );
#endif

267
MLV/shapes.c Normal file
View File

@@ -0,0 +1,267 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_shape.h"
#include "platform.h"
#include "image.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL_gfxPrimitives.h>
#elif defined( OS_APPLE )
# include <SDL/SDL_gfxPrimitives.h>
#else
# include <SDL/SDL_gfxPrimitives.h>
#endif
#else
#include "memory_debug.h"
#endif
#include "data_structure.h"
#include "warning_error.h"
#include "memory_management.h"
#include <stdarg.h>
#include "data_structure.h"
extern DataMLV *MLV_data;
///////////////////////////////////////////////////////////////////////////////
// Drawing operation on images //
///////////////////////////////////////////////////////////////////////////////
void MLV_draw_circle_on_image(int x, int y, int radius, MLV_Color color, MLV_Image* image){
circleColor( image->surface, x, y, radius, color );
}
void MLV_draw_filled_circle_on_image(int x, int y, int radius, MLV_Color color, MLV_Image* image){
filledCircleColor( image->surface, x, y, radius, color);
}
void MLV_draw_ellipse_on_image(int x, int y, int radius_x, int radius_y, MLV_Color color, MLV_Image* image){
ellipseColor(image->surface,x,y,radius_x,radius_y,color);
}
void MLV_draw_filled_ellipse_on_image(int x, int y, int radius_x, int radius_y, MLV_Color color, MLV_Image* image){
filledEllipseColor(image->surface,x,y,radius_x,radius_y,color);
}
void MLV_draw_polygon_on_image( const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image){
Sint16* tmp_vx = MLV_MALLOC( nb_points, Sint16 );
Sint16* tmp_vy = MLV_MALLOC( nb_points, Sint16 );
int i;
for( i=0; i< nb_points; i++){
tmp_vx[i] = vx[i];
tmp_vy[i] = vy[i];
}
polygonColor( image->surface, tmp_vx, tmp_vy, nb_points, color);
MLV_FREE( tmp_vx, Sint16 );
MLV_FREE( tmp_vy, Sint16 );
}
void MLV_draw_filled_polygon_on_image( const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image){
Sint16* tmp_vx = MLV_MALLOC( nb_points, Sint16 );
Sint16* tmp_vy = MLV_MALLOC( nb_points, Sint16 );
int i;
for( i=0; i< nb_points; i++){
tmp_vx[i] = vx[i];
tmp_vy[i] = vy[i];
}
filledPolygonColor( image->surface, tmp_vx, tmp_vy, nb_points, color);
MLV_FREE( tmp_vx, Sint16 );
MLV_FREE( tmp_vy, Sint16 );
}
void MLV_draw_bezier_curve_on_image( const int* vx, const int* vy, int nb_points, MLV_Color color, MLV_Image* image){
Sint16* tmp_vx = MLV_MALLOC( nb_points, Sint16 );
Sint16* tmp_vy = MLV_MALLOC( nb_points, Sint16 );
int i;
for( i=0; i< nb_points; i++){
tmp_vx[i] = vx[i];
tmp_vy[i] = vy[i];
}
bezierColor( image->surface, tmp_vx, tmp_vy, nb_points, 6 , color);
MLV_FREE( tmp_vx, Sint16 );
MLV_FREE( tmp_vy, Sint16 );
}
void MLV_draw_rectangle_on_image(int x, int y, int width, int height, MLV_Color color, MLV_Image* image){
rectangleColor(image->surface, x, y, x+width-1, y+height-1, color);
}
void MLV_draw_filled_rectangle_on_image(int x, int y, int width, int height, MLV_Color color, MLV_Image* image){
boxColor(image->surface, x, y, x+width-1, y+height-1, color);
}
void MLV_draw_line_on_image(int x1, int y1, int x2, int y2, MLV_Color color, MLV_Image* image){
lineColor( image->surface, x1, y1, x2, y2, color);
}
void draw_pixel_on_sdl_surface( SDL_Surface* surface, int x, int y, MLV_Color color ){
#if 0 // Je ne me souvient plus pourquoi pexelColor ne fonctionnait pas. Je crois que c'est la composante alpha qui pose problème.
pixelColor(MLV_data->screen, x, y, color);
#else
SDL_LockSurface(surface);
SDL_PixelFormat *fmt;
Uint32 *pixel;
fmt = surface->format;
pixel = ((Uint32*) surface->pixels)+ y*surface->pitch/4 + x;
Uint8 red, blue, green, alpha;
MLV_convert_color_to_rgba( color, &red, &green, &blue, &alpha );
int red_image, green_image, blue_image, alpha_image;
get_pixel_on_image_unsafe(
surface, x, y,
&red_image, &green_image, &blue_image, &alpha_image
);
int inv_alpha = 255 - alpha;
Uint32 red32 = ( alpha * red + inv_alpha * red_image )/255;
Uint32 blue32 = ( alpha * blue + inv_alpha * blue_image )/255;
Uint32 green32 = ( alpha * green + inv_alpha * green_image )/255;
Uint32 alpha32 = alpha_image;
/* set the Red component */
red32 = red32 >> fmt->Rloss;
red32 = red32 << fmt->Rshift;
/* set the Green component */
green32 = green32 >> fmt->Gloss;
green32 = green32 << fmt->Gshift;
/* set the Blue component */
blue32 = blue32 >> fmt->Bloss;
blue32 = blue32 << fmt->Bshift;
/* set the Alpha component */
alpha32 = alpha32 >> fmt->Aloss;
alpha32 = alpha32 << fmt->Ashift;
*pixel = red32 | green32 | blue32 | alpha32;
SDL_UnlockSurface(surface);
#endif
}
void draw_pixel( MLV_Image* image, int x, int y, MLV_Color color ){
SDL_Surface* surface = image->surface;
draw_pixel_on_sdl_surface( surface, x, y, color );
}
void MLV_draw_pixel_on_image(int x, int y, MLV_Color color, MLV_Image* image){
draw_pixel( image, x, y, color);
}
void MLV_draw_point_on_image(int x, int y, MLV_Color color, MLV_Image* image){
MLV_draw_pixel_on_image( x, y, color, image);
}
///////////////////////////////////////////////////////////////////////////////
// Drawing operation on iscreen //
///////////////////////////////////////////////////////////////////////////////
void MLV_draw_circle(int x, int y, int radius, MLV_Color color){
circleColor( MLV_data->screen, x, y, radius, color );
}
void MLV_draw_filled_circle(int x, int y, int radius, MLV_Color color){
filledCircleColor( MLV_data->screen, x, y, radius, color);
}
void MLV_draw_ellipse(int x, int y, int radius_x, int radius_y, MLV_Color color){
ellipseColor(MLV_data->screen,x,y,radius_x,radius_y,color);
}
void MLV_draw_filled_ellipse(int x, int y, int radius_x, int radius_y, MLV_Color color){
filledEllipseColor(MLV_data->screen,x,y,radius_x,radius_y,color);
}
void MLV_draw_polygon( const int* vx, const int* vy, int nb_points, MLV_Color color){
Sint16* tmp_vx = MLV_MALLOC( nb_points, Sint16 );
Sint16* tmp_vy = MLV_MALLOC( nb_points, Sint16 );
int i;
for( i=0; i< nb_points; i++){
tmp_vx[i] = vx[i];
tmp_vy[i] = vy[i];
}
polygonColor( MLV_data->screen, tmp_vx, tmp_vy, nb_points, color);
MLV_FREE( tmp_vx, Sint16 );
MLV_FREE( tmp_vy, Sint16 );
}
void MLV_draw_filled_polygon( const int* vx, const int* vy, int nb_points, MLV_Color color){
Sint16* tmp_vx = MLV_MALLOC( nb_points, Sint16 );
Sint16* tmp_vy = MLV_MALLOC( nb_points, Sint16 );
int i;
for( i=0; i< nb_points; i++){
tmp_vx[i] = vx[i];
tmp_vy[i] = vy[i];
}
filledPolygonColor( MLV_data->screen, tmp_vx, tmp_vy, nb_points, color);
MLV_FREE( tmp_vx, Sint16 );
MLV_FREE( tmp_vy, Sint16 );
}
void MLV_draw_bezier_curve( const int* vx, const int* vy, int nb_points, MLV_Color color){
Sint16* tmp_vx = MLV_MALLOC( nb_points, Sint16 );
Sint16* tmp_vy = MLV_MALLOC( nb_points, Sint16 );
int i;
for( i=0; i< nb_points; i++){
tmp_vx[i] = vx[i];
tmp_vy[i] = vy[i];
}
bezierColor( MLV_data->screen, tmp_vx, tmp_vy, nb_points, 6 , color);
MLV_FREE( tmp_vx, Sint16 );
MLV_FREE( tmp_vy, Sint16 );
}
void MLV_draw_rectangle(int x, int y, int width, int height, MLV_Color color){
rectangleColor(MLV_data->screen, x, y, x+width-1, y+height-1, color);
}
void MLV_draw_filled_rectangle(int x, int y, int width, int height, MLV_Color color){
boxColor(MLV_data->screen, x, y, x+width-1, y+height-1, color);
}
void MLV_draw_line(int x1, int y1, int x2, int y2, MLV_Color color){
lineColor( MLV_data->screen, x1, y1, x2, y2, color);
}
void MLV_draw_pixel(int x, int y, MLV_Color color){
draw_pixel_on_sdl_surface( MLV_data->screen, x, y, color );
}
void MLV_draw_point(int x, int y, MLV_Color color){
MLV_draw_pixel( x, y, color);
}

940
MLV/text.c Normal file
View File

@@ -0,0 +1,940 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "platform.h"
#ifdef OS_WINDOWS
/* Get va_list. */
#if __STDC__ || defined __cplusplus || defined _MSC_VER
# include <stdarg.h>
#else
# include <varargs.h>
#endif
extern int vasprintf (char **, const char *, va_list);
#endif
#include "MLV_text.h"
#include "MLV_text_va.h"
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
# include <SDL/SDL_ttf.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
# include <SDL_ttf/SDL_ttf.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
# include <SDL/SDL_ttf.h>
#endif
#else
#include "memory_debug.h"
#endif
#include <string.h>
#include "text.h"
#include "MLV_shape.h"
#include "data_structure.h"
#include "image.h"
#include "memory_management.h"
#include "warning_error.h"
#define SIZE_FONT 8
extern DataMLV* MLV_data;
void MLV_get_size_of_text_va(
const char *text, int *width, int *height, va_list pile
){
MLV_get_size_of_text_with_font_va(
text, width, height, MLV_data->defaultFont, pile
);
}
void MLV_get_size_of_text( const char *text, int *width, int *height, ... ){
va_list pile;
va_start( pile, height );
MLV_get_size_of_text_va( text, width, height, pile );
va_end( pile );
}
void MLV_get_size_of_text_with_font_va(
const char *text, int *width, int *height, const MLV_Font* font,
va_list pile
){
char* complete_text;
if( vasprintf( &complete_text, text, pile )==-1 ){
ERROR("Unexpected Error.");
}
if( strlen( complete_text ) ){
TTF_SizeUTF8(font->font, complete_text, width, height);
}else{
TTF_SizeUTF8(font->font, " ", width, height);
}
free( complete_text );
}
void MLV_get_size_of_text_with_font(
const char *text, int *width, int *height, const MLV_Font* font, ...
){
va_list pile;
va_start( pile, font );
MLV_get_size_of_text_with_font_va( text, width, height, font, pile );
va_end( pile );
}
void init_font(){
if ( TTF_Init() < 0 ) {
fprintf(
stderr, "Couldn't initialize TTF: %s - file : %s, ligne : %i\n",
SDL_GetError(), __FILE__, __LINE__
);
exit(1);
}
}
void quit_font(){
TTF_Quit();
}
MLV_Font* MLV_load_font( const char* file_font, int size ){
if( !MLV_data ){
ERROR("To use MLV_load_font, please initialise first the MLV_Library by calling MLV_create_window before MLV_load_font.")
}
MLV_Font* font = MLV_MALLOC( 1, MLV_Font );
font->size = size;
font->font = TTF_OpenFont( file_font, size );
if(!font->font) {
printf(
"TTF_OpenFont: %s - file : %s, ligne : %i\n",
TTF_GetError(), __FILE__, __LINE__
);
exit(1);
}
TTF_SetFontStyle( font->font , TTF_STYLE_NORMAL );
return font;
}
void MLV_free_font( MLV_Font* font ){
TTF_CloseFont( font->font );
MLV_FREE( font, MLV_Font );
}
void convertionColor( MLV_Color src, SDL_Color* dst ){
src = src >> 8;
dst->b = (Uint8) src;
src = src >> 8;
dst->g = (Uint8) src;
src = src >> 8;
dst->r = (Uint8) src;
}
void getDefaultFont( MLV_Font** const font ){
if( *font ) return;
*font = MLV_data->defaultFont;
}
void drawString(
SDL_Surface* textBox, int x, int y,
const char* message, MLV_Color color, TTF_Font* font
){
SDL_Color sdl_color;
convertionColor( color, &sdl_color);
SDL_Surface* text;
if( strlen( message ) ){
text = TTF_RenderUTF8_Solid(
font,
message,
sdl_color
);
}else{
text = TTF_RenderUTF8_Solid(
font,
" ",
sdl_color
);
}
SDL_Rect rectangle;
rectangle.x = x;
rectangle.y = y;
rectangle.w = text->w;
rectangle.h = text->h;
SDL_BlitSurface( text, NULL, textBox, &rectangle);
SDL_FreeSurface( text );
}
void MLV_draw_text_on_image_va(
int x, int y, const char *text, MLV_Color color, MLV_Image* image,
va_list pile
){
MLV_draw_text_with_font_on_image_va(
x, y, text, MLV_data->defaultFont, color, image, pile
);
}
void MLV_draw_text_on_image(
int x, int y, const char *text, MLV_Color color, MLV_Image* image, ...
){
va_list pile;
va_start( pile, image );
MLV_draw_text_on_image_va( x, y, text, color, image, pile );
va_end( pile );
}
void MLV_draw_text_with_font_on_image_va(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color,
MLV_Image* image, va_list pile
){
char* complete_text;
if( vasprintf( &complete_text, text, pile )==-1 ){
ERROR("Unexpected Error.");
}
drawString( image->surface, x, y, complete_text, color, font->font );
free( complete_text );
}
void MLV_draw_text_with_font_on_image(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color,
MLV_Image* image, ...
){
va_list pile;
va_start( pile, image );
MLV_draw_text_with_font_on_image_va( x, y, text, font, color, image, pile );
va_end( pile );
}
void MLV_draw_text_va(
int x, int y, const char *text, MLV_Color color, va_list pile
){
MLV_draw_text_with_font_va(
x, y, text, MLV_data->defaultFont, color, pile
);
}
void MLV_draw_text(int x, int y, const char *text, MLV_Color color, ... ){
va_list pile;
va_start( pile, color );
MLV_draw_text_va( x, y, text, color, pile );
va_end( pile );
}
void MLV_draw_text_with_font_va(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color,
va_list pile
){
char* complete_text;
if( vasprintf( &complete_text, text, pile )==-1 ){
ERROR("Unexpected Error.");
}
drawString( MLV_data->screen, x, y, complete_text, color, font->font );
free( complete_text );
}
void MLV_draw_text_with_font(
int x, int y, const char *text, const MLV_Font* font, MLV_Color color, ...
){
va_list pile;
va_start( pile, color );
MLV_draw_text_with_font_va( x, y, text, font, color, pile );
va_end( pile );
}
int internal_draw_adapted_text_box_size_with_font(
char* copy,
const MLV_Font* font,
int sizeInterligne,
int *width, int *height,
int * width_text
){
int nb_line=1;
*width = 0;
*height = 0;
if( copy[0] != '\0' ){
int width_line,height_line;
char * new = copy;
char* old = new;
while( ( new = strchr( new ,'\n') ) ){
(*new) = '\0';
++nb_line;
MLV_get_size_of_text_with_font(
old, &width_line, &height_line, font
);
if( width_line > *width ){
*width = width_line;
}
*height += height_line + sizeInterligne;
new ++;
old=new;
}
MLV_get_size_of_text_with_font( old, &width_line, &height_line, font );
if( width_line > *width ){
*width = width_line;
}
*height += height_line + sizeInterligne;
}
if( width_text ){
*width_text = *width;
}
//Ajout des bords
*width += 2*sizeInterligne;
*height += sizeInterligne;
return nb_line;
}
void internal_draw_text_box_with_font(
char* copy ,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
int corner_position_x,
int corner_position_y,
int width_text,
int nb_line,
SDL_Surface* textBox
){
char * new = copy;
char* old = new;
int position = corner_position_y + sizeInterligne;
int horizontal_offset = corner_position_x + sizeInterligne;
int i;
for( i=0; i<nb_line; i++){
new = strchr( new ,'\0');
int width_line,height_line;
MLV_get_size_of_text_with_font( old, &width_line, &height_line, font );
switch( text_justification ){
case MLV_TEXT_CENTER:
drawString(
textBox,
horizontal_offset + (width_text-width_line)/2, position ,
old, textColor, font->font
);
break;
case MLV_TEXT_LEFT:
drawString(
textBox,
horizontal_offset , position ,
old, textColor, font->font
);
break;
case MLV_TEXT_RIGHT:
drawString(
textBox,
horizontal_offset+width_text-width_line+sizeInterligne,
position,
old, textColor, font->font
);
break;
default:
ERROR("Valeur impossible pour horizontal_position.");
}
position += height_line + sizeInterligne;
new ++;
old=new;
}
}
void internal_draw_adapted_text_box_with_font_on_image(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
SDL_Surface *screen
){
char* copy = (char*) MLV_MALLOC( (strlen(message)+1), char );
snprintf(copy, strlen(message)+1, "%s", message);
int width,height,width_text;
int nb_line = internal_draw_adapted_text_box_size_with_font(
copy, font, sizeInterligne, &width, &height, &width_text
);
SDL_Rect rectangle;
rectangle.x = x;
rectangle.y = y;
rectangle.w = width;
rectangle.h = height;
SDL_Surface* textBox= create_surface(
width, height
);
SDL_SetAlpha(textBox, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
SDL_SetColorKey(textBox, SDL_SRCCOLORKEY, backgroundColor);
boxColor( textBox , 0, 0, width-1, height-1, backgroundColor);
internal_draw_text_box_with_font(
copy ,
font,
sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
0,
0,
width_text,
nb_line,
textBox
);
rectangleColor( textBox , 0, 0, width-1, height-1, borderColor);
SDL_BlitSurface( textBox, NULL, screen, &rectangle);
SDL_FreeSurface( textBox );
MLV_FREE(copy, char);
}
void MLV_draw_adapted_text_box_with_font_va(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
va_list pile
){
char* complete_message;
if( vasprintf( &complete_message, message, pile )==-1 ){
ERROR("Unexpected Error.");
}
internal_draw_adapted_text_box_with_font_on_image(
x, y,
complete_message,
font,
sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
MLV_data->screen
);
free( complete_message );
}
void MLV_draw_adapted_text_box_va(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification, va_list pile
){
MLV_draw_adapted_text_box_with_font_va(
x, y, message, MLV_data->defaultFont, sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification, pile
);
}
void MLV_draw_adapted_text_box(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification, ...
){
va_list pile;
va_start( pile, text_justification );
MLV_draw_adapted_text_box_va(
x, y, message, sizeInterligne, borderColor, textColor, backgroundColor,
text_justification, pile
);
va_end( pile );
}
void MLV_draw_adapted_text_box_with_font_on_image_va(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, va_list pile
){
char* complete_message;
if( vasprintf( &complete_message, message, pile )==-1 ){
ERROR("Unexpected Error.");
}
internal_draw_adapted_text_box_with_font_on_image(
x, y,
complete_message,
font,
sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
image->surface
);
free( complete_message );
}
void MLV_draw_adapted_text_box_on_image_va(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, va_list pile
){
MLV_draw_adapted_text_box_with_font_on_image_va(
x, y, message, MLV_data->defaultFont, sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
image, pile
);
}
void MLV_draw_adapted_text_box_on_image(
int x, int y,
const char* message,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, ...
){
va_list pile;
va_start( pile, image );
MLV_draw_adapted_text_box_on_image_va(
x, y, message, sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
image, pile
);
va_end( pile );
}
int MLV_get_size_of_adapted_text_box_with_font_va(
const char* message,
const MLV_Font* font,
int sizeInterligne,
int *result_width, int *result_height,
va_list pile
){
char* complete_message;
if( vasprintf( &complete_message, message, pile )==-1 ){
ERROR("Unexpected Error.");
}
char* copy = (char*) MLV_MALLOC( (strlen(complete_message)+1), char );
snprintf(copy, strlen(complete_message)+1, "%s", complete_message);
int result = internal_draw_adapted_text_box_size_with_font(
copy,
font,
sizeInterligne,
result_width, result_height,
NULL
);
MLV_FREE(copy, char);
free( complete_message );
return result;
}
int MLV_get_size_of_adapted_text_box_va(
const char* message,
int sizeInterligne,
int *result_width, int *result_height,
va_list pile
){
return MLV_get_size_of_adapted_text_box_with_font_va(
message,
MLV_data->defaultFont,
sizeInterligne,
result_width, result_height,
pile
);
}
int MLV_get_size_of_adapted_text_box(
const char* message,
int sizeInterligne,
int *result_width, int *result_height,
...
){
int result;
va_list pile;
va_start( pile, result_height );
result = MLV_get_size_of_adapted_text_box_va(
message, sizeInterligne, result_width, result_height, pile
);
va_end( pile );
return result;
}
void MLV_draw_adapted_text_box_with_font(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification, ...
){
va_list pile;
va_start( pile, text_justification );
MLV_draw_adapted_text_box_with_font_va(
x, y, message, font, sizeInterligne, borderColor, textColor,
backgroundColor, text_justification, pile
);
va_end( pile );
}
void MLV_draw_adapted_text_box_with_font_on_image(
int x, int y,
const char* message,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Image* image, ...
){
va_list pile;
va_start( pile, image );
MLV_draw_adapted_text_box_with_font_on_image_va(
x, y, message, font, sizeInterligne, borderColor, textColor,
backgroundColor, text_justification, image, pile
);
va_end( pile );
}
int MLV_get_size_of_adapted_text_box_with_font(
const char* message,
const MLV_Font* font,
int sizeInterligne,
int *result_width, int *result_height, ...
){
int result;
va_list pile;
va_start( pile, result_height );
result = MLV_get_size_of_adapted_text_box_with_font_va(
message, font, sizeInterligne, result_width, result_height, pile
);
va_end( pile );
return result;
}
void internal_draw_text_box_with_font_on_image(
int x, int y,
int width, int height,
const char* message ,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
SDL_Surface* image
){
SDL_Rect rectangle;
rectangle.x = x;
rectangle.y = y;
rectangle.w = width;
rectangle.h = height;
SDL_Surface* textBox= create_surface(
width, height
);
SDL_SetAlpha(textBox, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
SDL_SetColorKey(textBox, SDL_SRCCOLORKEY, backgroundColor);
boxColor( textBox , 0, 0, width-1, height-1, backgroundColor);
char* copy = (char*) MLV_MALLOC( (strlen(message)+1), char );
snprintf(copy, strlen(message)+1, "%s", message);
int real_width,real_height,width_text;
int nb_line = internal_draw_adapted_text_box_size_with_font(
copy, font, sizeInterligne, &real_width, &real_height, &width_text
);
int position_corner_x;
switch( horizontal_position ){
case MLV_HORIZONTAL_LEFT:
position_corner_x = 0;
break;
case MLV_HORIZONTAL_RIGHT:
position_corner_x = width - real_width;
break;
case MLV_HORIZONTAL_CENTER:
position_corner_x = (width - real_width)/2;
break;
default:
ERROR("MLV_Vertical_position ne contient pas de bonnes valeurs.");
}
int position_corner_y;
switch( vertical_position ){
case MLV_VERTICAL_TOP:
position_corner_y = 0;
break;
case MLV_VERTICAL_BOTTOM:
position_corner_y = height - real_height;
break;
case MLV_VERTICAL_CENTER:
position_corner_y = (height - real_height)/2;
break;
default:
ERROR("MLV_Vertical_position ne contient pas de bonnes valeurs.");
}
internal_draw_text_box_with_font(
copy ,
font,
sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
position_corner_x,
position_corner_y,
width_text,
nb_line,
textBox
);
rectangleColor( textBox , 0, 0, width-1, height-1, borderColor);
SDL_BlitSurface( textBox, NULL, image, &rectangle);
SDL_FreeSurface( textBox );
MLV_FREE(copy, char);
}
void MLV_draw_text_box_with_font_va(
int x, int y,
int width, int height,
const char* message ,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
va_list pile
){
char* complete_message;
if( vasprintf( &complete_message, message, pile )==-1 ){
ERROR("Unexpected Error.");
}
internal_draw_text_box_with_font_on_image(
x, y,
width, height,
complete_message,
font,
sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
horizontal_position,
vertical_position,
MLV_data->screen
);
free( complete_message );
}
void MLV_draw_text_box_va(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
va_list pile
){
MLV_draw_text_box_with_font_va(
x, y, width, height, message , MLV_data->defaultFont, sizeInterligne,
borderColor, textColor, backgroundColor, text_justification,
horizontal_position, vertical_position, pile
);
}
void MLV_draw_text_box(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
...
){
va_list pile;
va_start( pile, vertical_position );
MLV_draw_text_box_va(
x, y, width, height, message , sizeInterligne, borderColor, textColor,
backgroundColor, text_justification, horizontal_position,
vertical_position, pile
);
va_end( pile );
}
void MLV_draw_text_box_with_font(
int x, int y,
int width, int height,
const char* message ,
const MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
...
){
va_list pile;
va_start( pile, vertical_position );
MLV_draw_text_box_with_font_va(
x, y, width, height, message, font, sizeInterligne,
borderColor, textColor, backgroundColor, text_justification,
horizontal_position, vertical_position, pile
);
va_end( pile );
}
void MLV_draw_text_box_with_font_on_image_va(
int x, int y,
int width, int height,
const char* message ,
MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
va_list pile
){
char* complete_message;
if( vasprintf( &complete_message, message, pile )==-1 ){
ERROR("Unexpected Error.");
}
internal_draw_text_box_with_font_on_image(
x, y,
width, height,
complete_message,
font,
sizeInterligne,
borderColor, textColor, backgroundColor,
text_justification,
horizontal_position,
vertical_position,
image->surface
);
free( complete_message );
}
void MLV_draw_text_box_with_font_on_image(
int x, int y,
int width, int height,
const char* message ,
MLV_Font* font,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
...
){
va_list pile;
va_start( pile, image );
MLV_draw_text_box_with_font_on_image_va(
x, y, width, height, message, font, sizeInterligne, borderColor,
textColor, backgroundColor, text_justification, horizontal_position,
vertical_position, image, pile
);
va_end( pile );
}
void MLV_draw_text_box_on_image_va(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
va_list pile
){
MLV_draw_text_box_with_font_on_image_va(
x, y, width, height, message, MLV_data->defaultFont, sizeInterligne,
borderColor, textColor, backgroundColor, text_justification,
horizontal_position, vertical_position, image, pile
);
}
void MLV_draw_text_box_on_image(
int x, int y,
int width, int height,
const char* message ,
int sizeInterligne,
MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor,
MLV_Text_justification text_justification,
MLV_Horizontal_position horizontal_position,
MLV_Vertical_position vertical_position,
MLV_Image* image,
...
){
va_list pile;
va_start( pile, image );
MLV_draw_text_box_on_image_va(
x, y, width, height, message, sizeInterligne, borderColor, textColor,
backgroundColor, text_justification, horizontal_position,
vertical_position, image, pile
);
va_end( pile );
}
char* MLV_convert_unicode_to_string( int unicode ){
gunichar v = unicode;
gchar* message;
int size = g_unichar_to_utf8(v,NULL);
message = (char*) MLV_MALLOC( size + 1, gchar );
message[ size ] = '\0';
g_unichar_to_utf8(v, message);
// const char* encodage;
// g_get_charset( &encodage );
// printf("encodage : %s\n",encodage);
// GError* error;
//
// gchar* result = g_locale_from_utf8(
// message,
// -1,
// NULL,
// NULL,
// &error // pas d'erreur
// );
//
//
// MLV_FREE( message, gchar* );
// return result;
return message;
}

52
MLV/text.h Normal file
View File

@@ -0,0 +1,52 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__TEXT_H__
#define __MLV__TEXT_H__
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL_ttf.h>
#elif defined( OS_APPLE )
# include <SDL_ttf/SDL_ttf.h>
#else
# include <SDL/SDL_ttf.h>
#endif
#else
#include "memory_debug.h"
#endif
struct _MLV_Font {
int size;
TTF_Font* font;
};
void init_font();
void quit_font();
void drawString(
SDL_Surface* textBox, int x, int y,
const char* message, MLV_Color color, TTF_Font* font
);
#endif

107
MLV/time.c Normal file
View File

@@ -0,0 +1,107 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_time.h"
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_framerate.h>
#endif
#else
#include "memory_debug.h"
#endif
#include <time.h>
#include "warning_error.h"
#include "memory_management.h"
#include "data_structure.h"
extern DataMLV* MLV_data;
void MLV_wait_milliseconds(int milliseconds){
SDL_Delay( milliseconds );
}
void MLV_wait_seconds(int seconds){
SDL_Delay( seconds * 1000 );
}
int MLV_get_time(){
return SDL_GetTicks();
}
int MLV_get_date(
int* seconds, int* minutes, int* hours,
int* day, int* month, int* year,
int* day_of_the_week
){
time_t current_time;
time(&current_time);
struct tm * timeinfo = localtime (&current_time);
if( seconds ){
*seconds = timeinfo->tm_sec;
}
if( minutes ){
*minutes = timeinfo->tm_min;
}
if( hours ){
*hours = timeinfo->tm_hour;
}
if( day ){
*day = timeinfo->tm_mday;
}
if( month ){
*month = timeinfo->tm_mon;
}
if( year ){
*year = timeinfo->tm_year+1900;
}
if( day_of_the_week ){
*day_of_the_week = timeinfo->tm_wday;
}
return timeinfo->tm_isdst;
}
void MLV_change_frame_rate( int rate ){
SDL_setFramerate( &(MLV_data->frame_rate_manager), rate );
}
int MLV_get_frame_rate( ){
return( SDL_getFramerate( &(MLV_data->frame_rate_manager) ) );
}
void MLV_delay_according_to_frame_rate( ){
SDL_framerateDelay( &(MLV_data->frame_rate_manager) );
}

182
MLV/tree_map.c Normal file
View File

@@ -0,0 +1,182 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tree_map.h"
#include "tree_set.h"
#include "warning_error.h"
#include "memory_management.h"
struct _MLV_TreeMap {
MLV_TreeSet* set;
};
typedef struct {
MLV_Key* key;
void* data;
void (* data_destroying_function )( void* data );
} PairKeyData;
PairKeyData* create_pair_key_data(
MLV_Key* key,
void* data,
void (* data_destroying_function )( void* data )
){
PairKeyData* result = MLV_MALLOC( 1, PairKeyData );
result->key = key;
result->data = data;
result->data_destroying_function = data_destroying_function;
return result;
}
void free_pair_key_data( PairKeyData* pair ){
if( pair ){
MLV_free_key( pair->key );
if( pair->data_destroying_function ){
pair->data_destroying_function( pair->data );
}
}
MLV_FREE( pair, PairKeyData );
}
void free_pair_key_data_without_key( PairKeyData* pair ){
if( pair ){
if( pair->data_destroying_function ){
pair->data_destroying_function( pair->data );
}
}
MLV_FREE( pair, PairKeyData );
}
int compare_pairs_key_data( PairKeyData* pair1, PairKeyData* pair2 ){
return MLV_compare_keys( pair1->key, pair2->key );
}
MLV_TreeMap* MLV_create_tree_map(){
MLV_TreeMap* result = MLV_MALLOC( 1, MLV_TreeMap );
result->set = NULL;
return result;
}
void MLV_add_data_in_tree_map(
MLV_Key* key, void* data,
void (* data_destroying_function)( void* data ),
MLV_TreeMap* tree_map
){
tree_map->set = MLV_add_data_in_tree_set(
create_pair_key_data(
key, data, data_destroying_function
),
( void (*)( void* ) ) free_pair_key_data,
( int (*)( void*, void* ) ) compare_pairs_key_data,
tree_map->set
);
}
void* MLV_get_data_from_tree_map( MLV_Key* key, MLV_TreeMap* tree_map ){
PairKeyData* key_data = create_pair_key_data( key, NULL, NULL );
MLV_TreeSet* elem = MLV_find_tree_set( key_data, tree_map->set );
PairKeyData* founded_key_data = (PairKeyData*) elem->data;
free_pair_key_data_without_key( key_data );
return founded_key_data->data;
}
void free_key_of_pair_key_data( PairKeyData* pair ){
MLV_free_key( pair->key );
}
void wrapper_free_key_of_pair_key_data( void* pair, void* useless_data ){
free_key_of_pair_key_data( ( PairKeyData* ) pair );
}
void MLV_init_tree_map( MLV_TreeMap* tree_map ){
// On supprime les clés
MLV_foreach_data_tree_set(
wrapper_free_key_of_pair_key_data,
NULL,
tree_map->set
);
// On réinitialise la table
MLV_init_tree_set( tree_map->set );
}
typedef struct {
void* data_user;
void (* key_data_function )( MLV_Key* key, void* data, void* data_user );
} Wrapper_data_user;
Wrapper_data_user* create_wrapper_data_user(
void* data_user,
void (* key_data_function )( MLV_Key* key, void* data, void* data_user )
){
Wrapper_data_user* result = MLV_MALLOC( 1, Wrapper_data_user );
result->data_user = data_user;
result->key_data_function = key_data_function;
return result;
}
void free_wrapper_data_user( Wrapper_data_user* data ){
MLV_FREE( data, Wrapper_data_user );
}
void wrapper_key_data_function(
void* data,
void* data_user
){
PairKeyData* pair = ( PairKeyData* ) data;
Wrapper_data_user* wrapper_data_user = (Wrapper_data_user*) data_user;
if( wrapper_data_user->key_data_function ){
wrapper_data_user->key_data_function(
pair->key, pair->data, wrapper_data_user->data_user
);
}
}
void MLV_foreach_key_data_tree_map(
void (* key_data_function )( MLV_Key* key, void* data, void* data_user ),
void* data_user,
MLV_TreeMap* tree_map
){
Wrapper_data_user* wrapper_data = create_wrapper_data_user(
data_user, key_data_function
);
MLV_foreach_data_tree_set(
wrapper_key_data_function,
wrapper_data,
tree_map->set
);
free_wrapper_data_user( wrapper_data );
}
void MLV_clear_tree_map( MLV_TreeMap* tree_map ){
MLV_clear_tree_set( tree_map->set );
}
void MLV_free_tree_map( MLV_TreeMap* tree_map ){
MLV_clear_tree_map( tree_map );
MLV_FREE( tree_map, MLV_TreeMap );
}
void MLV_superficial_free_tree_map( MLV_TreeMap* tree_map ){
MLV_init_tree_map( tree_map );
MLV_FREE( tree_map, MLV_TreeMap );
}

52
MLV/tree_map.h Normal file
View File

@@ -0,0 +1,52 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__TREE_MAP_H__
#define __MLV__TREE_MAP_H__
#include "key.h"
typedef struct _MLV_TreeMap MLV_TreeMap;
MLV_TreeMap* MLV_create_tree_map();
void MLV_free_tree_map( MLV_TreeMap* tree_map );
void MLV_superficial_free_tree_map( MLV_TreeMap* tree_map );
void MLV_add_data_in_tree_map(
MLV_Key* key, void* data,
void (* data_destroying_function)( void* data ),
MLV_TreeMap* tree_map
);
void MLV_init_tree_map( MLV_TreeMap* tree_map );
void MLV_clear_tree_map( MLV_TreeMap* tree_map );
void* MLV_get_data_from_tree_map( MLV_Key* key, MLV_TreeMap* tree_map );
void MLV_foreach_key_data_tree_map(
void (* key_data_function )( MLV_Key* key, void* data, void* data_user ),
void* data_user,
MLV_TreeMap* tree_map
);
#endif

527
MLV/tree_set.c Normal file
View File

@@ -0,0 +1,527 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tree_set.h"
#include "warning_error.h"
#include "memory_management.h"
#include "mathematics.h"
/*
* Renvoie la hauteur d'un arbre
*/
int MLV_get_height_tree_set( MLV_TreeSet* tree_set ){
if( tree_set==NULL ){
return 0;
}
return tree_set->height;
}
/*
* Cette fonction substitue node par new_node
* dans le père de node.
*
* Avant :
* + <-- father
* / \
* + <-- node
*
* Après :
* + <-- father
* / \
* + <-- new_node
*
* Cette fonction ne modifie pas le contenu de new_node.
* Cette fonction renvoie un pointeur vers le père.
* Cette fonction n'accepte pas de node NULL.
*
*/
MLV_TreeSet* substitute_in_father_tree_Set(
MLV_TreeSet* node, MLV_TreeSet* new_node
){
if( node ){
ERROR_FULL("Node can't be NULL !");
}
MLV_TreeSet* father = node->father;
if( father ){
if( father->left_son == node ){
father->left_son = new_node;
}else{
father->right_son = new_node;
}
}
new_node->father = father;
return father;
}
/*
* Renvoie le noeud de l'arbre de valeur de clé maximale.
*/
MLV_TreeSet* MLV_get_maximal_node_of_tree_set( MLV_TreeSet* tree_set ){
MLV_TreeSet* result = NULL;
while( tree_set ){
result = tree_set;
tree_set = tree_set->right_son;
}
return result;
}
/*
* TODO
*
* Cette fonction retire un noeud de l'arbre.
* Cette focntion renvoi un pointeur vers le nouvel arbre
* obtenu.
*
*/
MLV_TreeSet* remove_node_of_tree_set( MLV_TreeSet* tree_set ){
NOT_IMPLEMENTED;
return NULL;
}
/*
* Cette fonction détruit les données contenues dans un noeud de l'arbre.
*
*/
void destroy_node_data_of_tree_set( MLV_TreeSet* tree_set ){
if( tree_set && tree_set->data_destroying_function ){
tree_set->data_destroying_function( tree_set->data );
}
}
/*
* Cette fonction suprime le noeud (en libérant la mémoire), mais
* ne suprrime pas la donnée qu'elle contient.
*
* Cette fonction renvoie un pointeur vers le nouvel arbre obtenu.
*/
MLV_TreeSet* destroy_node_of_tree_set( MLV_TreeSet* tree_set ){
MLV_TreeSet* new_tree;
new_tree = remove_node_of_tree_set( tree_set );
MLV_FREE( tree_set, MLV_TreeSet );
return new_tree;
}
/*
* Cette fonction détruit les données contenues dans un noeud, puis suprime le noeud
* de l'arbre et libère la mémoire associée à tree_set.
*
* Cette fonction renvoie un pointeur vers le nouvel arbre obtenu.
*
*/
MLV_TreeSet* destroy_node_and_his_data_of_tree_set( MLV_TreeSet* tree_set ){
MLV_TreeSet* new_tree;
destroy_node_data_of_tree_set( tree_set );
new_tree = remove_node_of_tree_set( tree_set );
MLV_FREE( tree_set, MLV_TreeSet );
return new_tree;
}
/*
* Cette fonction cherche un noeud ayant une donnée particulière.
* Cette fonction rencoie le noeud associé à cette donnée.
*/
MLV_TreeSet* MLV_find_tree_set( void* data, MLV_TreeSet* tree_set ){
if( tree_set == NULL ){
return NULL;
}
int comparaison = tree_set->sorting_function( data, tree_set->data );
if( comparaison == 0 ){
return tree_set;
}else if( comparaison < 0 ){
return MLV_find_tree_set( data, tree_set->left_son );
}else{
return MLV_find_tree_set( data, tree_set->right_son );
}
}
/*
* Supprime les données conetenu dans un tree_set et
* les remplaces par une autre donnée.
* La mémoire de l'ancienne donnée est suprimée.
*
*/
void change_data_of_node_tree_set(
void* data,
void (* data_destroying_function )( void* data ),
MLV_TreeSet * tree_set
){
destroy_node_data_of_tree_set( tree_set );
tree_set->data = data;
tree_set->data_destroying_function = data_destroying_function;
}
/*
* Créer un nouveau noeud.
*/
MLV_TreeSet* create_node_tree_set(
MLV_TreeSet* father, MLV_TreeSet* left_son, MLV_TreeSet* right_son,
void* data,
void (* data_destroying_function )( void* data ),
int (* sorting_function )( void* data1, void* data2 ),
int height
){
MLV_TreeSet* result = MLV_MALLOC( 1, MLV_TreeSet );
result->father = father;
result->left_son = left_son;
result->right_son = right_son;
result->data = data;
result->data_destroying_function = data_destroying_function;
result->sorting_function = sorting_function;
result->height = height;
return result;
}
/*
* Cette fonction équilibre localement le sous-arbre tree_set en équilibrant
* que sa racine.
*
* A l'issue de l'équilibrage, elle met à jour les hauteurs de tous les noeuds
* du sous-arbre associée à tree_set.
* Si les fils à tree_set étaient équilibrés, alors, tree_set devient lui aussi
* équilibré.
*
*/
MLV_TreeSet* equilibrate_localy_the_tree_set( MLV_TreeSet* tree_set ){
if( ! tree_set ) return NULL;
MLV_TreeSet *A, *B, *C, *D, *E, *F, *G;
MLV_TreeSet* father = tree_set->father;
int height_left = MLV_get_height_tree_set( tree_set->left_son );
int height_right = MLV_get_height_tree_set( tree_set->right_son );
int comparaison = height_left-height_right;
// Si les fils ont des tailles qui diffèrent d'au plus 1, alors le sous-arbre
// est déjà équilibré et il y a rien à faire.
if( abs( comparaison ) <= 1 ) return tree_set;
// Le sous arbres n'est pas équilibré.
// 4 type d'arbres non équilibrés peuvent se présenter
if( comparaison < 0 ){
/* B
* / \
* A \
* +
*/
B = tree_set;
A = B->left_son;
int height_right_left = MLV_get_height_tree_set( B->right_son->left_son );
int height_right_right = MLV_get_height_tree_set( B->right_son->right_son );
if( height_right_left > height_right_right ){
/* 1er type :
*
* B
* / \
* A F
* / \
* D G
* / \
* C E
*/
F = B->right_son;
D = F->left_son;
G = F->right_son;
C = D->left_son;
E = D->right_son;
}else{
/* 2ème type :
*
* B
* / \
* A D
* / \
* C F
* / \
* E G
*/
D = B->right_son;
C = D->left_son;
F = D->right_son;
E = F->left_son;
G = F->right_son;
}
}else{
/* F
* / \
* / G
* +
*/
F = tree_set;
G = F->right_son;
int height_left_left = MLV_get_height_tree_set( F->left_son->left_son );
int height_left_right = MLV_get_height_tree_set( F->left_son->right_son );
if( height_left_right > height_left_left ){
/* 3ème type :
*
* F
* / \
* B G
* / \
* A D
* / \
* C E
*/
B = F->left_son;
A = B->left_son;
D = B->right_son;
C = D->left_son;
E = D->right_son;
}else{
/* 4ème type :
*
* F
* / \
* D G
* / \
* B E
* / \
* A C
*/
D = F->left_son;
B = D->left_son;
E = D->right_son;
A = B->left_son;
C = B->right_son;
}
}
/*
* On réordonne l'arbre de façon à obtenir
*
* D
* / \
* B F
* / \ / \
* A C E G
*/
A->father = B;
C->father = B;
E->father = F;
G->father = F;
B->left_son = A;
B->right_son = C;
B->father = D;
B->height = max( A->height, C->height ) + 1;
F->left_son = E;
F->right_son = G;
F->father = D;
F->height = max( E->height, G->height ) + 1;
D->left_son = B;
D->right_son = F;
D->father = father;
D->height = max( B->height, F->height ) + 1;
// On met à jour le père du sous-arbre d'origine
if( father ){
if( father->left_son == tree_set ){
father->left_son = D;
}else{
father->right_son = D;
}
}
return D;
}
/*
* Algorithme d'insertion d'une nouvelle (cle, data) dans un arbre.
*/
MLV_TreeSet* MLV_add_data_in_tree_set(
void* data,
void (* data_destroying_function )( void* data ),
int (* sorting_function )( void* data1, void* data2 ),
MLV_TreeSet * tree_set
){
if( tree_set==NULL ){
return create_node_tree_set(
NULL, NULL, NULL,
data,
data_destroying_function, sorting_function,
1
);
}
// On cherche l'endroit où il faut insérer le noeud dans l'arbre.
MLV_TreeSet* current = tree_set;
MLV_TreeSet* father_of_insertion_point = NULL;
int comparaison;
while( current ){
comparaison = current->sorting_function( data, current->data );
if( comparaison == 0 ){
change_data_of_node_tree_set(
data, data_destroying_function, current
);
return tree_set;
}else if( comparaison < 0 ){
father_of_insertion_point = current;
current = current->left_son;
}else{
father_of_insertion_point = current;
current = current->right_son;
}
}
// on créé un nouveau noeud
current = create_node_tree_set(
father_of_insertion_point, NULL, NULL,
data,
data_destroying_function, sorting_function,
1
);
// On insère le nouveau noeud dans l'arbre.
// Ici, comme tree_set ne peut pas valoir NULL,
// father_of_insertion_point ne peut pas être NULL et
// comparaison contient une valeur.
// Le point d'insertion à donc toujours un père.
if( comparaison<0 ){
father_of_insertion_point->left_son = current;
}else{
father_of_insertion_point->right_son = current;
}
// On équilibre l'arbre.
// Pour cela on remonte l'arbre en paratn du sommet ajouté jusqu'à la
// racine et on rééqulibre localement chaque noeud rencontré.
current = father_of_insertion_point; // On part du père car le nouveau
// noeud est toujours équilibré.
MLV_TreeSet* new_root; // La nouvelle racine issue du rééquilibrage local.
while( current ){
new_root = equilibrate_localy_the_tree_set( current );
current = new_root->father;
}
// Comme father_of_inserion_point n'est pas NULL (voir explication
// précédente), current n'est pas NULL. Donc, new_root contient un valeur.
// D'après equilibrate_localy_the_tree_set, new_root est un arbre équilibré.
return new_root;
}
/*
* Execute un fonction sur chaque clé et donné de l'arbre.
*/
void MLV_foreach_data_tree_set(
void (* data_function )( void* data, void* data_user ),
void* data_user,
MLV_TreeSet* tree_set
){
if( tree_set ){
if( tree_set->left_son ){
MLV_foreach_data_tree_set( data_function, data_user, tree_set->left_son );
}
if( tree_set->right_son ){
MLV_foreach_data_tree_set( data_function, data_user, tree_set->right_son );
}
data_function( tree_set->data, data_user );
}
}
/*
* Execute un fonction sur chaque noeud de l'arbre.
*/
void foreach_node_tree_set(
void (* node_function)(MLV_TreeSet* tree_set, void* data_user),
void* data_user,
MLV_TreeSet* tree_set
){
if( tree_set ){
if( tree_set->left_son ){
foreach_node_tree_set( node_function, data_user, tree_set->left_son );
}
if( tree_set->right_son ){
foreach_node_tree_set( node_function, data_user, tree_set->right_son );
}
node_function( tree_set, data_user );
}
}
/*
* Un wrapper à utiliser avec foreach_node_tree_set.
*/
void wrapper_destroy_node_data_of_tree_set( MLV_TreeSet* tree_set, void* useless_data ){
destroy_node_data_of_tree_set( tree_set );
}
/*
* Un wrapper à utiliser avec foreach_node_tree_set.
*/
void wrapper_remove_node_of_tree_set( MLV_TreeSet* tree_set, void* useless_data ){
remove_node_of_tree_set( tree_set );
}
/*
* Un wrapper à utiliser avec foreach_node_tree_set.
*/
void wrapper_destroy_node_and_his_data_of_tree_set( MLV_TreeSet* tree_set, void* useless_data ){
destroy_node_and_his_data_of_tree_set( tree_set );
}
/*
* Un wrapper à utiliser avec foreach_node_tree_set.
*/
void wrapper_destroy_node_of_tree_set( MLV_TreeSet* tree_set, void* useless_data ){
destroy_node_of_tree_set( tree_set );
}
void free_tree_set( MLV_TreeSet* tree_set, void* useless_data ){
MLV_FREE( tree_set, MLV_TreeSet );
}
/*
* Cette fonction supprime tous les noeuds de l'abre sans détruire les données.
*/
void MLV_init_tree_set( MLV_TreeSet* tree_set ){
foreach_node_tree_set( free_tree_set, NULL, tree_set );
}
void deep_free_tree_set( MLV_TreeSet* tree_set, void* useless_data ){
destroy_node_data_of_tree_set( tree_set );
free_tree_set( tree_set, useless_data );
}
/*
* Cette fonction supprime tous les noeuds de l'abre et détruit les données
* associé à l'arbre.
*/
void MLV_clear_tree_set( MLV_TreeSet* tree_set ){
foreach_node_tree_set( deep_free_tree_set, NULL, tree_set );
}
/*
* Enlève une donnée de l'esemble.
* La donnée n'est pas supprimée.
*/
MLV_TreeSet* MLV_remove_data_from_tree_set( void* data, MLV_TreeSet* tree_set ){
MLV_TreeSet* node = MLV_find_tree_set( data, tree_set );
return destroy_node_of_tree_set( node );
}
/*
* Supprime une donnée de l'ensemble.
* La donnée est supprimée.
*/
MLV_TreeSet* MLV_remove_data_and_data_from_tree_set( void* data, MLV_TreeSet* tree_set ){
MLV_TreeSet* node = MLV_find_tree_set( data, tree_set );
destroy_node_data_of_tree_set( node );
return destroy_node_and_his_data_of_tree_set( node );
}
/*
* Supprime une donnée de l'ensemble.
* La donnée est supprimée.
*/
int MLV_is_in_tree_set( void* data, MLV_TreeSet* tree_set ){
return MLV_find_tree_set( data, tree_set )!=NULL ;
}

57
MLV/tree_set.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__TREE_SET_H__
#define __MLV__TREE_SET_H__
typedef struct _MLV_TreeSet MLV_TreeSet;
struct _MLV_TreeSet {
MLV_TreeSet* father;
MLV_TreeSet* left_son;
MLV_TreeSet* right_son;
void* data;
void (* data_destroying_function )( void* data );
int (* sorting_function )( void* data1, void*data2 );
int height;
};
MLV_TreeSet* MLV_add_data_in_tree_set(
void* data,
void (* data_destroying_function)( void* data ),
int (* sorting_function)( void* data1, void* data2 ),
MLV_TreeSet * tree_set
);
void MLV_init_tree_set( MLV_TreeSet* tree_set );
void MLV_clear_tree_set( MLV_TreeSet* tree_set );
void* MLV_get_data_from_tree_set( void* data, MLV_TreeSet* tree_set );
MLV_TreeSet* MLV_find_tree_set( void* data, MLV_TreeSet* tree_set );
void MLV_foreach_data_tree_set(
void (* data_function )( void* data, void* data_user ),
void* data_user,
MLV_TreeSet* tree_set
);
#endif

43
MLV/warning_error.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLV__WARNING_ERROR_H__
#define __MLV__WARNING_ERROR_H__
#include <stdio.h>
#include <stdlib.h>
#define ERROR(x) { fprintf( stderr, "Error detected by the function %s() in LibMLV : %s \n", __FUNCTION__, (x) ); exit(1); }
#define WARNING(x) { fprintf( stderr, "Warning generated by the function %s() in LibMLV : %s \n", __FUNCTION__, (x) ); }
#define TODO { fprintf( stderr, "The function %s() in LibThis Library is not implemented. \n", __FUNCTION__ ); exit(1); }
#define DEPRECATED(x) { fprintf( stderr, "The function %s() is deprecated. In the future, this function will disapear. Please use the %s() function instead of.\n", __FUNCTION__, (x) ); }
#define ERROR_FULL(x) { fprintf( stderr, "Error detected by the function %s() in LibMLV : %s ( file : %s, line : %i) \n", __FUNCTION__, (x), __FILE__, __LINE__ ); exit(1); }
#define WARNING_FULL(x) { fprintf( stderr, "Warning generated by the function %s() in LibMLV : %s ( file : %s, line : %i) \n", __FUNCTION__, (x), __FILE__, __LINE__ ); }
#define DEBUG(x) { fprintf( stderr, "DEBUG : %s - line : %i, file : %s\n", (x), __LINE__, __FILE__ ); }
#define NOT_IMPLEMENTED { fprintf( stderr, "The function %s() in LibMLV ( file : %s, line : %i ) is not implemented.\n", __FUNCTION__, __FILE__, __LINE__ ); exit(1); }
#endif

387
MLV/window.c Normal file
View File

@@ -0,0 +1,387 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_window.h"
#include "MLV_color.h"
#include "MLV_shape.h"
#include "config.h"
#include "text.h"
#include "input_box.h"
#include "MLV_color.h"
#include "MLV_audio.h"
#include <stdio.h>
#include <stdlib.h>
#include "platform.h"
#ifndef MEMORY_DEBUG
#if defined( OS_WINDOWS )
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
#elif defined( OS_APPLE )
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
#else
# include <SDL/SDL.h>
# include <SDL/SDL_gfxPrimitives.h>
#endif
#else
#include "memory_debug.h"
#endif
#include "warning_error.h"
#include "data_structure.h"
#include "image.h"
#include "memory_management.h"
#define SIZE_DEFAULT_FONT 12
int mlv_sdl_is_initialised = 0;
Uint32 mlv_width_of_desktop = 0;
Uint32 mlv_height_of_desktop = 0;
DataMLV *MLV_data = NULL;
void (*MLV_call_back_function_for_exit)(void*) = NULL;
void *MLV_call_back_data = NULL;
int events_filter(const SDL_Event *event){
if( event->type == SDL_QUIT ){
if( MLV_call_back_function_for_exit ){
(*(MLV_call_back_function_for_exit))(MLV_call_back_data);
return 1;
}else{
exit(0);
}
}
return input_box_events_filter(event);
}
/**************************************************************************/
/* Initialisation and closing functions for default font */
/**************************************************************************/
void initialize_default_font(
const char* path_to_font, unsigned int size_font
){
if( !MLV_data ){
ERROR("The MLV library has not been yet initialised. To initialise the \
MLV Library, create a new window with the MLV_create_window function."
);
}
MLV_data->defaultFont = MLV_load_font( path_to_font, size_font );
}
void free_default_font(){
if( !MLV_data ){
ERROR("The MLV library has not been yet initialised. To initialise the \
MLV Library, create a new window with the MLV_create_window function."
);
}
MLV_free_font( MLV_data->defaultFont );
}
/**************************************************************************/
/* Creation d'un fenetre graphique */
/**************************************************************************/
void initialise_graphic_window(
unsigned int width, unsigned int height, int full_screen_is_required
){
#if defined( OS_ANDROID )
Uint32 video_mode_flags = SDL_SWSURFACE | SDL_SRCALPHA;
#else
Uint32 video_mode_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_SRCALPHA;
#endif
if( full_screen_is_required ){
video_mode_flags |= SDL_FULLSCREEN;
}
MLV_data->full_screen_is_enable = full_screen_is_required;
if( MLV_data->screen ){
SDL_FreeSurface( MLV_data->screen );
}
MLV_data->screen = SDL_SetVideoMode( width, height, MLV_BPP, video_mode_flags );
width = MLV_data->screen->w;
height = MLV_data->screen->h;
MLV_data->width = width;
MLV_data->height = height;
MLV_data->rectangle.x = 0;
MLV_data->rectangle.y = 0;
MLV_data->rectangle.w = width;
MLV_data->rectangle.h = height;
if( MLV_data->save_screen ){
SDL_FreeSurface( MLV_data->screen );
}
MLV_data->save_screen = create_surface( width, height ); // do we have to use SDL_ALPHA_OPAQUE here ?
if ( MLV_data->screen == NULL ){
fprintf(stderr,"Unable to set %dx%d video: %s\n", width, height, SDL_GetError());
exit(1);
}
/**************************************************************************/
/* Initialisation de la couleur du fond de la fenetre en noir. */
/**************************************************************************/
MLV_draw_filled_rectangle(0,0,width,height,MLV_COLOR_BLACK);
MLV_actualise_window();
}
void initialise_sdl(){
if( ! mlv_sdl_is_initialised ){
if(
SDL_Init(
SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO
#if defined( OS_LINUX ) // SDL thread is not supported on Windows and MacOSX
| SDL_INIT_EVENTTHREAD // Cette option est importante !
// Elle permet de faire en sorte
// que le filtrage des évenements soit fait dés
// réception d'un evenement de la part de l'OS
// Si cette option n'est pas activée, le filtre
// d'evenement est applique seulement après un
// appel à poll_event. Dans ce cas la gestion
// de l'arret automatique du programme après
// utilisation de la croix des fenetre ne
// fonctione plus correctement. En effet, si
// l'utilisateur n'utilise pas de fonction mettant
// en jeu des évènement, le filtre n'est jamais
// appelé et le mécanisme d'arret automatique
// non plus.
#endif
) <0
){
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
}
}
void initialise_size_of_desktop(){
initialise_sdl();
if( mlv_width_of_desktop==0 || mlv_height_of_desktop==0 ){
const SDL_VideoInfo* info = SDL_GetVideoInfo();
mlv_width_of_desktop = info->current_w;
mlv_height_of_desktop = info->current_h;
}
}
void MLV_create_window_with_default_font(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height,
const char* path_to_font, unsigned int size_font
){
if( MLV_data ){
ERROR("The MLV library has yet been initialised.");
}
/**************************************************************************/
/* Initialisation de la strcutre de MLV */
/**************************************************************************/
MLV_data = MLV_MALLOC( 1, DataMLV );
MLV_data->screen = NULL;
MLV_data->save_screen = NULL;
/**************************************************************************/
/* Initialisation de la libriaire SDL pour l'uilisation de la video et du */
/* temps */
/**************************************************************************/
initialise_sdl();
/**************************************************************************/
/* Save the size of the desktop */
/**************************************************************************/
initialise_size_of_desktop();
/**************************************************************************/
/* Creation d'un fenetre graphique */
/**************************************************************************/
initialise_graphic_window( width, height, 0 );
/**************************************************************************/
/* Configuration des noms de la fenetre */
/**************************************************************************/
SDL_WM_SetCaption(window_name, icone_name);
/**************************************************************************/
/* Configuration du mechanisme permettant d'utiliser les boîtes de saisie */
/**************************************************************************/
init_input_box_mechanism();
/**************************************************************************/
/* Configuration des fonts */
/**************************************************************************/
init_font();
/**************************************************************************/
/* Création d'une font par default */
/**************************************************************************/
initialize_default_font( path_to_font, size_font );
/**************************************************************************/
/* Initialise the Framerate Manager */
/**************************************************************************/
SDL_initFramerate( &(MLV_data->frame_rate_manager) );
SDL_setFramerate( &(MLV_data->frame_rate_manager), 100 );
/**************************************************************************/
/* Initialise the internal Framerate Manager for MLV_wait_event */
/**************************************************************************/
SDL_initFramerate( &(MLV_data->frame_rate_manager_for_MLV_wait_event) );
SDL_setFramerate( &(MLV_data->frame_rate_manager_for_MLV_wait_event), 24 );
SDL_SetEventFilter(events_filter);
}
void MLV_create_window(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height
){
MLV_create_window_with_default_font(
window_name, icone_name, width, height,
DATA_PATH "/font/DejaVuSerif-Bold.ttf" , SIZE_DEFAULT_FONT
);
}
void MLV_change_default_font(
const char* path_to_font, unsigned int size_font
){
free_default_font();
initialize_default_font( path_to_font, size_font );
}
void MLV_enable_full_screen(){
initialise_graphic_window( MLV_data->width, MLV_data->height, 1 );
}
void MLV_create_full_screen_window(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height
){
MLV_create_window( window_name, icone_name, width, height );
MLV_enable_full_screen();
}
void MLV_create_full_screen_window_with_default_font(
const char* window_name, const char* icone_name,
unsigned int width, unsigned int height,
const char* path_to_font, unsigned int size_font
){
MLV_create_window_with_default_font(
window_name, icone_name, width, height, path_to_font, size_font
);
MLV_enable_full_screen();
}
void MLV_disable_full_screen(){
initialise_graphic_window( MLV_data->width, MLV_data->height, 0 );
}
int MLV_is_full_screen(){
return MLV_data->full_screen_is_enable;
}
void MLV_change_window_size( unsigned int with, unsigned int height ){
initialise_graphic_window( with, height, MLV_data->full_screen_is_enable );
}
void MLV_change_window_caption(
const char* window_name, const char* icone_name
){
SDL_WM_SetCaption( window_name, icone_name );
}
void MLV_get_window_size( unsigned int* width, unsigned int* height ){
*width = MLV_data->width;
*height = MLV_data->height;
}
int MLV_get_window_height(){
return MLV_data->height;
}
int MLV_get_window_width(){
return MLV_data->width;
}
void MLV_clear_window( MLV_Color color ){
MLV_draw_filled_rectangle(
0, 0, MLV_get_window_width( ), MLV_get_window_height( ), color
);
}
void MLV_free_window(){
if( ! MLV_data ){
ERROR("No window has been created.");
}
SDL_FreeSurface(MLV_data->screen);
SDL_FreeSurface(MLV_data->save_screen);
free_default_font();
quit_font();
MLV_FREE( MLV_data, DataMLV );
MLV_data = NULL;
SDL_Quit();
quit_input_box_mechanism();
}
void MLV_update_window(){
if( (! MLV_data ) || (! MLV_data->screen) ){
ERROR("A window can't be displayed whitout being created.");
}
SDL_Flip(MLV_data->screen);
}
#ifndef OS_APPLE // Hack to compile with MAC OS 10.9 (maverick)
inline
#endif
void MLV_actualise_window(){
MLV_update_window();
}
void MLV_execute_at_exit( void (*function)(void*), void* data ){
if( MLV_data ){
ERROR("The mlv window is yet initialized. The function execute_at_exit() must be executed before the create_window() function.");
}
if( MLV_call_back_function_for_exit ){
ERROR("The call back function for exiting program is yet initialized.");
}
MLV_call_back_function_for_exit = function;
MLV_call_back_data = data;
}
void MLV_get_desktop_size( unsigned int* width, unsigned int* height ){
initialise_size_of_desktop();
*width = mlv_width_of_desktop;
*height = mlv_height_of_desktop;
}
int MLV_get_desktop_height( ){
initialise_size_of_desktop();
return mlv_height_of_desktop;
}
int MLV_get_desktop_width( ){
initialise_size_of_desktop();
return mlv_width_of_desktop;
}

376
MLV/xml.c Normal file
View File

@@ -0,0 +1,376 @@
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "platform.h"
#ifdef OS_WINDOWS
/* Get va_list. */
#if __STDC__ || defined __cplusplus || defined _MSC_VER
# include <stdarg.h>
#else
# include <varargs.h>
#endif
extern int vasprintf (char **, const char *, va_list);
extern int asprintf (char **, const char *, ...);
#endif
#include "MLV_xml.h"
#include "MLV_xml_va.h"
#include "warning_error.h"
#include "memory_management.h"
#include "data_structure.h"
#include <glib.h>
#include <stdio.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <errno.h>
extern DataMLV* MLV_data;
struct _MLV_Xml {
xmlDocPtr doc;
// xmlNodePtr cur;
};
MLV_Xml* MLV_load_xml( const char* xml_file_path ){
MLV_Xml* result = MLV_MALLOC( 1, MLV_Xml );
result->doc = xmlParseFile( xml_file_path );
if (result->doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
MLV_FREE( result, MLV_Xml );
return NULL;
}
// result->cur = xmlDocGetRootElement( result->doc );
//
// if ( result->cur == NULL) {
// fprintf(stderr,"empty document\n");
// xmlFreeDoc(result->doc);
// MLV_FREE( result, MLV_Xml );
// return NULL;
// }
return result;
}
void MLV_free_xml( MLV_Xml* xml_data ){
if( xml_data ){
if( xml_data->doc ){
xmlFreeDoc( xml_data->doc );
}
MLV_FREE( xml_data, MLV_Xml );
}
}
void test_if_text_is_valid( const char* text, const char* xpath ){
if( ! text ){
char* message;
if(
asprintf(
&message,
"The xml file is probably corupted. The following element is not present: \"%s\" in the xml file.",
xpath
) < 0
){
ERROR_FULL("The error message can be constructed.");
}
ERROR( message );
}
}
void internal_scan_xml(
const MLV_Xml* xml_data, const char* xpath, va_list pile,
xmlXPathObjectPtr *result_search
){
xmlXPathContextPtr context;
char* complete_xpath;
if( vasprintf( &complete_xpath, xpath, pile ) < 0 ){
ERROR_FULL("Unexpected error");
}
context = xmlXPathNewContext( xml_data->doc );
*result_search = xmlXPathEvalExpression( (xmlChar*) complete_xpath, context);
MLV_FREE( complete_xpath, char );
xmlXPathFreeContext( context );
if( xmlXPathNodeSetIsEmpty((*result_search)->nodesetval) ){
xmlXPathFreeObject((*result_search));
*result_search = NULL;
}
}
char* internal_get_string_value_from_xml(
const MLV_Xml* xml_data, int i, const char* xpath, va_list pile
){
char* result = NULL;
xmlXPathObjectPtr result_search;
internal_scan_xml( xml_data, xpath, pile, &result_search );
if( !result_search ) return NULL;
xmlNodeSetPtr nodeset;
nodeset = result_search->nodesetval;
if( i < nodeset->nodeNr ){
result = (char*) xmlNodeListGetString(
xml_data->doc, nodeset->nodeTab[i]->xmlChildrenNode, 1
);
}
xmlXPathFreeObject(result_search);
return result;
}
MLV_Xml_error MLV_get_string_value_from_xml_va(
const MLV_Xml* xml_data, char** result, const char* xpath, va_list pile
){
*result = internal_get_string_value_from_xml( xml_data, 0, xpath, pile );
if( *result == NULL ){
return MLV_XML_THE_FIELD_DOESNT_EXIST;
}
return MLV_XML_NONE;
}
MLV_Xml_error MLV_get_string_value_from_xml(
const MLV_Xml* xml_data, char** result, const char* xpath, ...
){
MLV_Xml_error error;
va_list pile;
va_start( pile, xpath );
error = MLV_get_string_value_from_xml_va( xml_data, result, xpath, pile );
va_end( pile );
return error;
}
MLV_Xml_error MLV_get_integer_value_from_xml_va(
const MLV_Xml* xml_data, int* result, const char* xpath, va_list pile
){
long int value;
char* text;
MLV_Xml_error error;
error = MLV_get_string_value_from_xml_va( xml_data, &text, xpath, pile );
if( error ){
return error;
}
char* final;
errno = 0;
value = strtol(text, &final, 10 );
int err_sys = errno;
if( (final==NULL) || (*text='\0') || (*final != '\0') ){
error = MLV_XML_THE_FIELD_IS_NOT_AN_INTEGER;
}else if( err_sys==ERANGE ){
error = MLV_XML_THE_FIELD_IS_TOO_BIG;
}else if( err_sys != 0 && value == 0 ){
ERROR_FULL("A anormal error occurs during string to int conversion in XML Parsing." );
}else{
error = MLV_XML_NONE;
}
MLV_FREE( text, char );
*result = value;
return error;
}
MLV_Xml_error MLV_get_integer_value_from_xml(
const MLV_Xml* xml_data, int* result, const char* xpath, ...
){
MLV_Xml_error error;
va_list pile;
va_start( pile, xpath );
error = MLV_get_integer_value_from_xml_va( xml_data, result, xpath, pile );
va_end( pile );
return error;
}
MLV_Xml_error MLV_get_double_value_from_xml_va(
const MLV_Xml* xml_data, double* result, const char* xpath, va_list pile
){
double value;
char* text;
MLV_Xml_error error;
error = MLV_get_string_value_from_xml_va( xml_data, &text, xpath, pile );
if( error ){
return error;
}
char* final;
errno = 0;
value = strtod(text, &final );
int err_sys = errno;
if( (final==NULL) || (*text='\0') || (*final != '\0') ){
error = MLV_XML_THE_FIELD_IS_NOT_A_REAL;
}else if( err_sys==ERANGE ){
error = MLV_XML_THE_FIELD_IS_TOO_BIG;
}else if( err_sys != 0 && value == 0 ){
ERROR_FULL("A anormal error occurs during string to double conversion in XML Parsing." );
}else{
error = MLV_XML_NONE;
}
MLV_FREE( text, char );
*result = value;
return error;
}
MLV_Xml_error MLV_get_double_value_from_xml(
const MLV_Xml* xml_data, double* result, const char* xpath, ...
){
MLV_Xml_error error;
va_list pile;
va_start( pile, xpath );
error = MLV_get_double_value_from_xml_va( xml_data, result, xpath, pile );
va_end( pile );
return error;
}
MLV_Xml_error MLV_get_float_value_from_xml_va(
const MLV_Xml* xml_data, float* result, const char* xpath, va_list pile
){
float value;
char* text;
MLV_Xml_error error;
error = MLV_get_string_value_from_xml_va( xml_data, &text, xpath, pile );
if( error ){
return error;
}
char* final;
errno = 0;
value = strtof(text, &final);
int err_sys = errno;
if( (final==NULL) || (*text='\0') || (*final != '\0') ){
error = MLV_XML_THE_FIELD_IS_NOT_A_REAL;
}else if( err_sys==ERANGE ){
error = MLV_XML_THE_FIELD_IS_TOO_BIG;
}else if( err_sys != 0 && value == 0 ){
ERROR_FULL("A anormal error occurs during string to double conversion in XML Parsing." );
}else{
error = MLV_XML_NONE;
}
MLV_FREE( text, char );
*result = value;
return error;
}
MLV_Xml_error MLV_get_float_value_from_xml(
const MLV_Xml* xml_data, float* result, const char* xpath, ...
){
MLV_Xml_error error;
va_list pile;
va_start( pile, xpath );
error = MLV_get_float_value_from_xml_va( xml_data, result, xpath, pile );
va_end( pile );
return error;
}
int MLV_get_number_of_objects_from_xml_va(
const MLV_Xml* xml_data, const char* xpath, va_list pile
){
int result;
xmlXPathObjectPtr result_search;
internal_scan_xml( xml_data, xpath, pile, &result_search );
if( !result_search ) return 0;
result = result_search->nodesetval->nodeNr;
xmlXPathFreeObject(result_search);
return result;
}
int MLV_get_number_of_objects_from_xml(
const MLV_Xml* xml_data, const char* xpath, ...
){
int result;
va_list pile;
va_start( pile, xpath );
result = MLV_get_number_of_objects_from_xml_va( xml_data, xpath, pile );
va_end( pile );
return result;
}
MLV_Xml* MLV_get_xml_object_of_va(
const MLV_Xml* xml_data, const char* xpath, va_list pile
){
MLV_Xml* result = NULL;
ERROR_FULL("Not implemented.");
return result;
}
MLV_Xml* MLV_get_xml_object_of(
const MLV_Xml* xml_data, const char* xpath, ...
){
MLV_Xml* result;
va_list pile;
va_start( pile, xpath );
result = MLV_get_xml_object_of_va( xml_data, xpath, pile );
va_end( pile );
return result;
}
void MLV_print_xml( const MLV_Xml* xml_data ){
ERROR_FULL("Not implemented.");
}

35
Makefile Normal file
View File

@@ -0,0 +1,35 @@
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -pedantic -ansi
# Linker flags
LDFLAGS = -lMLV
# Target executable
TARGET = maison
# Source files
SRCS = maison.c
# Object files
OBJS = $(SRCS:.c=.o)
# Default target
all: $(TARGET)
# Link the target executable
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
# Compile source files to object files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Clean up build files
clean:
rm -f $(OBJS) $(TARGET)
# Phony targets
.PHONY: all clean

212
maison.c Normal file
View File

@@ -0,0 +1,212 @@
/**
*
* Ce programme montre comment il est possible de dessiner les figures
* géométriques suivantes :
*
* cercle
* disque ( cercle plein )
* ellipse
* ellipse pleine
* rectangle
* rectangle plein
* ligne
* point
* Courbe de Bézier
* polygone
* polygone plein
*
* Pour cela le programme utilise les fonctions suivantes :
*
*------------------------------------------------------------------------------
* MLV_draw_circle: Dessine un cercle à une position et un rayon spécifiés en
* paramètres.
*
* void MLV_draw_circle(
* int x, Coordonnée en X du centre du cercle
* int y, Coordonnée en Y du centre du cercle
* int radius, Rayon du cercle
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_filled_circle : Dessine un disque plein dont le centre et le rayon
* sont passés en parametres.
*
* void MLV_draw_filled_circle(
* int x, Coordonnée en X du centre du cercle
* int y, Coordonnée en Y du centre du cercle
* int radius, Rayon du cercle
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_ellipse : Dessine une ellipse dont la position, les rayons et la
* couleur sont passés en paramètres.
*
* MLV_draw_ellipse(
* int x, Coordonnée en X du centre de l'ellipse
* int y, Coordonnée en Y du centre de l'ellipse
* int radius_x, Rayon en X de l'ellipse
* int radius_y, Rayon en Y de l'ellipse
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_filled_ellipse : Dessine une ellipse pleine dont la position, les
* rayons et la couleur sont passés en paramètres.
*
* void MLV_draw_filled_ellipse(
* int x, Coordonnee en X du centre de l'ellipse
* int y, Coordonnee en Y du centre de l'ellipse
* int radius_x, Rayon en X de l'ellipse
* int radius_y, Rayon en Y de l'ellipse
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_rectangle : Dessine un rectangle dont la taille, la couleur et la
* position du sommet Nord-Ouest sont données en
* paramètres.
*
* void MLV_draw_rectangle(
* int x, Coordonnée en X du sommet Nord-Ouest du rectangle
* int y, Coordonnée en Y du sommet Nord-Ouest du rectangle
* int width, Largeur du rectangle
* int height, Hauteur du rectangle
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_filled_rectangle : Dessine un rectangle dont la taille, la couleur
* et la position du sommet Nord-Ouest sont données
* en paramètres.
* void MLV_draw_filled_rectangle(
* int x, Coordonnée en X du sommet Nord-Ouest du rectangle
* int y, Coordonnée en Y du sommet Nord-Ouest du rectangle
* int width, Largeur du rectangle
* int height, Hauteur du rectangle
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_line : Dessine une ligne dont les coordonnées des deux extrémités
* sont passées en paramètres.
* void MLV_draw_line(
* int x1, Coordonnée en X de la première extrémité de la ligne
* int y1, Coordonnée en Y de la première extrémité de la ligne
* int x2, Coordonnée en X de la deuxième extrémité de la ligne
* int y2, Coordonnée en Y de la deuxième extrémité de la ligne
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_point : Dessine un point dont les coordonées sont passées
* en paramètres.
*
* void MLV_draw_point(
* int x, Coordonnée en X du point
* int y, Coordonnée en Y du point
* MLV_Color color Couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_bezier_curve: Dessine une courbe de Bézier à partir d'une liste de
* sommets.
*
* void MLV_draw_bezier_curve(
* const int* vx, La liste des coordonnées en X des différents
* sommets de la courbe.
* const int* vy, La liste des coordonnées en Y des différents
* sommets de la courbe.
* int npoints, Le nombre de sommets de la courbe de Bézier.
* MLV_Color color La couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_polygon: Dessine un polygone à partir d'une liste de sommets.
*
* void MLV_draw_polygon(
* const int* vx, La liste des coordonnées en X des différents
* sommets du polygone.
* const int* vy, La liste des coordonnées en Y des différents
* sommets du polygone.
* int npoints, Le nombre de sommets du polygone.
* MLV_Color color La couleur du tracé
* );
*
* -----------------------------------------------------------------------------
* MLV_draw_polygon: Dessine un polygone plein à partir d'une liste de sommets.
*
* void MLV_draw_filled_polygon(
* const int* vx, La liste des coordonnées en X des différents
* sommets du polygone.
* const int* vy, La liste des coordonnées en Y des différents
* sommets du polygone.
* int npoints, Le nombre de sommets du polygone.
* MLV_Color color La couleur du tracé
* );
*
* -----------------------------------------------------------------------------
*
* Il existe d'autres fonctions de dessin. Vous les trouverez en consultant
* le fichier MLV_shape.h ou en tapant dans le terminal la commande :
*
* man MLV_shape.h
*/
#include <MLV/MLV_all.h>
int main(int argc, char *argv[]) {
/* Créé et affiche la fenêtre */
MLV_create_window("beginner - 2 - shapes", "shapes", 640, 480);
/* Dessine des cercles, ellipses, rectangles, lignes et points */
MLV_draw_circle(20, 20, 10, MLV_COLOR_PURPLE);
MLV_draw_filled_circle(50, 20, 10, MLV_COLOR_BROWN);
MLV_draw_ellipse(100, 20, 30, 10, MLV_COLOR_CYAN);
MLV_draw_filled_ellipse(170, 20, 30, 10, MLV_COLOR_PINK);
MLV_draw_rectangle(10, 50, 40, 20, MLV_COLOR_BLUE);
MLV_draw_filled_rectangle(70, 50, 40, 20, MLV_COLOR_GREEN);
MLV_draw_line(120, 50, 160, 90, MLV_COLOR_WHITE);
MLV_draw_point(10, 110, MLV_COLOR_RED);
/* Déclare les coordonnées pour la courbe de Bézier */
int coordonnee_x[4] = {10, 50, 90, 130};
int coordonnee_y[4] = {150, 190, 150, 190};
/* Dessine une courbe de Bézier avec ses sommets */
MLV_draw_bezier_curve(coordonnee_x, coordonnee_y, 4, MLV_COLOR_RED);
MLV_draw_circle(coordonnee_x[0], coordonnee_y[0], 3, MLV_COLOR_GREEN);
MLV_draw_circle(coordonnee_x[1], coordonnee_y[1], 3, MLV_COLOR_GREEN);
MLV_draw_circle(coordonnee_x[2], coordonnee_y[2], 3, MLV_COLOR_GREEN);
MLV_draw_circle(coordonnee_x[3], coordonnee_y[3], 3, MLV_COLOR_GREEN);
/* Déclare les coordonnées pour le polygone */
int coordonnee1_x[4] = {200, 240, 320, 280};
int coordonnee1_y[4] = {150, 190, 190, 150};
/* Dessine un polygone avec ses sommets */
MLV_draw_filled_polygon(coordonnee1_x, coordonnee1_y, 4, MLV_COLOR_BLUE);
MLV_draw_polygon(coordonnee1_x, coordonnee1_y, 4, MLV_COLOR_RED);
MLV_draw_circle(coordonnee1_x[0], coordonnee1_y[0], 3, MLV_COLOR_GREEN);
MLV_draw_circle(coordonnee1_x[1], coordonnee1_y[1], 3, MLV_COLOR_GREEN);
MLV_draw_circle(coordonnee1_x[2], coordonnee1_y[2], 3, MLV_COLOR_GREEN);
MLV_draw_circle(coordonnee1_x[3], coordonnee1_y[3], 3, MLV_COLOR_GREEN);
/* Affiche du texte */
MLV_draw_text(
10, 120,
"Juste au dessus de cette ligne, il y a un pixel rouge.",
MLV_COLOR_MAGENTA
);
/* Met à jour l'affichage */
MLV_actualise_window();
/* Attend 10 secondes avant la fin du programme */
MLV_wait_seconds(10);
/* Fermer la fenêtre */
MLV_free_window();
return 0;
}