Changeset 199
- Timestamp:
- Nov 19, 2003, 6:32:10 PM (17 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/examples/demo.c
r195 r199 79 79 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gradient.png", NULL); 80 80 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/beastie.png", NULL); 81 pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/stitch.jpg", NULL); 81 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/stitch.jpg", NULL); 82 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/caca.jpg", NULL); 82 83 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/dranac.jpeg", NULL); 83 84 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/artwork/aboire.png", NULL); … … 85 86 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/lilkim02.jpg", NULL); 86 87 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/etw.bmp", NULL); 88 pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/lena_std.png", NULL); 87 89 if(!pixbuf) return -2; 88 90 pixels = gdk_pixbuf_get_pixels(pixbuf); … … 100 102 while(!quit) 101 103 { 102 char key = caca_get_key();103 104 if( key&& demo)104 int event = caca_get_event(); 105 106 if(event && demo) 105 107 { 106 108 display_menu(); … … 108 110 demo = NULL; 109 111 } 110 else if( key)112 else if(event & CACA_EVENT_KEY_PRESS) 111 113 { 112 114 handle_key: 113 switch( key)115 switch(event & 0xff) 114 116 { 115 117 case 'q': … … 171 173 caca_clear(); 172 174 173 key = caca_get_key(); 174 if(key) 175 handle_event: 176 event = caca_get_event(); 177 if(event & CACA_EVENT_KEY_PRESS) 175 178 goto handle_key; 179 else if(event) 180 goto handle_event; 176 181 177 182 caca_refresh(); -
libcaca/trunk/examples/spritedit.c
r193 r199 57 57 int xa, ya, xb, yb; 58 58 char buf[BUFSIZ]; 59 int event; 59 60 60 switch(caca_get_key())61 while((event = caca_get_event())) 61 62 { 62 case 0: 63 break; 64 case 'q': 65 quit = 1; 66 break; 67 case '-': 68 if(frame > 0) 69 frame--; 70 break; 71 case '+': 72 if(frame < caca_get_sprite_frames(sprite) - 1) 73 frame++; 74 break; 63 if(event & CACA_EVENT_KEY_PRESS) 64 switch(event & 0xff) 65 { 66 case 0: 67 break; 68 case 'q': 69 quit = 1; 70 break; 71 case '-': 72 if(frame > 0) 73 frame--; 74 break; 75 case '+': 76 if(frame < caca_get_sprite_frames(sprite) - 1) 77 frame++; 78 break; 79 } 75 80 } 76 81 -
libcaca/trunk/src/blit.c
r198 r199 102 102 } 103 103 104 //pitch = (3 * w + 3) / 4 * 4;105 pitch = 4 * w;104 pitch = (3 * w + 3) / 4 * 4; 105 //pitch = 4 * w; 106 106 107 107 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++) … … 115 115 int fromx = w * (x - x1) / (x2 - x1 + 1); 116 116 int fromy = h * (y - y1) / (y2 - y1 + 1); 117 //int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy];118 //int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy];119 //int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy];120 int b = ((unsigned char *)pixels)[4 * fromx + pitch * fromy];121 int g = ((unsigned char *)pixels)[4 * fromx + 1 + pitch * fromy];122 int r = ((unsigned char *)pixels)[4 * fromx + 2 + pitch * fromy];117 int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy]; 118 int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy]; 119 int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy]; 120 //int b = ((unsigned char *)pixels)[4 * fromx + pitch * fromy]; 121 //int g = ((unsigned char *)pixels)[4 * fromx + 1 + pitch * fromy]; 122 //int r = ((unsigned char *)pixels)[4 * fromx + 2 + pitch * fromy]; 123 123 int hue, sat, val; 124 124 … … 143 143 hue = 1280 + 256 * (r - g) / delta; 144 144 145 hue = (hue + 128 + 8* _get_dither()) / 256;145 hue = (hue + 128 + 16 * _get_dither()) / 256; 146 146 147 147 if(val > (_get_dither() + 40) * 4) -
libcaca/trunk/src/caca.c
r193 r199 98 98 SLang_init_tty(-1, 0, 1); 99 99 100 SLkp_define_keysym("\e[M", 1001); 101 100 102 if(SLsmg_init_smg() == -1) 101 103 { … … 108 110 SLsmg_cls(); 109 111 SLtt_set_cursor_visibility(0); 112 SLtt_set_mouse_mode (1, 0); 110 113 SLsmg_refresh(); 111 114 … … 292 295 { 293 296 #if defined(USE_SLANG) 297 SLtt_set_mouse_mode(0, 0); 294 298 SLtt_set_cursor_visibility(1); 295 299 SLang_reset_tty(); -
libcaca/trunk/src/caca.h
r198 r199 64 64 65 65 /* 66 * Events 67 */ 68 enum caca_event 69 { 70 CACA_EVENT_NONE = 0x00000000, 71 CACA_EVENT_KEY_PRESS = 0x01000000, 72 CACA_EVENT_KEY_RELEASE = 0x02000000, 73 CACA_EVENT_MOUSE_CLICK = 0x04000000 74 }; 75 76 /* 66 77 * Keys 67 78 */ … … 108 119 void caca_end(void); 109 120 110 int caca_get_ key(void);121 int caca_get_event(void); 111 122 112 123 void caca_set_color(enum caca_color); -
libcaca/trunk/src/io.c
r198 r199 37 37 #include "caca_internals.h" 38 38 39 static void _push_key(unsigned char); 40 static unsigned char _pop_key(void); 41 static unsigned char _read_key(void); 42 39 43 static unsigned char back[5] = {0, 0, 0, 0, 0}; 44 45 int caca_get_event(void) 46 { 47 unsigned char key[6]; 48 49 /* If there were legacy keys, pop them */ 50 key[0] = _pop_key(); 51 if(key[0]) 52 return CACA_EVENT_KEY_PRESS | key[0]; 53 54 key[0] = _read_key(); 55 if(!key[0]) 56 return 0; 57 58 if(key[0] != 0x1b) 59 return CACA_EVENT_KEY_PRESS | key[0]; 60 61 /* 62 * Handle escape sequences 63 */ 64 65 key[1] = _read_key(); 66 if(!key[1]) 67 return CACA_EVENT_KEY_PRESS | key[0]; 68 69 key[2] = _read_key(); 70 if(!key[2]) 71 { 72 _push_key(key[1]); 73 return CACA_EVENT_KEY_PRESS | key[0]; 74 } 75 76 if(key[1] == 'O') 77 { 78 switch(key[2]) 79 { 80 case 'P': return CACA_EVENT_KEY_PRESS | CACA_KEY_F1; 81 case 'Q': return CACA_EVENT_KEY_PRESS | CACA_KEY_F2; 82 case 'R': return CACA_EVENT_KEY_PRESS | CACA_KEY_F3; 83 case 'S': return CACA_EVENT_KEY_PRESS | CACA_KEY_F4; 84 } 85 } 86 else if(key[1] == '[') 87 { 88 switch(key[2]) 89 { 90 case 'A': return CACA_EVENT_KEY_PRESS | CACA_KEY_UP; 91 case 'B': return CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN; 92 case 'C': return CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT; 93 case 'D': return CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT; 94 } 95 96 key[3] = _read_key(); 97 key[4] = _read_key(); 98 99 if(key[2] == 'M') 100 { 101 int event = CACA_EVENT_MOUSE_CLICK; 102 103 key[5] = _read_key(); 104 105 event |= (int)(key[3] - ' ') << 8; 106 event |= (int)(key[4] - ' ') << 4; 107 event |= (int)(key[5] - ' ') << 0; 108 109 return event; 110 } 111 112 if(key[2] == '1' && key[4] == '~') 113 switch(key[3]) 114 { 115 case '5': return CACA_EVENT_KEY_PRESS | CACA_KEY_F5; 116 case '7': return CACA_EVENT_KEY_PRESS | CACA_KEY_F6; 117 case '8': return CACA_EVENT_KEY_PRESS | CACA_KEY_F7; 118 case '9': return CACA_EVENT_KEY_PRESS | CACA_KEY_F8; 119 } 120 121 if(key[2] == '2' && key[4] == '~') 122 switch(key[3]) 123 { 124 case '0': return CACA_EVENT_KEY_PRESS | CACA_KEY_F9; 125 case '1': return CACA_EVENT_KEY_PRESS | CACA_KEY_F10; 126 case '3': return CACA_EVENT_KEY_PRESS | CACA_KEY_F11; 127 case '4': return CACA_EVENT_KEY_PRESS | CACA_KEY_F12; 128 } 129 130 _push_key(key[4]); 131 _push_key(key[3]); 132 } 133 134 /* Unknown escape sequence: return each key one after the other */ 135 _push_key(key[2]); 136 _push_key(key[1]); 137 return CACA_EVENT_KEY_PRESS | key[0]; 138 } 40 139 41 140 static void _push_key(unsigned char key) … … 70 169 } 71 170 72 int caca_get_key(void)73 {74 unsigned char key[5];75 76 /* If there were legacy keys, pop them */77 key[0] = _pop_key();78 if(key[0])79 return key[0];80 81 key[0] = _read_key();82 if(key[0] != 0x1b)83 return key[0];84 85 key[1] = _read_key();86 if(!key[1])87 return key[0];88 89 key[2] = _read_key();90 if(!key[2])91 {92 _push_key(key[1]);93 return key[0];94 }95 96 if(key[1] == 0x4f)97 {98 switch(key[2])99 {100 case 0x50: return CACA_KEY_F1;101 case 0x51: return CACA_KEY_F2;102 case 0x52: return CACA_KEY_F3;103 case 0x53: return CACA_KEY_F4;104 }105 }106 else if(key[1] == 0x5b)107 {108 switch(key[2])109 {110 case 0x41: return CACA_KEY_UP;111 case 0x42: return CACA_KEY_DOWN;112 case 0x43: return CACA_KEY_LEFT;113 case 0x44: return CACA_KEY_RIGHT;114 }115 116 key[3] = _read_key();117 key[4] = _read_key();118 119 if(key[2] == 0x31 && key[4] == 0x7e)120 switch(key[3])121 {122 case 0x35: return CACA_KEY_F5;123 case 0x37: return CACA_KEY_F6;124 case 0x38: return CACA_KEY_F7;125 case 0x39: return CACA_KEY_F8;126 }127 128 if(key[2] == 0x32 && key[4] == 0x7e)129 switch(key[3])130 {131 case 0x30: return CACA_KEY_F9;132 case 0x31: return CACA_KEY_F10;133 case 0x33: return CACA_KEY_F11;134 case 0x34: return CACA_KEY_F12;135 }136 137 _push_key(key[4]);138 _push_key(key[3]);139 }140 141 /* Unknown escape sequence: return 0 */142 _push_key(key[2]);143 _push_key(key[1]);144 return key[0];145 }146
Note: See TracChangeset
for help on using the changeset viewer.