dxx-rebirth/common/2d/box.cpp

115 lines
3.4 KiB
C++
Raw Normal View History

2006-03-20 17:12:09 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING.txt.
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below.
* See COPYING.txt for license details.
2006-03-20 17:12:09 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
2006-03-20 17:12:09 +00:00
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
2014-07-30 03:12:52 +00:00
#include <algorithm>
2006-03-20 17:12:09 +00:00
#include "u_mem.h"
#include "gr.h"
#include "grdef.h"
2015-12-13 18:00:49 +00:00
namespace dcx {
2015-12-05 22:57:23 +00:00
2016-12-29 03:27:10 +00:00
static void gr_ubox0(grs_canvas &canvas, const int left, const int top, const int right, const int bot, const uint8_t color)
2006-03-20 17:12:09 +00:00
{
int d;
2006-03-20 17:12:09 +00:00
unsigned char * ptr2;
2016-12-29 03:27:10 +00:00
const auto rowsize = canvas.cv_bitmap.bm_rowsize;
const auto ptr1 = &canvas.cv_bitmap.get_bitmap_data()[rowsize * top + left];
2006-03-20 17:12:09 +00:00
ptr2 = ptr1;
d = right - left;
std::fill_n(ptr1 + 1, (right - left) - 1, color);
2015-02-14 22:48:27 +00:00
for (uint_fast32_t i = bot - top + 1; i--;)
2006-03-20 17:12:09 +00:00
{
2016-07-06 01:54:24 +00:00
ptr2[0] = color;
ptr2[d] = color;
2016-12-29 03:27:10 +00:00
ptr2 += rowsize;
2006-03-20 17:12:09 +00:00
}
2015-01-29 04:27:37 +00:00
std::fill_n(ptr2 + 1, (right - left) - 1, color);
2006-03-20 17:12:09 +00:00
}
2016-02-12 04:02:28 +00:00
static void gr_ubox12(int left,int top,int right,int bot, const uint8_t color)
2006-03-20 17:12:09 +00:00
{
#if 0 // the following shifts the box up 1 unit in OpenGL
for (int i=top; i<=bot; i++ )
2006-03-20 17:12:09 +00:00
{
gr_upixel( left, i );
gr_upixel( right, i );
}
for (int i=left; i<=right; i++ )
{
gr_upixel( i, top );
gr_upixel( i, bot );
}
#endif
2016-12-29 03:27:10 +00:00
gr_uline(*grd_curcanv, i2f(left), i2f(top), i2f(right), i2f(top), color);
gr_uline(*grd_curcanv, i2f(right), i2f(top), i2f(right), i2f(bot), color);
gr_uline(*grd_curcanv, i2f(left), i2f(top), i2f(left), i2f(bot), color);
gr_uline(*grd_curcanv, i2f(left), i2f(bot), i2f(right), i2f(bot), color);
2006-03-20 17:12:09 +00:00
}
#if DXX_USE_EDITOR
2016-12-29 03:27:10 +00:00
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 uint8_t color)
{
const auto maxy = canvas.cv_bitmap.bm_h - 1;
if (top > maxy)
return;
const auto maxx = canvas.cv_bitmap.bm_w - 1;
if (left > maxx)
return;
if (bot > maxy)
bot = maxy;
if (right > maxx)
right = maxx;
gr_ubox0(canvas, left, top, right, bot, color);
}
2016-02-12 04:02:28 +00:00
static void gr_box12(uint_fast32_t left,uint_fast32_t top,uint_fast32_t right,uint_fast32_t bot, const uint8_t color)
2006-03-20 17:12:09 +00:00
{
if (top > MAXY ) return;
if (left > MAXX ) return;
if (bot > MAXY ) bot = MAXY;
if (right > MAXX ) right = MAXX;
2016-02-12 04:02:28 +00:00
gr_ubox12(left, top, right, bot, color);
2006-03-20 17:12:09 +00:00
}
2016-02-12 04:02:28 +00:00
#endif
2006-03-20 17:12:09 +00:00
2016-02-12 04:02:28 +00:00
void gr_ubox(int left,int top,int right,int bot, const uint8_t color)
2006-03-20 17:12:09 +00:00
{
2016-05-28 17:31:26 +00:00
if (TYPE==bm_mode::linear)
2016-12-29 03:27:10 +00:00
gr_ubox0(*grd_curcanv, left, top, right, bot, color);
2006-03-20 17:12:09 +00:00
else
2016-02-12 04:02:28 +00:00
gr_ubox12(left, top, right, bot, color);
2006-03-20 17:12:09 +00:00
}
#if DXX_USE_EDITOR
2016-02-12 04:02:28 +00:00
void gr_box(uint_fast32_t left,uint_fast32_t top,uint_fast32_t right,uint_fast32_t bot, const uint8_t color)
2006-03-20 17:12:09 +00:00
{
2016-05-28 17:31:26 +00:00
if (TYPE==bm_mode::linear)
2016-12-29 03:27:10 +00:00
gr_box0(*grd_curcanv, left, top, right, bot, color);
2006-03-20 17:12:09 +00:00
else
2016-02-12 04:02:28 +00:00
gr_box12(left, top, right, bot, color);
2006-03-20 17:12:09 +00:00
}
2016-02-12 04:02:28 +00:00
#endif
2015-12-05 22:57:23 +00:00
}