1 // -*- C++ -*-
2
3 /*
4 * Gnome Crystal library
5 * view-settings.cc
6 *
7 * Copyright (C) 2001-2011 Jean Bréfort <jean.brefort@normalesup.org>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 * USA
23 */
24
25 #include "config.h"
26 #include "view-settings.h"
27 #include "document.h"
28 #include "application.h"
29 #include "view.h"
30
31 namespace gcr {
32
33 class ViewSettingsDlgPrivate
34 {
35 public:
36 static void OnFoVChanged (ViewSettingsDlg *dlg);
37 static bool OnPsiChanged (ViewSettingsDlg *dlg);
38 static bool OnThetaChanged (ViewSettingsDlg *dlg);
39 static bool OnPhiChanged (ViewSettingsDlg *dlg);
40 static void OnBackgroundChanged (ViewSettingsDlg *dlg);
41 };
42
OnFoVChanged(ViewSettingsDlg * dlg)43 void ViewSettingsDlgPrivate::OnFoVChanged (ViewSettingsDlg *dlg)
44 {
45 dlg->m_pView->GetFoV () = gtk_spin_button_get_value_as_int (dlg->FoV);
46 dlg->m_pView->Update ();
47 dynamic_cast < Document * > (dlg->m_pView->GetDoc ())->SetDirty (true);
48 }
49
OnPsiChanged(ViewSettingsDlg * dlg)50 bool ViewSettingsDlgPrivate::OnPsiChanged (ViewSettingsDlg *dlg)
51 {
52 g_signal_handler_block (dlg->Psi, dlg->PsiSignal);
53 double value;
54 if (dlg->GetNumber (dlg->Psi, &value, gcugtk::MinEqMax, -180, 180)) {
55 dlg->m_pView->SetRotation (value, dlg->m_pView->GetTheta (), dlg->m_pView->GetPhi ());
56 dlg->m_pView->Update ();
57 dynamic_cast < Document * > (dlg->m_pView->GetDoc ())->SetDirty (true);
58 }
59 g_signal_handler_unblock (dlg->Psi, dlg->PsiSignal);
60 return false;
61 }
62
OnThetaChanged(ViewSettingsDlg * dlg)63 bool ViewSettingsDlgPrivate::OnThetaChanged (ViewSettingsDlg *dlg)
64 {
65 g_signal_handler_block (dlg->Theta, dlg->ThetaSignal);
66 double value;
67 if (dlg->GetNumber (dlg->Theta, &value, gcugtk::MinEqMaxEq, 0, 180)) {
68 dlg->m_pView->SetRotation (dlg->m_pView->GetPsi (), value, dlg->m_pView->GetPhi ());
69 dlg->m_pView->Update ();
70 dynamic_cast < Document * > (dlg->m_pView->GetDoc ())->SetDirty (true);
71 }
72 g_signal_handler_unblock (dlg->Theta, dlg->ThetaSignal);
73 return false;
74 }
75
OnPhiChanged(ViewSettingsDlg * dlg)76 bool ViewSettingsDlgPrivate::OnPhiChanged (ViewSettingsDlg *dlg)
77 {
78 g_signal_handler_block (dlg->Phi, dlg->PhiSignal);
79 double value;
80 if (dlg->GetNumber (dlg->Phi, &value, gcugtk::MinEqMax, -180, 180)) {
81 dlg->m_pView->SetRotation (dlg->m_pView->GetPsi (), dlg->m_pView->GetTheta (), value);
82 dlg->m_pView->Update ();
83 dynamic_cast < Document * > (dlg->m_pView->GetDoc ())->SetDirty (true);
84 }
85 g_signal_handler_unblock (dlg->Phi, dlg->PhiSignal);
86 return false;
87 }
88
OnBackgroundChanged(ViewSettingsDlg * dlg)89 void ViewSettingsDlgPrivate::OnBackgroundChanged (ViewSettingsDlg *dlg)
90 {
91 GdkRGBA rgba;
92 gtk_color_button_get_rgba (dlg->Background, &rgba);
93 dlg->m_pView->SetRed (rgba.red);
94 dlg->m_pView->SetGreen (rgba.green);
95 dlg->m_pView->SetBlue (rgba.blue);
96 dlg->m_pView->SetAlpha (rgba.alpha);
97 dlg->m_pView->Update ();
98 dynamic_cast < Document * > (dlg->m_pView->GetDoc ())->SetDirty (true);
99 }
100
ViewSettingsDlg(View * pView)101 ViewSettingsDlg::ViewSettingsDlg (View* pView): gcugtk::Dialog (static_cast < gcugtk::Application * > (pView->GetDoc ()->GetApp ()), UIDIR"/view-settings.ui", "view-settings", GETTEXT_PACKAGE, pView)
102 {
103 m_pView = pView;
104 FoV = GTK_SPIN_BUTTON (GetWidget ("fov"));
105 Psi = GTK_ENTRY (GetWidget ("psi"));
106 Theta = GTK_ENTRY (GetWidget ("theta"));
107 Phi = GTK_ENTRY (GetWidget ("phi"));
108 Background = GTK_COLOR_BUTTON (GetWidget ("color"));
109 GdkRGBA rgba;
110 m_pView->GetBackgroundColor (&rgba.red, &rgba.green, &rgba.blue, &rgba.alpha);
111 gtk_color_button_set_rgba (Background, &rgba);
112 g_signal_connect_swapped (Background, "color-set", G_CALLBACK (ViewSettingsDlgPrivate::OnBackgroundChanged), this);
113 double x0, x1, x2;
114 m_pView->GetRotation (&x0, &x1, &x2);
115 char m_buf[32];
116 snprintf (m_buf, sizeof (m_buf) - 1, "%g", x0);
117 gtk_entry_set_text (Psi, m_buf);
118 snprintf (m_buf, sizeof (m_buf) - 1, "%g", x1);
119 gtk_entry_set_text (Theta, m_buf);
120 snprintf (m_buf, sizeof (m_buf) - 1, "%g", x2);
121 gtk_entry_set_text (Phi, m_buf);
122 gtk_spin_button_set_value (FoV, (int) (m_pView->GetFoV ()));
123 g_signal_connect_swapped (G_OBJECT (Psi), "activate", G_CALLBACK (ViewSettingsDlgPrivate::OnPsiChanged), this);
124 PsiSignal = g_signal_connect_swapped (G_OBJECT (Psi), "focus-out-event", G_CALLBACK (ViewSettingsDlgPrivate::OnPsiChanged), this);
125 g_signal_connect_swapped (G_OBJECT (Theta), "activate", G_CALLBACK (ViewSettingsDlgPrivate::OnThetaChanged), this);
126 ThetaSignal = g_signal_connect_swapped (G_OBJECT (Theta), "focus-out-event", G_CALLBACK (ViewSettingsDlgPrivate::OnThetaChanged), this);
127 g_signal_connect_swapped (G_OBJECT (Phi), "activate", G_CALLBACK (ViewSettingsDlgPrivate::OnPhiChanged), this);
128 PhiSignal = g_signal_connect_swapped (G_OBJECT (Phi), "focus-out-event", G_CALLBACK (ViewSettingsDlgPrivate::OnPhiChanged), this);
129 g_signal_connect_swapped (FoV, "value-changed", G_CALLBACK (ViewSettingsDlgPrivate::OnFoVChanged), this);
130
131 gtk_widget_show_all (GTK_WIDGET (dialog));
132 }
133
~ViewSettingsDlg()134 ViewSettingsDlg::~ViewSettingsDlg ()
135 {
136 }
137
138 } // namespace gcr