Created
February 12, 2020 00:46
-
-
Save lighth7015/4c24a4e93bf03ef53bcce0774e23b526 to your computer and use it in GitHub Desktop.
FLTK MDI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "base.h" | |
#include "application.h" | |
MainApplication app; | |
MainApplication::MainApplication(const char* caption) | |
: Fl_Double_Window(640, 480, caption) | |
, menubar( 0, 0, 480, menuHeight) | |
, workspace( 0, 0, 280, 60, "") | |
{ | |
menubar.box(FL_FLAT_BOX); | |
menubar.menu(menu); | |
workspace.color((Fl_Color) 30); | |
workspace.box(FL_DOWN_BOX); | |
workspace.align(Fl_Align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE)); | |
workspace.labelcolor((Fl_Color) 0); | |
resizable(this); | |
show(); | |
} | |
void MainApplication::resize(int x, int y, int width, int height) { | |
menubar.resize(0, 0, w(), menuHeight); | |
workspace.resize(1, menuHeight, w(), (h() - menuHeight) - 1); | |
Fl_Double_Window::resize(x, y, width, height); | |
} | |
uint32_t MainApplication::menuHeight = 28; | |
Fl_Menu_Item MainApplication::menu[] = { | |
{ "&File", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0 }, | |
{ "&Edit", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0 }, | |
{ "&Window", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0 }, | |
{ "", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0 }, | |
{ "&Help", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0 }, | |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 } | |
}; | |
int main() { | |
return Fl::run(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "child.h" | |
class MainApplication: public Fl_Double_Window { | |
Fl_Menu_Bar menubar; | |
Fl_Scroll workspace; | |
static Fl_Menu_Item menu[]; | |
static uint32_t menuHeight; | |
std::vector<MDIChildWindow*> children; | |
friend class MDIChildWindow; | |
MDIChildWindow *form = new MDIChildWindow( *this, 12, 12, 250, 100 ); | |
public: | |
MainApplication(const char* caption = "Application Window"); | |
virtual void resize(int x, int y, int width, int height); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "base.h" | |
#include "application.h" | |
uint32_t MDIChildWindow::titleHeight = 30; | |
MDIWindowDecorations::MDIWindowDecorations(MDIChildWindow& parent, const char* caption) | |
: Fl_Box(parent.x(), parent.y(), parent.w(), parent.titleHeight, caption) | |
, window(parent) | |
{ | |
} | |
MDIChildWindow::MDIChildWindow(MainApplication& parent, int offsetX, int offsetY, int width, int h ) | |
: Fl_Group( parent.x() + offsetX, parent.y() + offsetY, width + offsetX, h + titleHeight + offsetY, "MDI Child") | |
, titlebar( *this, "MDI Child" ) | |
, parent( parent ) | |
{ | |
box(FL_UP_BOX); | |
color((Fl_Color)31); | |
align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE); | |
clip_children(true); | |
initialize(); | |
parent.children.push_back(this); | |
show(); | |
} | |
void MDIChildWindow::initialize() { | |
titlebar.box(FL_FLAT_BOX); | |
titlebar.labelcolor((Fl_Color)31); | |
titlebar.color((Fl_Color)176); | |
titlebar.align(292 | FL_ALIGN_CLIP | FL_ALIGN_INSIDE); | |
} | |
int MDIWindowDecorations::handle( int event_id ) { | |
switch (event_id) { | |
case FL_ENTER: | |
case FL_LEAVE: | |
break; | |
case FL_PUSH: | |
case FL_RELEASE: | |
switch (event_id) { | |
case FL_PUSH: | |
handleMotion = true; | |
originX = Fl::event_x(); | |
originY = Fl::event_y(); | |
break; | |
case FL_RELEASE: | |
handleMotion = false; | |
break; | |
} | |
return 1; | |
case FL_DRAG: | |
int eventX = Fl::event_x(), | |
eventY = Fl::event_y(); | |
if (handleMotion) { | |
switch (Fl::event_button()) { | |
case 1: | |
window.position(eventX + window.x() - originX, | |
eventY + window.y() - originY), | |
window.redraw(); | |
window.parent.redraw(); | |
printf( "React to dragging. (%d, %d)\n", | |
Fl::event_x() + window.x() - originX, | |
Fl::event_y() + window.y() - originY); | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MDIChildWindow; | |
class MainApplication; | |
class MDIWindowDecorations: public Fl_Box { | |
MDIChildWindow& window; | |
protected: | |
bool handleMotion = false; | |
uint32_t originX, originY; | |
int handle( int event_id ); | |
public: | |
MDIWindowDecorations(MDIChildWindow& parent, const char* caption); | |
}; | |
class MDIChildWindow: public Fl_Group { | |
MDIWindowDecorations titlebar; | |
MainApplication& parent; | |
static uint32_t titleHeight; | |
friend class MDIWindowDecorations; | |
void initialize(); | |
public: | |
MDIChildWindow(MainApplication& parent, int offsetX, int offsetY, int w, int h ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment