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

107 lines
3 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include "u_mem.h"
#include "gr.h"
#include "grdef.h"
#if DXX_USE_OGL
#include "ogl_init.h"
#endif
2006-03-20 17:12:09 +00:00
2014-09-06 23:55:43 +00:00
#include "compiler-make_unique.h"
2015-12-13 18:00:49 +00:00
namespace dcx {
2015-12-05 22:57:23 +00:00
2006-03-20 17:12:09 +00:00
grs_canvas * grd_curcanv; //active canvas
2014-11-30 22:09:19 +00:00
std::unique_ptr<grs_screen> grd_curscreen; //active screen
2006-03-20 17:12:09 +00:00
2014-11-15 03:31:41 +00:00
grs_canvas_ptr gr_create_canvas(uint16_t w, uint16_t h)
2006-03-20 17:12:09 +00:00
{
2014-09-17 02:45:12 +00:00
grs_canvas_ptr n = make_unique<grs_main_canvas>();
2015-01-17 04:31:17 +00:00
unsigned char *pixdata;
MALLOC(pixdata, unsigned char, MAX_BMP_SIZE(w, h));
2016-05-28 17:31:26 +00:00
gr_init_canvas(*n.get(), pixdata, bm_mode::linear, w, h);
return n;
2006-03-20 17:12:09 +00:00
}
2015-01-17 18:31:40 +00:00
grs_subcanvas_ptr gr_create_sub_canvas(grs_canvas &canv, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
2006-03-20 17:12:09 +00:00
{
2014-09-06 23:55:43 +00:00
auto n = make_unique<grs_subcanvas>();
2015-01-17 18:31:40 +00:00
gr_init_sub_canvas(*n.get(), canv, x, y, w, h);
return n;
2006-03-20 17:12:09 +00:00
}
2016-05-28 17:31:27 +00:00
void gr_init_canvas(grs_canvas &canv, unsigned char *const pixdata, const bm_mode pixtype, const uint16_t w, const uint16_t h)
2006-03-20 17:12:09 +00:00
{
2015-01-17 18:31:40 +00:00
canv.cv_fade_level = GR_FADE_OFF;
canv.cv_font = NULL;
canv.cv_font_fg_color = 0;
canv.cv_font_bg_color = 0;
2014-11-15 03:31:41 +00:00
auto wreal = w;
2015-01-17 18:31:40 +00:00
gr_init_bitmap(canv.cv_bitmap, pixtype, 0, 0, w, h, wreal, pixdata);
2006-03-20 17:12:09 +00:00
}
2015-01-17 18:31:40 +00:00
void gr_init_sub_canvas(grs_canvas &n, grs_canvas &src, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
2006-03-20 17:12:09 +00:00
{
2015-01-17 18:31:40 +00:00
n.cv_fade_level = src.cv_fade_level;
n.cv_font = src.cv_font;
n.cv_font_fg_color = src.cv_font_fg_color;
n.cv_font_bg_color = src.cv_font_bg_color;
gr_init_sub_bitmap (n.cv_bitmap, src.cv_bitmap, x, y, w, h);
2006-03-20 17:12:09 +00:00
}
2014-09-17 02:45:12 +00:00
grs_main_canvas::~grs_main_canvas()
2006-03-20 17:12:09 +00:00
{
2014-11-30 22:09:20 +00:00
gr_free_bitmap_data(cv_bitmap);
2006-03-20 17:12:09 +00:00
}
void gr_set_default_canvas()
2006-03-20 17:12:09 +00:00
{
grd_curcanv = &(grd_curscreen->sc_canvas);
}
void gr_set_current_canvas(grs_canvas &canv)
{
grd_curcanv = &canv;
}
void _gr_set_current_canvas(grs_canvas *canv)
{
_gr_set_current_canvas_inline(canv);
2006-03-20 17:12:09 +00:00
}
2017-01-01 00:45:45 +00:00
void gr_clear_canvas(grs_canvas &canvas, color_t color)
2006-03-20 17:12:09 +00:00
{
2017-01-01 00:45:45 +00:00
gr_rect(canvas, 0, 0, canvas.cv_bitmap.bm_w - 1, canvas.cv_bitmap.bm_h - 1, color);
2006-03-20 17:12:09 +00:00
}
2017-01-01 00:45:44 +00:00
void gr_settransblend(grs_canvas &canvas, const int fade_level, const uint8_t blend_func)
{
2017-01-01 00:45:44 +00:00
canvas.cv_fade_level = fade_level;
#if DXX_USE_OGL
2016-02-12 04:02:28 +00:00
ogl_set_blending(blend_func);
#endif
}
2015-12-05 22:57:23 +00:00
}