⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myapplication.h

📁 基于paragui实现的一个在linux操作系统下使用framebuffer来进行窗口模式的文件选择的源代码。
💻 H
字号:
#include "PmpListBox.h"#include "pgapplication.h"#include "pgnavigator.h"#include "vector"#include "sys/types.h"#include "sys/stat.h"#include "dirent.h"#include "iostream"#include "string.h"#include "PmpRichEdit.h"#include "stdlib.h"using namespace std;class MyApplication : public PG_Application, public PG_Navigator {public:        char *NowPath;        MyApplication();        ~MyApplication();        PmpListBox *MyListBox;        PmpRichEdit *MyRichEdit;        void GetFileList();        bool IsDirectory(char*);        void GoToNextPath(char*);        void BackToPrevPath();        void ShowItem(PmpListBox*);        const char* GetSelectedText(PmpListBox*);        bool handleListBoxItem(PmpListBox*,PmpRichEdit*); private:               vector<string> FileList;        char *FilePath;        char *FileName;        bool maiplayer;        bool eventKeyDown(const SDL_KeyboardEvent* key);};MyApplication::MyApplication():MyRichEdit(NULL),maiplayer(false){       NowPath = new char[1024];}MyApplication::~MyApplication(){      delete NowPath;}bool MyApplication::eventKeyDown(const SDL_KeyboardEvent* key) {	switch(key->keysym.sym) {		case SDLK_UP:                    if(MyRichEdit == NULL)                    {                        if(FileList.size() < 12 ||MyListBox->GetSelectedIndex() >=FileList.size() - 11)                        {                                 MyListBox->SelectPrevItem();                        }                        else if(MyListBox->GetScrollPosY() <= 20)                        {                                MyListBox->SelectPrevItem();                                MyListBox->Scroll(0);                        }                        else                        {                                       MyListBox->SelectPrevItem();                                MyListBox->Scroll((MyListBox->GetScrollPosY())-20);                        }                    }                    else                    {                        MyRichEdit -> Up();                    }          	break;		case SDLK_DOWN:                    if(MyRichEdit == NULL)                    {                        if(MyListBox->GetSelectedIndex() < 11)                        {                             MyListBox->SelectNextItem();                        }                        else                         {                                 MyListBox->SelectNextItem();                             MyListBox->Scroll((MyListBox->GetScrollPosY())+20);                        }                    }                    else                    {                        MyRichEdit -> Down();                    }                    break;                case SDLK_KP_ENTER:                        handleListBoxItem(MyListBox,MyRichEdit);	                        break;                case SDLK_F1:                        delete MyRichEdit;                        MyRichEdit = NULL;                        break;                default:                        break;                }}bool MyApplication::handleListBoxItem(PmpListBox *ListBox,PmpRichEdit *RichEdit){         char *s = new char[256];     strcpy(s,GetSelectedText(ListBox));     char *s1 = new char[1024];     strcpy(s1,NowPath);     strcat(s1,"/");     strcat(s1,s);     string s2 = s;     if(strcmp(s,"..") == 0 && strcmp(NowPath,"/home") != 0)     {                ListBox -> DeleteAll();                BackToPrevPath();                ShowItem(ListBox);                delete s;                delete s1;                return true;     }     if(IsDirectory(s1))     {                ListBox -> DeleteAll();                GoToNextPath(s);                ShowItem(ListBox);                delete s;                delete s1;                return true;     }     if(s2.compare(s2.size()-4,s2.size(),".cpp") == 0)     {                          char *s4 = new char[1024];                strcpy(s4,"cp ");                strcat(s4,s1);                strcat(s4," temp");                system(s4);                      MyRichEdit = new PmpRichEdit(NULL,PG_Rect(0,0,640,480));                MyRichEdit->LoadText("temp");                MyRichEdit->Show();                        delete s;                delete s1;                delete s4;                return true;     }     if(s2.compare(s2.size()-4,s2.size(),".mpg")== 0)     {                cout << "1" << endl;                 char *s3 = new char[256];                string cmd = "./maiplayer auto";                cout << "2" << endl;                cmd = cmd + s1;                system(cmd.c_str());                cout <<"3" << endl;                delete s;                delete s1;                delete s3;                return true;                    }     return false;}void MyApplication::BackToPrevPath(){     char *s = new char[1024];     strcpy(s,NowPath);     char *p = rindex(s,'/');     char A[1024] = "";     for(int i = 0; i < strlen(s)-strlen(p); i++)     {             A[i] = s[i];     }     strcpy(NowPath,A);     GetFileList();     delete s;   }void MyApplication::GoToNextPath(char *FileName){     char *s = new char[1024];     strcpy(s,NowPath);     strcat(s,"/");     strcat(s,FileName);     strcpy(NowPath,s);     GetFileList();      delete s;    }const char* MyApplication::GetSelectedText(PmpListBox *ListBox){     PG_ListBoxBaseItem *item = ListBox->GetSelectedItem();     const char *s = item->GetText();     return s;  } void MyApplication::GetFileList(){        DIR *dp;        struct dirent   *dirp;                FileList.clear();        dp = opendir(NowPath);        while(( dirp = readdir(dp)) != NULL)        {                        string s1 = dirp->d_name;                char *s = new char[1024];                strcpy(s,NowPath);                strcat(s,"/");                strcat(s,dirp->d_name);                if(s1.size() > 4 && s1.compare(s1.size()-4,s1.size(),".cpp") == 0)                {                       FileList.push_back(dirp->d_name);                }                if(s1.size() > 4 && s1.compare(s1.size()-4,s1.size(),".mpg") == 0)                {                       FileList.push_back(dirp->d_name);                }                if(IsDirectory(s))                {                     FileList.push_back(dirp->d_name);                }                 delete s;         }      }void MyApplication::ShowItem(PmpListBox *ListBox){             PG_ListBoxItem *item;       for(int i = 0; i < FileList.size(); i++)       {                            item = new PG_ListBoxItem(MyListBox,20,"");                  char A[256] = "";                   for(int t = 0 ; t < FileList[i].size(); ++t)                  {                            A[t] = FileList[i][t];                  }                  if( strcmp(A,".") != 0 && strcmp(A,"..") != 0)                  {                               item->SetIcon("1.gif");                          item->SetTextFormat("%s",A);                  }                  else                  {                               item->SetIcon("3.gif");                          item->SetTextFormat("%s",A);                  }       }       MyListBox->SelectFirstItem();}bool MyApplication::IsDirectory(char *FilePath){    struct stat buf;    lstat(FilePath,&buf);    if(S_ISDIR(buf.st_mode))    {          return true;    }    return false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -