Debian Codegraph @

common/2d/box.cpp

raw
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 #include "gr.h"
23
24 namespace dcx {
25
26 namespace {
27
28 static void gr_ubox0(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const color_palette_index color)
29 {
30 int d;
31 const auto rowsize = canvas.cv_bitmap.bm_rowsize;
32 const auto ptr1 = &canvas.cv_bitmap.get_bitmap_data()[rowsize * top + left];
33 auto ptr2 = ptr1;
34 d = right - left;
35
36 std::fill_n(ptr1 + 1, (right - left) - 1, color);
37 for (uint_fast32_t i = bot - top + 1; i--;)
38 {
39 ptr2[0] = color;
40 ptr2[d] = color;
41 ptr2 += rowsize;
42 }
43 std::fill_n(ptr2 + 1, (right - left) - 1, color);
44 }
45
46 static void gr_ubox12(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const color_palette_index color)
47 {
48 gr_uline(canvas, i2f(left), i2f(top), i2f(right), i2f(top), color);
49 gr_uline(canvas, i2f(right), i2f(top), i2f(right), i2f(bot), color);
50 gr_uline(canvas, i2f(left), i2f(top), i2f(left), i2f(bot), color);
51 gr_uline(canvas, i2f(left), i2f(bot), i2f(right), i2f(bot), color);
52 }
53
54 #if DXX_USE_EDITOR
55 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)
56 {
57 const auto maxy = canvas.cv_bitmap.bm_h - 1;
58 if (top > maxy)
59 return;
60 const auto maxx = canvas.cv_bitmap.bm_w - 1;
61 if (left > maxx)
62 return;
63 if (bot > maxy)
64 bot = maxy;
65 if (right > maxx)
66 right = maxx;
67 gr_ubox0(canvas, left, top, right, bot, color);
68 }
69
70 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)
71 {
72 const auto maxy = canvas.cv_bitmap.bm_h - 1;
73 if (top > maxy)
74 return;
75 const auto maxx = canvas.cv_bitmap.bm_w - 1;
76 if (left > maxx)
77 return;
78 if (bot > maxy)
79 bot = maxy;
80 if (right > maxx)
81 right = maxx;
82 gr_ubox12(canvas, left, top, right, bot, color);
83 }
84 #endif
85
86 }
87
88 void gr_ubox(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const color_palette_index color)
89 {
90 if (canvas.cv_bitmap.get_type() == bm_mode::linear)
91 gr_ubox0(canvas, left, top, right, bot, color);
92 else
93 gr_ubox12(canvas, left, top, right, bot, color);
94 }
95
96 #if DXX_USE_EDITOR
97 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)
98 {
99 if (canvas.cv_bitmap.get_type() == bm_mode::linear)
100 gr_box0(canvas, left, top, right, bot, color);
101 else
102 gr_box12(canvas, left, top, right, bot, color);
103 }
104 #endif
105
106 }