2017-04-24 3 views
0

リストから画像を使用してボタンを作成しようとしています。ボタンを中央に揃えたい私のコードは以下の通りです。私は、エラー "クラス" Fl_GIF_Image(const char *)ではない、 'イメージ'のメンバー 'W'の要求を取得し続けます。私は何をすべきかわからない。私はこれが画像の幅を与えると思った。何か案は?画像付きFLTKボタン

// 
// source.cpp 
// labapril20 
// 
// Created by Kate Godfrey on 4/20/17. 
// Copyright (c) 2017 Kate Godfrey. All rights reserved. 
// 

#include <FL/Fl.H> 
#include <FL/Fl_Window.H> 
#include <FL/Fl_Button.H> 
#include <FL/Fl_GIF_Image.H> 
#include <iostream> 
#include <time.h> 
#include <vector> 
#include <cstdio> 

using namespace std; 

int main(int argc, char **argv) { 
    srand(time(NULL)); // set random seed based on current time 
    vector<string> filenames {"cloudy.gif","fog.gif","lightning.gif","partsunny.gif","rain.gif","sunny.gif"}; 

    string filename = filenames.at(rand() % filenames.size()); // get randome filename 
    cout << "Image File: " << filename << endl; // for debugging 

    // Start add code for image on button 
    Fl_GIF_Image image(const char* filename); 

    Fl_Window *window = new Fl_Window(image.W(), image.H()); 

    Fl_Button *button = new Fl_Button(0, 0, image.W(), image.H(), filename); 
    //button->image(); 

    //cout << image.w() << "X" << image.h() << endl; // for debugging 

    // End code for image on button 
    window->end(); 
    window->show(argc, argv); 
    return Fl::run(); 



} 
+0

私はFLTKについて何も知らないが、なぜ生の所有ポインタを使用していますか?なぜあなたは時代遅れのrand()関数も使用していますか? –

+0

私は画像のグループをフォルダに保存しておき、ランダムにボタン画像として使用する画像の1つを選択してください。 –

+0

次にライブラリを見てください。 –

答えて

0

また笑 この

Fl_Window* w = new Fl_Window(340, 180); 
Fl_GIF_Image* gif = new Fl_GIF_Image("fog.gif"); 
Fl_Button* Btn01 = new Fl_Button(20,40,gif->w(),gif->h()); 
Btn01->image(gif); 

はそれが動作を期待してみてくださいDr.Mooreのクラスを取る誰かを見つけることは容易ではありません!