From b0f0d8fd71068c706b046293d836d4596958cabc Mon Sep 17 00:00:00 2001 From: Lignum Date: Fri, 5 May 2017 16:14:13 +0200 Subject: [PATCH] Add getColour/setColour to the window api --- .../computercraft/core/terminal/Terminal.java | 2 +- .../computercraft/shared/util/Palette.java | 3 +-- .../assets/computercraft/lua/rom/apis/window | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/terminal/Terminal.java b/src/main/java/dan200/computercraft/core/terminal/Terminal.java index 906e7603b..d5ff47a38 100644 --- a/src/main/java/dan200/computercraft/core/terminal/Terminal.java +++ b/src/main/java/dan200/computercraft/core/terminal/Terminal.java @@ -25,7 +25,7 @@ public class Terminal private TextBuffer m_textColour[]; private TextBuffer m_backgroundColour[]; - private Palette m_palette; + private final Palette m_palette; private boolean m_changed; diff --git a/src/main/java/dan200/computercraft/shared/util/Palette.java b/src/main/java/dan200/computercraft/shared/util/Palette.java index 3be6cac9b..704bdb52e 100644 --- a/src/main/java/dan200/computercraft/shared/util/Palette.java +++ b/src/main/java/dan200/computercraft/shared/util/Palette.java @@ -82,8 +82,7 @@ public class Palette { if(i >= 0 && i < colours.length ) { - Colour c = Colour.values()[ i ]; - colours[i] = new PaletteColour( c.getR(), c.getG(), c.getB() ); + setColour( i, Colour.values()[ i ] ); } } diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/window b/src/main/resources/assets/computercraft/lua/rom/apis/window index c5e83c61c..db28e99ee 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/window +++ b/src/main/resources/assets/computercraft/lua/rom/apis/window @@ -57,6 +57,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local nTextColor = colors.white local nBackgroundColor = colors.black local tLines = {} + local tPalette = {} do local sEmptyText = sEmptySpaceLine local sEmptyTextColor = tEmptyColorLines[ nTextColor ] @@ -68,6 +69,11 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) backgroundColor = sEmptyBackgroundColor, } end + + for i=0,15 do + local c = 2 ^ i + tPalette[c] = table.pack( parent.getColour( c ) ) + end end -- Helper functions @@ -87,6 +93,12 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) local function updateCursorColor() parent.setTextColor( nTextColor ) end + + local function updatePalette() + for k,v in pairs(tPalette) do + parent.setColour( k, table.unpack( v ) ) + end + end local function redrawLine( n ) local tLine = tLines[ n ] @@ -276,6 +288,21 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) setTextColor( color ) end + function window.setColour( colour, r, g, b ) + local tCol = tPalette[ colour ] + tCol[1] = r + tCol[2] = g + tCol[3] = b + end + + window.setColor = window.setColour + + function window.getColour( colour ) + return table.unpack( tPalette[ colour ] ) + end + + window.getColor = window.getColour + local function setBackgroundColor( color ) if not parent.isColor() then if color ~= colors.white and color ~= colors.black and color ~= colors.gray and color ~= colors.lightGray then