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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#![allow(
clippy::too_many_arguments,
clippy::let_and_return,
clippy::from_over_into
)]
use super::{Context, Texture};
use crate::prelude::*;
use std::fmt;
// @short_description: Functions for creating and manipulating
// sub-textures.
//
// These functions allow high-level textures to be created that
// represent a sub-region of another texture. For example these
// can be used to implement custom texture atlasing schemes.
pub struct SubTexture {
// Texture _parent;
// This is the texture that was passed in to
// _sub_texture_new. If this is also a sub texture then we will
// use the full texture from that to render instead of making a
// chain. However we want to preserve the next texture in case the
// user is expecting us to keep a reference and also so that we can
// later add a sub_texture_get_parent_texture() function. */
// Texture *next_texture;
// This is the texture that will actually be used to draw. It will
// point to the end of the chain if a sub texture of a sub texture
// is created */
// Texture *full_texture;
// The offset of the region represented by this sub-texture. This is
// the offset in full_texture which won't necessarily be the same as
// the offset passed to _sub_texture_new if next_texture is
// actually already a sub texture */
// int sub_x;
// int sub_y;
}
impl SubTexture {
/// Creates a high-level `SubTexture` representing a sub-region of
/// any other `Texture`. The sub-region must strictly lye within the
/// bounds of the `parent_texture`. The returned texture implements the
/// `MetaTexture` interface because it's not a low level texture
/// that hardware can understand natively.
///
/// Remember: Unless you are using high level drawing APIs such
/// as `rectangle` or other APIs documented to understand the
/// `MetaTexture` interface then you need to use the
/// `MetaTexture` interface to resolve a `SubTexture` into a
/// low-level texture before drawing.
/// ## `ctx`
/// A `Context` pointer
/// ## `parent_texture`
/// The full texture containing a sub-region you want
/// to make a `SubTexture` from.
/// ## `sub_x`
/// The top-left x coordinate of the parent region to make
/// a texture from.
/// ## `sub_y`
/// The top-left y coordinate of the parent region to make
/// a texture from.
/// ## `sub_width`
/// The width of the parent region to make a texture from.
/// ## `sub_height`
/// The height of the parent region to make a texture
/// from.
///
/// # Returns
///
/// A newly allocated `SubTexture`
/// representing a sub-region of `parent_texture`.
pub fn new<P: Is<Texture>>(
ctx: &Context,
parent_texture: &P,
sub_x: i32,
sub_y: i32,
sub_width: i32,
sub_height: i32,
) -> SubTexture {
// Texture *full_texture;
// SubTexture *sub_tex;
// Texture *tex;
// unsigned int next_width, next_height;
// next_width = texture_get_width (next_texture);
// next_height = texture_get_height (next_texture);
// The region must specify a non-zero subset of the full texture */
// _RETURN_VAL_IF_FAIL (sub_x >= 0 && sub_y >= 0, NULL);
// _RETURN_VAL_IF_FAIL (sub_width > 0 && sub_height > 0, NULL);
// _RETURN_VAL_IF_FAIL (sub_x + sub_width <= next_width, NULL);
// _RETURN_VAL_IF_FAIL (sub_y + sub_height <= next_height, NULL);
// sub_tex = g_new (SubTexture, 1);
// tex = TEXTURE (sub_tex);
// _texture_init (tex, ctx, sub_width, sub_height,
// _texture_get_format (next_texture),
// NULL, /* no loader */
// &sub_texture_vtable);
// If the next texture is also a sub texture we can avoid one level
// of indirection by referencing the full texture of that texture
// instead. */
// if (is_sub_texture (next_texture))
// {
// SubTexture *other_sub_tex = SUB_TEXTURE (next_texture);
// full_texture = other_sub_tex->full_texture;
// sub_x += other_sub_tex->sub_x;
// sub_y += other_sub_tex->sub_y;
// }
// else
// full_texture = next_texture;
// sub_tex->next_texture = object_ref (next_texture);
// sub_tex->full_texture = object_ref (full_texture);
// sub_tex->sub_x = sub_x;
// sub_tex->sub_y = sub_y;
// return _sub_texture_object_new (sub_tex);
unimplemented!()
}
/// Retrieves the parent texture that `self` derives its content
/// from. This is the texture that was passed to
/// `SubTexture::new` as the parent_texture argument.
///
/// # Returns
///
/// The parent texture that `self`
/// derives its content from.
pub fn parent(&self) -> Option<Texture> {
// return sub_texture->next_texture;
unimplemented!()
}
}
impl fmt::Display for SubTexture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SubTexture")
}
}