File: x11smiley.c

package info (click to toggle)
netmaze 0.81+jpg0.82-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,208 kB
  • ctags: 912
  • sloc: ansic: 8,277; tcl: 1,223; makefile: 60; sh: 26
file content (224 lines) | stat: -rw-r--r-- 4,194 bytes parent folder | download | duplicates (5)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * x11: draw smileyface
 */

#include <math.h>
#include <stdio.h>

/*
#include <X11/Xlib.h>
#include <X11/Xutil.h>
*/

#include "netmaze.h"
#include "x11smiley.h"

#define MAXSMHIGH 1024
#define SMBASE 128
#define MAXFACEANZ 768

extern struct shared_struct *sm;

struct data {
  double w1;
  double w2;
  double y;
  short    step;
} datas[512];

struct sdata {
  short x1;
  short x2;
  short step;
} winkel[128][512];

short lineanz[128];
XSegment facelines[MAXFACEANZ];

/*
extern GRAFIX grafix;
*/
extern GC whitegc;

void init_smiley(void)
{
  short i,j=0,k,l,d;
  short *data = smiley;
  double w,s;

  for(i=0,j=0;i<256;j++) /* Linewerte in Winkelwerte */
  {
    if(*data == 0x7fff)
    {
      datas[j].step = 1;
      i++; data++;
    }
    else
    {
      datas[j].y  = 128.0 * cos(asin((double) (128-i) / 128.0));
      datas[j].w1 = asin((double) (*data++ - 128) / datas[j].y);
      datas[j].w2 = asin((double) (*data++ - 128) / datas[j].y);
      datas[j].step = 0;
    }
  }

  for(i=0;i<128;i++) /* Winkelwerte in Winkel-Line-Werte */
  {
    w = M_PI * i / 128.0;

    for(j=0,k=0,d=0,l=0;j<256;k++)
    {
      if(datas[k].step == 1)
      {
        winkel[i][l].step = 1; j++; l++;
      }
      else if((s = datas[k].w1 + w) < M_PI_2)
      {
        winkel[i][l].x1 = datas[k].y * sin(s);
        if((s = datas[k].w2 + w) < M_PI_2)
          winkel[i][l].x2 = datas[k].y * sin(s);
        else
          winkel[i][l].x2 = datas[k].y;
        winkel[i][l].step = 0; d++; l++;
      }
    }
    lineanz[i] = d;
  }
}

void draw_smiley(Drawable wind,short x,short y,short win,short r)
{
  short j,k,k1;
  double scale,scale1,jmp=0.5;
  int faceanz = 0,lclip,rclip;

  lclip=(IMAGEWIDTH-WXSIZE)>>1;
  rclip=lclip+WXSIZE-1;
  scale1 = scale = (double) r / 128.0;

  y -= r;

  if(win < 0)
  {
    win = - win;
    scale1 = -scale1;
  }

  if(lineanz[win] == 0) return;

  for(j=0,k=0;j<256;j++) /* very simple test-drawroutine */
  {
    jmp += scale;
    if(jmp >= 1)
    {
      k1 = k;
      while(jmp >= 1)
      {
        k = k1;
        while(winkel[win][k].step == 0)
        {
          if(faceanz < MAXFACEANZ)
          {
            facelines[faceanz].x1 = x+winkel[win][k].x1*scale1;
            facelines[faceanz].x2 = x+winkel[win][k].x2*scale1;
            facelines[faceanz].y1 = facelines[faceanz].y2 = y;
            faceanz++;
          }
          k++;
        }
        y++; k++;
        jmp -= 1;
      }
    }
    else
    {
      while(winkel[win][k].step == 0)  k++;
      k++;
    }
  }
  XDrawSegments(sm->grafix.display,wind,whitegc,facelines,faceanz);

}

void image_face(long x,long r,int win,int col)
{
  int j,k,k1,y;
  double scale,scale1,jmp=0.5;
  extern void image_hline(int x1,int y1,int x2,int val);
  int lclip=(IMAGEWIDTH-WXSIZE)>>1;
  int rclip=((IMAGEWIDTH+WXSIZE)>>1)-1;

  scale1 = scale = (double) r / 128.0;

  if(win < 0)
  {
    win = - win;
    scale1 = -scale1;
  }

  if(lineanz[win] == 0) return;

  x += (IMAGEWIDTH>>1);
  y = (IMAGEHEIGHT>>1) - r;

  for(j=0,k=0;j<256;j++) /* very simple test-drawroutine */
  {
    jmp += scale;
    if(jmp >= 1)
    {
      k1 = k;
      while(jmp >= 1)
      {
        k = k1;
        while(winkel[win][k].step == 0)
        {
          int xi1,xi2;
          int x1=x+winkel[win][k].x1*scale1;
          int x2=x+winkel[win][k].x2*scale1;
          k++;

          if(x1>x2) 
          {
            if(x2<lclip)
            {
              if(x1<lclip)
                continue;
              x2=lclip;
            }
            if(x1>rclip)
            { 
              if(x2>rclip)
                continue;
              x1=rclip;
            }
            image_hline(x2,y,x1,col);
          }
          else
          {
            if(x1<lclip)
            {
              if(x2<lclip)
                continue;
              x1=lclip;
            }
            if(x2>rclip)
            { 
              if(x1>rclip)
                continue;
              x2=rclip;
            }
            image_hline(x1,y,x2,col);
          }
        }
        y++; k++;
        jmp -= 1;
      }
    }
    else
    {
      while(winkel[win][k].step == 0)  k++;
      k++;
    }
  }
}