7696be99afa1a3cb596e91c44e9960fc9c6665ba
[blender.git] / source / blender / src / drawimasel.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <string.h>
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifdef _WIN32
40 #include "BLI_winstuff.h"
41 #pragma warning (once : 4761)
42 #endif
43
44 #include "MEM_guardedalloc.h"
45 #include "BMF_Api.h"
46 #include "BLI_blenlib.h"
47 #include "IMB_imbuf_types.h"
48 #include "DNA_screen_types.h"
49 #include "DNA_space_types.h"
50 #include "BKE_global.h"
51 #include "BIF_fsmenu.h"
52 #include "BIF_gl.h"
53 #include "BIF_resources.h"
54 #include "BIF_screen.h"
55 #include "BIF_interface.h"
56 #include "BIF_imasel.h"
57 #include "BIF_mywindow.h"
58 #include "BIF_space.h"
59 #include "BSE_drawimasel.h"
60 #include "BSE_filesel.h"
61
62 #include "interface.h"
63 #include "blendef.h"
64 #include "mydevice.h"
65
66 #define IMALINESIZE 16
67 /* well, who would have thought ... */
68 #define lrectwrite(a, b, c, d, rect)    {glRasterPos2i(a,  b);glDrawPixels((c)-(a)+1, (d)-(b)+1, GL_RGBA, GL_UNSIGNED_BYTE,  rect);}
69
70 /* GLOBALS */
71 extern char *fsmenu;
72
73 void viewgate(short sx, short sy, short ex, short ey) 
74 {
75         short wx, wy;
76         wx = curarea->winrct.xmin; wy = curarea->winrct.ymin;
77         glViewport(wx+sx, wy+sy, (wx+ex )-(wx+sx)+1, (wy+ey )-(wy+sy)+1); 
78         glScissor(wx+sx, wy+sy, (wx+ex )-(wx+sx)+1, (wy+ey )-(wy+sy)+1);
79         myortho2((float)sx+0.5 , (float)ex+0.5, (float)sy+0.5, (float)ey+0.5);
80 }       
81         
82 void areaview (void) 
83 {
84         short wx, wy;
85         wx = curarea->winrct.xmin; wy = curarea->winrct.ymin;
86         glViewport(wx,  wy, curarea->winx, curarea->winy); 
87         glScissor(wx,  wy, curarea->winx, curarea->winy); 
88         myortho2(-0.5, (float)(curarea->winx)-0.5, -0.5, (float)(curarea->winy)-0.5);
89
90 }
91                 
92 void calc_hilite(SpaceImaSel *simasel)
93 {
94         OneSelectableIma *ima;
95         ImaDir  *direntry;
96         short   mx, my;
97         int     i, area_event;
98         
99         if (simasel->hilite > -1) {
100                 direntry = simasel->firstdir; 
101                 while(direntry){
102                         direntry->hilite = 0;
103                         direntry = direntry->next;
104                 }       
105                 simasel->hilite = -1;
106         }
107         
108         if (simasel->totalima){
109                 simasel->hilite_ima =  0;
110                 ima = simasel->first_sel_ima;
111                 while (ima){
112                         ima->selectable = 0;
113                         ima = ima->next;
114                 }
115         }
116                 
117         area_event = 0;
118         mx = simasel->mx;
119         my = simasel->my;
120                 
121         if (simasel->desx > 0){
122                 if ( (mx > simasel->desx) && (mx < simasel->deex) && (my > simasel->desy) && (my < simasel->deey) ) area_event = IMS_INDIR;
123         }
124         if (simasel->fesx > 0){
125                 if ( (mx > simasel->fesx) && (mx < simasel->feex) && (my > simasel->fesy) && (my < simasel->feey) ) area_event = IMS_INFILE;
126         }       
127         
128         switch(area_event){
129         case IMS_INDIR:
130                 simasel->hilite = simasel->topdir + ((simasel->deey - my - 4) / IMALINESIZE);
131                 
132                 if (my >= simasel->deey)                                        simasel->hilite = -1;
133                 if (simasel->hilite >= simasel->totaldirs)  simasel->hilite = -1;
134         
135                 if (simasel->hilite > -1){
136                         direntry = simasel->firstdir; 
137                         for (i = simasel->hilite; i>0; i--){
138                                 direntry = direntry->next;
139                         }
140                         direntry->hilite = 1;
141                         
142                 }
143                 simasel->mouse_move_redraw = 1;
144                 break;
145         
146         case IMS_INFILE:
147                 if (simasel->totalima){
148                         ima = simasel->first_sel_ima;
149                         while (ima){
150                                 ima->selectable = 0;
151                                 
152                                 if (ima->draw_me) {
153                                         if ((mx > ima->sx) && (mx < ima->sx+76) && (my > ima->sy-16) && (my < ima->sy+76)) {
154                                                 ima->selectable = 1;
155                                                 simasel->hilite_ima = ima;
156                                                 simasel->mouse_move_redraw = 1;
157                                         }
158                                 }
159                                 
160                                 ima = ima->next;
161                         }       
162                 }
163                 break;
164         }
165 }
166
167
168 void make_sima_area(SpaceImaSel *simasel)
169 {
170         OneSelectableIma *ima;
171         short rh, dm, sc;
172         short boxperline, boxlines, boxlinesinview, boxlinesleft;
173
174 /*  ima slider  box */
175         simasel->fssx =  8; 
176         simasel->fssy = 8; 
177         simasel->fsex = 30; 
178         simasel->fsey = curarea->winy-64;
179 /*  ima entry's  box */
180         simasel->fesx = simasel->fsex + 8; 
181         simasel->fesy = simasel->fssy; 
182         simasel->feex = curarea->winx- 8;  
183         simasel->feey = curarea->winy-64;
184 /*  ima names */
185         simasel->dnsx = 38; 
186         simasel->dnsy = curarea->winy - 29; 
187         simasel->dnw  = curarea->winx - 8 - 38; 
188         simasel->dnh  = 21;
189         simasel->fnsx = simasel->fesx; 
190         simasel->fnsy = curarea->winy - 29 - 29; 
191         simasel->fnw  = curarea->winx - 8 - simasel->fnsx; 
192         simasel->fnh  = 21;
193         
194         if ((simasel->mode & 1)==1){
195         /*  dir slider  box */
196                 simasel->dssx =   8; 
197                 
198                 simasel->dsex =  30; 
199                 simasel->dsey = curarea->winy-64;
200         /*  dir entry's  box */
201                 simasel->desx =  38;
202                 simasel->desy =   8; 
203                 
204                 simasel->deex = 208; 
205                 simasel->deey = curarea->winy-64;
206                 simasel->dssy = simasel->desy; 
207                 if (simasel->deex > (curarea->winx -8) ) simasel->deex = curarea->winx - 8;
208                 if (simasel->deex <= simasel->desx ) simasel->dssx =  0;
209         /*  file slider & entry & name box ++ */
210                 simasel->fssx += 216; 
211                 simasel->fsex += 216;
212                 simasel->fesx += 216;
213                 simasel->fnsx += 216;
214                 simasel->fnw  -= 216;
215         }else{
216                 simasel->desx =  0;
217         }
218         
219         if ((simasel->mode & 2) == 2){  
220                 simasel->fesy += 32;
221                 simasel->infsx = simasel->fesx; simasel->infsy =  8;
222                 simasel->infex = simasel->feex; simasel->infey = 28;
223         }else{
224                 simasel->infsx = 0;
225         }
226         
227         simasel->dsdh = simasel->deey - simasel->desy - 4;
228         
229         if (simasel->dsdh  <= 16)  { simasel->desx  = 0; }
230         if ((simasel->feex-16)  <= simasel->fesx)  { simasel->fesx  = 0; }
231         if ((simasel->infex-16) <= simasel->infsx) { simasel->infsx = 0; }
232         
233         if ((simasel->deey  ) <= simasel->desy)    { simasel->desx  = 0; }
234         if ((simasel->feey  ) <= simasel->fesy)    { simasel->fesx  = 0; }
235         if ((simasel->infey )  > simasel->feey)    { simasel->infsx  = 0;}
236         
237         /* Dir Slider */
238         if (simasel->desx  != 0){
239                 simasel->dirsli = 0;
240                 
241                 simasel->dirsli_lines = (simasel->dsdh / IMALINESIZE);
242                 simasel->dirsli_h  = 0;
243                 
244                 if (simasel->topdir < 0) simasel->topdir = 0;
245                 if (simasel->topdir > (simasel->totaldirs - simasel->dirsli_lines) ) simasel->topdir = (simasel->totaldirs - simasel->dirsli_lines);
246                 
247                 if ( (simasel->totaldirs * IMALINESIZE) >= simasel->dsdh ){
248                         simasel->dirsli = 1;
249                         simasel->dirsli_sx = simasel->dssx+2;
250                         simasel->dirsli_ex = simasel->dsex-2;   
251                         
252                         simasel->dirsli_h   = (simasel->dsdh) * (float)simasel->dirsli_lines / (float)simasel->totaldirs;
253                         simasel->dirsli_ey  = simasel->dsey - 2;
254                         if (simasel->topdir) {
255                                 rh = (simasel->dsdh - simasel->dirsli_h);
256                                 simasel->dirsli_ey -= rh * (float)((float)simasel->topdir / (float)(simasel->totaldirs - simasel->dirsli_lines ));
257                         }
258                         
259                         if (simasel->dirsli_h < 4) simasel->dirsli_h = 4;
260                         
261                 }else{
262                         simasel->topdir = 0;
263                 }
264         }
265         
266         if (simasel->totalima){
267                 /* there are images */
268                 
269                 ima = simasel->first_sel_ima;
270                 
271                 
272                 boxperline      =   (simasel->feex - simasel->fesx) /  80;
273                 if (boxperline) boxlines = 1 + (simasel->totalima / boxperline); else boxlines = 1;
274                 boxlinesinview  =   (simasel->feey - simasel->fesy) / 100;
275                 boxlinesleft    =   boxlines - boxlinesinview;
276                 
277                 if (boxlinesleft > 0){
278                         /* slider needed */
279                         
280                         simasel->slider_height = boxlinesinview / (float)(boxlines+1);
281                         simasel->slider_space  = 1.0 - simasel->slider_height;
282                         
283                         simasel->imasli_sx = simasel->fssx+1; 
284                         simasel->imasli_ex = simasel->fsex-1; 
285                         simasel->fsdh      = simasel->fsey -  simasel->fssy - 4;
286                 
287                         simasel->imasli_h  = simasel->fsdh * simasel->slider_height;
288                         if (simasel->imasli_h < 6) simasel->imasli_h = 6;
289                         simasel->imasli_ey = simasel->fsey - 2 - (simasel->fsdh * simasel->slider_space * simasel->image_slider);
290                         
291                         simasel->imasli = 1;
292                 
293                 }else{
294                         simasel->image_slider = 0;
295                         simasel->imasli = 0;
296                 }
297                 
298                 sc = simasel->image_slider * (boxlinesleft * 100);
299                 
300                 simasel->curimax = simasel->fesx + 8;
301                 simasel->curimay = simasel->feey - 90 + sc;
302                 
303                 dm = 1;
304                 if (simasel->curimay-2  < simasel->fesy) dm = 0;
305                 if (simasel->curimay+80 > simasel->feey) dm = 0;
306                 if (simasel->curimax+72 > simasel->feex) dm = 0;
307                 
308                 simasel->total_selected = 0;
309                 while (ima){
310                         ima->draw_me = dm;
311                         
312                         if (ima->selected) simasel->total_selected++;
313         
314                         ima->sx = simasel->curimax;
315                         ima->sy = simasel->curimay+16;
316                         
317                         ima->ex = ima->sx + ima->dw;
318                         ima->ey = ima->sy + ima->dh;
319                         
320                         simasel->curimax += 80;
321                         if (simasel->curimax + 72 > simasel->feex){
322                                 
323                                 simasel->curimax  = simasel->fesx + 8;
324                                 simasel->curimay -= 100;
325                                 
326                                 dm = 1;
327                                 if (simasel->curimay+80 > simasel->feey) dm = 0;
328                                 if (simasel->curimay-8  < simasel->fesy) dm = 0;
329                                 
330                         }
331                         ima = ima->next;
332                 }
333         }
334 }
335
336 static void str_image_type(int ftype, char *name)
337 {
338         strcpy(name, "");
339         
340         if((ftype & JPG_MSK) == JPG_STD) strcat(name, "std ");
341         if((ftype & JPG_MSK) == JPG_VID) strcat(name, "video ");
342         if((ftype & JPG_MSK) == JPG_JST) strcat(name, "amiga ");
343         if((ftype & JPG_MSK) == JPG_MAX) strcat(name, "max ");
344         
345         if( ftype == AN_hamx)   { strcat(name, "hamx "); return; }
346         
347         if( ftype == IMAGIC )   { strcat(name, "sgi ");  return; }
348         if( ftype & JPG )       { strcat(name, "jpeg ");  }
349         if( ftype & TGA )       { strcat(name, "targa "); }
350         if( ftype & PNG )       { strcat(name, "png "); }
351         if( ftype & AMI )       { strcat(name, "iff ");   }
352 }
353
354 void draw_sima_area(SpaceImaSel *simasel)
355 {               
356         uiBlock *block;
357         OneSelectableIma *ima;
358         ImaDir      *direntry;
359         int   i, info;
360         short sx, sy, ex, ey, sc;
361         char naam[256], infostr[256];
362         
363         glClearColor(0.4375, 0.4375, 0.4375, 0.0);
364         glClear(GL_COLOR_BUFFER_BIT);
365         
366         sprintf(naam, "win %d", curarea->win);
367         block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSSF, UI_HELV, curarea->win);
368         uiBlockSetCol(block, BUTBLUE);
369         
370         if (simasel->desx >  0){
371                 /*  DIR ENTRYS */
372                 cpack(C_DERK);
373                 glRecti(simasel->dssx,  simasel->dssy,  simasel->dsex,  simasel->dsey);
374                 glRecti(simasel->desx,  simasel->desy,  simasel->deex,  simasel->deey);
375         
376                 uiEmboss(simasel->dssx, simasel->dssy, simasel->dsex, simasel->dsey,1);
377                 uiEmboss(simasel->desx, simasel->desy, simasel->deex, simasel->deey,1);
378                 
379                 if (simasel->dirsli == 1) {
380                         sx = simasel->dirsli_sx+2;
381                         sy = simasel->dirsli_ey - simasel->dirsli_h+2;
382                         ex = simasel->dirsli_ex-2;
383                         ey = simasel->dirsli_ey-2;
384                         
385                         cpack(C_BACK);
386                         
387                         glRecti(sx,  sy,  ex,  ey);
388                         uiEmboss(sx, sy, ex,ey,0);
389                 }
390                 if (simasel->totaldirs) {
391                         sx = simasel->desx+8;
392                         sy = simasel->deey-IMALINESIZE;
393                         
394                         direntry = simasel->firstdir; 
395                         if (simasel->topdir){
396                                 for(i = simasel->topdir; i>0; i--){
397                                         direntry = direntry->next;
398                                 }
399                         }
400                         viewgate(simasel->desx, simasel->desy, simasel->deex-4, simasel->deey);
401                         
402                         i = simasel->dirsli_lines;
403                         if (i > simasel->totaldirs) i = simasel->totaldirs;
404                         for(;i > 0; i--){
405                                 strcpy(naam,  direntry->name);
406                                 
407                                 cpack(0xFFFFFF);
408                                 if (direntry->selected == 1){
409                                         cpack(0x7777CC);
410                                         glRecti(simasel->desx+2,  sy-4,  simasel->deex-4,  sy+IMALINESIZE-4);
411                                         cpack(0xFFFFFF);
412                                 }
413                                 if (direntry->hilite == 1){
414                                         cpack(0x999999);
415                                         glRecti(simasel->desx+2,  sy-4,  simasel->deex-4,  sy+IMALINESIZE-4);
416                                         cpack(0xFFFFFF);
417                                 }
418                                 
419                                 glRasterPos2i(sx,  sy);
420                                 BMF_DrawString(G.font, naam);
421                                 
422                                 direntry = direntry->next;
423                                 sy-=IMALINESIZE;
424                         }
425                         areaview();
426                         
427                 }
428                 
429                 /* status icons */
430                 
431                 sx = simasel->desx;
432                 sy = simasel->deey+6;
433                 
434                 glRasterPos2f(sx+16*0, sy);
435                 if (bitset(simasel->fase, IMS_FOUND_BIP)) {
436                         BIF_draw_icon(ICON_BPIBFOLDER_HLT);
437                 } else if (bitset(simasel->fase, IMS_WRITE_NO_BIP)) {
438                         BIF_draw_icon(ICON_BPIBFOLDER_DEHLT);
439                 } else {
440                         BIF_draw_icon(ICON_BPIBFOLDER_DEHLT);
441                 }
442
443                 glRasterPos2f(sx+16*1, sy);
444                 if (bitset(simasel->fase, IMS_KNOW_INF)) {
445                         BIF_draw_icon(ICON_FOLDER_HLT);
446                 } else {
447                         BIF_draw_icon(ICON_FOLDER_DEHLT);
448                 }
449                 
450                 glRasterPos2f(sx+16*2, sy);
451                 if (bitset(simasel->fase, IMS_KNOW_IMA)) {
452                         BIF_draw_icon(ICON_BLUEIMAGE_HLT);
453                 } else {
454                         BIF_draw_icon(ICON_BLUEIMAGE_DEHLT);
455                 }
456         }
457         
458         if (simasel->fesx >  0) {
459                 int extrabutsize;
460                 
461                 cpack(C_DARK);
462
463                 glRecti(simasel->fssx,  simasel->fssy,  simasel->fsex,  simasel->fsey);
464
465                 glRecti(simasel->fesx,  simasel->fesy,  simasel->feex,  simasel->feey);
466
467                 uiEmboss(simasel->fssx-1, simasel->fssy-1, simasel->fsex+1, simasel->fsey+1,1);
468                 uiEmboss(simasel->fesx-1, simasel->fesy-1, simasel->feex+1, simasel->feey+1,1);
469                 
470                 if (simasel->imasli == 1){
471                         sx = simasel->imasli_sx;
472                         sy = simasel->imasli_ey - simasel->imasli_h;
473                         ex = simasel->imasli_ex;
474                         ey = simasel->imasli_ey;
475                         
476                         cpack(C_BACK);
477
478                         glRecti(sx,  sy,  ex,  ey);
479                         uiEmboss(sx, sy, ex, ey, 1);
480                 }
481         
482                 info = 0;
483                 strcpy(infostr, "");
484                 if (simasel->totalima){
485                         viewgate(simasel->fesx, simasel->fesy, simasel->feex, simasel->feey);
486                 
487                         ima = simasel->first_sel_ima;
488                         
489                         while (ima){
490                                 sc = 0;
491                                 
492                                 sx = ima->sx- 6; sy = ima->sy-20 + sc; 
493                                 ex = ima->sx+71; ey = ima->sy+70 + sc;  
494                                 
495                                 if(ima->selected == 1){
496                                         cpack(0xCC6666);
497                                         glRecti(sx, sy,  ex, ey);
498                                 }
499                                 if(ima->selectable == 1){
500                                         if (ima->selected ) cpack(0xEE8888); else cpack(0x999999);
501                                         
502                                         if (((simasel->mode & 8) != 8) && (simasel->hilite_ima == ima)){
503                                                 glRecti(sx, sy,  ex, ey); uiEmboss(sx,sy, ex,ey, 1);
504                                         }
505                                         if (ima->disksize/1000 > 1000){ sprintf(infostr,  "%s  %.2fMb  x%i y%i  %i bits ",ima->file_name,(ima->disksize/1024)/1024.0, ima->orgx, ima->orgy, ima->orgd);
506                                         }else{ sprintf(infostr,  "%s  %dKb  x%i y%i  %i bits ",  ima->file_name,ima->disksize/1024,          ima->orgx, ima->orgy, ima->orgd);
507                                         }       
508                                         if (ima->anim == 1){ strcat (infostr, "movie"); }else{
509                                                 str_image_type(ima->ibuf_type, naam);
510                                                 strcat (infostr, naam);
511                                         }
512                                         info = 1;
513                                 }
514                                 
515                                 sx = ima->sx; sy = ima->sy + sc;
516                                 ex = ima->ex; ey = ima->ey + sc;
517                                 
518                                 if (ima->anim == 0) cpack(C_DARK); else cpack(C_DERK);
519                                 
520                                 glRecti(sx, sy,  ex, ey);
521                                 uiEmboss(sx-1,sy-1, ex+1,ey+1, 1);
522                                 
523                                 cpack(0);
524                                 strcpy(naam, ima->file_name);
525                                 naam[11] = 0;
526                         
527                                 glRasterPos2i(sx+32-BMF_GetStringWidth(G.fonts, naam) / 2  ,  sy-16);
528                                 BMF_DrawString(G.fonts, naam);
529                                 
530                                 if ((ima) && (ima->pict) && (ima->pict->rect)){
531                                         if ( (ey > simasel->fesy) && (sy < simasel->feey)){
532                                                 lrectwrite(sx, sy, ex-1, ey-1, ima->pict->rect);
533                                         }
534                                 }
535                         
536                                 ima = ima->next;
537                         }
538                         
539                         if ((simasel->mode & 8) == 8) {  /* if loep */
540                                 
541                                 if (bitset(simasel->fase, IMS_KNOW_IMA) && (simasel->hilite_ima)) {
542                         
543                                         ima = simasel->hilite_ima;
544                                         glPixelZoom(2.0,  2.0);
545                                         
546                                         sx = ima->sx + (ima->ex - ima->sx)/2 - (ima->ex - ima->sx);
547                                         sy = ima->sy + (ima->ey - ima->sy)/2 - (ima->ey - ima->sy);
548                                         
549                                         ex = sx + 2*(ima->ex - ima->sx);
550                                         ey = sy + 2*(ima->ey - ima->sy);
551                                         
552                                         /* cpack(C_DERK); */
553                                         /* uiEmboss(sx-8,sy-8, ex+8,ey+8, 1); */
554                                         /* glRecti(sx-7, sy-7,  ex+7, ey+7); */
555                                         uiEmboss(sx-1,sy-1, ex+1,ey+1, 0);
556                                 
557                                         lrectwrite(sx, sy, sx+ (ima->ex - ima->sx)-1, sy+ (ima->ey - ima->sy)-1, ima->pict->rect);
558                                         
559                                         glPixelZoom(1.0,  1.0);
560                                 }
561                         }
562                         areaview();  /*  reset viewgate */
563                 }
564                 
565                 
566                 /* INFO */
567                 if (simasel->infsx > 0){
568                         cpack(C_DARK);
569
570                         glRecti(simasel->infsx,  simasel->infsy,  simasel->infex,  simasel->infey);
571                         uiEmboss(simasel->infsx, simasel->infsy, simasel->infex, simasel->infey,1);
572                 
573                         if ((info)&&(strlen(infostr) > 0)){
574                                 
575                                 sx = curarea->winrct.xmin;
576                                 sy = curarea->winrct.ymin;
577                                 
578                                 viewgate(simasel->infsx, simasel->infsy, simasel->infex, simasel->infey);
579                         
580                                 cpack(0xAAAAAA);
581                                 glRasterPos2i(simasel->infsx+4,  simasel->infsy+6);
582                                 BMF_DrawString(G.font, infostr);
583                                 
584                                 areaview();  /*  reset viewgate */
585         
586                         }
587                 }
588
589                 extrabutsize= (simasel->returnfunc)?60:0;
590                 if (simasel->dnw > extrabutsize+8) {
591                         simasel->dnw-= extrabutsize;
592                         uiDefBut(block, TEX, 1,"", simasel->dnsx, simasel->dnsy, simasel->dnw, simasel->dnh, simasel->dir,  0.0, (float)FILE_MAXFILE-1, 0, 0, "");
593                         if (extrabutsize)
594                                 uiDefBut(block, BUT, 5, "Load", simasel->dnsx+simasel->dnw, simasel->dnsy, extrabutsize, 21, NULL, 0.0, 0.0, 0, 0, "Load the selected image");
595                 }
596                 if (simasel->fnw > extrabutsize+8) {
597                         simasel->fnw-= extrabutsize;
598                         uiDefBut(block, TEX, 2,"", simasel->fnsx, simasel->fnsy, simasel->fnw, simasel->fnh, simasel->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
599                         if (extrabutsize)
600                                 uiDefBut(block, BUT, 6, "Cancel",       simasel->fnsx+simasel->fnw, simasel->fnsy, extrabutsize, 21, NULL, 0.0, 0.0, 0, 0, "Cancel image loading");
601                 }
602         }
603         
604         if (curarea->winx > 16) {
605                 char *menu= fsmenu_build_menu();
606
607                 uiDefBut(block, BUT, 13, "P", 8, (short)(curarea->winy-29), 20, 21, 0, 0, 0, 0, 0, "");
608                 uiDefButS(block, MENU, 3 , menu, 8, (short)(curarea->winy-58), 20, 21, &simasel->fileselmenuitem, 0, 0, 0, 0, "");
609
610                 MEM_freeN(menu);
611         }
612         
613         uiDrawBlock(block);
614 }
615
616 void select_ima_files(SpaceImaSel *simasel)
617 {
618         short set_reset;
619         short mval[2], oval[2];
620         
621         set_reset =  1 - (simasel->hilite_ima->selected);
622         
623         getmouseco_areawin(mval);
624         oval[0] = mval[0] + 1;
625         
626         while(get_mbut()&R_MOUSE) { 
627                 getmouseco_areawin(mval);
628                 if ((oval[0] != mval[0]) || (oval[1] != mval[1])){
629                         simasel->mx = mval[0];
630                         simasel->my = mval[1];
631                         
632                         calc_hilite(simasel);
633                         
634                         if (simasel->hilite_ima){
635                                 simasel->hilite_ima->selected = set_reset;
636                                 scrarea_do_windraw(curarea);
637                                 screen_swapbuffers();   
638                         }
639                         oval[0] = mval[0];
640                         oval[1] = mval[1];
641                 }
642         }
643 }
644
645 void move_imadir_sli(SpaceImaSel *simasel)
646 {
647         
648         short mval[2], lval[2], fh;
649         float rh;
650         
651         getmouseco_areawin(mval);
652         
653         if ((mval[0] > simasel->dirsli_sx) && 
654             (mval[0] < simasel->dirsli_ex) && 
655                 (mval[1] > simasel->dirsli_ey - simasel->dirsli_h) &&
656                 (mval[1] < simasel->dirsli_ey) ){
657                 
658                 /*  extactly in the slider  */
659                 fh = simasel->dirsli_ey - mval[1];
660                 lval[1]=1;
661                 while(get_mbut()&L_MOUSE) { 
662                         getmouseco_areawin(mval);
663                         if (mval[1] != lval[1]){
664                                 
665                                 rh = (float)(simasel->dsey - mval[1] - fh - simasel->dssy) / (simasel->dsdh - simasel->dirsli_h);
666                                 
667                                 simasel->topdir = 1 + rh * (simasel->totaldirs - simasel->dirsli_lines);
668                                 
669                                 scrarea_do_windraw(curarea);
670                                 uiEmboss(simasel->dirsli_sx, simasel->dirsli_ey - simasel->dirsli_h, 
671                                                    simasel->dirsli_ex, simasel->dirsli_ey,1);
672                             screen_swapbuffers();
673                                 lval[1] = mval[1];
674                         }
675                 }       
676         }else{
677                 if (mval[1] < simasel->dirsli_ey - simasel->dirsli_h)
678                         simasel->topdir += (simasel->dirsli_lines - 1); 
679                 else
680                         simasel->topdir -= (simasel->dirsli_lines - 1); 
681                         
682                 while(get_mbut()&L_MOUSE) {  }
683         }
684 }
685
686 void move_imafile_sli(SpaceImaSel *simasel)
687 {
688         short mval[2], cmy, omy = 0;
689         short ssl, sdh, ssv;
690         
691         getmouseco_areawin(mval);
692         cmy = mval[1];
693         
694         if ((mval[0] > simasel->imasli_sx) && 
695             (mval[0] < simasel->imasli_ex) && 
696                 (mval[1] > simasel->imasli_ey - simasel->imasli_h) &&
697                 (mval[1] < simasel->imasli_ey) ){
698                 
699                 ssv = simasel->fsey - simasel->imasli_ey - 2;
700                 
701                 while(get_mbut() & L_MOUSE) { 
702                         getmouseco_areawin(mval);
703                         if (mval[1] != omy){
704                                 sdh = simasel->fsdh - simasel->imasli_h;
705                                 ssl = cmy -  mval[1] + ssv;
706                                 
707                                 if (ssl < 0)   { ssl = 0; }
708                                 if (ssl > sdh) { ssl = sdh; }
709                                 
710                                 simasel->image_slider = ssl / (float)sdh;
711                                 
712                                 scrarea_do_windraw(curarea);
713                                 uiEmboss(simasel->imasli_sx, simasel->imasli_ey - simasel->imasli_h, 
714                                                    simasel->imasli_ex, simasel->imasli_ey, 1);
715                            
716                                 screen_swapbuffers();
717                                 omy = mval[1];
718                         }
719                 }
720         }else{
721                 while(get_mbut() & L_MOUSE) {  }
722         }
723 }
724
725 void ima_select_all(SpaceImaSel *simasel)
726 {
727         OneSelectableIma *ima;
728         int reselect = 0;
729         
730         ima = simasel->first_sel_ima;
731         if (!ima) return;
732         
733         while(ima){
734                 if (ima->selected == 1) reselect = 1;
735                 ima = ima->next;
736         }
737         ima = simasel->first_sel_ima;
738         if (reselect == 1){
739                 while(ima){
740                         ima->selected = 0;
741                         ima = ima->next;
742                 }
743         }else{
744                 while(ima){
745                         ima->selected = 1;
746                         ima = ima->next;
747                 }
748         }
749 }
750
751 void pibplay(SpaceImaSel *simasel)
752 {
753         OneSelectableIma *ima;
754         int sx= 8, sy= 8;
755         
756         ima = simasel->first_sel_ima;
757         if (!ima) return ;
758         
759         sx = curarea->winrct.xmin + 8; 
760         sy = curarea->winrct.ymin + 8;
761         
762         while(!(get_mbut()&L_MOUSE)){
763                 scrarea_do_windraw(curarea);     
764                 
765                 lrectwrite(sx, sy, sx+ima->dw-1, sy+ima->dh-1, ima->pict->rect);
766                 
767                 ima = ima->next;
768                 if (!ima) ima = simasel->first_sel_ima;
769                 screen_swapbuffers();   
770         }
771 }
772
773
774
775 /* ************** hoofdtekenfunktie ************** */
776
777 void drawimasel()       /* hoofdtekenfunktie */
778 {
779         SpaceImaSel *simasel;
780         simasel= curarea->spacedata.first;
781         
782         /* ortho: xmin xmax, ymin, ymax! */
783         myortho2(-0.5, (float)(curarea->winx)-0.5, -0.5, (float)(curarea->winy)-0.5);
784         
785         if (simasel->fase == 0){
786                 checkdir(simasel->dir);
787                 clear_ima_dir(simasel);
788         }
789
790         if (!bitset(simasel->fase, IMS_KNOW_DIR)){
791                 if(simasel->firstdir)   free_ima_dir(simasel->firstdir);
792                 if(simasel->firstfile)  free_ima_dir(simasel->firstfile);
793                 simasel->firstdir   = 0;
794                 simasel->firstfile  = 0;
795         
796                 if (get_ima_dir(simasel->dir, IMS_DIR,  &simasel->totaldirs,  &simasel->firstdir) < 0){
797                         /* error */
798                         strcpy(simasel->dir, simasel->dor);
799                         get_ima_dir(simasel->dir, IMS_DIR,  &simasel->totaldirs,  &simasel->firstdir);
800                 }
801                 
802                 if (get_ima_dir(simasel->dir, IMS_FILE, &simasel->totalfiles, &simasel->firstfile) < 0){
803                         /* error */
804                         strcpy(simasel->file, simasel->fole);
805                         get_ima_dir(simasel->dir, IMS_FILE, &simasel->totalfiles, &simasel->firstfile);
806                 }
807                 
808                 simasel->topdir  = 0;
809                 simasel->topfile = 0;
810                 simasel->fase |= IMS_KNOW_DIR;
811                 
812                 check_for_pib(simasel);
813                 
814                 strcpy(simasel->fole, simasel->file);
815                 strcpy(simasel->dor,  simasel->dir);
816         }
817                 
818         if (!bitset(simasel->fase, IMS_FOUND_BIP)){
819                 /* Make the first Bip file ever in this directory */
820                 if ( !bitset(simasel->fase, IMS_KNOW_INF)){
821                         if (!bitset(simasel->fase, IMS_DOTHE_INF)){
822                                 if(simasel->first_sel_ima)      free_sel_ima(simasel->first_sel_ima);
823                                 simasel->first_sel_ima   = 0;
824                                 simasel->fase |= IMS_DOTHE_INF;
825                                 addafterqueue(curarea->win, AFTERIMASELIMA, 1);
826                         }
827                 }
828         }else{
829                 if (!bitset(simasel->fase, IMS_KNOW_BIP)){
830                         addafterqueue(curarea->win, AFTERPIBREAD, 1);
831                 }
832         }
833         
834         make_sima_area(simasel);
835         calc_hilite(simasel);
836         draw_sima_area(simasel);
837         
838         curarea->win_swap= WIN_BACK_OK;
839 }
840