bbs project statistics
------------------------
31 c++ source files.
27 c++ header files.
4973 总计 lines code.
所有复杂可控图形元素继承自 Widget 接口
class Widget {
public:
Widget();
virtual int processEvent(Client&, Event);
virtual ~Widget();
};
举例:
class Menu : public Widget {
private:
std::vector<MenuItem> _menu_items;
int _start_row;
int _start_col;
int _width;
int _select;
void draw(Client&, bool force);
public:
Menu() : _start_row(-1), _start_col(-1), _width(0), _select(0) { }
void setStartRow(int r) { _start_row = r; }
void setStartCol(int c) { _start_col = c; }
void setWidth(int w) { _width = w; }
int getResult() { return _select; }
void addItem(int key, char shortCut, String label);
int processEvent(Client&, Event);
};
另例:
class VI : public Widget {
private:
Text m_text;
int m_width, m_height, m_offset, m_row, m_col;
void view_update_footer(Client& client, bool force);
void view_update_body(Client& client, bool force);
void model_update_col(Client& client);
void on_key_right(Client& client);
void on_key_left(Client& client);
void on_key_up(Client& client);
void on_key_down(Client& client);
void on_key_home(Client& client);
void on_key_end(Client& client);
void on_key_del(Client& client);
public:
VI();
void setWidth(int);
void setHeight(int);
int processEvent(Client&, Event);
};
再例:
class Notepad : public Widget {
private:
Text m_text;
int m_width, m_height, m_offset, m_row, m_col;
void view_update_footer(Client& client, bool force);
void view_update_body(Client& client, bool force);
void model_update_col(Client& client);
public:
Notepad();
void setWidth(int);
void setHeight(int);
int processEvent(Client&, Event);
};
app 层调用:
比如浏览text控件的接口设计和调用:
class TextViewer : public Widget {
private:
Text m_text;
int m_width, m_height, m_offset;
void view_update_footer(Client& client, bool force);
void view_update_body(Client& client, bool force);
public:
TextViewer();
void setWidth(int);
void setHeight(int);
int processEvent(Client&, Event);
Text& text() {
return m_text;
}
};
void state_topic_content(Client& client, Event event)
{
if (event.type == EV_INIT) {
TextViewer *textViewer = new TextViewer;
int topicid = client.getIntProperty("topicid");
BBS::instance()->loadTopicContent(topicid, textViewer->text());
client.setController(textViewer);
}
int response = client.processWidgetEvent(event);
if (response == R_DONE) {
client.backward();
}
}
-----------------
目前设计单一状态单一控件
如果gui部分要求复杂,可以扩展为单状态多控件,每个控件可以用字符串指定id
或者用整形指定id,根据id设定focus顺序,生成如下界面
username: [__________] <-entry_field0
password: [__________] <-entry_field1
email: [__________] <-entry_field2
..
[submit] [cancel] <-button0 button1
..
根据操作在各个控件间转换阵地
可以使用类似frame或者form可容器控件管理
....
--
FROM 202.120.174.*