This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ONScripter_directdraw.cpp
108 lines (97 loc) · 3.38 KB
/
ONScripter_directdraw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* -*- C++ -*-
*
* ONScripter_directdraw.cpp
*
* Copyright (C) 2015-2016 jh10001 <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ONScripter.h"
#include <string.h>
#include <assert.h>
extern ONScripter ons;
void DirectDraw::loadTexture(int no, const char *filename)
{
assert(no >= 0 && no < MAX_TEXTURE_NUM);
if (!texture_info[no])
{
SDL_DestroyTexture(texture_info[no]);
texture_info[no] = NULL;
}
char s[256];
strncpy(s, filename, sizeof(s));
bool has_alpha;
int location;
SDL_Surface *surface = ons.createSurfaceFromFile(s, &has_alpha, &location);
if (surface) texture_info[no] = SDL_CreateTextureFromSurface(ons.renderer, surface);
}
void DirectDraw::deleteTexture(int no)
{
assert(no >= 0 && no < MAX_TEXTURE_NUM);
if (!texture_info[no]) return;
SDL_DestroyTexture(texture_info[no]);
texture_info[no] = NULL;
}
void DirectDraw::draw(int no, int dx, int dy, int w, int h, int sx, int sy, int alpha, bool add)
{
assert(no >= 0 && no < MAX_TEXTURE_NUM);
if (!texture_info[no]) return;
SDL_SetTextureBlendMode(texture_info[no], add ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(texture_info[no], alpha);
SDL_Rect src_rect = {sx, sy, w, h}, dst_rect = {dx, dy, w, h};
ons.setScreenDirty(true);
SDL_RenderCopy(ons.renderer, texture_info[no], &src_rect, &dst_rect);
}
void DirectDraw::draw2(int no, int dcx, int dcy, int sx, int sy, int w, int h, float xs, float ys, float rot, int alpha, bool add)
{
assert(no >= 0 && no < MAX_TEXTURE_NUM);
if (!texture_info[no]) return;
SDL_SetTextureBlendMode(texture_info[no], add ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(texture_info[no], alpha);
int dx = dcx-w/2*xs, dy = dcy-h/2*ys;
SDL_Rect src_rect = {sx, sy, w, h}, dst_rect = {dx, dy, (int)(w*xs), (int)(h*ys)};
ons.setScreenDirty(true);
SDL_RenderCopyEx(ons.renderer, texture_info[no], &src_rect, &dst_rect, rot, NULL, SDL_FLIP_NONE);
}
void DirectDraw::fill(int lx, int ly, int rx, int ry, int r, int g, int b)
{
SDL_SetRenderDrawColor(ons.renderer, r, g, b , SDL_ALPHA_OPAQUE);
SDL_Rect rect;
rect.x = lx;
rect.y = ly;
rect.w = rx - lx;
rect.h = ry - ly;
SDL_RenderFillRect(ons.renderer, &rect);
}
void DirectDraw::getTextureSize(int no, int &w, int &h)
{
assert(no >= 0 && no < MAX_TEXTURE_NUM);
if (!texture_info[no])
{
w = 0;
h = 0;
return;
}
SDL_QueryTexture(texture_info[no], NULL, NULL, &w, &h);
}
void DirectDraw::present()
{
SDL_RenderPresent(ons.renderer);
}
void DirectDraw::clear()
{
SDL_SetRenderDrawColor(ons.renderer, 0, 0, 0 , SDL_ALPHA_OPAQUE);
SDL_RenderClear(ons.renderer);
}