|
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!
//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
//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);
}
//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
//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);
}
//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
//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);
}
//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]
|