Completed
Pull Request — master (#100)
by
unknown
02:35
created

uiScrollbar::getScrollbarX()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 38

Duplication

Lines 47
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 47
loc 47
rs 9.0303
ccs 0
cts 40
cp 0
cc 1
eloc 38
nc 1
nop 0
crap 2
1
<?php
2
3
namespace eXpansion\Framework\Gui\Components;
4
5
use FML\Controls\Frame;
6
use FML\Controls\Label;
7
use FML\Controls\Quad;
8
use FML\Script\Script;
9
use FML\Types\Renderable;
10
11
class uiScrollbar extends abstractUiElement implements Renderable
12
{
13
14
    const AXIS_X = "X";
15
    const AXIS_Y = "Y";
16
17
    /**
18
     * @var string
19
     */
20
    private $axis;
21
    /**
22
     * @var float
23
     */
24
    private $length;
25
    /**
26
     * @var float
27
     */
28
    private $scrollbarSize;
29
30
    /**
31
     * uiScrollbar constructor.
32
     * @param string $axis
33
     * @param float $posX
34
     * @param float $posY
35
     * @param $scrollbarSize
36
     * @param float $length
37
     */
38
    public function __construct($axis, $posX, $posY, $scrollbarSize, $length)
39
    {
40
41
        $this->axis = $axis;
42
        $this->setPosition($posX, $posY);
43
        $this->length = $length;
44
        if ($this->axis == "X") {
45
            $this->setWidth($length);
46
            $this->setHeight(5.);
47
        } else {
48
            $this->setHeight($length);
49
            $this->setWidth(5.);
50
        }
51
        $this->scrollbarSize = $scrollbarSize;
52
    }
53
54
    /**
55
     * Render the XML element
56
     *
57
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
58
     * @return \DOMElement
59
     */
60
    public function render(\DOMDocument $domDocument)
61
    {
62
        if ($this->axis == self::AXIS_X) {
63
            $frame = $this->getScrollbarX();
64
        } else {
65
            $frame = $this->getScrollbarY();
66
        }
67
68
        return $frame->render($domDocument);
69
    }
70
71 View Code Duplication
    private function getScrollbarX()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        $frame = new Frame();
74
        $frame->setPosition($this->posX, $this->posY)
75
            ->addClass('uiScrollbarControl');
76
77
        $scrollbar = new Quad();
78
        $scrollbar->setPosition(5, 0)
79
            ->setSize($this->scrollbarSize, 5)
80
            ->setBackgroundColor('fffa')
81
            ->setFocusBackgroundColor("ffff")
82
            ->addClass('uiScrollbar')
83
            ->addDataAttribute('axis', $this->axis)
84
            ->setAlign('left', 'bottom')
85
            ->setScriptEvents(true);
86
87
        $leftLabel = new Label();
88
        $leftLabel->setPosition(0, 0)
89
            ->setSize(5, 5)
90
            ->setText("⏴")
91
            ->setScriptEvents(true)
92
            ->setAreaColor('aaa')
93
            ->setAreaFocusColor('777')
94
            ->setAlign("left", "bottom");
95
96
        $rightLabel = new Label();
97
        $rightLabel->setPosition($this->length, 0)
98
            ->setSize(5, 5)
99
            ->setText("⏵")
100
            ->setScriptEvents(true)
101
            ->setAreaColor('aaa')
102
            ->setAreaFocusColor('777')
103
            ->setAlign("right", "bottom");
104
105
        $background = new Quad();
106
        $background->setSize($this->length, 5)
107
            ->setAlign("left", "bottom")
108
            ->setBackgroundColor("000a");
109
110
        $frame->addChild($scrollbar);
111
        $frame->addChild($leftLabel);
112
        $frame->addChild($rightLabel);
113
        $frame->addChild($background);
114
115
        return $frame;
116
117
    }
118
119 View Code Duplication
    private function getScrollbarY()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
    {
121
        $frame = new Frame();
122
        $frame->setPosition($this->posX, $this->posY)
123
            ->addClass('uiScrollbarControl');
124
125
126
        $scrollbar = new Quad();
127
        $scrollbar->setPosition(0, -5)
128
            ->setSize(5, $this->scrollbarSize)
129
            ->setBackgroundColor('fffa')
130
            ->setFocusBackgroundColor('ffff')
131
            ->addClass('uiScrollbar')
132
            ->addDataAttribute('axis', $this->axis)
133
            ->setAlign('right', 'top')
134
            ->setScriptEvents(true);
135
136
        $topLabel = new Label();
137
        $topLabel->setPosition(0, 0)
138
            ->setSize(5, 5)
139
            ->setText("⏶")
140
            ->setScriptEvents(true)
141
            ->setAreaColor('aaa')
142
            ->setAreaFocusColor('777')
143
            ->setAlign("right", "top");
144
145
        $bottomLabel = new Label();
146
        $bottomLabel->setPosition(0, -$this->length)
147
            ->setSize(5, 5)
148
            ->setText("⏷")
149
            ->setScriptEvents(true)
150
            ->setAreaColor('aaa')
151
            ->setAreaFocusColor('777')
152
            ->setAlign("right", "bottom");
153
154
        $background = new Quad();
155
        $background->setSize(5, $this->length)
156
            ->setAlign("right", "top")
157
            ->setBackgroundColor("000a");
158
159
        $frame->addChild($scrollbar);
160
        $frame->addChild($topLabel);
161
        $frame->addChild($bottomLabel);
162
        $frame->addChild($background);
163
164
        return $frame;
165
    }
166
167
    /**
168
     * Prepare the given Script for rendering by adding the needed Labels, etc.
169
     *
170
     * @param Script $script Script to prepare
171
     * @return static
172
     */
173
    public function prepare(Script $script)
174
    {
175
        // do nothing
176
    }
177
178
179
}
180