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 <stdlib.h> |
||
| 21 | #include <stdio.h> |
||
| 22 | |||
| 23 | #include "u_mem.h" |
||
| 24 | #include "gr.h" |
||
| 25 | #include "grdef.h" |
||
| 26 | #if DXX_USE_OGL |
||
| 27 | #include "ogl_init.h" |
||
| 28 | #endif |
||
| 29 | #include <memory> |
||
| 30 | |||
| 31 | namespace dcx { |
||
| 32 | |||
| 33 | grs_canvas * grd_curcanv; //active canvas |
||
| 34 | std::unique_ptr<grs_screen> grd_curscreen; //active screen |
||
| 35 | |||
| 36 | grs_canvas_ptr gr_create_canvas(uint16_t w, uint16_t h) |
||
| 37 | { |
||
| 38 | grs_canvas_ptr n = std::make_unique<grs_main_canvas>(); |
||
| 39 | unsigned char *pixdata; |
||
| 40 | MALLOC(pixdata, unsigned char, MAX_BMP_SIZE(w, h)); |
||
| 41 | gr_init_canvas(*n.get(), pixdata, bm_mode::linear, w, h); |
||
| 42 | return n; |
||
| 43 | } |
||
| 44 | |||
| 45 | grs_subcanvas_ptr gr_create_sub_canvas(grs_canvas &canv, uint16_t x, uint16_t y, uint16_t w, uint16_t h) |
||
| 46 | { |
||
| 47 | auto n = std::make_unique<grs_subcanvas>(); |
||
| 48 | gr_init_sub_canvas(*n.get(), canv, x, y, w, h); |
||
| 49 | return n; |
||
| 50 | } |
||
| 51 | |||
| 52 | void gr_init_canvas(grs_canvas &canv, unsigned char *const pixdata, const bm_mode pixtype, const uint16_t w, const uint16_t h) |
||
| 53 | { |
||
| 54 | canv.cv_fade_level = GR_FADE_OFF; |
||
| 55 | canv.cv_font = NULL; |
||
| 56 | canv.cv_font_fg_color = 0; |
||
| 57 | canv.cv_font_bg_color = 0; |
||
| 58 | auto wreal = w; |
||
| 59 | gr_init_bitmap(canv.cv_bitmap, pixtype, 0, 0, w, h, wreal, pixdata); |
||
| 60 | } |
||
| 61 | |||
| 62 | void gr_init_sub_canvas(grs_canvas &n, grs_canvas &src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) |
||
| 63 | { |
||
| 64 | n.cv_fade_level = src.cv_fade_level; |
||
| 65 | n.cv_font = src.cv_font; |
||
| 66 | n.cv_font_fg_color = src.cv_font_fg_color; |
||
| 67 | n.cv_font_bg_color = src.cv_font_bg_color; |
||
| 68 | |||
| 69 | gr_init_sub_bitmap (n.cv_bitmap, src.cv_bitmap, x, y, w, h); |
||
| 70 | } |
||
| 71 | |||
| 72 | grs_main_canvas::~grs_main_canvas() |
||
| 73 | { |
||
| 74 | gr_free_bitmap_data(cv_bitmap); |
||
| 75 | } |
||
| 76 | |||
| 77 | #if DXX_DEBUG_CURRENT_CANVAS_ORIGIN > 0 |
||
| 78 | /* `g_cc_file`, `g_cc_line` are write-only for the program and are meant |
||
| 79 | * to be read back by a debugger. |
||
| 80 | */ |
||
| 81 | __attribute_used |
||
| 82 | static const char *g_cc_file[DXX_DEBUG_CURRENT_CANVAS_ORIGIN]; |
||
| 83 | __attribute_used |
||
| 84 | static unsigned g_cc_line[DXX_DEBUG_CURRENT_CANVAS_ORIGIN]; |
||
| 85 | static unsigned g_cc_which; |
||
| 86 | #endif |
||
| 87 | |||
| 88 | void (gr_set_default_canvas)(DXX_DEBUG_CURRENT_CANVAS_FILE_LINE_COMMA_N_DECL_VARS) |
||
| 89 | { |
||
| 90 | (gr_set_current_canvas)(grd_curscreen->sc_canvas DXX_DEBUG_CURRENT_CANVAS_FILE_LINE_COMMA_L_PASS_VARS); |
||
| 91 | } |
||
| 92 | |||
| 93 | void (gr_set_current_canvas)(grs_canvas &canv DXX_DEBUG_CURRENT_CANVAS_FILE_LINE_COMMA_L_DECL_VARS) |
||
| 94 | { |
||
| 95 | #if DXX_DEBUG_CURRENT_CANVAS_ORIGIN > 0 |
||
| 96 | const auto which = g_cc_which; |
||
| 97 | g_cc_which = (g_cc_which + 1) % DXX_DEBUG_CURRENT_CANVAS_ORIGIN; |
||
| 98 | g_cc_file[which] = file; |
||
| 99 | g_cc_line[which] = line; |
||
| 100 | #endif |
||
| 101 | grd_curcanv = &canv; |
||
| 102 | } |
||
| 103 | |||
| 104 | void gr_set_current_canvas2(grs_canvas *canv DXX_DEBUG_CURRENT_CANVAS_FILE_LINE_COMMA_L_DECL_VARS) |
||
| 105 | { |
||
| 106 | (gr_set_current_canvas_inline)(canv DXX_DEBUG_CURRENT_CANVAS_FILE_LINE_COMMA_L_PASS_VARS); |
||
| 107 | } |
||
| 108 | |||
| 109 | void gr_clear_canvas(grs_canvas &canvas, const color_palette_index color) |
||
| 110 | { |
||
| 111 | gr_rect(canvas, 0, 0, canvas.cv_bitmap.bm_w - 1, canvas.cv_bitmap.bm_h - 1, color); |
||
| 112 | } |
||
| 113 | |||
| 114 | void gr_settransblend(grs_canvas &canvas, const int fade_level, const gr_blend blend_func) |
||
| 115 | { |
||
| 116 | canvas.cv_fade_level = fade_level; |
||
| 117 | #if DXX_USE_OGL |
||
| 118 | ogl_set_blending(blend_func); |
||
| 119 | #endif |
||
| 120 | } |
||
| 121 | |||
| 122 | } |