1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| #include <gtk/gtk.h>
#include <stdlib.h>
#include <SDL.h>
#include "gtksdl.h"
#include <SDL_ttf.h>
GtkWidget *pSdl;
GtkWidget *pWindow;
SDL_Surface * screen;
void initSDL(void);
void Clicked(GtkWidget*,gpointer);
int main(int argc, char **argv)
{
initSDL();
gtk_init(&argc, &argv);
GtkWidget * pButton = gtk_button_new_with_label("test");
GtkWidget * pVbox = gtk_vbox_new(TRUE,0);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
pSdl = gtk_sdl_new (200, 100, 32, SDL_SWSURFACE,screen);
gtk_box_pack_start(GTK_BOX(pVbox),pSdl,TRUE,TRUE,0);
gtk_box_pack_start(GTK_BOX(pVbox),pButton,TRUE,TRUE,0);
gtk_container_add(GTK_CONTAINER(pWindow),pVbox);
g_signal_connect(G_OBJECT(pButton),"clicked",G_CALLBACK(Clicked),NULL);
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(pWindow);
gtk_main();
return EXIT_SUCCESS;
}
void Clicked(GtkWidget * pWindow,gpointer data)
{
SDL_Surface * double_buffer = SDL_SetVideoMode(200, 100, 32, SDL_SWSURFACE);
SDL_Surface * Phrase = NULL;
SDL_Color TextColor;
TTF_Font * Police;
int i;
TextColor.r = 255;
TextColor.g = 0;
TextColor.b = 0;
Police = TTF_OpenFont("comic.ttf",50);
Phrase = TTF_RenderText_Blended(Police,"bonjour",TextColor);
for(i=0;i<0x0000FF;i+=0x000002)
{
SDL_FillRect( double_buffer, NULL, i);
SDL_BlitSurface(Phrase,NULL,double_buffer,NULL);
SDL_BlitSurface(double_buffer,NULL,screen,NULL);
gtk_sdl_display_update (GTK_SDL(pSdl));
}
SDL_FreeSurface(double_buffer);
SDL_FreeSurface(Phrase);
}
void initSDL(void)
{
if(TTF_Init()== -1 )
{
fprintf(stderr, "Impossible d'initialiser SDL_ttf : %s", TTF_GetError());
exit(EXIT_FAILURE);
}
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Erreur à l'initialisation de la SDL : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
} |