~ubuntu-branches/ubuntu/vivid/rlvm/vivid-proposed

« back to all changes in this revision

Viewing changes to src/machine/rloperation/rgb_colour_t.h

  • Committer: Package Import Robot
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2014-10-22 03:24:19 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20141022032419-yqxls9ky4n1w811n
Tags: 0.14-1
* New upstream release
* Bump Standards-Version to 3.9.6: nothing needs to be changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi:tw=80:et:ts=2:sts=2
 
3
//
 
4
// -----------------------------------------------------------------------
 
5
//
 
6
// This file is part of RLVM, a RealLive virtual machine clone.
 
7
//
 
8
// -----------------------------------------------------------------------
 
9
//
 
10
// Copyright (C) 2009 Elliot Glaysher
 
11
//
 
12
// This program is free software; you can redistribute it and/or modify
 
13
// it under the terms of the GNU General Public License as published by
 
14
// the Free Software Foundation; either version 3 of the License, or
 
15
// (at your option) any later version.
 
16
//
 
17
// This program is distributed in the hope that it will be useful,
 
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
// GNU General Public License for more details.
 
21
//
 
22
// You should have received a copy of the GNU General Public License
 
23
// along with this program; if not, write to the Free Software
 
24
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
25
// -----------------------------------------------------------------------
 
26
 
 
27
#ifndef SRC_MACHINE_RLOPERATION_RGB_COLOUR_T_H_
 
28
#define SRC_MACHINE_RLOPERATION_RGB_COLOUR_T_H_
 
29
 
 
30
#include <string>
 
31
#include <vector>
 
32
 
 
33
#include "machine/rloperation.h"
 
34
#include "systems/base/colour.h"
 
35
 
 
36
struct RGBColour_T {
 
37
  typedef RGBAColour type;
 
38
 
 
39
  static type getData(RLMachine& machine,
 
40
                      const libreallive::ExpressionPiecesVector& p,
 
41
                      unsigned int& position) {
 
42
    int r = IntConstant_T::getData(machine, p, position);
 
43
    int g = IntConstant_T::getData(machine, p, position);
 
44
    int b = IntConstant_T::getData(machine, p, position);
 
45
    return RGBAColour(r, g, b);
 
46
  }
 
47
 
 
48
  static void ParseParameters(unsigned int& position,
 
49
                              const std::vector<std::string>& input,
 
50
                              libreallive::ExpressionPiecesVector& output) {
 
51
    IntConstant_T::ParseParameters(position, input, output);
 
52
    IntConstant_T::ParseParameters(position, input, output);
 
53
    IntConstant_T::ParseParameters(position, input, output);
 
54
  }
 
55
 
 
56
  enum { is_complex = false };
 
57
};
 
58
 
 
59
// RGB colour triplet with option alpha.
 
60
struct RGBMaybeAColour_T {
 
61
  typedef RGBAColour type;
 
62
 
 
63
  static type getData(RLMachine& machine,
 
64
                      const libreallive::ExpressionPiecesVector& p,
 
65
                      unsigned int& position) {
 
66
    int r = IntConstant_T::getData(machine, p, position);
 
67
    int g = IntConstant_T::getData(machine, p, position);
 
68
    int b = IntConstant_T::getData(machine, p, position);
 
69
 
 
70
    int a;
 
71
    if (position < p.size()) {
 
72
      a = IntConstant_T::getData(machine, p, position);
 
73
    } else {
 
74
      a = 255;
 
75
    }
 
76
 
 
77
    return RGBAColour(r, g, b, a);
 
78
  }
 
79
 
 
80
  static void ParseParameters(unsigned int& position,
 
81
                              const std::vector<std::string>& input,
 
82
                              libreallive::ExpressionPiecesVector& output) {
 
83
    IntConstant_T::ParseParameters(position, input, output);
 
84
    IntConstant_T::ParseParameters(position, input, output);
 
85
    IntConstant_T::ParseParameters(position, input, output);
 
86
 
 
87
    if (position < input.size()) {
 
88
      IntConstant_T::ParseParameters(position, input, output);
 
89
    } else {
 
90
      output.emplace_back(new libreallive::IntegerConstant(255));
 
91
      position++;
 
92
    }
 
93
  }
 
94
 
 
95
  enum { is_complex = false };
 
96
};
 
97
 
 
98
#endif  // SRC_MACHINE_RLOPERATION_RGB_COLOUR_T_H_