GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Nov-2007, 17:30
shitao1201 shitao1201 is offline
New Member
 
Join Date: Nov 2007
Posts: 2
shitao1201 is on a distinguished road

Cannot draw things in the draw area


Hi, I am a newer to fltk,now i use this library to implement a plc ladder drawing software.
But now i encountered some problems. In my project there are four classes:class SoftPlcUI,
SoftEditArea,class PLCELEMENT,class LD,as below source codes display. The SoftPlcUI is a UI
window, and SoftEditArea is a area that we can draw things on it. My purpose is to draw the
element implement in the class PLCELEMENT and LD, when i push the button "-||-"i display on the UI
window or the menu item "LD". But the result is the things i draw dit not display on the
SoftEditArea. Can someone help to solve this problem? Thank you!

CPP / C++ / C Code:
//SoftPlcUi.h
#ifndef __SoftPLCUI_H_
#define __SoftPLCUI_H_
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Scrollbar.H>
#include <FL/Fl_Box.H>
#include "SoftEditArea.h"

#define WINDOW_WIDTH 800
#define WINDOW_HEIGTH 600

class SoftPlcUI 
{
    bool changed_;
    void close_cb();
    void quit_cb();
public:
    SoftPlcUI();
private:
    Fl_Window *main_window;
    inline void cb_window__i(Fl_Window*, void*);
    static void cb_window_(Fl_Window*, void*);    
    static Fl_Menu_Item main_menu[];
    inline void cb_Quit_i(Fl_Menu_*, void*);
    static void cb_Quit(Fl_Menu_*, void*);

    inline void cb_buttonld_i(Fl_Button*, void*);
    static void cb_buttonld(Fl_Button*, void*);

    inline void cb_menuld_i(Fl_Menu_*, void*);
    static void cb_menuld(Fl_Menu_*, void*);

    Fl_Button *ld_button_;
public:
    SoftEditArea *SoftPlcArea;
private:
    Fl_Scroll    *scroll;
public:
    ~SoftPlcUI();
    void show();
};
#endif

CPP / C++ / C Code:
//SoftPlcUi.cxx
#include "SoftPlcUi.h"
#include "SoftPlcElement.h"
#include <FL/Fl_Pixmap.H>
#include <stdlib.h>

void SoftPlcUI::close_cb()
{
    exit(0);
}

void SoftPlcUI::quit_cb()
{
    exit(0);
}

inline void SoftPlcUI::cb_window__i(Fl_Window*, void*) 
{
    close_cb();
}
void SoftPlcUI::cb_window_(Fl_Window* o, void* v) 
{
    ((SoftPlcUI*)(o->user_data()))->cb_window__i(o, v);
}

inline void SoftPlcUI::cb_Quit_i(Fl_Menu_*, void*) 
{
    quit_cb();
}

void SoftPlcUI::cb_Quit(Fl_Menu_* o, void* v) 
{
    ((SoftPlcUI*)(o->parent()->user_data()))->cb_Quit_i(o, v);
}

Fl_Menu_Item SoftPlcUI::main_menu[] = 
{
    {"&File",0,0,0,FL_SUBMENU},
    {"&New...", FL_CTRL+'n', 0, 0},
    {"&Open...", FL_CTRL+'o', 0, 0},
//=============================================================
    {"&Quit", FL_CTRL+'q', (Fl_Callback*)SoftPlcUI::cb_Quit},
    {0},
    {"Draw",0,0,0,FL_SUBMENU},
    {"LD", 0,0},
    {0},
    {0}
};

static const char *idata_ld[] = {
"16 16 4 1",
" \tc None",
".\tc #000000",
"/\tc #7F7F7F",
"-\tc #FFFFFF",
"                ",
"                ",
"    .      .    ",
"    .      .    ",
"    .      .    ",
"    .      .    ",
"    .      .    ",
".....      .....",
".....      .....",
"    .      .    ",
"    .      .    ",
"    .      .    ",
"    .      .    ",
"    .      .    ",
"                ",
"                "
};

static Fl_Pixmap image_ld(idata_ld);

SoftPlcUI::SoftPlcUI() 
{
    Fl_Window* w;
    {
        Fl_Window* o = main_window = new Fl_Window(WINDOW_WIDTH, WINDOW_HEIGTH, "SoftPlc Develop System v0.1");
        w = o;
        o->callback((Fl_Callback*)cb_window_, (void*)(this));
        
        { 
            Fl_Menu_Bar* o = new Fl_Menu_Bar(0, 0, WINDOW_WIDTH, 25);
            o->color(FL_BLUE);
            o->menu(main_menu);
        }
        
        { 
            Fl_Pack* o = new Fl_Pack(0, 25, WINDOW_WIDTH, 25);
            o->type(1);
            { 
                Fl_Button* o = ld_button_ = new Fl_Button(25, 25, 25, 25);
                o->type(102);
                o->down_box(FL_UP_BOX);
                o->selection_color(3);
                o->image(image_ld);
            }
            o->end();
        }

        scroll = new Fl_Scroll(0, 50, WINDOW_WIDTH, WINDOW_HEIGTH-50);
        { 
            SoftEditArea* o = SoftPlcArea = new SoftEditArea(0, 50, AREA_WIN_WIDTH, AREA_WIN_HEIGTH, "");
            o->box(FL_FLAT_BOX);
            o->color(FL_WHITE);
            o->selection_color(FL_BLUE);
            o->labeltype(FL_NORMAL_LABEL);
            o->labelfont(0);
            o->labelsize(14);
            o->labelcolor(56);
            o->align(FL_ALIGN_CENTER);
            o->when(FL_WHEN_RELEASE);
            Fl_Group::current()->resizable(o);
        }

        scroll->end();
        o->end();
    }
}

