Xonotic
image.qc File Reference
#include "image.qh"
+ Include dependency graph for image.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Image_configureImage (entity me, string path)
 
float Image_drag (entity me, vector coords)
 
float Image_drag_setStartPos (entity me, vector coords)
 
void Image_draw (entity me)
 
void Image_initZoom (entity me)
 
void Image_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 
void Image_setZoom (entity me, float newzoom, float atMousePosition)
 
string Image_toString (entity me)
 
void Image_updateAspect (entity me)
 

Function Documentation

◆ Image_configureImage()

void Image_configureImage ( entity  me,
string  path 
)

Definition at line 7 of file image.qc.

8  {
9  me.src = path;
10  }

◆ Image_drag()

float Image_drag ( entity  me,
vector  coords 
)

Definition at line 131 of file image.qc.

132  {
133  if (me.imgSize.x > 1 || me.imgSize.y > 1)
134  {
135  me.zoomOffset_x = me.start_zoomOffset.x + (me.start_coords.x - coords.x) / me.imgSize.x;
136  me.zoomOffset_y = me.start_zoomOffset.y + (me.start_coords.y - coords.y) / me.imgSize.y;
137  me.updateAspect(me);
138  }
139  return 1;
140  }

◆ Image_drag_setStartPos()

float Image_drag_setStartPos ( entity  me,
vector  coords 
)

Definition at line 122 of file image.qc.

123  {
124  // if(me.imgSize_x > 1 || me.imgSize_y > 1) // check disabled: mousewheel zoom may start from a non-zoomed-in image
125  {
126  me.start_zoomOffset = me.zoomOffset;
127  me.start_coords = coords;
128  }
129  return 1;
130  }

◆ Image_draw()

void Image_draw ( entity  me)

Definition at line 19 of file image.qc.

References draw_ClearClip(), draw_Picture(), draw_SetClip(), and SUPER.

20  {
21  bool willClip = me.imgSize.x > 1 || me.imgSize.y > 1;
22  if (willClip) draw_SetClip();
23  draw_Picture(me.imgOrigin, me.src, me.imgSize, me.color, 1);
24  if (willClip) draw_ClearClip();
25  SUPER(Image).draw(me);
26  }
#define SUPER(cname)
Definition: oo.qh:219
Definition: image.qh:4
+ Here is the call graph for this function:

◆ Image_initZoom()

void Image_initZoom ( entity  me)

Definition at line 11 of file image.qc.

12  {
13  me.zoomOffset = '0.5 0.5 0';
14  me.zoomFactor = 1;
15  if (me.forcedAspect == -2) me.zoomBox = -1; // calculate zoomBox at the first updateAspect call
16  if (me.zoomLimitedByTheBox) me.zoomMax = -1; // calculate zoomMax at the first updateAspect call
17  }

◆ Image_resizeNotify()

void Image_resizeNotify ( entity  me,
vector  relOrigin,
vector  relSize,
vector  absOrigin,
vector  absSize 
)

Definition at line 191 of file image.qc.

References SUPER.

192  {
193  SUPER(Image).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
194  me.updateAspect(me);
195  }
#define SUPER(cname)
Definition: oo.qh:219
Definition: image.qh:4

◆ Image_setZoom()

void Image_setZoom ( entity  me,
float  newzoom,
float  atMousePosition 
)

Definition at line 141 of file image.qc.

References bound(), max(), min(), and time.

142  {
143  float prev_zoomFactor;
144  prev_zoomFactor = me.zoomFactor;
145  if (newzoom < 0) // multiply by the current zoomFactor (but can also snap to real dimensions or to box)
146  {
147  me.zoomFactor *= -newzoom;
148  float realSize_in_the_middle, boxSize_in_the_middle;
149  realSize_in_the_middle = ((prev_zoomFactor - 1) * (me.zoomFactor - 1) < 0);
150  boxSize_in_the_middle = (me.zoomBox > 0 && (prev_zoomFactor - me.zoomBox) * (me.zoomFactor - me.zoomBox) < 0);
151  if (realSize_in_the_middle && boxSize_in_the_middle)
152  {
153  // snap to real dimensions or to box
154  if (prev_zoomFactor < me.zoomFactor) me.zoomFactor = min(1, me.zoomBox);
155  else me.zoomFactor = max(1, me.zoomBox);
156  }
157  else if (realSize_in_the_middle)
158  {
159  me.zoomFactor = 1; // snap to real dimensions
160  }
161  else if (boxSize_in_the_middle)
162  {
163  me.zoomFactor = me.zoomBox; // snap to box
164  }
165  }
166  else if (newzoom == 0) // reset (no zoom)
167  {
168  if (me.zoomBox > 0) me.zoomFactor = me.zoomBox;
169  else me.zoomFactor = 1;
170  }
171  else // directly set
172  {
173  me.zoomFactor = newzoom;
174  }
175  me.zoomFactor = bound(1 / 16, me.zoomFactor, 16);
176  if (me.zoomMax > 0 && me.zoomFactor > me.zoomMax) me.zoomFactor = me.zoomMax;
177  if (prev_zoomFactor != me.zoomFactor)
178  {
179  me.zoomTime = time;
180  if (atMousePosition)
181  {
182  me.zoomOffset_x = me.start_zoomOffset.x + (me.start_coords.x - 0.5) / me.imgSize.x;
183  me.zoomOffset_y = me.start_zoomOffset.y + (me.start_coords.y - 0.5) / me.imgSize.y;
184  // updateAspect will reset zoomOffset to '0.5 0.5 0' if
185  // with this zoomFactor the image will not be zoomed in
186  // (updateAspect will check the new values of imgSize).
187  }
188  }
189  me.updateAspect(me);
190  }
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:

