2011-12-17 10:55:37 +00:00
|
|
|
/* Terrain tab */
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "../shared/functions.h"
|
|
|
|
#include "../shared/constants.h"
|
|
|
|
#include "../sky.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
static SmallPreview* _preview_horizon;
|
|
|
|
static SkyDefinition _definition;
|
|
|
|
|
|
|
|
static Color _cbPreviewHorizon(SmallPreview* preview, double x, double y, double xoffset, double yoffset, double scaling)
|
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
Vector3 eye = {0.0, 0.0, 0.0};
|
|
|
|
Vector3 look;
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-18 21:59:33 +00:00
|
|
|
look.x = cos(M_PI * (x / 1.28 + 0.5)) * cos(M_PI * (y / 2.56));
|
|
|
|
look.y = -sin(M_PI * (y / 2.56));
|
|
|
|
look.z = sin(M_PI * (x / 1.28 + 0.5)) * cos(M_PI * (y / 2.56));
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
return skyGetColorCustom(eye, look, &_definition, NULL, NULL);
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
static inline void _updatePreview()
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
skyValidateDefinition(&_definition);
|
|
|
|
guiPreviewRedraw(_preview_horizon);
|
|
|
|
}
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
static void _redrawColorGradation(GtkImage* image, ColorGradation* gradation)
|
|
|
|
{
|
2011-12-17 15:54:10 +00:00
|
|
|
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 1, 8, 200, 30);
|
2011-12-17 14:46:09 +00:00
|
|
|
void* pixels = gdk_pixbuf_get_pixels(pixbuf);
|
|
|
|
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
int x, y;
|
|
|
|
guint32* pixel;
|
|
|
|
Color col;
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 15:54:10 +00:00
|
|
|
for (x = 0; x < 200; x++)
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 15:54:10 +00:00
|
|
|
for (y = 0; y < 30; y++)
|
2011-12-17 14:46:09 +00:00
|
|
|
{
|
|
|
|
pixel = (guint32*)(pixels + y * rowstride + x * 4);
|
2011-12-17 15:54:10 +00:00
|
|
|
col = colorGradationGet(gradation, (double)x / 200.0);
|
2011-12-17 14:46:09 +00:00
|
|
|
*pixel = (guint32)colorTo32BitRGBA(&col);
|
|
|
|
}
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
gtk_image_set_from_pixbuf(image, pixbuf);
|
|
|
|
gdk_pixbuf_unref(pixbuf);
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
static void _cbDaytimeChanged(GtkRange* range, gpointer data)
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
_definition.daytime = gtk_range_get_value(range);
|
|
|
|
_updatePreview();
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
static void _cbSunSizeChanged(GtkRange* range, gpointer data)
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
_definition.sun_radius = gtk_range_get_value(range);
|
|
|
|
_updatePreview();
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
static void _cbHazeHeightChanged(GtkRange* range, gpointer data)
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
_definition.haze_height = gtk_range_get_value(range);
|
|
|
|
_updatePreview();
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
static void _cbHazeSmoothingChanged(GtkRange* range, gpointer data)
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
_definition.haze_smoothing = gtk_range_get_value(range);
|
|
|
|
_updatePreview();
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _cbRevertConfig(GtkWidget* widget, gpointer data)
|
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
skyCopyDefinition(skyGetDefinition(), &_definition);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_daytime")), _definition.daytime);
|
|
|
|
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_sun_size")), _definition.sun_radius);
|
|
|
|
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_haze_height")), _definition.haze_height);
|
|
|
|
gtk_range_set_value(GTK_RANGE(GET_WIDGET("sky_haze_smoothing")), _definition.haze_smoothing);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
_redrawColorGradation(GTK_IMAGE(GET_WIDGET("sky_colorgradient_sun")), &_definition.sun_color);
|
|
|
|
_redrawColorGradation(GTK_IMAGE(GET_WIDGET("sky_colorgradient_zenith")),& _definition.zenith_color);
|
|
|
|
_redrawColorGradation(GTK_IMAGE(GET_WIDGET("sky_colorgradient_haze")), &_definition.haze_color);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
_updatePreview();
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _cbApplyConfig(GtkWidget* widget, gpointer data)
|
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
skySetDefinition(_definition);
|
2011-12-17 10:55:37 +00:00
|
|
|
guiUpdate();
|
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
void guiSkyInit()
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
2011-12-17 14:46:09 +00:00
|
|
|
_definition = skyCreateDefinition();
|
2011-12-17 10:55:37 +00:00
|
|
|
|
|
|
|
/* Buttons */
|
2011-12-17 14:46:09 +00:00
|
|
|
g_signal_connect(GET_WIDGET("sky_apply"), "clicked", G_CALLBACK(_cbApplyConfig), NULL);
|
|
|
|
g_signal_connect(GET_WIDGET("sky_revert"), "clicked", G_CALLBACK(_cbRevertConfig), NULL);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
|
|
|
/* Configs */
|
2011-12-17 14:46:09 +00:00
|
|
|
gtk_range_set_range(GTK_RANGE(GET_WIDGET("sky_daytime")), 0.0, 1.0);
|
2011-12-18 21:59:33 +00:00
|
|
|
gtk_range_set_range(GTK_RANGE(GET_WIDGET("sky_sun_size")), 0.0, 0.3);
|
2011-12-17 14:46:09 +00:00
|
|
|
gtk_range_set_range(GTK_RANGE(GET_WIDGET("sky_haze_height")), 0.0, 1.0);
|
|
|
|
gtk_range_set_range(GTK_RANGE(GET_WIDGET("sky_haze_smoothing")), 0.0, 1.0);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
|
|
|
/* Config signals */
|
2011-12-17 14:46:09 +00:00
|
|
|
g_signal_connect(GET_WIDGET("sky_daytime"), "value-changed", G_CALLBACK(_cbDaytimeChanged), NULL);
|
|
|
|
g_signal_connect(GET_WIDGET("sky_sun_size"), "value-changed", G_CALLBACK(_cbSunSizeChanged), NULL);
|
|
|
|
g_signal_connect(GET_WIDGET("sky_haze_height"), "value-changed", G_CALLBACK(_cbHazeHeightChanged), NULL);
|
|
|
|
g_signal_connect(GET_WIDGET("sky_haze_smoothing"), "value-changed", G_CALLBACK(_cbHazeSmoothingChanged), NULL);
|
2011-12-17 10:55:37 +00:00
|
|
|
|
|
|
|
/* Previews */
|
2011-12-17 14:46:09 +00:00
|
|
|
_preview_horizon = guiPreviewNew(GTK_IMAGE(GET_WIDGET("sky_preview_horizon")));
|
|
|
|
guiPreviewConfigScaling(_preview_horizon, 0.01, 0.01, 0.0);
|
|
|
|
guiPreviewConfigScrolling(_preview_horizon, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
guiPreviewSetViewport(_preview_horizon, 0.0, 0.0, 0.01);
|
|
|
|
guiPreviewSetRenderer(_preview_horizon, _cbPreviewHorizon);
|
|
|
|
|
|
|
|
guiSkyUpdate();
|
2011-12-17 10:55:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:46:09 +00:00
|
|
|
void guiSkyUpdate()
|
2011-12-17 10:55:37 +00:00
|
|
|
{
|
|
|
|
_cbRevertConfig(NULL, NULL);
|
|
|
|
}
|