SoftPlcUI::~SoftPlcUI() 
{
    delete main_window;
}

void SoftPlcUI::show() 
{
    char *prog = (char *)"floorplan";
    main_window->show(1, &prog);
}

CPP / C++ / C Code:
//SoftEditArea.h
#ifndef __SOFT_EDITAREA_H_
#define __SOFT_EDITAREA_H_

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/fl_draw.H>
#include <string.h>
#include <stdio.h>

#define SIDE_LINE_X 20
#define AREA_WIN_WIDTH 1000
#define AREA_WIN_HEIGTH 1640

class SoftEditArea : public Fl_Widget 
{
public:
    SoftEditArea(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X, Y, W, H, L) 
    {
    }
    virtual void draw(); 
    void drawld(int x, int y);
    ~SoftEditArea(){};
public:
};

#endif
CPP / C++ / C Code:
//SoftEditArea.cxx
#include "SoftEditArea.h"
#include "SoftPlcElement.h"
#include <stdio.h>

void SoftEditArea::draw()
{
    fl_color(FL_WHITE);
    fl_rectf(x(), y(), w(), h());
    fl_color(FL_RED);
    fl_yxline(SIDE_LINE_X, 50, h()+ 50);
    fl_yxline(w()- 20, 50, h()+ 50);
}

void SoftEditArea::drawld(int x, int y)
{
    PLCELEMENT *point;
    point = new LD;
    point->draw_element(x, y, (void *)0);
}

CPP / C++ / C Code:
//SoftPlcElement.h
#ifndef __SOFTPLCELEMENT_H_
#define __SOFTPLCELEMENT_H_

#include <Fl/Fl_Widget.H>
#include <string.h>

#define m_nAreRow 100
#define m_nAreCol 16

class PLCELEMENT
{
protected:
    char name[10];
    char code[10];
    char addr[10];
    Fl_Widget *_widget;
public:
    PLCELEMENT(int x, int y)
    {
        strcpy(name, "");
        strcpy(code, "");
        strcpy(addr, "");
    }
    PLCELEMENT()
    {
        strcpy(name, "");
        strcpy(code, "");
        strcpy(addr, "");
    }

    virtual void draw_element(int x, int y, void *){}
    virtual int testaddr(){return 0;}

};

class LD :public PLCELEMENT
{
public:
    LD(int x, int y)
        :PLCELEMENT(x, y)
    {
        strcpy(code , "LD");
        strcpy(name , "");
        strcpy(addr , "");
    };

    LD():PLCELEMENT()
    {
    }
    void draw_element(int x, int y, void *pDC);
    void draw_text(int x, int y, void *pDC);
};
#endif
CPP / C++ / C Code:
//SoftPlcElement.cxx
#include "SoftPlcElement.h"
#include <stdio.h>
#include <Fl/Fl_Widget.H>
#include <Fl/fl_draw.H>

void LD::draw_element(int x, int y, void *pDC)
{
    fl_color(FL_BLACK);
    fl_xyline(_widget->x() + x, _widget->y()+y, _widget->x()+x+20);
    fl_yxline(_widget->x() + x+20, _widget->y()+y-10, y+10);
    fl_xyline(_widget->x() + x+40, _widget->y()+y, _widget->x() + x+60);
    fl_yxline(_widget->x()+ x+40, _widget->y()+y-10, _widget->y()+y+10);
}

void LD::draw_text(int x, int y, void *pDC)
{
    int width = 0;
    int startx = 0;
    width = strlen("LD")*8;
    startx = x+(60 - width)/2;
    fl_draw("LD", startx, y-50);
    width = strlen("X001")*8;
    startx = x+(60 - width)/2;
    fl_draw("X001", startx, y-30);
}

CPP / C++ / C Code:
//main.cxx
#include "SoftPlcUi.h"

int main(int  argc, char *argv[])
{
    SoftPlcUI    *ui = new SoftPlcUI();
    ui->show();
    
    return (Fl::run());
}
Last edited by cable_guy_67 : 06-Nov-2007 at 17:42. Reason: Please surround your FLTK code with [cpp] your code [/cpp]
  #2  
Old 07-Nov-2007, 03:33
shitao1201 shitao1201 is offline
New Member
 
Join Date: Nov 2007
Posts: 2
shitao1201 is on a distinguished road

Re: Cannot draw things in the draw area


Anybody can help me? Thanks advance!
  #3  
Old 13-Nov-2007, 05:14
rbp rbp is offline
Junior Member
 
Join Date: Nov 2005
Location: Melbourne, Australia
Posts: 60
rbp will become famous soon enough

Re: Cannot draw things in the draw area


how does drawld() get called? I didn't see a reference to it in your draw() function. Read about overloading draw() here:
http://www.fltk.org/documentation.ph...sing.html#draw

You can only do drawing from within draw() or functions called from this function.

Also drawld() will call draw_element(), but draw_text() is never accessed as far as I can tell.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 14:46
area of n-sided regular polygon earachefl C++ Forum 6 12-May-2006 14:53
Re: GIDPanel - Member's Area is now open JdS GIDNetwork™ 2 17-Jun-2005 20:35
calling abstract base class method calls draw instead achoo FLTK Forum 1 19-Dec-2004 09:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:11.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.