◆ Image_toString()

string Image_toString ( entity  me)

Definition at line 3 of file image.qc.

4  {
5  return me.src;
6  }

◆ Image_updateAspect()

void Image_updateAspect ( entity  me)

Definition at line 27 of file image.qc.

References bound(), draw_PictureSize(), eX, eY, and vector().

28  {
29  float asp = 0;
30  if (me.size.x <= 0 || me.size.y <= 0) return;
31  if (me.forcedAspect == 0)
32  {
33  me.imgOrigin = '0 0 0';
34  me.imgSize = '1 1 0';
35  }
36  else
37  {
38  vector sz = '0 0 0';
39  if (me.forcedAspect < 0)
40  {
41  if (me.src != "") sz = draw_PictureSize(me.src);
42  if (sz.x <= 0 || sz.y <= 0)
43  {
44  // image is broken or doesn't exist, set the size for the placeholder image
45  sz.x = me.size.x;
46  sz.y = me.size.y;
47  }
48  asp = sz.x / sz.y;
49  }
50  else
51  {
52  asp = me.forcedAspect;
53  }
54 
55  if (me.forcedAspect <= -2)
56  {
57  me.imgSize_x = sz.x / me.size.x;
58  me.imgSize_y = sz.y / me.size.y;
59  if (me.zoomBox < 0 && (me.imgSize.x > 1 || me.imgSize.y > 1))
60  {
61  // image larger than the containing box, zoom it out to fit into the box
62  if (me.size.x > asp * me.size.y) me.zoomBox = (me.size.y * asp / me.size.x) / me.imgSize.x;
63  else me.zoomBox = (me.size.x / (asp * me.size.y)) / me.imgSize.y;
64  me.zoomFactor = me.zoomBox;
65  }
66  }
67  else
68  {
69  if (me.size.x > asp * me.size.y)
70  {
71  // x too large, so center x-wise
72  me.imgSize = eY + eX * (me.size.y * asp / me.size.x);
73  }
74  else
75  {
76  // y too large, so center y-wise
77  me.imgSize = eX + eY * (me.size.x / (asp * me.size.y));
78  }
79  }
80  }
81 
82  if (me.zoomMax < 0)
83  {
84  if (me.zoomBox > 0)
85  {
86  me.zoomMax = me.zoomBox;
87  }
88  else
89  {
90  if (me.size.x > asp * me.size.y) me.zoomMax = (me.size.y * asp / me.size.x) / me.imgSize.x;
91  else me.zoomMax = (me.size.x / (asp * me.size.y)) / me.imgSize.y;
92  }
93  }
94 
95  if (me.zoomMax > 0 && me.zoomFactor > me.zoomMax) me.zoomFactor = me.zoomMax;
96  if (me.zoomFactor) me.imgSize = me.imgSize * me.zoomFactor;
97 
98  if (me.imgSize.x > 1 || me.imgSize.y > 1)
99  {
100  if (me.zoomSnapToTheBox)
101  {
102  if (me.imgSize.x > 1) me.zoomOffset_x = bound(0.5 / me.imgSize.x, me.zoomOffset.x, 1 - 0.5 / me.imgSize.x);
103  else me.zoomOffset_x = bound(1 - 0.5 / me.imgSize.x, me.zoomOffset.x, 0.5 / me.imgSize.x);
104 
105  if (me.imgSize.y > 1) me.zoomOffset_y = bound(0.5 / me.imgSize.y, me.zoomOffset.y, 1 - 0.5 / me.imgSize.y);
106  else me.zoomOffset_y = bound(1 - 0.5 / me.imgSize.y, me.zoomOffset.y, 0.5 / me.imgSize.y);
107  }
108  else
109  {
110  me.zoomOffset_x = bound(0, me.zoomOffset.x, 1);
111  me.zoomOffset_y = bound(0, me.zoomOffset.y, 1);
112  }
113  }
114  else
115  {
116  me.zoomOffset = '0.5 0.5 0';
117  }
118 
119  me.imgOrigin_x = 0.5 - me.zoomOffset.x * me.imgSize.x;
120  me.imgOrigin_y = 0.5 - me.zoomOffset.y * me.imgSize.y;
121  }
const vector eY
Definition: vector.qh:45
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector eX
Definition: vector.qh:44
+ Here is the call graph for this function: