Use Gdk::RGBA (!25)

The Gdk::RGBA data type was introduced to replace Gdk::Color in
Gtkmm 3.0 [1], with Gdk::Color being deprecated in Gtkmm 3.10 [2].

With this commit we make the change to Gdk::RGBA data type which is the
modern replacement to Gdk::Color.  Gdk::RGBA can be used almost as a
drop in replacement because it keeps most of the Gdk::Color interface.

Also, this commit removes the C Gtk call introduced during the
port-to-gtk3 patchset by commit:
    5379352766
    repare-for-gtk3: Prepare for removal of Gtk::Widget::modify_fg() (#7)

[1] Gtkmm 3.0.1 NEWS file
    https://gitlab.gnome.org/GNOME/gtkmm/blob/3.0.1/NEWS#L48
        * RGBA replaces Color, though Color still exists because it is
          used by TextView.  We hope to deprecated Color completely in
          gtkmm 3.2.

[2] Gtkmm 3.10.0 NEWS file
    https://gitlab.gnome.org/GNOME/gtkmm/blob/3.10.0/NEWS#L127
        Gdk:
        * Deprecate Color.

Closes !25 - Modern Gtk3 - part 1
This commit is contained in:
Luca Bacci 2019-02-20 12:20:20 +01:00 committed by Mike Fleetwood
parent 2c19a620b1
commit 74bb981ed2
11 changed files with 52 additions and 41 deletions

View File

@ -58,7 +58,11 @@ private:
Glib::RefPtr<Pango::Layout> pango_layout;
Gdk::Color color_partition, color_used, color_unused, color_unallocated, color_text ;
Gdk::RGBA color_partition;
Gdk::RGBA color_used;
Gdk::RGBA color_unused;
Gdk::RGBA color_unallocated;
Gdk::RGBA color_text;
int used, unused, unallocated ;
};

View File

@ -81,7 +81,7 @@ private:
int y_usage_start, usage_height ;
int x_text, y_text ;
Gdk::Color color ;
Gdk::RGBA color;
Glib::RefPtr<Pango::Layout> pango_layout;
// Pointer to real partition. (Alias to element in Win_GParted::display_partitions[] vector).
@ -115,7 +115,10 @@ private:
const visual_partition * selected_vp ;
int TOT_SEP, MIN_SIZE ;
Gdk::Color color_used, color_unused, color_unallocated, color_text;
Gdk::RGBA color_used;
Gdk::RGBA color_unused;
Gdk::RGBA color_unallocated;
Gdk::RGBA color_text;
};
} //GParted

View File

@ -38,9 +38,9 @@ public:
Frame_Resizer_Base() ;
~Frame_Resizer_Base() ;
void set_rgb_partition_color( const Gdk::Color & color ) ;
void override_default_rgb_unused_color( const Gdk::Color & color ) ;
void set_rgb_partition_color(const Gdk::RGBA& color);
void override_default_rgb_unused_color(const Gdk::RGBA& color);
void set_x_min_space_before( int x_min_space_before ) ;
void set_x_start( int x_start ) ;
void set_x_end( int x_end ) ;
@ -78,7 +78,12 @@ protected:
Gtk::DrawingArea drawingarea ;
Gdk::Color color_used, color_unused, color_arrow, color_background, color_partition, color_arrow_rectangle;
Gdk::RGBA color_used;
Gdk::RGBA color_unused;
Gdk::RGBA color_arrow;
Gdk::RGBA color_background;
Gdk::RGBA color_partition;
Gdk::RGBA color_arrow_rectangle;
std::vector<Gdk::Point> arrow_points;

View File

