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

Last change on this file since 106 was 106, checked in by Sam Hocevar, 15 years ago
  • Rename the "eh" variable to "wm" because it's a window manager, not an event handler.
  • No longer pass the window manager to functions, there's only one.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Starting work on singleton code; will get rid of all

references to an arbitrary window_manager* because
there's only going to be one, and it's not ever
going to change.

File size: 3.4 KB
RevLine 
[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
[2]12#include "filesel.hpp"
13#include "input.hpp"
14#include "scroller.hpp"
15#include "jdir.hpp"
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; }
[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);
28  virtual void note_selection(image *screen, input_manager *inm, int x);
[2]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    jfree(f[i]);
38  for (i=0;i<td;i++)
39    jfree(d[i]);
40  if (tf) jfree(f);
41  if (td) jfree(d);
42}
43
[106]44void file_picker::note_selection(image *screen, input_manager *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     
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]86void 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
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++)
[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;
[2]115  reconfigure(); 
116}
117
[106]118jwindow *file_dialog(char const *prompt, char const *def,
[39]119                     int ok_id, char const *ok_name, int cancel_id,
120                     char const *cancel_name, char const *FILENAME_str,
121                     int filename_id)
[2]122{
123  int wl=WINDOW_FRAME_LEFT,wh=WINDOW_FRAME_TOP;
124  int wh2=wh+5+wm->font()->height()+5;
125  int wh3=wh2+wm->font()->height()+12;
126  jwindow *j=wm->new_window(0,0,-1,-1,
127                            new info_field(wl+5,wh+5,0,prompt,
128                            new text_field(wl,wh2,filename_id,
129                                           ">","****************************************",def,
130                            new button(wl+50,wh3,ok_id,     ok_name,
131                            new button(wl+100,wh3,cancel_id,cancel_name,
132                            new file_picker(wl+15,wh3+wm->font()->height()+10,filename_id,8,
133                                          NULL))))),
134
135                            FILENAME_str);
136  return j;
137}
138
139
140
141
142
Note: See TracBrowser for help on using the repository browser.