| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/2dlib/viewport.cpp $ |
| 21 | * $Revision: 7 $ |
| 22 | * $Date: 12/19/97 5:23p $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * this class manages a specific viewing region of either a screen or bitmap. |
| 26 | * functions such as font setting and bitmap bltting are supported |
| 27 | * under this class. |
| 28 | * |
| 29 | * this class also spawns a pen object which effectively locks the screen or |
| 30 | * bitmap associated with it. |
| 31 | * |
| 32 | * $Log: /DescentIII/Main/2dlib/viewport.cpp $ |
| 33 | * |
| 34 | * 7 12/19/97 5:23p Samir |
| 35 | * Cleaned up a lot of code to call renderer code. |
| 36 | * |
| 37 | * 6 12/19/97 12:32p Samir |
| 38 | * Support alpha for text. Stubbed out clipping support. |
| 39 | * |
| 40 | * 5 11/18/97 12:32p Samir |
| 41 | * Took out useless lines. |
| 42 | * |
| 43 | * 4 11/14/97 12:05p Samir |
| 44 | * don't free font, just init it. |
| 45 | * |
| 46 | * 20 6/13/97 1:17p Samir |
| 47 | * Fucked up last checkin |
| 48 | * |
| 49 | * 19 6/13/97 1:00p Samir |
| 50 | * lock when called will always lock, so if the lock fails, then it's not |
| 51 | * viewport's job to fix it. |
| 52 | * |
| 53 | * 18 6/12/97 6:29p Samir |
| 54 | * DDGR v2.0 Changes in 2d system implemented. |
| 55 | * |
| 56 | * 17 6/06/97 12:18p Samir |
| 57 | * OpenGL HACKS to call renderer for some drawing functions. Must fix. |
| 58 | * |
| 59 | * 16 5/15/97 3:47p Samir |
| 60 | * Fixed lock_clear. |
| 61 | * |
| 62 | * 15 5/13/97 6:36p Samir |
| 63 | * added lock_clear functions. |
| 64 | * |
| 65 | * 14 4/01/97 4:37p Samir |
| 66 | * Simply better circle functions using viewport line and pixel functions. |
| 67 | * made an hline function that clips and a setpixel function that clips. |
| 68 | * |
| 69 | * 13 3/28/97 3:07p Samir |
| 70 | * Clear function now takes a color |
| 71 | * |
| 72 | * 12 3/28/97 2:50p Samir |
| 73 | * Fixed clip_rect fuckup. |
| 74 | * |
| 75 | * 11 2/18/97 1:04p Samir |
| 76 | * Changed prototype for setpixel |
| 77 | * |
| 78 | * 10 2/18/97 11:38a Samir |
| 79 | * Added getpixel and setpixel to grViewport. NOTE: you must lock the |
| 80 | * viewport when doing these ops. |
| 81 | * |
| 82 | * 9 2/04/97 4:56p Samir |
| 83 | * added 'hack' in viewport lock. see the function to see what I mean. |
| 84 | * |
| 85 | * 8 2/04/97 12:50p Samir |
| 86 | * Viewports now lock on CLIP_LEFT, CLIP_TOP |
| 87 | * |
| 88 | * 7 2/04/97 11:14a Samir |
| 89 | * Improved clipping system by adding a separate clipport based off of the |
| 90 | * viewport's rectangle in it's parent surface |
| 91 | * |
| 92 | * 6 2/03/97 7:56p Samir |
| 93 | * |
| 94 | * 5 1/31/97 11:02a Samir |
| 95 | * Adjusted clear function to use x,y,width,height parms. |
| 96 | * |
| 97 | * 4 1/30/97 6:28p Samir |
| 98 | * Stupid me, left some dummy text causing errors. |
| 99 | * |
| 100 | * 3 1/30/97 6:01p Samir |
| 101 | * The partition of memory and os surfaces as well as the change in |
| 102 | * ddgr_surface structure and all related changes. |
| 103 | * |
| 104 | * $NoKeywords: $ |
| 105 | */ |
| 106 | |
| 107 | #include <algorithm> |
| 108 | |
| 109 | #include "gr.h"cxx . . $ `<file>/2dlib/gr.h`/ |
| 110 | #include "lib2d.h"cxx . . $ `<file>/2dlib/lib2d.h`/ |
| 111 | #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/ |
| 112 | |
| 113 | #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 114 | |
| 115 | #define CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`! (vp_InitLeft + vp_Left) |
| 116 | #define CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`! (vp_InitTop + vp_Top) |
| 117 | #define CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`! (vp_InitLeft + vp_Right) |
| 118 | #define CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`! (vp_InitTop + vp_Bottom) |
| 119 | |
| 120 | int grViewportcxx . . $ grViewport#::vp_Lockedcxx . . $ grViewport#vp_Locked. = 0; |
| 121 | grViewportcxx . . $ grViewport# *grViewportcxx . . $ grViewport#::vp_Current_VPcxx . . $ grViewport#vp_Current_VP. = nullptr; |
| 122 | |
| 123 | // --------------------------------------------------------------------------- |
| 124 | // grViewport constructor and destructor |
| 125 | // --------------------------------------------------------------------------- |
| 126 | |
| 127 | grViewportcxx . . $ grViewport#::grViewportcxx . . $ grViewport#grViewport(d2b842a68930ff26).(grScreencxx . . $ grScreen# *scr_parent) { |
| 128 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(scr_parent != nullptr); |
| 129 | |
| 130 | sf_Parentcxx . . $ grViewport#sf_Parent. = scr_parent; // screen is a child of grSurface, so we |
| 131 | // can do this. |
| 132 | vp_InitLeftcxx . . $ grViewport#vp_InitLeft. = vp_Leftcxx . . $ grViewport#vp_Left. = 0; // define bounds = entire screen |
| 133 | vp_InitTopcxx . . $ grViewport#vp_InitTop. = vp_Topcxx . . $ grViewport#vp_Top. = 0; |
| 134 | vp_InitRightcxx . . $ grViewport#vp_InitRight. = vp_Rightcxx . . $ grViewport#vp_Right. = sf_Parentcxx . . $ grViewport#sf_Parent.->widthcxx . . $ grSurface#width(455f465bc33b4cdf).() - 1; |
| 135 | vp_InitBottomcxx . . $ grViewport#vp_InitBottom. = vp_Bottomcxx . . $ grViewport#vp_Bottom. = sf_Parentcxx . . $ grViewport#sf_Parent.->heightcxx . . $ grSurface#height(455f465bc33b4cdf).() - 1; |
| 136 | |
| 137 | // initialize font object |
| 138 | // setup text settings. |
| 139 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[0] = GR_WHITEcxx . . $ GR_WHITE.; |
| 140 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[1] = GR_WHITEcxx . . $ GR_WHITE.; |
| 141 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[2] = GR_WHITEcxx . . $ GR_WHITE.; |
| 142 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[3] = GR_WHITEcxx . . $ GR_WHITE.; |
| 143 | char_Propscxx . . $ grViewport#char_Props..alphacxx . . $ tCharProperties#alpha. = 255; |
| 144 | |
| 145 | text_Spacingcxx . . $ grViewport#text_Spacing. = 1; |
| 146 | text_Line_spacingcxx . . $ grViewport#text_Line_spacing. = 1; |
| 147 | text_Fontcxx . . $ grViewport#text_Font..initcxx . . $ grFont#init(85c52e162fed56f9).(DEFAULT_FONTcxx . . $ `2dlib/gr.h:150:9`!); |
| 148 | } |
| 149 | |
| 150 | grViewportcxx . . $ grViewport#::grViewportcxx . . $ grViewport#grViewport(bfea4a94c1105442).(grSurfacecxx . . $ grSurface# *sf_parent) { |
| 151 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(sf_parent != nullptr); |
| 152 | |
| 153 | sf_Parentcxx . . $ grViewport#sf_Parent. = sf_parent; |
| 154 | |
| 155 | vp_InitLeftcxx . . $ grViewport#vp_InitLeft. = vp_Leftcxx . . $ grViewport#vp_Left. = 0; // define bounds = entire bitmap |
| 156 | vp_InitTopcxx . . $ grViewport#vp_InitTop. = vp_Topcxx . . $ grViewport#vp_Top. = 0; |
| 157 | vp_InitRightcxx . . $ grViewport#vp_InitRight. = vp_Rightcxx . . $ grViewport#vp_Right. = sf_Parentcxx . . $ grViewport#sf_Parent.->widthcxx . . $ grSurface#width(455f465bc33b4cdf).() - 1; |
| 158 | vp_InitBottomcxx . . $ grViewport#vp_InitBottom. = vp_Bottomcxx . . $ grViewport#vp_Bottom. = sf_Parentcxx . . $ grViewport#sf_Parent.->heightcxx . . $ grSurface#height(455f465bc33b4cdf).() - 1; |
| 159 | |
| 160 | // initialize font object |
| 161 | // setup text settings. |
| 162 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[0] = GR_WHITEcxx . . $ GR_WHITE.; |
| 163 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[1] = GR_WHITEcxx . . $ GR_WHITE.; |
| 164 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[2] = GR_WHITEcxx . . $ GR_WHITE.; |
| 165 | char_Propscxx . . $ grViewport#char_Props..colcxx . . $ tCharProperties#col.[3] = GR_WHITEcxx . . $ GR_WHITE.; |
| 166 | char_Propscxx . . $ grViewport#char_Props..alphacxx . . $ tCharProperties#alpha. = 255; |
| 167 | |
| 168 | text_Spacingcxx . . $ grViewport#text_Spacing. = 1; |
| 169 | text_Line_spacingcxx . . $ grViewport#text_Line_spacing. = 1; |
| 170 | text_Fontcxx . . $ grViewport#text_Font..initcxx . . $ grFont#init(85c52e162fed56f9).(DEFAULT_FONTcxx . . $ `2dlib/gr.h:150:9`!); |
| 171 | } |
| 172 | |
| 173 | grViewportcxx . . $ grViewport#::~cxx . . $ grViewport#`~grViewport`(ced63f7c635d850d).grViewportcxx . . $ grViewport#() { |
| 174 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(!vp_Locked); // Viewport shouldn't be locked here! |
| 175 | |
| 176 | // text_Font.free(); |
| 177 | } |
| 178 | |
| 179 | void grViewportcxx . . $ grViewport#::set_clipping_rectcxx . . $ grViewport#set_clipping_rect(748afa4755bc9595).(int left, int top, int right, int bottom) { |
| 180 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(!vp_Locked); // YOU CANT DO THIS WHILE LOCKED! |
| 181 | |
| 182 | // these are local to the viewport. |
| 183 | // vp_Left = left; |
| 184 | // vp_Top = top; |
| 185 | // vp_Right = right; |
| 186 | // vp_Bottom = bottom; |
| 187 | } |
| 188 | |
| 189 | // these functions set and restore the state of the viewport (font, colors, etc.) |
| 190 | void grViewportcxx . . $ grViewport#::get_statecxx . . $ grViewport#get_state(2ac10c8cd52dc500).(tVPStatecxx . . $ tVPState# *state) { |
| 191 | state->fontcxx . . $ tVPState#font. =cxx . . $ grFont#`operator=`(4193a2fe8f1b874f). text_Fontcxx . . $ grViewport#text_Font.; |
| 192 | state->text_spacingcxx . . $ tVPState#text_spacing. = text_Spacingcxx . . $ grViewport#text_Spacing.; |
| 193 | state->text_line_spacingcxx . . $ tVPState#text_line_spacing. = text_Line_spacingcxx . . $ grViewport#text_Line_spacing.; |
| 194 | get_char_propertiescxx . . $ grViewport#get_char_properties(9bd9ddac0cef7fd2).(&state->chpropscxx . . $ tVPState#chprops.); |
| 195 | } |
| 196 | |
| 197 | void grViewportcxx . . $ grViewport#::set_statecxx . . $ grViewport#set_state(3da10eeccd9af7c3).(const tVPStatecxx . . $ tVPState# *state) { |
| 198 | set_char_propertiescxx . . $ grViewport#set_char_properties(5133d185afc50666).(GR_VPCP_ALLcxx . . $ `2dlib/gr.h:140:9`!, &state->chpropscxx . . $ tVPState#chprops.); |
| 199 | text_Fontcxx . . $ grViewport#text_Font. =cxx . . $ grFont#`operator=`(4193a2fe8f1b874f). state->fontcxx . . $ tVPState#font.; |
| 200 | text_Spacingcxx . . $ grViewport#text_Spacing. = state->text_spacingcxx . . $ tVPState#text_spacing.; |
| 201 | text_Line_spacingcxx . . $ grViewport#text_Line_spacing. = state->text_line_spacingcxx . . $ tVPState#text_line_spacing.; |
| 202 | } |
| 203 | |
| 204 | // --------------------------------------------------------------------------- |
| 205 | // font functions |
| 206 | // --------------------------------------------------------------------------- |
| 207 | |
| 208 | // --------------------------------------------------------------------------- |
| 209 | // bltting functions |
| 210 | // --------------------------------------------------------------------------- |
| 211 | |
| 212 | void grViewportcxx . . $ grViewport#::clearcxx . . $ grViewport#clear(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) // clear with background color |
| 213 | { |
| 214 | sf_Parentcxx . . $ grViewport#sf_Parent.->clearcxx . . $ grSurface#clear(6fb2c7d311165c4f).(CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`!, CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!, (vp_Rightcxx . . $ grViewport#vp_Right. - vp_Leftcxx . . $ grViewport#vp_Left.) + 1, (vp_Bottomcxx . . $ grViewport#vp_Bottom. - vp_Topcxx . . $ grViewport#vp_Top.) + 1, col); |
| 215 | } |
| 216 | |
| 217 | void grViewportcxx . . $ grViewport#::bltcxx . . $ grViewport#blt(3c4a031b05aa6aa3).(int dx, int dy, grSurfacecxx . . $ grSurface# *ssf) { |
| 218 | int x1, y1, x2, y2, sx, sy; |
| 219 | |
| 220 | // perform rectangular clipping |
| 221 | x1 = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(dx); |
| 222 | y1 = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(dy); |
| 223 | x2 = x1 + ssf->widthcxx . . $ grSurface#width(455f465bc33b4cdf).() - 1; |
| 224 | y2 = y1 + ssf->heightcxx . . $ grSurface#height(455f465bc33b4cdf).() - 1; |
| 225 | |
| 226 | if (x1 < CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`!) |
| 227 | sx = CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`! - x1; |
| 228 | else |
| 229 | sx = 0; |
| 230 | if (y1 < CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!) |
| 231 | sy = CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`! - y1; |
| 232 | else |
| 233 | sy = 0; |
| 234 | |
| 235 | if (clip_rectcxx . . $ grViewport#clip_rect(3139a728715e5e03).(x1, y1, x2, y2) == 2) |
| 236 | return; |
| 237 | |
| 238 | sf_Parentcxx . . $ grViewport#sf_Parent.->bltcxx . . $ grSurface#blt(ff120d6cc88a52cd).(x1, y1, ssf, sx, sy, x2 - x1 + 1, y2 - y1 + 1); |
| 239 | } |
| 240 | |
| 241 | void grViewportcxx . . $ grViewport#::bltcxx . . $ grViewport#blt(ff120d6cc88a52cd).(int dx, int dy, grSurfacecxx . . $ grSurface# *ssf, int sx, int sy, int sw, int sh) { |
| 242 | int x1, y1, x2, y2; |
| 243 | |
| 244 | x1 = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(dx); |
| 245 | y1 = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(dy); |
| 246 | x2 = x1 + sw - 1; |
| 247 | y2 = y1 + sh - 1; |
| 248 | if (clip_rectcxx . . $ grViewport#clip_rect(3139a728715e5e03).(x1, y1, x2, y2) == 2) |
| 249 | return; |
| 250 | |
| 251 | sf_Parentcxx . . $ grViewport#sf_Parent.->bltcxx . . $ grSurface#blt(ff120d6cc88a52cd).(x1, y1, ssf, sx, sy, x2 - x1 + 1, y2 - y1 + 1); |
| 252 | } |
| 253 | |
| 254 | // --------------------------------------------------------------------------- |
| 255 | // general lock creation functions |
| 256 | // --------------------------------------------------------------------------- |
| 257 | |
| 258 | grSurfacecxx . . $ grSurface# *grViewportcxx . . $ grViewport#::lockcxx . . $ grViewport#lock(acdc12544967986e).() { |
| 259 | int rowsize; |
| 260 | |
| 261 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(!vp_Locked); |
| 262 | |
| 263 | sf_Parentcxx . . $ grViewport#sf_Parent.->lockcxx . . $ grSurface#lock(f35eb304381040d9).(CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`!, CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!, &rowsize); |
| 264 | vp_Lockedcxx . . $ grViewport#vp_Locked. = 1; |
| 265 | |
| 266 | if (vp_Lockedcxx . . $ grViewport#vp_Locked.) { |
| 267 | pen_Objcxx . . $ grViewport#pen_Obj..sfcxx . . $ gr_pen#sf. = &sf_Parentcxx . . $ grViewport#sf_Parent.->ddsfObjcxx . . $ grSurface#ddsfObj.; |
| 268 | pen_Objcxx . . $ grViewport#pen_Obj..rowsizecxx . . $ gr_pen#rowsize. = sf_Parentcxx . . $ grViewport#sf_Parent.->rowsizecxx . . $ grSurface#rowsize(455f465bc33b4cdf).(); |
| 269 | pen_Objcxx . . $ grViewport#pen_Obj..rgbcolorcxx . . $ gr_pen#rgbcolor. = GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(255, 255, 255); |
| 270 | |
| 271 | // SUPERHACK. Pen functions don't use the adjusted pointer of grSurface, but use the |
| 272 | // base data pointer provided by locking the entire surface at (0,0). Pen functions |
| 273 | // use global coordinates, so they can calculate the adjusted pointer themselves. This |
| 274 | // makes global_x and global_y consisitent with the surface base pointer. This problem |
| 275 | // was caused by the clipping rect being a virtual viewport within a viewport to make |
| 276 | // the 3d system work better. |
| 277 | pen_Objcxx . . $ grViewport#pen_Obj..datacxx . . $ gr_pen#data. = sf_Parentcxx . . $ grViewport#sf_Parent.->m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.; |
| 278 | } |
| 279 | |
| 280 | grViewportcxx . . $ grViewport#::vp_Current_VPcxx . . $ grViewport#vp_Current_VP. = this; |
| 281 | |
| 282 | return sf_Parentcxx . . $ grViewport#sf_Parent.; |
| 283 | } |
| 284 | |
| 285 | void grViewportcxx . . $ grViewport#::unlockcxx . . $ grViewport#unlock(49f6e7a06ebc5aa8).() { |
| 286 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 287 | |
| 288 | sf_Parentcxx . . $ grViewport#sf_Parent.->unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).(); |
| 289 | vp_Lockedcxx . . $ grViewport#vp_Locked. = 0; |
| 290 | |
| 291 | grViewportcxx . . $ grViewport#::vp_Current_VPcxx . . $ grViewport#vp_Current_VP. = nullptr; |
| 292 | |
| 293 | pen_Objcxx . . $ grViewport#pen_Obj..datacxx . . $ gr_pen#data. = nullptr; |
| 294 | pen_Objcxx . . $ grViewport#pen_Obj..rowsizecxx . . $ gr_pen#rowsize. = 0; |
| 295 | pen_Objcxx . . $ grViewport#pen_Obj..sfcxx . . $ gr_pen#sf. = nullptr; |
| 296 | } |
| 297 | |
| 298 | // --------------------------------------------------------------------------- |
| 299 | // miscellaneous viewport functions |
| 300 | // --------------------------------------------------------------------------- |
| 301 | |
| 302 | void grViewportcxx . . $ grViewport#::setpixelcxx . . $ grViewport#setpixel(8c880916ccadf15d).(ddgr_colorcxx . . $ ddgr_color# col, int x, int y) { |
| 303 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 304 | |
| 305 | rend_SetPixelcxx . . $ rend_SetPixel(8c880916ccadf15d).(col, x, y); |
| 306 | } |
| 307 | |
| 308 | void grViewportcxx . . $ grViewport#::setpixelccxx . . $ grViewport#setpixelc(8c880916ccadf15d).(ddgr_colorcxx . . $ ddgr_color# col, int x, int y) { |
| 309 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 310 | |
| 311 | if (x < CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`! || x > CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`! || y < CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`! || y > CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`!) |
| 312 | return; |
| 313 | |
| 314 | rend_SetPixelcxx . . $ rend_SetPixel(8c880916ccadf15d).(col, x, y); |
| 315 | } |
| 316 | |
| 317 | ddgr_colorcxx . . $ ddgr_color# grViewportcxx . . $ grViewport#::getpixelcxx . . $ grViewport#getpixel(58c590d1186ea715).(int x, int y) { |
| 318 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 319 | |
| 320 | return rend_GetPixelcxx . . $ rend_GetPixel(58c590d1186ea715).(x, y); |
| 321 | } |
| 322 | |
| 323 | ddgr_colorcxx . . $ ddgr_color# grViewportcxx . . $ grViewport#::getpixelccxx . . $ grViewport#getpixelc(58c590d1186ea715).(int x, int y) { |
| 324 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 325 | |
| 326 | if (x < CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`! || x > CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`! || y < CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`! || y > CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`!) |
| 327 | return 0; |
| 328 | |
| 329 | return rend_GetPixelcxx . . $ rend_GetPixel(58c590d1186ea715).(x, y); |
| 330 | } |
| 331 | |
| 332 | void grViewportcxx . . $ grViewport#::lock_clearcxx . . $ grViewport#lock_clear(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) { |
| 333 | int l = CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`!, t = CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!, r = CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`!, b = CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`!; |
| 334 | ddgr_surfacecxx . . $ ddgr_surface# *memsurf = sf_Parentcxx . . $ grViewport#sf_Parent.->scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.; |
| 335 | |
| 336 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 337 | |
| 338 | if (sf_Parentcxx . . $ grViewport#sf_Parent.->ddsfObjcxx . . $ grSurface#ddsfObj..flagscxx . . $ ddgr_surface#flags. & SURFFLAG_RENDERERcxx . . $ SURFFLAG_RENDERER.) { |
| 339 | rend_FillRectcxx . . $ rend_FillRect(fe09a4b73d8d396f).(col, l, t, r, b); |
| 340 | } else { |
| 341 | memsurf->bppcxx . . $ ddgr_surface#bpp. = pen_Objcxx . . $ grViewport#pen_Obj..sfcxx . . $ gr_pen#sf.->bppcxx . . $ ddgr_surface#bpp.; |
| 342 | |
| 343 | gr_mem_surf_Initcxx . . $ gr_mem_surf_Init(29b5e7245e149caf).(memsurf, pen_Objcxx . . $ grViewport#pen_Obj..datacxx . . $ gr_pen#data., pen_Objcxx . . $ grViewport#pen_Obj..rowsizecxx . . $ gr_pen#rowsize.); |
| 344 | gr_mem_surf_Clearcxx . . $ gr_mem_surf_Clear(18895a2c8f8b731a).(memsurf, col, l, t, r - l + 1, b - t + 1); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void grViewportcxx . . $ grViewport#::lock_clearcxx . . $ grViewport#lock_clear(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# col, int l, int t, int r, int b) { |
| 349 | ddgr_surfacecxx . . $ ddgr_surface# *memsurf = sf_Parentcxx . . $ grViewport#sf_Parent.->scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.; |
| 350 | |
| 351 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked); |
| 352 | |
| 353 | l = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(l); |
| 354 | t = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(t); |
| 355 | r = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(r); |
| 356 | b = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(b); |
| 357 | |
| 358 | clip_rectcxx . . $ grViewport#clip_rect(3139a728715e5e03).(l, t, r, b); |
| 359 | |
| 360 | if (sf_Parentcxx . . $ grViewport#sf_Parent.->ddsfObjcxx . . $ grSurface#ddsfObj..flagscxx . . $ ddgr_surface#flags. & SURFFLAG_RENDERERcxx . . $ SURFFLAG_RENDERER.) { |
| 361 | rend_FillRectcxx . . $ rend_FillRect(fe09a4b73d8d396f).(col, l, t, r, b); |
| 362 | } else { |
| 363 | memsurf->bppcxx . . $ ddgr_surface#bpp. = pen_Objcxx . . $ grViewport#pen_Obj..sfcxx . . $ gr_pen#sf.->bppcxx . . $ ddgr_surface#bpp.; |
| 364 | gr_mem_surf_Initcxx . . $ gr_mem_surf_Init(29b5e7245e149caf).(memsurf, pen_Objcxx . . $ grViewport#pen_Obj..datacxx . . $ gr_pen#data., pen_Objcxx . . $ grViewport#pen_Obj..rowsizecxx . . $ gr_pen#rowsize.); |
| 365 | gr_mem_surf_Clearcxx . . $ gr_mem_surf_Clear(18895a2c8f8b731a).(memsurf, col, l, t, r - l + 1, b - t + 1); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | // --------------------------------------------------------------------------- |
| 370 | // private functions |
| 371 | // --------------------------------------------------------------------------- |
| 372 | |
| 373 | // grPen::clip_rect |
| 374 | // returns 2 if totally clipped |
| 375 | // returns 1 if partially clipped |
| 376 | // returns 0 if not clipped. |
| 377 | |
| 378 | int grViewportcxx . . $ grViewport#::clip_rectcxx . . $ grViewport#clip_rect(3139a728715e5e03).(int &l, int &t, int &r, int &b) { |
| 379 | int clipped = 0; |
| 380 | |
| 381 | if (l > r) |
| 382 | stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(l, r); |
| 383 | if (t > b) |
| 384 | stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(t, b); |
| 385 | |
| 386 | if (l > CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`! || t > CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`! || r < CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`! || b < CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!) |
| 387 | return 2; |
| 388 | |
| 389 | if (l < CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`!) { |
| 390 | l = CLIP_LEFTcxx . . $ `2dlib/viewport.cpp:115:9`!; |
| 391 | clipped = 1; |
| 392 | } |
| 393 | if (t < CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!) { |
| 394 | t = CLIP_TOPcxx . . $ `2dlib/viewport.cpp:116:9`!; |
| 395 | clipped = 1; |
| 396 | } |
| 397 | if (r > CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`!) { |
| 398 | r = CLIP_RIGHTcxx . . $ `2dlib/viewport.cpp:117:9`!; |
| 399 | clipped = 1; |
| 400 | } |
| 401 | if (b > CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`!) { |
| 402 | b = CLIP_BOTTOMcxx . . $ `2dlib/viewport.cpp:118:9`!; |
| 403 | clipped = 1; |
| 404 | } |
| 405 | |
| 406 | return clipped; |
| 407 | } |