@ -46,9 +46,9 @@ Dialog_Partition_Copy::~Dialog_Partition_Copy()
void Dialog_Partition_Copy::set_data( const Partition & selected_partition, const Partition & copied_partition )
{
this ->set_title( Glib::ustring::compose( _("Paste %1"), copied_partition .get_path() ) ) ;
//set partition color
Gdk::Color partition_color( Utils::get_color( copied_partition.filesystem ) );
// Set partition color
Gdk::RGBA partition_color(Utils::get_color(copied_partition.filesystem));
frame_resizer_base->set_rgb_partition_color( partition_color );
//set some widely used values...

View File

@ -120,14 +120,14 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : pa
bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Gdk::Cairo::set_source_color(cr, color_partition);
Gdk::Cairo::set_source_rgba(cr, color_partition);
cr->rectangle(0, 0, 400, 60);
cr->fill();
if ( partition.filesystem != FS_UNALLOCATED )
{
// Used
Gdk::Cairo::set_source_color(cr, color_used);
Gdk::Cairo::set_source_rgba(cr, color_used);
cr->rectangle(BORDER,
BORDER,
used,
@ -135,7 +135,7 @@ bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtr<Cairo::Conte
cr->fill();
// Unused
Gdk::Cairo::set_source_color(cr, color_unused);
Gdk::Cairo::set_source_rgba(cr, color_unused);
cr->rectangle(BORDER + used,
BORDER,
unused,
@ -143,7 +143,7 @@ bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtr<Cairo::Conte
cr->fill();
// Unallocated
Gdk::Cairo::set_source_color(cr, color_unallocated);
Gdk::Cairo::set_source_rgba(cr, color_unallocated);
cr->rectangle(BORDER + used + unused,
BORDER,
unallocated,
@ -152,7 +152,7 @@ bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtr<Cairo::Conte
}
// Text
Gdk::Cairo::set_source_color(cr, color_text);
Gdk::Cairo::set_source_rgba(cr, color_text);
cr->move_to(180, BORDER + 6);
pango_layout->show_in_cairo_context(cr);

View File

@ -373,7 +373,7 @@ void Dialog_Partition_New::combobox_changed(bool type)
//set fitting resizer colors
{
Gdk::Color color_temp;
Gdk::RGBA color_temp;
//Background color
color_temp.set((combo_type.get_active_row_number() == 2) ? "darkgrey" : "white");
frame_resizer_base->override_default_rgb_unused_color(color_temp);

View File

@ -57,9 +57,9 @@ void Dialog_Partition_Resize_Move::set_data( const Partition & selected_partitio
Set_Resizer( false ) ;
Resize_Move_Normal( partitions ) ;
}
//set partition color
Gdk::Color partition_color( Utils::get_color( selected_partition.filesystem ) );
// Set partition color
Gdk::RGBA partition_color(Utils::get_color(selected_partition.filesystem));
frame_resizer_base->set_rgb_partition_color( partition_color );
//store the original values

View File

@ -69,8 +69,7 @@ void Dialog_Rescue_Data::draw_dialog()
msg_label.append(_("You might encounter errors trying to view these file systems."));
Gtk::Label *inconsis_label=manage(Utils::mk_label(msg_label));
Gdk::Color c( "red" );
gtk_widget_modify_fg(GTK_WIDGET(inconsis_label->gobj()), GTK_STATE_NORMAL, c.gobj());
inconsis_label->override_color(Gdk::RGBA("red"), Gtk::STATE_FLAG_NORMAL);
this->get_vbox()->pack_end(*inconsis_label, Gtk::PACK_SHRINK, 5);
}
message->append("</b></big>");

View File

@ -220,7 +220,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr<Cairo::Context>&
const visual_partition& vp)
{
//partition...
Gdk::Cairo::set_source_color(cr, vp.color);
Gdk::Cairo::set_source_rgba(cr, vp.color);
cr->rectangle(vp.x_start,
vp.y_start,
vp.length,
@ -230,7 +230,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr<Cairo::Context>&
//used..
if ( vp .used_length > 0 )
{
Gdk::Cairo::set_source_color(cr, color_used);
Gdk::Cairo::set_source_rgba(cr, color_used);
cr->rectangle(vp.x_used_start,
vp.y_usage_start,
vp.used_length,
@ -241,7 +241,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr<Cairo::Context>&
//unused
if ( vp .unused_length > 0 )
{
Gdk::Cairo::set_source_color(cr, color_unused);
Gdk::Cairo::set_source_rgba(cr, color_unused);
cr->rectangle(vp.x_unused_start,
vp.y_usage_start,
vp.unused_length,
@ -252,7 +252,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr<Cairo::Context>&
//unallocated
if ( vp .unallocated_length > 0 )
{
Gdk::Cairo::set_source_color(cr, color_unallocated);
Gdk::Cairo::set_source_rgba(cr, color_unallocated);
cr->rectangle(vp.x_unallocated_start,
vp.y_usage_start,
vp.unallocated_length,
@ -263,7 +263,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr<Cairo::Context>&
//text
if ( vp .x_text > 0 )
{
Gdk::Cairo::set_source_color(cr, color_text);
Gdk::Cairo::set_source_rgba(cr, color_text);
cr->move_to(vp.x_text, vp.y_text);
vp.pango_layout->show_in_cairo_context(cr);
}
@ -328,7 +328,7 @@ bool DrawingAreaVisualDisk::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
//selection
if ( selected_vp )
{
Gdk::Cairo::set_source_color(cr, color_used);
Gdk::Cairo::set_source_rgba(cr, color_used);
cr->rectangle(selected_vp->x_start + BORDER/2,
selected_vp->y_start + BORDER/2,
selected_vp->length - BORDER,

View File

@ -74,12 +74,12 @@ void Frame_Resizer_Base::init()
this ->show_all_children();
}
void Frame_Resizer_Base::set_rgb_partition_color( const Gdk::Color & color )
void Frame_Resizer_Base::set_rgb_partition_color(const Gdk::RGBA& color)
{
this ->color_partition = color ;
}
void Frame_Resizer_Base::override_default_rgb_unused_color( const Gdk::Color & color )
void Frame_Resizer_Base::override_default_rgb_unused_color(const Gdk::RGBA& color)
{
this ->color_unused = color ;
}
@ -366,29 +366,29 @@ void Frame_Resizer_Base::draw_partition(const Cairo::RefPtr<Cairo::Context>& cr)
UNUSED = 0 ;
// Background color
Gdk::Cairo::set_source_color(cr, color_background);
Gdk::Cairo::set_source_rgba(cr, color_background);
cr->rectangle(0, 0, 536, 50);
cr->fill();
// The two rectangles on each side of the partition
Gdk::Cairo::set_source_color(cr, color_arrow_rectangle);
Gdk::Cairo::set_source_rgba(cr, color_arrow_rectangle);
cr->rectangle(0, 0, 10, 50);
cr->fill();
cr->rectangle(526, 0, 10, 50);
cr->fill();
// Partition
Gdk::Cairo::set_source_color(cr, color_partition);
Gdk::Cairo::set_source_rgba(cr, color_partition);
cr->rectangle(X_START, 0, X_END - X_START, 50);
cr->fill();
// Used
Gdk::Cairo::set_source_color(cr, color_used);
Gdk::Cairo::set_source_rgba(cr, color_used);
cr->rectangle(X_START + BORDER, BORDER, USED, 34);
cr->fill();
// Unused
Gdk::Cairo::set_source_color(cr, color_unused);
Gdk::Cairo::set_source_rgba(cr, color_unused);
cr->rectangle(X_START + BORDER + USED, BORDER, UNUSED, 34);
cr->fill();
@ -414,16 +414,16 @@ void Frame_Resizer_Base::draw_resize_grip(const Cairo::RefPtr<Cairo::Context>& c
arrow_points[ 1 ] .set_x( X_END + GRIPPER ) ;
arrow_points[ 2 ] .set_x( X_END ) ;
}
// Attach resize arrows to the partition
Gdk::Cairo::set_source_color(cr, color_arrow_rectangle);
Gdk::Cairo::set_source_rgba(cr, color_arrow_rectangle);
cr->rectangle((arrow_type == ARROW_LEFT ? X_START - GRIPPER : X_END + 1) + 0.5,
5 + 0.5,
9,
40);
cr->stroke();
Gdk::Cairo::set_source_color(cr, color_arrow);
Gdk::Cairo::set_source_rgba(cr, color_arrow);
cr->move_to(arrow_points[0].get_x(), arrow_points[0].get_y());
cr->line_to(arrow_points[1].get_x(), arrow_points[1].get_y());
cr->line_to(arrow_points[2].get_x(), arrow_points[2].get_y());

View File

@ -162,24 +162,24 @@ bool Frame_Resizer_Extended::drawingarea_on_mouse_motion( GdkEventMotion * ev )
void Frame_Resizer_Extended::draw_partition(const Cairo::RefPtr<Cairo::Context>& cr)
{
// Background color
Gdk::Cairo::set_source_color(cr, color_background);
Gdk::Cairo::set_source_rgba(cr, color_background);
cr->rectangle(0, 0, 536, 50);
cr->fill();
// The two rectangles on each side of the partition
Gdk::Cairo::set_source_color(cr, color_arrow_rectangle);
Gdk::Cairo::set_source_rgba(cr, color_arrow_rectangle);
cr->rectangle(0, 0, 10, 50);
cr->fill();
cr->rectangle(526, 0, 10, 50);
cr->fill();
// Used
Gdk::Cairo::set_source_color(cr, color_used);
Gdk::Cairo::set_source_rgba(cr, color_used);
cr->rectangle(USED_START + BORDER, BORDER, USED, 34);
cr->fill();
// Partition
Gdk::Cairo::set_source_color(cr, color_partition);
Gdk::Cairo::set_source_rgba(cr, color_partition);
for( short t = 0; t < 9 ; t++ )
{
cr->rectangle(X_START + t + 0.5, t + 0.5, X_END - X_START - t*2, 50 - t*2);