Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * Portions of this file are copyright Rebirth contributors and licensed as
3
 * described in COPYING.txt.
4
 * Portions of this file are copyright Parallax Software and licensed
5
 * according to the Parallax license below.
6
 * See COPYING.txt for license details.
7
 
8
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
10
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
16
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
18
*/
19
 
20
#include <algorithm>
21
#include "u_mem.h"
22
 
23
 
24
#include "gr.h"
25
#include "grdef.h"
26
 
27
namespace dcx {
28
 
29
static void gr_ubox0(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const color_palette_index color)
30
{
31
        int d;
32
        const auto rowsize = canvas.cv_bitmap.bm_rowsize;
33
        const auto ptr1 = &canvas.cv_bitmap.get_bitmap_data()[rowsize * top + left];
34
        auto ptr2 = ptr1;
35
        d = right - left;
36
 
37
        std::fill_n(ptr1 + 1, (right - left) - 1, color);
38
        for (uint_fast32_t i = bot - top + 1; i--;)
39
        {
40
                ptr2[0] = color;
41
                ptr2[d] = color;
42
                ptr2 += rowsize;
43
        }
44
        std::fill_n(ptr2 + 1, (right - left) - 1, color);
45
}
46
 
47
static void gr_ubox12(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const color_palette_index color)
48
{
49
        gr_uline(canvas, i2f(left), i2f(top), i2f(right), i2f(top), color);
50
        gr_uline(canvas, i2f(right), i2f(top), i2f(right), i2f(bot), color);
51
        gr_uline(canvas, i2f(left), i2f(top), i2f(left), i2f(bot), color);
52
        gr_uline(canvas, i2f(left), i2f(bot), i2f(right), i2f(bot), color);
53
}
54
 
55
#if DXX_USE_EDITOR
56
static void gr_box0(grs_canvas &canvas, const uint_fast32_t left, const uint_fast32_t top, uint_fast32_t right, uint_fast32_t bot, const color_palette_index color)
57
{
58
        const auto maxy = canvas.cv_bitmap.bm_h - 1;
59
        if (top > maxy)
60
                return;
61
        const auto maxx = canvas.cv_bitmap.bm_w - 1;
62
        if (left > maxx)
63
                return;
64
        if (bot > maxy)
65
                bot = maxy;
66
        if (right > maxx)
67
                right = maxx;
68
        gr_ubox0(canvas, left, top, right, bot, color);
69
}
70
 
71
static void gr_box12(grs_canvas &canvas, const uint_fast32_t left, const uint_fast32_t top, uint_fast32_t right, uint_fast32_t bot, const color_palette_index color)
72
{
73
        const auto maxy = canvas.cv_bitmap.bm_h - 1;
74
        if (top > maxy)
75
                return;
76
        const auto maxx = canvas.cv_bitmap.bm_w - 1;
77
        if (left > maxx)
78
                return;
79
        if (bot > maxy)
80
                bot = maxy;
81
        if (right > maxx)
82
                right = maxx;
83
        gr_ubox12(canvas, left, top, right, bot, color);
84
}
85
#endif
86
 
87
void gr_ubox(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const color_palette_index color)
88
{
89
        if (canvas.cv_bitmap.get_type() == bm_mode::linear)
90
                gr_ubox0(canvas, left, top, right, bot, color);
91
    else
92
                gr_ubox12(canvas, left, top, right, bot, color);
93
}
94
 
95
#if DXX_USE_EDITOR
96
void gr_box(grs_canvas &canvas, const uint_fast32_t left, const uint_fast32_t top, const uint_fast32_t right, const uint_fast32_t bot, const color_palette_index color)
97
{
98
        if (canvas.cv_bitmap.get_type() == bm_mode::linear)
99
                gr_box0(canvas, left, top, right, bot, color);
100
        else
101
                gr_box12(canvas, left, top, right, bot, color);
102
}
103
#endif
104
 
105
}