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

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

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

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