From ce6b7c8fc229c2ed16c524ba4b0f1ad8e305557e Mon Sep 17 00:00:00 2001 From: Gilbert Date: Mon, 26 Feb 2018 19:49:42 +0100 Subject: [PATCH] Solarized Color Scheme (#4322) * Solarized Color Scheme * Some color adjustments * * huge cleanup * put color scheme defs in seperate file * Solarize changed some more colors. more to come? * save - more colors * Better scheme handling. LAYERS-Tab still missing. * More color adjustments. 2D-Plater: * Removed grid if no objects are present. * Bed has now different color than the background. * reverted faded background color. * Added comment to preferences to avoid merge issues. * added comments added and changed comments * * LAYERS tab colorized. * Better color for support. * Added comments. * * forgot to removed/undo comment about keys in 2D - are they documented somewhere? * * adjusted lighing - hopefully to the better. --- lib/Slic3r/GUI/2DBed.pm | 21 ++++- lib/Slic3r/GUI/3DScene.pm | 59 ++++++++---- lib/Slic3r/GUI/ColorScheme.pm | 121 +++++++++++++++++++++++++ lib/Slic3r/GUI/Plater/2D.pm | 51 +++++++---- lib/Slic3r/GUI/Plater/2DToolpaths.pm | 49 +++++++--- lib/Slic3r/GUI/Plater/3DPreview.pm | 2 +- lib/Slic3r/GUI/Plater/SplineControl.pm | 25 +++-- lib/Slic3r/GUI/Preferences.pm | 10 ++ 8 files changed, 274 insertions(+), 64 deletions(-) create mode 100644 lib/Slic3r/GUI/ColorScheme.pm diff --git a/lib/Slic3r/GUI/2DBed.pm b/lib/Slic3r/GUI/2DBed.pm index afa31f951..b18bfa821 100644 --- a/lib/Slic3r/GUI/2DBed.pm +++ b/lib/Slic3r/GUI/2DBed.pm @@ -11,11 +11,21 @@ use Wx qw(:misc :pen :brush :font :systemsettings wxTAB_TRAVERSAL wxSOLID); use Wx::Event qw(EVT_PAINT EVT_ERASE_BACKGROUND EVT_MOUSE_EVENTS EVT_SIZE); use base qw(Wx::Panel Class::Accessor); +# Color Scheme +use Slic3r::GUI::ColorScheme; + __PACKAGE__->mk_accessors(qw(bed_shape interactive pos _scale_factor _shift on_move _painted)); sub new { my ($class, $parent, $bed_shape) = @_; + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + my $myGetSchemeName = \&{"Slic3r::GUI::ColorScheme::$Slic3r::GUI::Settings->{_}{colorscheme}"}; + $myGetSchemeName->(); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + } + my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, [250,-1], wxTAB_TRAVERSAL); $self->{user_drawn_background} = $^O ne 'darwin'; $self->bed_shape($bed_shape // []); @@ -38,9 +48,10 @@ sub _repaint { # On MacOS the background is erased, on Windows the background is not erased # and on Linux/GTK the background is erased to gray color. # Fill DC with the background on Windows & Linux/GTK. - my $color = Wx::SystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT); - $dc->SetPen(Wx::Pen->new($color, 1, wxSOLID)); - $dc->SetBrush(Wx::Brush->new($color, wxSOLID)); + my $brush_background = Wx::Brush->new(Wx::Colour->new(@BACKGROUND255), wxSOLID); + my $pen_background = Wx::Pen->new(Wx::Colour->new(@BACKGROUND255), 1, wxSOLID); + $dc->SetPen($pen_background); + $dc->SetBrush($brush_background); my $rect = $self->GetUpdateRegion()->GetBox(); $dc->DrawRectangle($rect->GetLeft(), $rect->GetTop(), $rect->GetWidth(), $rect->GetHeight()); } @@ -89,7 +100,7 @@ sub _repaint { # draw bed fill { $dc->SetPen(Wx::Pen->new(Wx::Colour->new(0,0,0), 1, wxSOLID)); - $dc->SetBrush(Wx::Brush->new(Wx::Colour->new(255,255,255), wxSOLID)); + $dc->SetBrush(Wx::Brush->new(Wx::Colour->new(@BED_COLOR), wxSOLID)); $dc->DrawPolygon([ map $self->to_pixels($_), @$bed_shape ], 0, 0); } @@ -105,7 +116,7 @@ sub _repaint { } @polylines = @{intersection_pl(\@polylines, [$bed_polygon])}; - $dc->SetPen(Wx::Pen->new(Wx::Colour->new(230,230,230), 1, wxSOLID)); + $dc->SetPen(Wx::Pen->new(Wx::Colour->new(@BED_GRID), 1, wxSOLID)); $dc->DrawLine(map @{$self->to_pixels([map unscale($_), @$_])}, @$_[0,-1]) for @polylines; } diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 54acbc471..fd7dadb44 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -44,8 +44,6 @@ __PACKAGE__->mk_accessors( qw(_quat _dirty init use constant TRACKBALLSIZE => 0.8; use constant TURNTABLE_MODE => 1; use constant GROUND_Z => -0.02; -use constant SELECTED_COLOR => [0,1,0]; -use constant HOVER_COLOR => [0.4,0.9,0]; use constant PI => 3.1415927; # Constant to determine if Vertex Buffer objects are used to draw @@ -61,6 +59,9 @@ use constant VIEW_FRONT => [0.0,90.0]; use constant VIEW_BACK => [180.0,90.0]; use constant VIEW_DIAGONAL => [45.0,45.0]; +# Color Scheme +use Slic3r::GUI::ColorScheme; + use constant GIMBAL_LOCK_THETA_MAX => 170; # make OpenGL::Array thread-safe @@ -71,9 +72,15 @@ use constant GIMBAL_LOCK_THETA_MAX => 170; sub new { my ($class, $parent) = @_; - - # We can only enable multi sample anti aliasing wih wxWidgets 3.0.3 and with a hacked Wx::GLCanvas, + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + my $myGetSchemeName = \&{"Slic3r::GUI::ColorScheme::$Slic3r::GUI::Settings->{_}{colorscheme}"}; + $myGetSchemeName->(); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + } + + # We can only enable multi sample anti aliasing with wxWidgets 3.0.3 and with a hacked Wx::GLCanvas, # which exports some new WX_GL_XXX constants, namely WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES. my $can_multisample = Wx::wxVERSION >= 3.000003 && @@ -747,7 +754,7 @@ sub InitGL { glEnable(GL_MULTISAMPLE) if ($self->{can_multisample}); # ambient lighting - glLightModelfv_p(GL_LIGHT_MODEL_AMBIENT, 0.3, 0.3, 0.3, 1); + glLightModelfv_p(GL_LIGHT_MODEL_AMBIENT, 0.1, 0.1, 0.1, 1); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); @@ -755,10 +762,10 @@ sub InitGL { # light from camera glLightfv_p(GL_LIGHT1, GL_POSITION, 1, 0, 1, 0); - glLightfv_p(GL_LIGHT1, GL_SPECULAR, 0.3, 0.3, 0.3, 1); - glLightfv_p(GL_LIGHT1, GL_DIFFUSE, 0.2, 0.2, 0.2, 1); + glLightfv_p(GL_LIGHT1, GL_SPECULAR, 0.8, 0.8, 0.8, 1); + glLightfv_p(GL_LIGHT1, GL_DIFFUSE, 0.4, 0.4, 0.4, 1); - # Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. + # Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. Default: GL_SMOOTH glShadeModel(GL_SMOOTH); glMaterialfv_p(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, 0.3, 0.3, 0.3, 1); @@ -781,7 +788,12 @@ sub Render { $self->SetCurrent($context); $self->InitGL; - glClearColor(1, 1, 1, 1); + if($SOLID_BACKGROUNDCOLOR == 1){ + glClearColor(@BACKGROUND_COLOR, 0); + } else { + glClearColor(1, 1, 1, 1); + } + glClearDepth(1); glDepthFunc(GL_LESS); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -834,7 +846,7 @@ sub Render { } # draw fixed background - if ($self->background) { + if ($SOLID_BACKGROUNDCOLOR == 0 && $self->background) { glDisable(GL_LIGHTING); glPushMatrix(); glLoadIdentity(); @@ -844,10 +856,10 @@ sub Render { glLoadIdentity(); glBegin(GL_QUADS); - glColor3f(0.0,0.0,0.0); + glColor3f( @BOTTOM_COLOR ); # bottom color glVertex2f(-1.0,-1.0); glVertex2f(1,-1.0); - glColor3f(10/255,98/255,144/255); + glColor3f( @TOP_COLOR ); # top color glVertex2f(1, 1); glVertex2f(-1.0, 1); glEnd(); @@ -881,7 +893,7 @@ sub Render { # fall back on old behavior glVertexPointer_c(3, GL_FLOAT, 0, $self->bed_triangles->ptr()); } - glColor4f(0.8, 0.6, 0.5, 0.4); + glColor4f( @GROUND_COLOR ); glNormal3d(0,0,1); glDrawArrays(GL_TRIANGLES, 0, $self->bed_triangles->elements / 3); glDisableClientState(GL_VERTEX_ARRAY); @@ -891,7 +903,7 @@ sub Render { glEnable(GL_DEPTH_TEST); # draw grid - glLineWidth(3); + glLineWidth(2); glEnableClientState(GL_VERTEX_ARRAY); my $grid_vertex; if (HAS_VBO) { @@ -904,7 +916,7 @@ sub Render { # fall back on old behavior glVertexPointer_c(3, GL_FLOAT, 0, $self->bed_grid_lines->ptr()); } - glColor4f(0.2, 0.2, 0.2, 0.4); + glColor4f( @GRID_COLOR ); glNormal3d(0,0,1); glDrawArrays(GL_LINES, 0, $self->bed_grid_lines->elements / 3); glDisableClientState(GL_VERTEX_ARRAY); @@ -965,7 +977,7 @@ sub Render { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); - glColor4f(0.8, 0.8, 0.8, 0.5); + glColor4f( @COLOR_CUTPLANE ); if ($self->cutting_plane_axis == X) { glVertex3f($bb->x_min+$plane_z, $bb->y_min-20, $bb->z_min-20); glVertex3f($bb->x_min+$plane_z, $bb->y_max+20, $bb->z_min-20); @@ -1050,9 +1062,9 @@ sub draw_volumes { my $b = ($volume_idx & 0x00FF0000) >> 16; glColor4f($r/255.0, $g/255.0, $b/255.0, 1); } elsif ($volume->selected) { - glColor4f(@{ &SELECTED_COLOR }, $volume->color->[3]); + glColor4f( @SELECTED_COLOR , $volume->color->[3]); } elsif ($volume->hover) { - glColor4f(@{ &HOVER_COLOR }, $volume->color->[3]); + glColor4f( @HOVER_COLOR, $volume->color->[3]); } else { glColor4f(@{ $volume->color }); } @@ -1165,6 +1177,7 @@ use OpenGL qw(:glconstants :gluconstants :glufunctions); use List::Util qw(first min max); use Slic3r::Geometry qw(scale unscale epsilon); use Slic3r::Print::State ':steps'; +use Slic3r::GUI::ColorScheme; __PACKAGE__->mk_accessors(qw( colors @@ -1176,12 +1189,20 @@ __PACKAGE__->mk_accessors(qw( _objects_by_volumes )); -sub default_colors { [1,0.95,0.2,1], [1,0.45,0.45,1], [0.5,1,0.5,1], [0.5,0.5,1,1] } +sub default_colors { [@COLOR_PARTS], [@COLOR_INFILL], [@COLOR_SUPPORT], [@COLOR_UNKNOWN] } sub new { my $class = shift; my $self = $class->SUPER::new(@_); + + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + my $myGetSchemeName = \&{"Slic3r::GUI::ColorScheme::$Slic3r::GUI::Settings->{_}{colorscheme}"}; + $myGetSchemeName->(); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + } + $self->colors([ $self->default_colors ]); $self->color_by('volume'); # object | volume $self->color_toolpaths_by('role'); # role | extruder diff --git a/lib/Slic3r/GUI/ColorScheme.pm b/lib/Slic3r/GUI/ColorScheme.pm new file mode 100644 index 000000000..e5a4b53f6 --- /dev/null +++ b/lib/Slic3r/GUI/ColorScheme.pm @@ -0,0 +1,121 @@ +package Slic3r::GUI::ColorScheme; +use strict; +use warnings; + +use POSIX; +use vars qw(@ISA @EXPORT); +use Exporter 'import'; +our @ISA = 'Exporter'; +our @EXPORT = qw($DEFAULT_COLORSCHEME $SOLID_BACKGROUNDCOLOR @SELECTED_COLOR @HOVER_COLOR @TOP_COLOR @BOTTOM_COLOR @GRID_COLOR @GROUND_COLOR @COLOR_CUTPLANE @COLOR_PARTS @COLOR_INFILL @COLOR_SUPPORT @COLOR_UNKNOWN @BED_COLOR @BED_GRID @BED_SELECTED @BED_OBJECTS @BED_DRAGGED @BED_CENTER @BED_SKIRT @BED_CLEARANCE @BED_DARK @BACKGROUND255 @TOOL_DARK @TOOL_SUPPORT @TOOL_INFILL @TOOL_SHADE @TOOL_COLOR @BACKGROUND_COLOR @SPLINE_L_PEN @SPLINE_O_PEN @SPLINE_I_PEN @SPLINE_R_PEN ); + +# DEFAULT values +our $DEFAULT_COLORSCHEME = 1; +our $SOLID_BACKGROUNDCOLOR = 0; +our @SELECTED_COLOR = (0, 1, 0); +our @HOVER_COLOR = (0.4, 0.9, 0); # Hover over Model +our @TOP_COLOR = (10/255,98/255,144/255); # TOP Backgroud color +our @BOTTOM_COLOR = (0,0,0); # BOTTOM Backgroud color +our @BACKGROUND_COLOR = @TOP_COLOR; # SOLID background color +our @GRID_COLOR = (0.2, 0.2, 0.2, 0.4); # Grid color +our @GROUND_COLOR = (0.8, 0.6, 0.5, 0.4); # Ground or Plate color +our @COLOR_CUTPLANE = (.8, .8, .8, 0.5); +our @COLOR_PARTS = (1, 0.95, 0.2, 1); # Perimeter color +our @COLOR_INFILL = (1, 0.45, 0.45, 1); +our @COLOR_SUPPORT = (0.5, 1, 0.5, 1); +our @COLOR_UNKNOWN = (0.5, 0.5, 1, 1); +our @BED_COLOR = (255, 255, 255); +our @BED_GRID = (230, 230, 230); +our @BED_SELECTED = (255, 166, 128); +our @BED_OBJECTS = (210, 210, 210); +our @BED_DRAGGED = (128, 128, 255); +our @BED_CENTER = (200, 200, 200); +our @BED_SKIRT = (150, 150, 150); +our @BED_CLEARANCE = (0, 0, 200); +our @BACKGROUND255 = (255, 255, 255); +our @TOOL_DARK = (0, 0, 0); +our @TOOL_SUPPORT = (0, 0, 0); +our @TOOL_INFILL = (0, 0, 0); +our @TOOL_SHADE = (0.95, 0.95, 0.95); +our @TOOL_COLOR = (0.7, 0, 0); +our @SPLINE_L_PEN = (50, 50, 50); +our @SPLINE_O_PEN = (200, 200, 200); +our @SPLINE_I_PEN = (255, 0, 0); +our @SPLINE_R_PEN = (5, 120, 160); +our @BED_DARK = (0, 0, 0); + +# S O L A R I Z E +# # http://ethanschoonover.com/solarized +our @COLOR_BASE03 = (0.00000,0.16863,0.21176); +our @COLOR_BASE02 = (0.02745,0.21176,0.25882); +our @COLOR_BASE01 = (0.34510,0.43137,0.45882); +our @COLOR_BASE00 = (0.39608,0.48235,0.51373); +our @COLOR_BASE0 = (0.51373,0.58039,0.58824); +our @COLOR_BASE1 = (0.57647,0.63137,0.63137); +our @COLOR_BASE2 = (0.93333,0.90980,0.83529); +our @COLOR_BASE3 = (0.99216,0.96471,0.89020); +our @COLOR_YELLOW = (0.70980,0.53725,0.00000); +our @COLOR_ORANGE = (0.79608,0.29412,0.08627); +our @COLOR_RED = (0.86275,0.19608,0.18431); +our @COLOR_MAGENTA = (0.82745,0.21176,0.50980); +our @COLOR_VIOLET = (0.42353,0.44314,0.76863); +our @COLOR_BLUE = (0.14902,0.54510,0.82353); +our @COLOR_CYAN = (0.16471,0.63137,0.59608); +our @COLOR_GREEN = (0.52157,0.60000,0.00000); + +# create your own theme: +# 1. add new sub and name it according to your scheme +# 2. add that name to Preferences.pm +# 3. Choose your newly created theme in Slic3rs' Preferences (File -> Preferences). + +sub getSolarized { # add this name to Preferences.pm + $DEFAULT_COLORSCHEME = 0; # DISABLE default color scheme + $SOLID_BACKGROUNDCOLOR = 1; # Switch between SOLID or FADED background color + @SELECTED_COLOR = @COLOR_MAGENTA; # Color of selected Model + @HOVER_COLOR = @COLOR_VIOLET; # Color when hovering over Model + # @TOP_COLOR = @COLOR_BASE2; # FADE Background color - only used if $SOLID_BACKGROUNDCOLOR = 0 + # @BOTTOM_COLOR = @COLOR_BASE02; # FADE Background color - only used if $SOLID_BACKGROUNDCOLOR = 0 + @BACKGROUND_COLOR = @COLOR_BASE3; # SOLID Background color - REQUIRED for NOT getDefault + @GRID_COLOR = (@COLOR_BASE1, 0.4); # Grid + @GROUND_COLOR = (@COLOR_BASE2, 0.4); # Ground or Plate + @COLOR_CUTPLANE = (@COLOR_BASE1, 0.5); # Cut plane + @COLOR_PARTS = (@TOOL_COLOR, 1); # Perimeter + @COLOR_INFILL = (@COLOR_BASE2, 1); # Infill + @COLOR_SUPPORT = (@TOOL_SUPPORT, 1); # Support + @COLOR_UNKNOWN = (@COLOR_CYAN, 1); # I don't know what that color's for! + + # 2DBed.pm and ./plater/2D.pm colors + @BED_COLOR = map { ceil($_ * 255) } @COLOR_BASE2; # do math -> multiply each value by 255 and round up + @BED_GRID = map { ceil($_ * 255) } @COLOR_BASE1; # Bed, Ground or Plate + @BED_SELECTED = map { ceil($_ * 255) } @SELECTED_COLOR; # Selected Model + @BED_OBJECTS = map { ceil($_ * 255) } @COLOR_PARTS; # Models on bed + @BED_DRAGGED = map { ceil($_ * 255) } @COLOR_CYAN; # Color while dragging + @BED_CENTER = map { ceil($_ * 255) } @COLOR_BASE1; # Cross hair + @BED_SKIRT = map { ceil($_ * 255) } @COLOR_BASE01; # Brim/Skirt + @BED_CLEARANCE = map { ceil($_ * 255) } @COLOR_BLUE; # not sure what that does + @BED_DARK = map { ceil($_ * 255) } @COLOR_BASE01; # not sure what that does + @BACKGROUND255 = map { ceil($_ * 255) } @BACKGROUND_COLOR; # Backgroud color, this time RGB + + # 2DToolpaths.pm colors : LAYERS Tab + @TOOL_DARK = @COLOR_BASE01; # Brim/Skirt + @TOOL_SUPPORT = @COLOR_GREEN; # Support + @TOOL_INFILL = @COLOR_BASE1; # Infill + @TOOL_COLOR = @COLOR_BLUE; # Perimeter + @TOOL_SHADE = @COLOR_BASE2; # Shade; model inside + + # Colors for *Layer heights...* dialog + @SPLINE_L_PEN = map { ceil($_ * 255) } @COLOR_BASE01; # Line color + @SPLINE_O_PEN = map { ceil($_ * 255) } @COLOR_BASE1; # Original color + @SPLINE_I_PEN = map { ceil($_ * 255) } @COLOR_MAGENTA; # Interactive color + @SPLINE_R_PEN = map { ceil($_ * 255) } @COLOR_VIOLET; # Resulting color + +} + +sub getDefault{ + $DEFAULT_COLORSCHEME = 1; # ENABLE default color scheme + # Define your function here + # getDefault is just a dummy function and uses the default values from above. +} + + + +1; # REQUIRED at EOF diff --git a/lib/Slic3r/GUI/Plater/2D.pm b/lib/Slic3r/GUI/Plater/2D.pm index 3081ba351..377052745 100644 --- a/lib/Slic3r/GUI/Plater/2D.pm +++ b/lib/Slic3r/GUI/Plater/2D.pm @@ -13,6 +13,9 @@ use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL); use Wx::Event qw(EVT_MOUSE_EVENTS EVT_KEY_DOWN EVT_PAINT EVT_ERASE_BACKGROUND EVT_SIZE); use base 'Wx::Panel'; +# Color Scheme +use Slic3r::GUI::ColorScheme; + use constant CANVAS_TEXT => join('-', +(localtime)[3,4]) eq '13-8' ? 'What do you want to print today? ™' # Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap. : 'Drag your objects here'; @@ -21,9 +24,16 @@ sub new { my $class = shift; my ($parent, $size, $objects, $model, $config) = @_; + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + my $myGetSchemeName = \&{"Slic3r::GUI::ColorScheme::$Slic3r::GUI::Settings->{_}{colorscheme}"}; + $myGetSchemeName->(); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + } + my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, $size, wxTAB_TRAVERSAL); # This has only effect on MacOS. On Windows and Linux/GTK, the background is painted by $self->repaint(). - $self->SetBackgroundColour(Wx::wxWHITE); + $self->SetBackgroundColour(Wx::Colour->new(@BACKGROUND255)); $self->{objects} = $objects; $self->{model} = $model; @@ -33,15 +43,17 @@ sub new { $self->{on_right_click} = sub {}; $self->{on_instances_moved} = sub {}; - $self->{objects_brush} = Wx::Brush->new(Wx::Colour->new(210,210,210), wxSOLID); - $self->{instance_brush} = Wx::Brush->new(Wx::Colour->new(255,128,128), wxSOLID); - $self->{selected_brush} = Wx::Brush->new(Wx::Colour->new(255,166,128), wxSOLID); - $self->{dragged_brush} = Wx::Brush->new(Wx::Colour->new(128,128,255), wxSOLID); + $self->{objects_brush} = Wx::Brush->new(Wx::Colour->new(@BED_OBJECTS), wxSOLID); + $self->{instance_brush} = Wx::Brush->new(Wx::Colour->new(@BED_SELECTED), wxSOLID); + $self->{selected_brush} = Wx::Brush->new(Wx::Colour->new(@BED_SELECTED), wxSOLID); + $self->{dragged_brush} = Wx::Brush->new(Wx::Colour->new(@BED_DRAGGED), wxSOLID); + $self->{bed_brush} = Wx::Brush->new(Wx::Colour->new(@BED_COLOR), wxSOLID); $self->{transparent_brush} = Wx::Brush->new(Wx::Colour->new(0,0,0), wxTRANSPARENT); - $self->{grid_pen} = Wx::Pen->new(Wx::Colour->new(230,230,230), 1, wxSOLID); - $self->{print_center_pen} = Wx::Pen->new(Wx::Colour->new(200,200,200), 1, wxSOLID); - $self->{clearance_pen} = Wx::Pen->new(Wx::Colour->new(0,0,200), 1, wxSOLID); - $self->{skirt_pen} = Wx::Pen->new(Wx::Colour->new(150,150,150), 1, wxSOLID); + $self->{grid_pen} = Wx::Pen->new(Wx::Colour->new(@BED_GRID), 1, wxSOLID); + $self->{print_center_pen} = Wx::Pen->new(Wx::Colour->new(@BED_CENTER), 1, wxSOLID); + $self->{clearance_pen} = Wx::Pen->new(Wx::Colour->new(@BED_CLEARANCE), 1, wxSOLID); + $self->{skirt_pen} = Wx::Pen->new(Wx::Colour->new(@BED_SKIRT), 1, wxSOLID); + $self->{dark_pen} = Wx::Pen->new(Wx::Colour->new(@BED_DARK), 1, wxSOLID); $self->{user_drawn_background} = $^O ne 'darwin'; @@ -109,21 +121,18 @@ sub repaint { # On MacOS the background is erased, on Windows the background is not erased # and on Linux/GTK the background is erased to gray color. # Fill DC with the background on Windows & Linux/GTK. - my $brush_background = Wx::Brush->new(Wx::wxWHITE, wxSOLID); - $dc->SetPen(wxWHITE_PEN); + my $brush_background = Wx::Brush->new(Wx::Colour->new(@BACKGROUND255), wxSOLID); + my $pen_background = Wx::Pen->new(Wx::Colour->new(@BACKGROUND255), 1, wxSOLID); + $dc->SetPen($pen_background); $dc->SetBrush($brush_background); my $rect = $self->GetUpdateRegion()->GetBox(); $dc->DrawRectangle($rect->GetLeft(), $rect->GetTop(), $rect->GetWidth(), $rect->GetHeight()); } - - # draw grid - $dc->SetPen($self->{grid_pen}); - $dc->DrawLine(map @$_, @$_) for @{$self->{grid}}; # draw bed { $dc->SetPen($self->{print_center_pen}); - $dc->SetBrush($self->{transparent_brush}); + $dc->SetBrush($self->{bed_brush}); $dc->DrawPolygon($self->scaled_points_to_pixel($self->{bed_polygon}, 1), 0, 0); } @@ -141,20 +150,24 @@ sub repaint { # draw frame if (0) { - $dc->SetPen(wxBLACK_PEN); + $dc->SetPen($self->{dark_pen}); $dc->SetBrush($self->{transparent_brush}); $dc->DrawRectangle(0, 0, @size); } # draw text if plate is empty if (!@{$self->{objects}}) { - $dc->SetTextForeground(Wx::Colour->new(150,50,50)); + $dc->SetTextForeground(Wx::Colour->new(@BED_OBJECTS)); $dc->SetFont(Wx::Font->new(14, wxDEFAULT, wxNORMAL, wxNORMAL)); $dc->DrawLabel(CANVAS_TEXT, Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); + } else { + # draw grid + $dc->SetPen($self->{grid_pen}); + $dc->DrawLine(map @$_, @$_) for @{$self->{grid}}; } # draw thumbnails - $dc->SetPen(wxBLACK_PEN); + $dc->SetPen($self->{dark_pen}); $self->clean_instance_thumbnails; for my $obj_idx (0 .. $#{$self->{objects}}) { my $object = $self->{objects}[$obj_idx]; diff --git a/lib/Slic3r/GUI/Plater/2DToolpaths.pm b/lib/Slic3r/GUI/Plater/2DToolpaths.pm index 2c5a4a7d6..a9e4ef17e 100644 --- a/lib/Slic3r/GUI/Plater/2DToolpaths.pm +++ b/lib/Slic3r/GUI/Plater/2DToolpaths.pm @@ -12,15 +12,24 @@ use Wx qw(:misc :sizer :slider :statictext wxWHITE); use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN); use base qw(Wx::Panel Class::Accessor); +# Color Scheme +use Slic3r::GUI::ColorScheme; + __PACKAGE__->mk_accessors(qw(print enabled)); sub new { my $class = shift; my ($parent, $print) = @_; - + my $self = $class->SUPER::new($parent, -1, wxDefaultPosition); - $self->SetBackgroundColour(wxWHITE); - + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( my $getScheme = Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + $getScheme->(); + $self->SetBackgroundColour(Wx::Colour->new(@BACKGROUND255)); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + $self->SetBackgroundColour(Wx::wxWHITE); + } + # init GUI elements my $canvas = $self->{canvas} = Slic3r::GUI::Plater::2DToolpaths::Canvas->new($self, $print); my $slider = $self->{slider} = Wx::Slider->new( @@ -130,6 +139,9 @@ use List::Util qw(min max first); use Slic3r::Geometry qw(scale unscale epsilon X Y); use Slic3r::Print::State ':steps'; +# Color Scheme +use Slic3r::GUI::ColorScheme; + __PACKAGE__->mk_accessors(qw( print z layers color init bb @@ -148,7 +160,13 @@ __PACKAGE__->mk_accessors(qw( sub new { my ($class, $parent, $print) = @_; - + + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + my $myGetSchemeName = \&{"Slic3r::GUI::ColorScheme::$Slic3r::GUI::Settings->{_}{colorscheme}"}; + $myGetSchemeName->(); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + } my $self = (Wx::wxVERSION >= 3.000003) ? # The wxWidgets 3.0.3-beta have a bug, they crash with NULL attribute list. $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", @@ -310,7 +328,12 @@ sub Render { $self->SetCurrent($context); $self->InitGL; - glClearColor(1, 1, 1, 0); + if ($DEFAULT_COLORSCHEME==1){ + glClearColor(1, 1, 1, 0); + } else{ + glClearColor(@BACKGROUND_COLOR, 0); + } + glClear(GL_COLOR_BUFFER_BIT); if (!$self->GetParent->enabled || !$self->layers) { @@ -358,7 +381,7 @@ sub Render { glTranslatef(@$copy, 0); foreach my $slice (@{$layer->slices}) { - glColor3f(0.95, 0.95, 0.95); + glColor3f(@TOOL_SHADE); # Inside part shade if ($tess) { gluTessBeginPolygon($tess); @@ -370,7 +393,7 @@ sub Render { gluTessEndPolygon($tess); } - glColor3f(0.9, 0.9, 0.9); + glColor3f(@TOOL_COLOR); # Perimeter foreach my $polygon (@$slice) { foreach my $line (@{$polygon->lines}) { glBegin(GL_LINES); @@ -392,33 +415,33 @@ sub Render { # draw brim if ($self->print->step_done(STEP_BRIM) && $layer->id == 0 && !$brim_drawn) { - $self->color([0, 0, 0]); + $self->color(@TOOL_DARK); $self->_draw(undef, $print_z, $_) for @{$self->print->brim}; $brim_drawn = 1; } if ($self->print->step_done(STEP_SKIRT) && ($self->print->has_infinite_skirt() || $self->print->config->skirt_height > $layer->id) && !$skirt_drawn) { - $self->color([0, 0, 0]); + $self->color(@TOOL_DARK); $self->_draw(undef, $print_z, $_) for @{$self->print->skirt}; $skirt_drawn = 1; } foreach my $layerm (@{$layer->regions}) { if ($object->step_done(STEP_PERIMETERS)) { - $self->color([0.7, 0, 0]); + $self->color(@TOOL_COLOR); $self->_draw($object, $print_z, $_) for map @$_, @{$layerm->perimeters}; } if ($object->step_done(STEP_INFILL)) { - $self->color([0, 0, 0.7]); + $self->color(@TOOL_INFILL); $self->_draw($object, $print_z, $_) for map @$_, @{$layerm->fills}; } } if ($object->step_done(STEP_SUPPORTMATERIAL)) { if ($layer->isa('Slic3r::Layer::Support')) { - $self->color([0, 0, 0]); + $self->color(@TOOL_SUPPORT); $self->_draw($object, $print_z, $_) for @{$layer->support_fills}; $self->_draw($object, $print_z, $_) for @{$layer->support_interface_fills}; } @@ -446,7 +469,7 @@ sub _draw_path { return if $print_z - $path->height > $self->z - epsilon; if (abs($print_z - $self->z) < epsilon) { - glColor3f(@{$self->color}); + glColor3f($self->color->[0], $self->color->[1], $self->color->[2]); } else { glColor3f(0.8, 0.8, 0.8); } diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index ce7a5f579..c4f9e6c5e 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -4,7 +4,7 @@ use warnings; use utf8; use Slic3r::Print::State ':steps'; -use Wx qw(:misc :sizer :slider :statictext wxWHITE); +use Wx qw(:misc :sizer :slider :statictext); use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN); use base qw(Wx::Panel Class::Accessor); diff --git a/lib/Slic3r/GUI/Plater/SplineControl.pm b/lib/Slic3r/GUI/Plater/SplineControl.pm index 469842a40..92918d435 100644 --- a/lib/Slic3r/GUI/Plater/SplineControl.pm +++ b/lib/Slic3r/GUI/Plater/SplineControl.pm @@ -9,22 +9,32 @@ use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL); use Wx::Event qw(EVT_MOUSE_EVENTS EVT_PAINT EVT_ERASE_BACKGROUND EVT_SIZE); use base 'Wx::Panel'; +# Color Scheme +use Slic3r::GUI::ColorScheme; + sub new { my $class = shift; my ($parent, $size, $object) = @_; + if ( ( defined $Slic3r::GUI::Settings->{_}{colorscheme} ) && ( Slic3r::GUI::ColorScheme->can($Slic3r::GUI::Settings->{_}{colorscheme}) ) ) { + my $myGetSchemeName = \&{"Slic3r::GUI::ColorScheme::$Slic3r::GUI::Settings->{_}{colorscheme}"}; + $myGetSchemeName->(); + } else { + Slic3r::GUI::ColorScheme->getDefault(); + } + my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, $size, wxTAB_TRAVERSAL); $self->{object} = $object; $self->{is_valid} = 0; # This has only effect on MacOS. On Windows and Linux/GTK, the background is painted by $self->repaint(). - $self->SetBackgroundColour(Wx::wxWHITE); + $self->SetBackgroundColour(Wx::Colour->new(@BACKGROUND255)); - $self->{line_pen} = Wx::Pen->new(Wx::Colour->new(50,50,50), 1, wxSOLID); - $self->{original_pen} = Wx::Pen->new(Wx::Colour->new(200,200,200), 1, wxSOLID); - $self->{interactive_pen} = Wx::Pen->new(Wx::Colour->new(255,0,0), 1, wxSOLID); - $self->{resulting_pen} = Wx::Pen->new(Wx::Colour->new(5,120,160), 1, wxSOLID); + $self->{line_pen} = Wx::Pen->new(Wx::Colour->new(@SPLINE_L_PEN), 1, wxSOLID); + $self->{original_pen} = Wx::Pen->new(Wx::Colour->new(@SPLINE_O_PEN), 1, wxSOLID); + $self->{interactive_pen} = Wx::Pen->new(Wx::Colour->new(@SPLINE_I_PEN), 1, wxSOLID); + $self->{resulting_pen} = Wx::Pen->new(Wx::Colour->new(@SPLINE_R_PEN), 1, wxSOLID); $self->{user_drawn_background} = $^O ne 'darwin'; @@ -63,8 +73,9 @@ sub repaint { # On MacOS the background is erased, on Windows the background is not erased # and on Linux/GTK the background is erased to gray color. # Fill DC with the background on Windows & Linux/GTK. - my $brush_background = Wx::Brush->new(Wx::wxWHITE, wxSOLID); - $dc->SetPen(wxWHITE_PEN); + my $brush_background = Wx::Brush->new(Wx::Colour->new(@BACKGROUND255), wxSOLID); + my $pen_background = Wx::Pen->new(Wx::Colour->new(@BACKGROUND255), 1, wxSOLID); + $dc->SetPen($pen_background); $dc->SetBrush($brush_background); my $rect = $self->GetUpdateRegion()->GetBox(); $dc->DrawRectangle($rect->GetLeft(), $rect->GetTop(), $rect->GetWidth(), $rect->GetHeight()); diff --git a/lib/Slic3r/GUI/Preferences.pm b/lib/Slic3r/GUI/Preferences.pm index 6fb779b3f..23da73d8d 100644 --- a/lib/Slic3r/GUI/Preferences.pm +++ b/lib/Slic3r/GUI/Preferences.pm @@ -92,6 +92,16 @@ sub new { tooltip => 'In 2D plater, Move objects using keyboard by nudge value of', default => $Slic3r::GUI::Settings->{_}{nudge_val}, )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( # colorscheme + opt_id => 'colorscheme', + type => 'select', + label => 'Color Scheme', + tooltip => 'Choose between color schemes - restart of Slic3r required.', + labels => ['Default','Solarized'], # add more schemes, if you want in ColorScheme.pm. + values => ['getDefault','getSolarized'], # add more schemes, if you want - those are the names of the corresponding function in ColorScheme.pm. + default => $Slic3r::GUI::Settings->{_}{colorscheme} // 'getDefault', + width => 130, + )); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);