| 1 | #include <FL/Fl.H> |
| 2 | #include <FL/Fl_Window.H> |
| 3 | #include <FL/Fl_Button.H> |
| 4 | #include <FL/Fl_Choice.H> |
| 5 | #include <FL/Fl_File_Chooser.H> |
| 6 | #include <FL/Fl_Box.H> |
| 7 | #include <FL/Fl_Scroll.H> |
| 8 | #include <FL/Fl_Image.H> |
| 9 | #include <FL/Fl_PNG_Image.H> |
| 10 | #include <FL/Fl_JPEG_Image.H> |
| 11 | |
| 12 | #include <exception> |
| 13 | #include <iostream> |
| 14 | #include <string> |
| 15 | |
| 16 | #include <sys/stat.h> |
| 17 | #include <dirent.h> |
| 18 | |
| 19 | #include "src/fe/theme.hh" |
| 20 | #include "src/fe/window.hh" |
| 21 | #include "src/fe/widget.hh" |
| 22 | #include "src/fe/background.hh" |
| 23 | #include "src/fe/thumbnail.hh" |
| 24 | |
| 25 | #include "src/uw/background.hh" |
| 26 | |
| 27 | void thumbnail_cb(Fl_Widget *widget, void *userdata) { |
| 28 | (void)widget; |
| 29 | const char *filepath = static_cast<const char *>(userdata); |
| 30 | if (filepath) { |
| 31 | uw::Background b(filepath); |
| 32 | b.setWallpaper(uw::Mode::TILE); |
| 33 | fe::Widget::getSetButton()->deactivate(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void usage(fe::Window w) { |
| 38 | std::cout << w.getName() << "-" << w.getVersion() << '\n'; |
| 39 | std::cout << "usage: " << w.getName() << " " << w.getOptions() << " <image>" |
| 40 | << std::endl; |
| 41 | } |
| 42 | |
| 43 | int main(int argc, char **argv) { |
| 44 | fe::Window w; |
| 45 | |
| 46 | if (argc == 1) { |
| 47 | std::string tit = w.getName() + " " + w.getVersion(); |
| 48 | Fl_Window *window = |
| 49 | new Fl_Window(w.getWidth(), w.getHeight(), tit.c_str()); |
| 50 | |
| 51 | fe::Theme::SetDarkTheme(); |
| 52 | |
| 53 | |
| 54 | fe::Widget::setChooseButton(new Fl_Button(10, 740, 200, 40, "画像を選択")); |
| 55 | fe::Widget::setSetButton(new Fl_Button(230, 740, 200, 40, "背景の設置")); |
| 56 | fe::Widget::getSetButton()->deactivate(); |
| 57 | |
| 58 | |
| 59 | Fl_Choice *modeChoice = new Fl_Choice(450, 740, 200, 40, ""); |
| 60 | modeChoice->add("タイル"); |
| 61 | modeChoice->add("中央"); |
| 62 | modeChoice->add("全画像"); |
| 63 | modeChoice->value(0); |
| 64 | modeChoice->align(FL_ALIGN_TOP); |
| 65 | modeChoice->color(FL_BACKGROUND_COLOR); |
| 66 | modeChoice->textcolor(FL_FOREGROUND_COLOR); |
| 67 | modeChoice->selection_color(FL_BACKGROUND2_COLOR); |
| 68 | fe::Widget::setModeChoice(modeChoice); |
| 69 | |
| 70 | |
| 71 | fe::Widget::setScroll(new Fl_Scroll(10, 10, 780, 720)); |
| 72 | fe::Widget::getScroll()->type(Fl_Scroll::VERTICAL); |
| 73 | fe::Widget::getScroll()->begin(); |
| 74 | |
| 75 | |
| 76 | fe::Thumbnail thumbnail; |
| 77 | thumbnail.init(); |
| 78 | |
| 79 | fe::Widget::getScroll()->end(); |
| 80 | |
| 81 | |
| 82 | fe::Widget::getChooseButton()->callback(fe::Background::chooseImageCb, |
| 83 | (void *)fe::Widget::getSetButton()); |
| 84 | fe::Widget::getSetButton()->callback(fe::Background::setWallpaperCb); |
| 85 | |
| 86 | fe::Widget::getScroll()->end(); |
| 87 | window->end(); |
| 88 | window->show(argc, argv); |
| 89 | |
| 90 | return Fl::run(); |
| 91 | } |
| 92 | |
| 93 | if (argc < 3) { |
| 94 | usage(w); |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | std::string modeStr = argv[1]; |
| 99 | std::string filename = argv[2]; |
| 100 | |
| 101 | uw::Mode mode; |
| 102 | |
| 103 | if (modeStr == "-t") mode = uw::TILE; |
| 104 | else if (modeStr == "-f") mode = uw::FILL; |
| 105 | else if (modeStr == "-c") mode = uw::CENTER; |
| 106 | else { |
| 107 | usage(w); |
| 108 | return 1; |
| 109 | } |
| 110 | |
| 111 | try { |
| 112 | uw::Background background(filename); |
| 113 | |
| 114 | if (!background.setWallpaper(mode)) { |
| 115 | std::cerr << "背景を設定に失敗。" << std::endl; |
| 116 | return 1; |
| 117 | } |
| 118 | } catch (const std::exception &e) { |
| 119 | std::cerr << "エラー: " << e.what() << std::endl; |
| 120 | return 1; |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |