Changeset 109


Ignore:
Timestamp:
Aug 14, 2010, 11:15:41 PM (10 years ago)
Author:
sam
Message:

Get rid of GtkVideo, it was pretty useless in the current shape.

Location:
trunk/src
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r108 r109  
    1616test_map_LDFLAGS = `pkg-config --libs sdl gl SDL_image`
    1717
    18 editor_SOURCES = gtk/editor.cpp gtk/gtkvideo.cpp gtk/gtkvideo.h
     18editor_SOURCES = gtk/editor.cpp
    1919editor_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image gtk+-2.0 gtkgl-2.0`
    2020editor_LDADD = libcommon.a
  • trunk/src/gtk/editor.cpp

    r106 r109  
    99
    1010#include <cstdio>
     11#include <cstdlib>
    1112#include <cmath>
    1213
     
    1415#include <gtkgl/gtkglarea.h>
    1516
    16 #include "gtkvideo.h"
    1717#include "ticker.h"
     18#include "video.h"
    1819#include "game.h"
    1920
     
    2223static gint main_quit(GtkWidget *widget, GdkEventExpose *event)
    2324{
     25    (void)widget;
     26    (void)event;
     27
    2428    quit = 1;
     29    gtk_main_quit();
    2530    return FALSE;
     31}
     32
     33static gboolean tick(void *widget)
     34{
     35    float const delta_time = 33.33333f;
     36
     37    // FIXME: do not do anything if the previous tick was too recent?
     38
     39    // FIXME: only quit if all assets have been cleaned
     40    if (quit)
     41        return FALSE;
     42
     43    /* Tick the game */
     44    Ticker::TickGame(delta_time);
     45
     46    gtk_widget_draw(GTK_WIDGET(widget), NULL);
     47
     48    return TRUE;
     49}
     50
     51static gint init(GtkWidget *widget)
     52{
     53    /* OpenGL functions can be called only if make_current returns true */
     54    if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     55    {
     56        Video::Setup(widget->allocation.width,
     57                     widget->allocation.height);
     58    }
     59    return TRUE;
     60}
     61
     62static gint draw(GtkWidget *widget, GdkEventExpose *event)
     63{
     64    if (event->count == 0 && gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     65    {
     66        // FIXME: do not do anything if the game tick wasn't called?
     67        float const delta_time = 33.33333f;
     68
     69        /* Clear the screen, tick the renderer, and show the frame */
     70        Video::Clear();
     71        Ticker::TickRender(delta_time);
     72        gtk_gl_area_swapbuffers(GTK_GL_AREA(widget));
     73    }
     74
     75    return TRUE;
     76}
     77
     78static gint reshape(GtkWidget *widget, GdkEventConfigure *event)
     79{
     80    (void)event;
     81
     82    if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     83    {
     84        Video::Setup(widget->allocation.width,
     85                     widget->allocation.height);
     86    }
     87    return TRUE;
    2688}
    2789
    2890int main(int argc, char **argv)
    2991{
    30     GtkWidget *window, *glarea;
    31 
    32     /* initialize gtk */
     92    /* Initialize GTK */
    3393    gtk_init(&argc, &argv);
    3494
     95    if (gdk_gl_query() == FALSE)
     96    {
     97        g_print("OpenGL not supported\n");
     98        return EXIT_FAILURE;
     99    }
     100
    35101    /* Create new top level window. */
    36     window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
     102    GtkWidget *window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
    37103    gtk_window_set_title(GTK_WINDOW(window), "Simple");
    38104    gtk_container_set_border_width(GTK_CONTAINER(window), 5);
     
    41107    gtk_signal_connect(GTK_OBJECT(window), "delete_event",
    42108                       GTK_SIGNAL_FUNC(main_quit), NULL);
    43 
    44109
    45110    /* You should always delete gtk_gl_area widgets before exit or else
     
    53118    gtk_quit_add_destroy(1, GTK_OBJECT(window));
    54119
     120    /* Create new OpenGL widget. */
     121    int attrlist[] =
     122    {
     123        GDK_GL_RGBA,
     124        GDK_GL_RED_SIZE, 1,
     125        GDK_GL_GREEN_SIZE, 1,
     126        GDK_GL_BLUE_SIZE, 1,
     127        GDK_GL_DOUBLEBUFFER,
     128        GDK_GL_NONE
     129    };
    55130
    56     /* Create new OpenGL widget. */
    57     GtkVideo *video = new GtkVideo("LOL", 640, 480);
    58     glarea = GTK_WIDGET(video->GetWidget());
     131    GtkWidget *glarea = gtk_gl_area_new(attrlist);
    59132
    60     /* put glarea into window and show it all */
     133    gtk_widget_set_events(GTK_WIDGET(glarea),
     134                          GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
     135
     136    gtk_signal_connect(GTK_OBJECT(glarea), "expose_event",
     137                       GTK_SIGNAL_FUNC(draw), NULL);
     138    gtk_signal_connect(GTK_OBJECT(glarea), "configure_event",
     139                       GTK_SIGNAL_FUNC(reshape), NULL);
     140    gtk_signal_connect(GTK_OBJECT(glarea), "realize",
     141                       GTK_SIGNAL_FUNC(init), NULL);
     142
     143    // FIXME: is this needed?
     144    gtk_widget_set_usize(GTK_WIDGET(glarea), 400, 300);
     145
     146    /* Put glarea into window and show it all */
    61147    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(glarea));
    62148    gtk_widget_show(GTK_WIDGET(glarea));
    63149    gtk_widget_show(GTK_WIDGET(window));
    64150
    65     Game *game = new Game("maps/testmap.tmx");
     151    // FIXME: detect when the game is killed
     152    new Game("maps/testmap.tmx");
    66153
    67     for (;;)
    68     {
    69         // Do GTK stuff until the user wants to quit
    70         while (g_main_context_iteration(NULL, FALSE));
     154    //gtk_idle_add(tick, glarea);
     155    gtk_timeout_add(33, tick, glarea);
     156    gtk_main();
    71157
    72         if (quit)
    73             break;
    74 
    75         game->SetMouse(0, 0);
    76         Ticker::TickGame(33.33333f);
    77 
    78         video->PreRender();
    79         Ticker::TickRender(33.33333f);
    80         video->PostRender(33.33333f);
    81     }
    82 
    83     delete video;
    84 
    85     return 0;
     158    return EXIT_SUCCESS;
    86159}
Note: See TracChangeset for help on using the changeset viewer.