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

Last change on this file since 56 was 56, checked in by Sam Hocevar, 11 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 3.6 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#ifdef __WATCOMC__
13#   include <direct.h>
14#endif
15
16#include "filesel.hpp"
17#include "input.hpp"
18#include "scroller.hpp"
19#include "jdir.hpp"
20
21class file_picker : public spicker
22{
23  char **f,**d;
24  int tf,td,wid,sid;
25  char cd[300];
26  public:
27  file_picker(int X, int Y, int ID, int Rows, ifield *Next);
28  virtual int total() { return tf+td; }
29  virtual int item_width(window_manager *wm) { return wm->font()->width()*wid; }
30  virtual int item_height(window_manager *wm) { return wm->font()->height()+1; }
31  virtual void draw_item(window_manager *wm, image *screen, int x, int y, int num, int active);
32  virtual void note_selection(window_manager *wm, image *screen, input_manager *inm, int x);
33  void free_up();
34  ~file_picker() { free_up(); }
35} ;
36
37void file_picker::free_up()
38{
39  int i=0;
40  for (;i<tf;i++)
41    jfree(f[i]);
42  for (i=0;i<td;i++)
43    jfree(d[i]);
44  if (tf) jfree(f);
45  if (td) jfree(d);
46}
47
48void file_picker::note_selection(window_manager *wm, image *screen, input_manager *inm, int x)
49{
50  if (x<td)
51  {
52    if (strcmp(d[x],"."))
53    {
54      int x1,y1,x2,y2;
55      area(x1,y1,x2,y2,wm);
56      screen->bar(x1,y1,x2,y2,wm->medium_color());
57
58      char st[200],curdir[200];
59      sprintf(st,"%s/%s",cd,d[x]);
60      getcwd(curdir,200);
61      chdir(st);
62      getcwd(cd,200);
63      chdir(curdir);
64
65      free_up();
66      get_directory(cd,f,tf,d,td);
67      wid=0;
68      int i=0;
69      for (;i<tf;i++)
70      if ((int)strlen(f[i])>wid) wid=strlen(f[i]);
71      for (i=0;i<td;i++)
72      if ((int)strlen(d[i])+2>wid) wid=strlen(d[i])+2;
73      sx=0;
74
75     
76
77      reconfigure(); 
78      draw_first(screen,wm);
79    }
80  } else
81  {
82    char nm[200];
83    sprintf(nm,"%s/%s",cd,f[x-td]);
84    text_field *link=(text_field *)inm->get(sid);
85    link->change_data(nm,strlen(nm),1,screen,wm);
86  }
87
88}
89
90void file_picker::draw_item(window_manager *wm, image *screen, int x, int y, int num, int active)
91{
92  if (active)
93    screen->bar(x,y,x+item_width(wm)-1,y+item_height(wm)-1,wm->black());
94
95  if (num<td)
96  {
97    char st[100];
98    sprintf(st,"<%s>",d[num]);
99    wm->font()->put_string(screen,x,y,st,wm->bright_color());
100  } else
101    wm->font()->put_string(screen,x,y,f[num-td],wm->bright_color());
102}
103
104file_picker::file_picker(int X, int Y, int ID, int Rows, ifield *Next)
105  : spicker(X,Y,0,Rows,1,1,0,Next)
106{
107 
108  sid=ID;
109
110  strcpy(cd,".");
111 
112  get_directory(cd,f,tf,d,td);
113  wid=0;
114  int i=0;
115  for (;i<tf;i++)
116    if ((int)strlen(f[i])>wid) wid=strlen(f[i]);
117  for (i=0;i<td;i++)
118    if ((int)strlen(d[i])+2>wid) wid=strlen(d[i])+2;
119  reconfigure(); 
120}
121
122jwindow *file_dialog(window_manager *wm, char const *prompt, char const *def,
123                     int ok_id, char const *ok_name, int cancel_id,
124                     char const *cancel_name, char const *FILENAME_str,
125                     int filename_id)
126{
127  int wl=WINDOW_FRAME_LEFT,wh=WINDOW_FRAME_TOP;
128  int wh2=wh+5+wm->font()->height()+5;
129  int wh3=wh2+wm->font()->height()+12;
130  jwindow *j=wm->new_window(0,0,-1,-1,
131                            new info_field(wl+5,wh+5,0,prompt,
132                            new text_field(wl,wh2,filename_id,
133                                           ">","****************************************",def,
134                            new button(wl+50,wh3,ok_id,     ok_name,
135                            new button(wl+100,wh3,cancel_id,cancel_name,
136                            new file_picker(wl+15,wh3+wm->font()->height()+10,filename_id,8,
137                                          NULL))))),
138
139                            FILENAME_str);
140  return j;
141}
142
143
144
145
146
Note: See TracBrowser for help on using the repository browser.