LightingWindow.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2010 James Legg.
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 */
00011 
00012 #include "LightingWindow.h"
00013 #include <Debug.h>
00014 
00015 LightSettingWidget::LightSettingWidget()
00016     :   Gtk::HBox(false, 6)
00017     ,   m_x_label("x")
00018     ,   m_x_adjustment(0.5, -128, 128, 0.05, 0.2)
00019     ,   m_x_spin(m_x_adjustment, 0, 3)
00020     ,   m_y_label("y")
00021     ,   m_y_adjustment(0.5, -128, 128, 0.05, 0.2)
00022     ,   m_y_spin(m_y_adjustment, 0, 3)
00023     ,   m_z_label("z")
00024     ,   m_z_adjustment(0.5, -128, 128, 0.05, 0.2)
00025     ,   m_z_spin(m_z_adjustment, 0, 3)
00026     ,   m_w_label("w")
00027     ,   m_w_adjustment(0.5, -128, 128, 0.05, 0.2)
00028     ,   m_w_spin(m_w_adjustment, 0, 3)
00029     ,   m_colour_label("colour")
00030 {
00031     pack_start(m_x_label);
00032     pack_start(m_x_spin);
00033     m_x_spin.signal_value_changed().connect(
00034             sigc::mem_fun(*this, &LightSettingWidget::on_x_change));
00035     pack_start(m_y_label);
00036     pack_start(m_y_spin);
00037     m_y_spin.signal_value_changed().connect(
00038             sigc::mem_fun(*this, &LightSettingWidget::on_y_change));
00039     pack_start(m_z_label);
00040     pack_start(m_z_spin);
00041     m_z_spin.signal_value_changed().connect(
00042             sigc::mem_fun(*this, &LightSettingWidget::on_z_change));
00043     pack_start(m_w_label);
00044     pack_start(m_w_spin);
00045     m_w_spin.signal_value_changed().connect(
00046             sigc::mem_fun(*this, &LightSettingWidget::on_w_change));
00047     pack_start(m_colour_label);
00048     pack_start(m_colour_button);
00049     m_colour_button.signal_color_set().connect(
00050             sigc::mem_fun(*this, &LightSettingWidget::on_colour_change));
00051 }
00052 
00053 Track::LightSettings LightSettingWidget::get_light_settings() const
00054 {
00055     return m_light_settings;
00056 }
00057 
00058 void LightSettingWidget::set_light_settings(Track::LightSettings settings)
00059 {
00060     m_light_settings = settings;
00061     m_x_spin.set_value(m_light_settings.position[0]);
00062     m_y_spin.set_value(m_light_settings.position[1]);
00063     m_z_spin.set_value(m_light_settings.position[2]);
00064     m_w_spin.set_value(m_light_settings.position[3]);
00065     Gdk::Color colour;
00066     colour.set_rgb(m_light_settings.colour[0]*65535,
00067                    m_light_settings.colour[1]*65535,
00068                    m_light_settings.colour[2]*65535);
00069     m_colour_button.set_color(colour);
00070     m_colour_button.set_alpha(m_light_settings.colour[3]*65535);
00071 }
00072 
00073 sigc::signal<void> LightSettingWidget::signal_changed()
00074 {
00075     return m_signal_changed;
00076 }
00077 
00078 void LightSettingWidget::on_x_change()
00079 {
00080     m_x_spin.update();
00081     m_light_settings.position[0] = m_x_spin.get_value();
00082     m_signal_changed.emit();
00083 }
00084 
00085 void LightSettingWidget::on_y_change()
00086 {
00087     m_y_spin.update();
00088     m_light_settings.position[1] = m_y_spin.get_value();
00089     m_signal_changed.emit();
00090 }
00091 
00092 void LightSettingWidget::on_z_change()
00093 {
00094     m_z_spin.update();
00095     m_light_settings.position[2] = m_z_spin.get_value();
00096     m_signal_changed.emit();
00097 }
00098 
00099 void LightSettingWidget::on_w_change()
00100 {
00101     m_w_spin.update();
00102     m_light_settings.position[3] = m_w_spin.get_value();
00103     m_signal_changed.emit();
00104 }
00105 
00106 void LightSettingWidget::on_colour_change()
00107 {
00108     Gdk::Color c = m_colour_button.get_color();
00109     m_light_settings.colour[0] = float(c.get_red()) / 65535.0;
00110     m_light_settings.colour[1] = float(c.get_green()) / 65535.0;
00111     m_light_settings.colour[2] = float(c.get_blue()) / 65535.0;
00112     m_light_settings.colour[3] = float(m_colour_button.get_alpha()) / 65535.0;
00113     m_signal_changed.emit();
00114 }
00115 
00116 LightingWindow::LightingWindow()
00117     :   m_box(false, 12)
00118     ,   m_fog_frame()
00119     ,   m_fog_frame_label("<b>Fog</b>")
00120     ,   m_fog_table(3, 2)
00121     ,   m_fog_enabled_button("Enable fog")
00122     ,   m_fog_colour_label("Fog colour")
00123     ,   m_fog_density_label("Fog density")
00124     ,   m_fog_density_adjustment(0.004, 0.00001, 1.0, 0.0005, 0.001)
00125     ,   m_fog_density_spin(m_fog_density_adjustment, 0.0, 5)
00126     ,   m_light_frame()
00127     ,   m_light_frame_label("<b>Lights</b>")
00128     ,   m_light_table(2, 2)
00129     ,   m_ambient_light_label("ambient light colour")
00130     ,   m_num_lights_label("number of lights")
00131     ,   m_num_lights_adjustment(2, 0, 8, 1, 2)
00132     ,   m_num_lights_spin(m_num_lights_adjustment)
00133 {
00134     set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG); 
00135     set_title("Lighting");
00136     
00137     m_fog_table.attach(m_fog_enabled_button, 0, 2, 0, 1);
00138     m_fog_table.attach(m_fog_colour_label, 0, 1, 1, 2);
00139     m_fog_table.attach(m_fog_colour_button, 1, 2, 1, 2);
00140     m_fog_table.attach(m_fog_density_label, 0, 1, 2, 3);
00141     m_fog_table.attach(m_fog_density_spin, 1, 2, 2, 3);
00142     m_fog_table.set_spacings(6);
00143     m_fog_table.set_border_width(4);
00144     m_fog_frame.add(m_fog_table);
00145     m_fog_frame.set_label_widget(m_fog_frame_label);
00146     m_fog_frame_label.set_use_markup();
00147     m_fog_frame.set_shadow_type(Gtk::SHADOW_NONE);
00148     
00149     m_light_table.attach(m_ambient_light_label, 0, 1, 0, 1);
00150     m_light_table.attach(m_ambient_light_button, 1, 2, 0, 1);
00151     m_light_table.attach(m_num_lights_label, 0, 1, 1, 2);
00152     m_light_table.attach(m_num_lights_spin, 1, 2, 1, 2);
00153     m_light_table.set_spacings(6);
00154     m_light_table.set_border_width(4);
00155     m_light_frame.add(m_light_table);
00156     m_light_frame.set_label_widget(m_light_frame_label);
00157     m_light_frame_label.set_use_markup();
00158     m_light_frame.set_shadow_type(Gtk::SHADOW_NONE);
00159     
00160     m_box.pack_start(m_fog_frame);
00161     m_box.pack_start(m_light_frame);
00162     add(m_box);
00163     m_box.show_all();
00164     
00165     m_fog_enabled_button.signal_clicked().connect(
00166             sigc::mem_fun(*this, &LightingWindow::on_fog_enabled_change));
00167     m_fog_colour_button.signal_color_set().connect(
00168             sigc::mem_fun(*this, &LightingWindow::on_fog_colour_change));
00169     m_fog_density_spin.signal_value_changed().connect(
00170             sigc::mem_fun(*this, &LightingWindow::on_fog_density_change));
00171     m_ambient_light_button.signal_color_set().connect(
00172             sigc::mem_fun(*this, &LightingWindow::on_ambient_light_change));
00173     m_num_lights_spin.signal_value_changed().connect(
00174             sigc::mem_fun(*this, &LightingWindow::on_num_lights_change));
00175 }
00176 
00177 const Track::Lighting & LightingWindow::get_lighting() const
00178 {
00179     return m_lighting;
00180 }
00181 
00182 void LightingWindow::set_lighting(const Track::Lighting & settings)
00183 {
00184     m_lighting = settings;
00186     m_fog_density_adjustment.set_value(m_lighting.get_fog().density);
00187     m_fog_enabled_button.set_active(m_lighting.get_fog().enabled);
00188     Gdk::Color c;
00189     c.set_rgb(m_lighting.get_ambient_light()[0] * 65535, 
00190               m_lighting.get_ambient_light()[1] * 65535,
00191               m_lighting.get_ambient_light()[2] * 65535);
00192     m_ambient_light_button.set_color(c);
00193     m_ambient_light_button.set_alpha(m_lighting.get_ambient_light()[3]);
00194     c.set_rgb(m_lighting.get_fog().colour[0] * 65535, 
00195               m_lighting.get_fog().colour[1] * 65535,
00196               m_lighting.get_fog().colour[2] * 65535);
00197     m_fog_colour_button.set_color(c);
00198     m_fog_colour_button.set_alpha(m_lighting.get_fog().colour[3]);
00199     m_num_lights_spin.set_value(m_lighting.get_lights().size());
00200     update_light_widgets();
00201 }
00202 
00203 sigc::signal<void> LightingWindow::signal_changed()
00204 {
00205     return m_signal_changed;
00206 }
00207 
00208 void LightingWindow::on_fog_colour_change()
00209 {
00210     Track::FogSettings fog = m_lighting.get_fog();
00211     Gdk::Color c = m_fog_colour_button.get_color();
00212     fog.colour[0] = float(c.get_red())/ 65535.0;
00213     fog.colour[1] = float(c.get_green())/ 65535.0;
00214     fog.colour[2] = float(c.get_blue())/ 65535.0;
00215     fog.colour[3] = float(m_ambient_light_button.get_alpha()) / 65535.0;
00216     m_lighting.set_fog(fog);
00217     m_signal_changed.emit();
00218 }
00219 
00220 void LightingWindow::on_fog_density_change()
00221 {
00222     Track::FogSettings fog = m_lighting.get_fog();
00223     m_fog_density_spin.update();
00224     fog.density = m_fog_density_spin.get_value();
00225     m_lighting.set_fog(fog);
00226     m_signal_changed.emit();
00227 }
00228 
00229 void LightingWindow::on_fog_enabled_change()
00230 {
00231     Track::FogSettings fog = m_lighting.get_fog();
00232     fog.enabled = m_fog_enabled_button.get_active();
00233     m_fog_density_spin.set_sensitive(fog.enabled);
00234     m_fog_colour_button.set_sensitive(fog.enabled);
00235     m_lighting.set_fog(fog);
00236     m_signal_changed.emit();
00237 }
00238 
00239 void LightingWindow::on_ambient_light_change()
00240 {
00241     float a[4];
00242     Gdk::Color c(m_ambient_light_button.get_color());
00243     a[0] = float (c.get_red()) / 65535.0;
00244     a[1] = float (c.get_green()) / 65535.0;
00245     a[2] = float (c.get_blue()) / 65535.0;
00246     a[3] = float (m_ambient_light_button.get_alpha()) / 65535.0;
00247     m_lighting.set_ambient(a);
00248     m_signal_changed.emit();
00249 }
00250 
00251 void LightingWindow::on_num_lights_change()
00252 {
00253     int num_lights = m_num_lights_spin.get_value_as_int();
00254     std::vector<Track::LightSettings> lights = m_lighting.get_lights();
00255     lights.resize(num_lights);
00256     m_lighting.set_lights(lights);
00257     update_light_widgets();
00258     m_signal_changed.emit();
00259 }
00260 
00261 void LightingWindow::on_light_setting_changed(int index)
00262 {
00263     std::vector<Track::LightSettings> settings = m_lighting.get_lights();
00264     settings[index] = m_light_setting_widgets[index]->get_light_settings();
00265     m_lighting.set_lights(settings);
00266     m_signal_changed.emit();
00267 }
00268 
00269 void LightingWindow::update_light_widgets()
00270 {
00271     int num_lights = m_lighting.get_lights().size();
00272     m_light_setting_widgets.resize(num_lights);
00273     m_light_table.resize(num_lights+2, 2);
00274     for (int i = 0; i < num_lights; i++)
00275     {
00276         m_light_setting_widgets[i] = boost::shared_ptr<LightSettingWidget>(new LightSettingWidget);
00277         m_light_setting_widgets[i]->set_light_settings(m_lighting.get_lights()[i]);
00278         m_light_setting_widgets[i]->show_all();
00279         m_light_setting_widgets[i]->signal_changed().connect(
00280             sigc::bind(sigc::mem_fun(*this,
00281                                      &LightingWindow::on_light_setting_changed),
00282                        i));
00283         m_light_table.attach(*m_light_setting_widgets[i], 0, 2, i+2, i+3);
00284     }
00285 }

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:13 2010 by Doxygen version 1.4.7 for Racer version svn335.