[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
| 4 | * |
---|
| 5 | * This software was released into the Public Domain. As with most public |
---|
| 6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
| 7 | * Jonathan Clark. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "config.h" |
---|
| 11 | |
---|
[481] | 12 | #include "filesel.h" |
---|
| 13 | #include "input.h" |
---|
| 14 | #include "scroller.h" |
---|
| 15 | #include "jdir.h" |
---|
[2] | 16 | |
---|
| 17 | class file_picker : public spicker |
---|
| 18 | { |
---|
| 19 | char **f,**d; |
---|
| 20 | int tf,td,wid,sid; |
---|
| 21 | char cd[300]; |
---|
| 22 | public: |
---|
| 23 | file_picker(int X, int Y, int ID, int Rows, ifield *Next); |
---|
| 24 | virtual int total() { return tf+td; } |
---|
[106] | 25 | virtual int item_width() { return wm->font()->width()*wid; } |
---|
| 26 | virtual int item_height() { return wm->font()->height()+1; } |
---|
| 27 | virtual void draw_item(image *screen, int x, int y, int num, int active); |
---|
[120] | 28 | virtual void note_selection(image *screen, InputManager *inm, int x); |
---|
[2] | 29 | void free_up(); |
---|
| 30 | ~file_picker() { free_up(); } |
---|
[124] | 31 | } ; |
---|
[2] | 32 | |
---|
| 33 | void file_picker::free_up() |
---|
| 34 | { |
---|
| 35 | int i=0; |
---|
| 36 | for (;i<tf;i++) |
---|
[129] | 37 | free(f[i]); |
---|
[2] | 38 | for (i=0;i<td;i++) |
---|
[129] | 39 | free(d[i]); |
---|
| 40 | if (tf) free(f); |
---|
| 41 | if (td) free(d); |
---|
[2] | 42 | } |
---|
| 43 | |
---|
[120] | 44 | void file_picker::note_selection(image *screen, InputManager *inm, int x) |
---|
[2] | 45 | { |
---|
| 46 | if (x<td) |
---|
| 47 | { |
---|
| 48 | if (strcmp(d[x],".")) |
---|
| 49 | { |
---|
| 50 | int x1,y1,x2,y2; |
---|
[106] | 51 | area(x1,y1,x2,y2); |
---|
[2] | 52 | screen->bar(x1,y1,x2,y2,wm->medium_color()); |
---|
| 53 | |
---|
| 54 | char st[200],curdir[200]; |
---|
| 55 | sprintf(st,"%s/%s",cd,d[x]); |
---|
| 56 | getcwd(curdir,200); |
---|
| 57 | chdir(st); |
---|
| 58 | getcwd(cd,200); |
---|
| 59 | chdir(curdir); |
---|
| 60 | |
---|
| 61 | free_up(); |
---|
| 62 | get_directory(cd,f,tf,d,td); |
---|
| 63 | wid=0; |
---|
| 64 | int i=0; |
---|
| 65 | for (;i<tf;i++) |
---|
[4] | 66 | if ((int)strlen(f[i])>wid) wid=strlen(f[i]); |
---|
[2] | 67 | for (i=0;i<td;i++) |
---|
[4] | 68 | if ((int)strlen(d[i])+2>wid) wid=strlen(d[i])+2; |
---|
[2] | 69 | sx=0; |
---|
| 70 | |
---|
| 71 | |
---|
[124] | 72 | |
---|
| 73 | reconfigure(); |
---|
[106] | 74 | draw_first(screen); |
---|
[2] | 75 | } |
---|
| 76 | } else |
---|
| 77 | { |
---|
| 78 | char nm[200]; |
---|
| 79 | sprintf(nm,"%s/%s",cd,f[x-td]); |
---|
| 80 | text_field *link=(text_field *)inm->get(sid); |
---|
[106] | 81 | link->change_data(nm,strlen(nm),1,screen); |
---|
[2] | 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
[106] | 86 | void file_picker::draw_item(image *screen, int x, int y, int num, int active) |
---|
[2] | 87 | { |
---|
| 88 | if (active) |
---|
[106] | 89 | screen->bar(x,y,x+item_width()-1,y+item_height()-1,wm->black()); |
---|
[2] | 90 | |
---|
| 91 | if (num<td) |
---|
| 92 | { |
---|
| 93 | char st[100]; |
---|
| 94 | sprintf(st,"<%s>",d[num]); |
---|
| 95 | wm->font()->put_string(screen,x,y,st,wm->bright_color()); |
---|
| 96 | } else |
---|
| 97 | wm->font()->put_string(screen,x,y,f[num-td],wm->bright_color()); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | file_picker::file_picker(int X, int Y, int ID, int Rows, ifield *Next) |
---|
| 101 | : spicker(X,Y,0,Rows,1,1,0,Next) |
---|
| 102 | { |
---|
[124] | 103 | |
---|
[2] | 104 | sid=ID; |
---|
| 105 | |
---|
| 106 | strcpy(cd,"."); |
---|
[124] | 107 | |
---|
[2] | 108 | get_directory(cd,f,tf,d,td); |
---|
| 109 | wid=0; |
---|
| 110 | int i=0; |
---|
| 111 | for (;i<tf;i++) |
---|
[4] | 112 | if ((int)strlen(f[i])>wid) wid=strlen(f[i]); |
---|
[2] | 113 | for (i=0;i<td;i++) |
---|
[4] | 114 | if ((int)strlen(d[i])+2>wid) wid=strlen(d[i])+2; |
---|
[124] | 115 | reconfigure(); |
---|
[2] | 116 | } |
---|
| 117 | |
---|
[120] | 118 | Jwindow *file_dialog(char const *prompt, char const *def, |
---|
[124] | 119 | int ok_id, char const *ok_name, int cancel_id, |
---|
[39] | 120 | char const *cancel_name, char const *FILENAME_str, |
---|
| 121 | int filename_id) |
---|
[2] | 122 | { |
---|
[111] | 123 | int wh2 = 5 + wm->font()->height() + 5; |
---|
| 124 | int wh3 = wh2 + wm->font()->height() + 12; |
---|
[120] | 125 | Jwindow *j=wm->new_window(0,0,-1,-1, |
---|
[124] | 126 | new info_field(5, 5, 0, prompt, |
---|
[111] | 127 | new text_field(0, wh2, filename_id, |
---|
[124] | 128 | ">","****************************************",def, |
---|
| 129 | new button(50, wh3, ok_id, ok_name, |
---|
| 130 | new button(100, wh3, cancel_id, cancel_name, |
---|
| 131 | new file_picker(15, wh3 + wm->font()->height() + 10, filename_id, 8, |
---|
| 132 | NULL))))), |
---|
[2] | 133 | |
---|
[124] | 134 | FILENAME_str); |
---|
[2] | 135 | return j; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | |
---|