-
Notifications
You must be signed in to change notification settings - Fork 11
/
logo_gui.cpp
executable file
·146 lines (102 loc) · 3.44 KB
/
logo_gui.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "logo_gui.h"
#include <fstream>
//-------------------------------------------------------------------
logo_gui::logo_gui()
{
pos_mode = 0;
top_colour.set( "#550000");
bottom_colour.set( "#220000");
}
//-------------------------------------------------------------------
logo_gui::~logo_gui()
{
}
//-------------------------------------------------------------------
void logo_gui::load_logo(string bundle_path)
{
stringstream file_name;
logo_loaded = false;
if (!logo_loaded)
{
file_name.str("");
file_name << bundle_path << "logo.png";
ifstream check_file(file_name.str() );
if (check_file)
{
// Load pixbuf
image_ptr_ = Gdk::Pixbuf::create_from_file (file_name.str().c_str());
logo_loaded = true;
}
check_file.close();
}
if (logo_loaded)
{
// Detect transparent colors for loaded image
format = Cairo::FORMAT_RGB24;
if (image_ptr_->get_has_alpha())
{
format = Cairo::FORMAT_ARGB32;
}
}
set_size_request(100,140);
}
//-------------------------------------------------------------------
bool logo_gui::on_expose_event(GdkEventExpose* event)
{
// This is where we draw on the window
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
Cairo::RefPtr<Cairo::LinearGradient> back_grad =
Cairo::LinearGradient::create( 0,0,0,allocation.get_height() );
switch (pos_mode)
{
case 0:
back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
break;
case 1:
back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
back_grad->add_color_stop_rgba(1,
(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
1);
break;
case 2:
back_grad->add_color_stop_rgba(0,
(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
1);
back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
break;
}
// fill background
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->set_source(back_grad);
cr->fill();
if (logo_loaded)
{
// Create a new ImageSurface
image_surface_ptr_ = Cairo::ImageSurface::create (format, image_ptr_->get_width(), image_ptr_->get_height());
float image_width = image_ptr_->get_width();
float image_height = image_ptr_->get_height();
// Create the new Context for the ImageSurface
image_context_ptr_ = Cairo::Context::create (image_surface_ptr_);
// Draw the image on the new Context
Gdk::Cairo::set_source_pixbuf (image_context_ptr_, image_ptr_, 0.0, 0.0);
image_context_ptr_->paint();
// Draw the source image on the widget context
cr->scale( width / image_width, height / image_height );
cr->set_source (image_surface_ptr_, 6.0, 0.0);
cr->paint();
}
}
return true;
}