- Timestamp:
- Nov 9, 2003, 7:10:44 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/libee/line.c
r97 r101 28 28 #include "ee.h" 29 29 30 struct line 31 { 32 int x1, y1; 33 int x2, y2; 34 char c; 35 void (*draw) (struct line*); 36 }; 37 38 static void clip_line(struct line*); 30 39 static uint8_t clip_bits(int, int); 31 static void draw_solid_line( int, int, int, int, char);40 static void draw_solid_line(struct line*); 32 41 33 42 void ee_draw_line(int x1, int y1, int x2, int y2, char c) 34 43 { 44 struct line s; 45 s.x1 = x1; 46 s.y1 = y1; 47 s.x2 = x2; 48 s.y2 = y2; 49 s.c = c; 50 s.draw = draw_solid_line; 51 clip_line(&s); 52 } 53 54 static void clip_line(struct line* s) 55 { 35 56 uint8_t bits1, bits2; 36 57 37 bits1 = clip_bits( x1,y1);38 bits2 = clip_bits( x2,y2);58 bits1 = clip_bits(s->x1, s->y1); 59 bits2 = clip_bits(s->x2, s->y2); 39 60 40 61 if(bits1 & bits2) … … 44 65 { 45 66 if(bits2 == 0) 46 draw_solid_line(x1, y1, x2, y2, c);67 s->draw(s); 47 68 else 48 ee_draw_line(x2, y2, x1, y1, c); 69 { 70 int tmp; 71 tmp = s->x1; s->x1 = s->x2; s->x2 = tmp; 72 tmp = s->y1; s->y1 = s->y2; s->y2 = tmp; 73 clip_line(s); 74 } 49 75 50 76 return; … … 53 79 if(bits1 & (1<<0)) 54 80 { 55 y1 = y2 - (x2-0) * (y2-y1) / (x2-x1);56 x1 = 0;81 s->y1 = s->y2 - (s->x2 - 0) * (s->y2 - s->y1) / (s->x2 - s->x1); 82 s->x1 = 0; 57 83 } 58 84 else if( bits1 & (1<<1) ) 59 85 { 60 86 int xmax = ee_get_width() - 1; 61 y1 = y2 - (x2-xmax) * (y2-y1) / (x2-x1);62 x1 = xmax;87 s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); 88 s->x1 = xmax; 63 89 } 64 90 else if( bits1 & (1<<2) ) 65 91 { 66 x1 = x2 - (y2-0) * (x2-x1) / (y2-y1);67 y1 = 0;92 s->x1 = s->x2 - (s->y2 - 0) * (s->x2 - s->x1) / (s->y2 - s->y1); 93 s->y1 = 0; 68 94 } 69 95 else if( bits1 & (1<<3) ) 70 96 { 71 97 int ymax = ee_get_height() - 1; 72 x1 = x2 - (y2-ymax) * (x2-x1) / (y2-y1);73 y1 = ymax;98 s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); 99 s->y1 = ymax; 74 100 } 75 101 76 ee_draw_line(x1, y1, x2, y2, c);102 clip_line(s); 77 103 } 78 104 79 static void draw_solid_line(int x1, int y1, int x2, int y2, char c)105 static uint8_t clip_bits(int x, int y) 80 106 { 107 uint8_t b = 0; 108 109 if(x < 0) 110 b |= (1<<0); 111 else if(x >= ee_get_width()) 112 b |= (1<<1); 113 114 if(y < 0) 115 b |= (1<<2); 116 else if(y >= ee_get_height()) 117 b |= (1<<3); 118 119 return b; 120 } 121 122 static void draw_solid_line(struct line* s) 123 { 124 int x1 = s->x1; 125 int y1 = s->y1; 126 int x2 = s->x2; 127 int y2 = s->y2; 128 81 129 int dx = abs(x2-x1); 82 130 int dy = abs(y2-y1); … … 96 144 { 97 145 ee_goto(x1, y1); 98 ee_putchar( c);146 ee_putchar(s->c); 99 147 if(delta > 0) 100 148 { … … 119 167 { 120 168 ee_goto(x1, y1); 121 ee_putchar( c);169 ee_putchar(s->c); 122 170 if(delta > 0) 123 171 { … … 135 183 } 136 184 137 static uint8_t clip_bits(int x, int y)138 {139 uint8_t b = 0;140 141 if(x < 0)142 b |= (1<<0);143 else if(x >= ee_get_width())144 b |= (1<<1);145 146 if(y < 0)147 b |= (1<<2);148 else if(y >= ee_get_height())149 b |= (1<<3);150 151 return b;152 }153
Note: See TracChangeset
for help on using the changeset viewer.