source: abuse/trunk/src/imlib/filesel.cpp @ 481

Last change on this file since 481 was 481, checked in by Sam Hocevar, 11 years ago

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

File size: 3.4 KB
Line 
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
12#include "filesel.h"
13#include "input.h"
14#include "scroller.h"
15#include "jdir.h"
16
17class 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; }
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);
28  virtual void note_selection(image *screen, InputManager *inm, int x);
29  void free_up();
30  ~file_picker() { free_up(); }
31} ;
32
33void file_picker::free_up()
34{
35  int i=0;
36  for (;i<tf;i++)
37    free(f[i]);
38  for (i=0;i<td;i++)
39    free(d[i]);
40  if (tf) free(f);
41  if (td) free(d);
42}
43
44void file_picker::note_selection(image *screen, InputManager *inm, int x)
45{
46  if (x<td)
47  {
48    if (strcmp(d[x],"."))
49    {
50      int x1,y1,x2,y2;
51      area(x1,y1,x2,y2);
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++)
66      if ((int)strlen(f[i])>wid) wid=strlen(f[i]);
67      for (i=0;i<td;i++)
68      if ((int)strlen(d[i])+2>wid) wid=strlen(d[i])+2;
69      sx=0;
70
71
72
73      reconfigure();
74      draw_first(screen);
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);
81    link->change_data(nm,strlen(nm),1,screen);
82  }
83
84}
85
86void file_picker::draw_item(image *screen, int x, int y, int num, int active)
87{
88  if (active)
89    screen->bar(x,y,x+item_width()-1,y+item_height()-1,wm->black());
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
100file_picker::file_picker(int X, int Y, int ID, int Rows, ifield *Next)
101  : spicker(X,Y,0,Rows,1,1,0,Next)
102{
103
104  sid=ID;
105
106  strcpy(cd,".");
107
108  get_directory(cd,f,tf,d,td);
109  wid=0;
110  int i=0;
111  for (;i<tf;i++)
112    if ((int)strlen(f[i])>wid) wid=strlen(f[i]);
113  for (i=0;i<td;i++)
114    if ((int)strlen(d[i])+2>wid) wid=strlen(d[i])+2;
115  reconfigure();
116}
117
118Jwindow *file_dialog(char const *prompt, char const *def,
119             int ok_id, char const *ok_name, int cancel_id,
120                     char const *cancel_name, char const *FILENAME_str,
121                     int filename_id)
122{
123  int wh2 = 5 + wm->font()->height() + 5;
124  int wh3 = wh2 + wm->font()->height() + 12;
125  Jwindow *j=wm->new_window(0,0,-1,-1,
126                new info_field(5, 5, 0, prompt,
127                            new text_field(0, wh2, filename_id,
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))))),
133
134                FILENAME_str);
135  return j;
136}
137
138
139
140
141
Note: See TracBrowser for help on using the repository browser.