From 01ba7df88811b62134e4403ce159c3eb952eb054 Mon Sep 17 00:00:00 2001
From: Christophe CURIS
Date: Sun, 30 May 2021 15:48:03 +0200
Subject: [PATCH] WINGs: Better presentation for example code in the tutorial
As this code will be an example for users, it should promote good practices
of which indentation is an important one. Proper spacing is also important
for the readability of the code.
Signed-off-by: Christophe CURIS
---
WINGs_tutorial/EighthWindow.c | 146 +++++-----
WINGs_tutorial/FifthWindow.c | 106 +++----
WINGs_tutorial/FirstWindow.c | 10 +-
WINGs_tutorial/FourthWindow.c | 250 ++++++++--------
WINGs_tutorial/NinthWindow.c | 421 +++++++++++++--------------
WINGs_tutorial/SecondWindow.c | 15 +-
WINGs_tutorial/SeventhWindow.c | 197 +++++++------
WINGs_tutorial/SixthWindow.c | 118 ++++----
WINGs_tutorial/ThirdWindow.c | 33 +--
WINGs_tutorial/WINGGraphics.html | 14 +-
WINGs_tutorial/WINGMenu.html | 32 ++-
WINGs_tutorial/WINGsRemark.html | 125 ++++----
WINGs_tutorial/WINGstep1.html | 10 +-
WINGs_tutorial/glframe.c | 595 ++++++++++++++++++++-------------------
14 files changed, 1068 insertions(+), 1004 deletions(-)
rewrite WINGs_tutorial/EighthWindow.c (86%)
rewrite WINGs_tutorial/FourthWindow.c (64%)
rewrite WINGs_tutorial/NinthWindow.c (80%)
rewrite WINGs_tutorial/SeventhWindow.c (89%)
rewrite WINGs_tutorial/SixthWindow.c (87%)
rewrite WINGs_tutorial/glframe.c (93%)
diff --git a/WINGs_tutorial/EighthWindow.c b/WINGs_tutorial/EighthWindow.c
dissimilarity index 86%
index 628cd20..1a32b7c 100644
--- a/WINGs_tutorial/EighthWindow.c
+++ b/WINGs_tutorial/EighthWindow.c
@@ -1,70 +1,76 @@
-#include "editmenu.h"
-
-#define WINWIDTH 300
-#define WINHEIGHT 400
-#define MENUWIDTH 80
-#define MENITEMHT 21
-
-struct datacouple{WMWindow *window;
- WEditMenu *menu;
-} datacouple;
-
-void closeAll(WMWidget *self,void *data){
- WMDestroyWidget(self);
- exit(0);
-}
-
-void getMenu(WMWidget *self, void *data){
- WMPoint position;
- struct datacouple *tmp=(struct datacouple *)data;
- if(WMGetButtonSelected(self)){
- position=WMGetViewScreenPosition(WMWidgetView(tmp->window));
- WEditMenuShowAt(tmp->menu,(position.x>MENUWIDTH)?position.x-MENUWIDTH:0, position.y+MENITEMHT,tmp->window);
- }else
- WEditMenuHide(tmp->menu);
-}
-
-int main (int argc, char **argv){
-
-Display *display;
-WMScreen *screen;
-WMWindow *win;
-WEditMenu *submenu, *menu;
-WEditMenuItem * menuitem;
-struct datacouple Mainmenu;
- WMButton *Button;
-
-WMInitializeApplication("MenuWindow", &argc, argv);
-display = XOpenDisplay("");
-screen = WMCreateScreen(display, DefaultScreen(display));
-win = WMCreateWindow(screen, "Menu");
-WMResizeWidget(win, WINWIDTH, WINHEIGHT);
-WMSetWindowCloseAction(win, closeAll, NULL);
-
- submenu=WCreateEditMenu(screen,"Submenu");
- menuitem =WAddMenuItemWithTitle(submenu,"Submenu item");
- menu=WCreateEditMenu(screen,"Main menu");
- menuitem = WAddMenuItemWithTitle(menu,"To submenu");
- WSetEditMenuSubmenu(menu, menuitem , submenu);
- menuitem = WAddMenuItemWithTitle(menu,"Main item");
-
-Mainmenu.window=win;
-Mainmenu.menu=menu;
-
- Button =WMCreateButton(win,WBTPushOnPushOff);
- WMSetButtonText (Button, "Menu");
- WMSetButtonAction (Button, getMenu, &Mainmenu);
- WMMoveWidget(Button, 1,1);
-
-WMRealizeWidget(win);
-WMRealizeWidget(Button);
-WMRealizeWidget(menu);
-WMRealizeWidget(submenu);
-
-WMMapSubwidgets(win);
-WMMapWidget(win);
-
-WMScreenMainLoop(screen);
-
-return 0;
-}
+#include "editmenu.h"
+
+#define WINWIDTH 300
+#define WINHEIGHT 400
+#define MENUWIDTH 80
+#define MENITEMHT 21
+
+struct datacouple{
+ WMWindow *window;
+ WEditMenu *menu;
+} datacouple;
+
+void closeAll(WMWidget *self,void *data)
+{
+ WMDestroyWidget(self);
+ exit(0);
+}
+
+void getMenu(WMWidget *self, void *data)
+{
+ WMPoint position;
+ struct datacouple *tmp = (struct datacouple *) data;
+
+ if (WMGetButtonSelected(self)) {
+ position = WMGetViewScreenPosition(WMWidgetView(tmp->window));
+ WEditMenuShowAt(tmp->menu,
+ (position.x > MENUWIDTH)?(position.x - MENUWIDTH):0,
+ position.y + MENITEMHT, tmp->window);
+ } else
+ WEditMenuHide(tmp->menu);
+}
+
+int main(int argc, char **argv)
+{
+ Display *display;
+ WMScreen *screen;
+ WMWindow *win;
+ WEditMenu *submenu, *menu;
+ WEditMenuItem * menuitem;
+ struct datacouple Mainmenu;
+ WMButton *Button;
+
+ WMInitializeApplication("MenuWindow", &argc, argv);
+ display = XOpenDisplay("");
+ screen = WMCreateScreen(display, DefaultScreen(display));
+ win = WMCreateWindow(screen, "Menu");
+ WMResizeWidget(win, WINWIDTH, WINHEIGHT);
+ WMSetWindowCloseAction(win, closeAll, NULL);
+
+ submenu = WCreateEditMenu(screen, "Submenu");
+ menuitem = WAddMenuItemWithTitle(submenu, "Submenu item");
+ menu = WCreateEditMenu(screen, "Main menu");
+ menuitem = WAddMenuItemWithTitle(menu, "To submenu");
+ WSetEditMenuSubmenu(menu, menuitem, submenu);
+ menuitem = WAddMenuItemWithTitle(menu, "Main item");
+
+ Mainmenu.window = win;
+ Mainmenu.menu = menu;
+
+ Button = WMCreateButton(win, WBTPushOnPushOff);
+ WMSetButtonText(Button, "Menu");
+ WMSetButtonAction(Button, getMenu, &Mainmenu);
+ WMMoveWidget(Button, 1, 1);
+
+ WMRealizeWidget(win);
+ WMRealizeWidget(Button);
+ WMRealizeWidget(menu);
+ WMRealizeWidget(submenu);
+
+ WMMapSubwidgets(win);
+ WMMapWidget(win);
+
+ WMScreenMainLoop(screen);
+
+ return 0;
+}
diff --git a/WINGs_tutorial/FifthWindow.c b/WINGs_tutorial/FifthWindow.c
index 3260b7b..2ed6770 100644
--- a/WINGs_tutorial/FifthWindow.c
+++ b/WINGs_tutorial/FifthWindow.c
@@ -12,64 +12,74 @@ WMText *text;
WMColor *color;
WMFrame *controlframe;
-char textbuf[40];
-void closeAll(WMWidget *self,void *data){
+void closeAll(WMWidget *self, void *data)
+{
WMDestroyWidget(self);
- fprintf(stderr,"I've been used!\n");
+ fprintf(stderr, "I've been used!\n");
exit(0);
}
-static void selectFiles(void *self, void *data){
- int i=0;
+static void selectFiles(void *self, void *data)
+{
+ int i = 0;
WMOpenPanel *oPanel;
+
oPanel = WMGetOpenPanel(screen);
if (WMRunModalFilePanelForDirectory(oPanel, NULL, "/tmp",
- "Search..", NULL) == True){
- snprintf(textbuf,39,"%s\n-", WMGetFilePanelFileName(oPanel));
- WMFreezeText(text);
- WMAppendTextStream(text,textbuf);
- WMThawText(text);
+ "Search..", NULL) == True) {
+ char textbuf[40];
+
+ snprintf(textbuf, sizeof(textbuf), "%s\n-", WMGetFilePanelFileName(oPanel));
+ WMFreezeText(text);
+ WMAppendTextStream(text, textbuf);
+ WMThawText(text);
}
- return ;
+ return;
}
-static void handleEvents(XEvent *event, void *data){
- WMWidget *widget = (WMWidget*)data;
+static void handleEvents(XEvent *event, void *data)
+{
+ char textbuf[40];
+ WMWidget *widget = (WMWidget*) data;
+
switch (event->type) {
case ButtonPress:
- snprintf(textbuf,39,"Button down at (%i,%i) \n-",event->xbutton.x,event->xbutton.y);
+ snprintf(textbuf, sizeof(textbuf), "Button down at (%i,%i) \n-",
+ event->xbutton.x, event->xbutton.y);
WMFreezeText(text);
- WMAppendTextStream(text,textbuf);
+ WMAppendTextStream(text, textbuf);
WMThawText(text);
break;
}
}
-static void resizeHandler(void *self, WMNotification *notif){
+static void resizeHandler(void *self, WMNotification *notif)
+{
WMSize size = WMGetViewSize(WMWidgetView(win));
WMMoveWidget(controlframe, size.width-ButtonsetSize.width, size.height-ButtonsetSize.height);
- WMResizeWidget(text, size.width-MARGIN -10, size.height-80);
+ WMResizeWidget(text, size.width - MARGIN - 10, size.height - 80);
}
-int main (int argc, char **argv){
-
-WMButton *Button;
+int main(int argc, char **argv)
+{
+ WMButton *Button;
- WMInitializeApplication("FifthWindow", &argc, argv);
- if (!(display = XOpenDisplay(""))){
- fprintf(stderr,"err: cannot open display");
- exit(1);
- }
- screen = WMCreateScreen(display, DefaultScreen(display));
+ WMInitializeApplication("FifthWindow", &argc, argv);
+ display = XOpenDisplay("");
+ if (!display) {
+ fprintf(stderr, "err: cannot open display");
+ exit(1);
+ }
+ screen = WMCreateScreen(display, DefaultScreen(display));
/* window */
win = WMCreateWindow(screen, "");
WMResizeWidget(win, WINWIDTH, WINHEIGHT);
WMSetWindowCloseAction(win, closeAll, NULL);
- WMCreateEventHandler(WMWidgetView(win), ButtonPressMask,handleEvents, win);
- color = WMCreateRGBColor(screen, 124<<9,206<<8,162<<8, False);
+ WMCreateEventHandler(WMWidgetView(win), ButtonPressMask, handleEvents, win);
+ color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
WMSetWidgetBackgroundColor((WMWidget *)win, color);
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
WMAddNotificationObserver(resizeHandler, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win));
@@ -77,43 +87,43 @@ WMButton *Button;
/* Text area */
text = WMCreateText(win);
- WMResizeWidget(text, WINWIDTH-MARGIN, WINHEIGHT -80);
+ WMResizeWidget(text, WINWIDTH - MARGIN, WINHEIGHT - 80);
WMMoveWidget(text, 10, 10);
WMSetTextHasVerticalScroller(text, True);
WMSetTextEditable(text, False);
/* frame and two buttons */
- controlframe=WMCreateFrame(win);
+ controlframe = WMCreateFrame(win);
WMSetWidgetBackgroundColor((WMWidget *)controlframe, color);
- WMSetFrameRelief(controlframe,WRFlat);
+ WMSetFrameRelief(controlframe, WRFlat);
- Button =WMCreateButton(controlframe,WBTMomentaryPush);
+ Button = WMCreateButton(controlframe, WBTMomentaryPush);
WMSetWidgetBackgroundColor((WMWidget *)Button, color);
- WMSetButtonText (Button, "Files");
- WMSetButtonAction (Button, selectFiles, NULL);
+ WMSetButtonText(Button, "Files");
+ WMSetButtonAction(Button, selectFiles, NULL);
ButtonsetSize = WMGetViewSize(WMWidgetView(Button));
- WMMoveWidget(Button, MARGIN, MARGIN);
+ WMMoveWidget(Button, MARGIN, MARGIN);
- Button =WMCreateButton(controlframe,WBTMomentaryPush);
+ Button = WMCreateButton(controlframe, WBTMomentaryPush);
WMSetWidgetBackgroundColor((WMWidget *)Button, color);
- WMSetButtonText (Button, "Quit");
- WMSetButtonAction (Button, closeAll, NULL);
- WMMoveWidget(Button,2*MARGIN+ButtonsetSize.width, MARGIN);
- ButtonsetSize.width = 3*MARGIN+2*ButtonsetSize.width;
- ButtonsetSize.height=2*MARGIN+ButtonsetSize.height;
- WMResizeWidget(controlframe,ButtonsetSize.width,ButtonsetSize.height);
+ WMSetButtonText(Button, "Quit");
+ WMSetButtonAction(Button, closeAll, NULL);
+ WMMoveWidget(Button, 2*MARGIN + ButtonsetSize.width, MARGIN);
+ ButtonsetSize.width = 3*MARGIN + 2*ButtonsetSize.width;
+ ButtonsetSize.height = 2*MARGIN + ButtonsetSize.height;
+ WMResizeWidget(controlframe, ButtonsetSize.width, ButtonsetSize.height);
WMMapSubwidgets(controlframe);
resizeHandler(NULL,NULL);
- /* end of frame and buttons setup */
+ /* end of frame and buttons setup */
- WMMapSubwidgets(win);
- WMMapWidget(win);
- WMRealizeWidget(win);
+ WMMapSubwidgets(win);
+ WMMapWidget(win);
+ WMRealizeWidget(win);
- WMScreenMainLoop(screen);
+ WMScreenMainLoop(screen);
-return 0;
+ return 0;
}
diff --git a/WINGs_tutorial/FirstWindow.c b/WINGs_tutorial/FirstWindow.c
index 6d38916..1d705c2 100644
--- a/WINGs_tutorial/FirstWindow.c
+++ b/WINGs_tutorial/FirstWindow.c
@@ -1,8 +1,8 @@
-int main (int argc, char **argv){
-
- Display *display;
- WMScreen *screen;
- WMWindow *win;
+int main (int argc, char **argv)
+{
+ Display *display;
+ WMScreen *screen;
+ WMWindow *win;
WMInitializeApplication("FirstWindow", &argc, argv);
diff --git a/WINGs_tutorial/FourthWindow.c b/WINGs_tutorial/FourthWindow.c
dissimilarity index 64%
index 66b98a1..93115fa 100644
--- a/WINGs_tutorial/FourthWindow.c
+++ b/WINGs_tutorial/FourthWindow.c
@@ -1,122 +1,128 @@
-#define MARGIN 14
-#define WINWIDTH 300
-#define WINHEIGHT 400
-
-Display *display;
-WMScreen *screen;
-
-WMButton *Button;
-WMWindow *win;
-WMSize ButtonsetSize;
-
-WMBox *box;
-WMText *text;
-WMColor *color;
-
-char textbuf[40];
-
-void closeAll(WMWidget *self,void *data){
- WMDestroyWidget(self);
- fprintf(stderr,"I've been used!\n");
- exit(0);
-}
-
-static void selectFiles(void *self, void *data){
- WMOpenPanel *oPanel;
- oPanel = WMGetOpenPanel(screen);
- if (WMRunModalFilePanelForDirectory(oPanel, NULL, "/tmp",
- "Search..", NULL) == True){
- snprintf(textbuf,39,"%s\n-", WMGetFilePanelFileName(oPanel));
- WMFreezeText(text);
- WMAppendTextStream(text,textbuf);
- WMThawText(text);
- }
- return ;
-}
-
-static void handleEvents(XEvent *event, void *data){
- WMWidget *widget = (WMWidget*)data;
- switch (event->type) {
- case ButtonPress:
- snprintf(textbuf,39,"Button down at (%i,%i) \n-",event->xbutton.x,event->xbutton.y);
- WMFreezeText(text);
- WMAppendTextStream(text,textbuf);
- WMThawText(text);
- break;
- }
-}
-
-static void resizeHandler(void *self, WMNotification *notif){
- WMSize size = WMGetViewSize(WMWidgetView(win));
- WMMoveWidget(box, size.width-ButtonsetSize.width, size.height-ButtonsetSize.height);
- WMResizeWidget(text, size.width-MARGIN -10, size.height-80);
-}
-
-
-int main (int argc, char **argv){
-
- WMInitializeApplication("FourthWindow", &argc, argv);
- if (!(display = XOpenDisplay(""))){
- fprintf(stderr,"err: cannot open display");
- exit(-1);
- }
- screen = WMCreateScreen(display, DefaultScreen(display));
-
- /* window */
- win = WMCreateWindow(screen, "");
- WMResizeWidget(win, WINWIDTH, WINHEIGHT);
- WMSetWindowCloseAction(win, closeAll, NULL);
-
- color = WMCreateRGBColor(screen, 124<<9,206<<8,162<<8, False);
- WMSetWidgetBackgroundColor((WMWidget *)win, color);
-
- WMCreateEventHandler(WMWidgetView(win), ButtonPressMask,handleEvents, win);
- WMSetViewNotifySizeChanges(WMWidgetView(win), True);
- WMAddNotificationObserver(resizeHandler, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win));
-
- /* Text area */
-
- text = WMCreateText(win);
- WMResizeWidget(text, WINWIDTH-MARGIN, WINHEIGHT -80);
- WMMoveWidget(text, 10, 10);
- WMSetTextHasVerticalScroller(text, True);
- WMSetTextEditable(text, False);
- WMSetTextIgnoresNewline(text, False);
-
- /* box with buttons */
- box=WMCreateBox(win);
- WMSetBoxBorderWidth(box, MARGIN);
- WMSetWidgetBackgroundColor((WMWidget *)box, color);
- WMSetBoxHorizontal(box, True);
-
-
- Button =WMCreateButton(box,WBTMomentaryPush);
- WMSetWidgetBackgroundColor((WMWidget *)Button, color);
- WMSetButtonText (Button, "Files");
- WMSetButtonAction (Button, selectFiles, NULL);
- WMMapWidget(Button);
- ButtonsetSize = WMGetViewSize(WMWidgetView(Button));
-
- WMAddBoxSubview(box, WMWidgetView(Button), True, False, 60, 1000, MARGIN);
-
- Button =WMCreateButton(box,WBTMomentaryPush);
- WMSetWidgetBackgroundColor((WMWidget *)Button, color);
- WMSetButtonText (Button, "Quit");
- WMSetButtonAction (Button, closeAll, NULL);
- WMMapWidget(Button);
-
- WMAddBoxSubview(box, WMWidgetView(Button), True,False, 60, 1000, 0);
- WMResizeWidget(box, 4*MARGIN+2*ButtonsetSize.width,2*MARGIN+ButtonsetSize.height);
- ButtonsetSize =WMGetViewSize(WMWidgetView(box));
- resizeHandler(NULL,NULL);
- /* end of box and buttons setup */
-
- WMMapWidget(win);
-
- WMMapSubwidgets(win);
- WMRealizeWidget(win);
-
- WMScreenMainLoop(screen);
-
-return 0;
-}
+#define MARGIN 14
+#define WINWIDTH 300
+#define WINHEIGHT 400
+
+Display *display;
+WMScreen *screen;
+
+WMButton *Button;
+WMWindow *win;
+WMSize ButtonsetSize;
+
+WMBox *box;
+WMText *text;
+WMColor *color;
+
+void closeAll(WMWidget *self,void *data)
+{
+ WMDestroyWidget(self);
+ fprintf(stderr, "I've been used!\n");
+ exit(0);
+}
+
+static void selectFiles(void *self, void *data)
+{
+ WMOpenPanel *oPanel;
+ oPanel = WMGetOpenPanel(screen);
+ if (WMRunModalFilePanelForDirectory(oPanel, NULL, "/tmp",
+ "Search..", NULL) == True) {
+ char textbuf[40];
+
+ snprintf(textbuf, sizeof(textbuf), "%s\n-", WMGetFilePanelFileName(oPanel));
+ WMFreezeText(text);
+ WMAppendTextStream(text, textbuf);
+ WMThawText(text);
+ }
+ return;
+}
+
+static void handleEvents(XEvent *event, void *data)
+{
+ WMWidget *widget = (WMWidget*) data;
+ char textbuf[40];
+
+ switch (event->type) {
+ case ButtonPress:
+ snprintf(textbuf, sizeof(textbuf), "Button down at (%i,%i) \n-",
+ event->xbutton.x, event->xbutton.y);
+ WMFreezeText(text);
+ WMAppendTextStream(text, textbuf);
+ WMThawText(text);
+ break;
+ }
+}
+
+static void resizeHandler(void *self, WMNotification *notif)
+{
+ WMSize size = WMGetViewSize(WMWidgetView(win));
+ WMMoveWidget(box, size.width - ButtonsetSize.width, size.height - ButtonsetSize.height);
+ WMResizeWidget(text, size.width - MARGIN - 10, size.height - 80);
+}
+
+
+int main(int argc, char **argv)
+{
+ WMInitializeApplication("FourthWindow", &argc, argv);
+ if (!(display = XOpenDisplay(""))) {
+ fprintf(stderr, "err: cannot open display");
+ exit(-1);
+ }
+ screen = WMCreateScreen(display, DefaultScreen(display));
+
+ /* window */
+ win = WMCreateWindow(screen, "");
+ WMResizeWidget(win, WINWIDTH, WINHEIGHT);
+ WMSetWindowCloseAction(win, closeAll, NULL);
+
+ color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
+ WMSetWidgetBackgroundColor((WMWidget *)win, color);
+
+ WMCreateEventHandler(WMWidgetView(win), ButtonPressMask, handleEvents, win);
+ WMSetViewNotifySizeChanges(WMWidgetView(win), True);
+ WMAddNotificationObserver(resizeHandler, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win));
+
+ /* Text area */
+ text = WMCreateText(win);
+ WMResizeWidget(text, WINWIDTH - MARGIN, WINHEIGHT - 80);
+ WMMoveWidget(text, 10, 10);
+ WMSetTextHasVerticalScroller(text, True);
+ WMSetTextEditable(text, False);
+ WMSetTextIgnoresNewline(text, False);
+
+ /* box with buttons */
+ box = WMCreateBox(win);
+ WMSetBoxBorderWidth(box, MARGIN);
+ WMSetWidgetBackgroundColor((WMWidget *)box, color);
+ WMSetBoxHorizontal(box, True);
+
+ Button = WMCreateButton(box, WBTMomentaryPush);
+ WMSetWidgetBackgroundColor((WMWidget *)Button, color);
+ WMSetButtonText(Button, "Files");
+ WMSetButtonAction(Button, selectFiles, NULL);
+ WMMapWidget(Button);
+ ButtonsetSize = WMGetViewSize(WMWidgetView(Button));
+
+ WMAddBoxSubview(box, WMWidgetView(Button), True, False, 60, 1000, MARGIN);
+
+ Button = WMCreateButton(box, WBTMomentaryPush);
+ WMSetWidgetBackgroundColor((WMWidget *)Button, color);
+ WMSetButtonText(Button, "Quit");
+ WMSetButtonAction(Button, closeAll, NULL);
+ WMMapWidget(Button);
+
+ WMAddBoxSubview(box, WMWidgetView(Button), True, False, 60, 1000, 0);
+ WMResizeWidget(box, 4 * MARGIN + 2 * ButtonsetSize.width,
+ 2 * MARGIN + ButtonsetSize.height);
+ ButtonsetSize = WMGetViewSize(WMWidgetView(box));
+ resizeHandler(NULL, NULL);
+ /* end of box and buttons setup */
+
+ WMMapWidget(win);
+
+ WMMapSubwidgets(win);
+ WMRealizeWidget(win);
+
+ WMScreenMainLoop(screen);
+
+ return 0;
+}
diff --git a/WINGs_tutorial/NinthWindow.c b/WINGs_tutorial/NinthWindow.c
dissimilarity index 80%
index 5680209..4d301da 100644
--- a/WINGs_tutorial/NinthWindow.c
+++ b/WINGs_tutorial/NinthWindow.c
@@ -1,206 +1,215 @@
-#include "editmenu.h" /* This must be the MODIFIED .h file */
-#include
-#include
-#include
-#include
-#define WINWIDTH 300
-#define WINHEIGHT 400
-#define MENUWIDTH 85
-#define MENITEMHT 21
-#define LOGPROGRAM "xconsole"
-#define ERRMSGFIFO "/tmp/WINGsWindowfifo"
-#define FIFONAMELEN 20
-#define NOLOGWINDOW (-2) /* value when there is no console window */
-#define FIFOERROR (-1) /* value when there is a problem w/ console */
-#define FIFOLOWESTPOSS 0
-
-
-int windowCounter=0;
-int fifonr;
-int sibpid;
-char fifofilename[FIFONAMELEN+5];
-
-struct dataStruct{
- WMWindow *window;
- WEditMenu *menu;
-} dataStruct;
-
-
- /* functions for the message window part: */
-
-void redirectmsg(int sig){
-
- // clean up after SIGCHLD, and set fifonr to flag it
- fifonr=NOLOGWINDOW;
- if (!access(fifofilename,F_OK|W_OK))
- unlink(fifofilename);
- return;
-}
-
-
-int showMessageWindow(){
-
- sprintf(fifofilename,"%s%i",ERRMSGFIFO,(unsigned short)getpid());
-
- (void) signal(SIGCHLD,redirectmsg); // clean up if message console is killed
-
- if(access(fifofilename,F_OK)==-1)
- fifonr=mknod(fifofilename,0640|O_EXCL|S_IFIFO,(dev_t)0);
- else {fifonr=FIFOERROR;
- wwarning("Fifo file already exists\n");
- }
- /* fifonr == FIFOERROR if mknod/mkfifo or access failed, mknod returns -1 on failure */
-
-if(fifonr!=FIFOERROR){
-
- sibpid=fork();
- if(sibpid==0){
- execlp(LOGPROGRAM , LOGPROGRAM, "-file",fifofilename,"-geometry","250x400", "-title","Window Messages",(char *)0);
- exit(1);
-}else
- fifonr=open(fifofilename,O_WRONLY);
-}
- return fifonr;
-}
-
- /* general and menu handling functions */
-
-void closeAll(WMWidget *self,void *data){
-
- WMDestroyWidget(self);
- if(--windowCounter<1){
- if (fifonr>=FIFOLOWESTPOSS)
- kill(sibpid,SIGTERM);
- if (!access(fifofilename,F_OK|W_OK))
- unlink(fifofilename);
- exit(0);
- }
-}
-
-
-void menuItemAction(void *self, void *data){
-
- if (fifonrwindow));
- WEditMenuShowAt(tmp->menu,(position.x>MENUWIDTH)?position.x-MENUWIDTH:0, position.y+MENITEMHT,tmp->window);
- }else{
- WEditMenuHide(tmp->menu);
- WDeselectItem(tmp->menu); // remove selection before next pop up
- }
-}
-
-
-static void notificationHandler(void *self, WMNotification *notif){
-
-if(!strcmp("WMWindowClose",WMGetNotificationName(notif)))
- closeAll(self,NULL);
-if(!strcmp(WMViewSizeDidChangeNotification,WMGetNotificationName(notif))){
- //resize actions
- WMSize size = WMGetViewSize(WMWidgetView(self));
- }
-}
-
- /* main widget creating functions */
-
-WMWindow * makeMainwindow(Display *display, WMScreen *screen){
-WMWindow *window;
-
- window = WMCreateWindow(screen, "Menu");
- WMResizeWidget(window, WINWIDTH, WINHEIGHT);
- WMSetWindowCloseAction(window, closeAll, NULL);
- WMAddNotificationObserver(notificationHandler, window, "WMWindowClose", WMWidgetView(window));
- WMSetViewNotifySizeChanges(WMWidgetView(window), True);
- WMAddNotificationObserver(notificationHandler, window, WMViewSizeDidChangeNotification, WMWidgetView(window));
- WMAddNotificationObserver(notificationHandler, window, "WMWindowClose", NULL);
- WMRealizeWidget(window);
- return window;
-}
-
-
-WEditMenu * makeMenus(WMScreen *screen,WEditMenu *menu, WEditMenu *submenu){
-WEditMenuItem * menuitem;
-
- submenu=WCreateEditMenu(screen,"Submenu");
- menuitem =WAddMenuItemWithTitle(submenu,"Submenu item");
- WSetEditMenuItemAction( menuitem, menuItemAction);
- menuitem =WAddMenuItemWithTitle(submenu,"2nd submenu item");
- WSetEditMenuItemAction( menuitem, menuItemAction);
- menuitem =WAddMenuItemWithTitle(submenu,"3d submenu item");
- WSetEditMenuItemAction( menuitem, menuItemAction);
- menu=WCreateEditMenu(screen,"Main menu");
- menuitem = WAddMenuItemWithTitle(menu,"1st main item");
- WSetEditMenuItemAction( menuitem, menuItemAction);
- menuitem = WAddMenuItemWithTitle(menu,"2nd main item");
- WSetEditMenuItemAction( menuitem, menuItemAction);
- menuitem = WAddMenuItemWithTitle(menu,"To submenu");
- WSetEditMenuSubmenu(menu, menuitem , submenu);
- menuitem = WAddMenuItemWithTitle(menu,"Quit");
- WSetEditMenuItemAction( menuitem, menuItemCloseAction);
- WMRealizeWidget(submenu);WMRealizeWidget(menu);
- return menu;
-}
-
-
-WMButton * makeButtonsTop( WMWidget *window, void *AppData){
-WMButton *Button;
-
- Button =WMCreateButton(window,WBTPushOnPushOff);
- WMSetButtonText (Button, "Menu");
- WMSetButtonAction (Button, getMenu, AppData);
- WMMoveWidget(Button, 4,2);
- WMRealizeWidget(Button);
- return Button;
-}
-
-
-int main (int argc, char **argv){
-
-Display *display;
-WMScreen *screen;
-WMWindow *mainwindow;
-WEditMenu *submenu, *menu;
-WEditMenuItem * menuitem;
-struct dataStruct Mainmenu;
-WMButton *menubutton;
-
-fifonr=NOLOGWINDOW;
-
-WMInitializeApplication("MenuWindow", &argc, argv);
-display = XOpenDisplay("");
-screen = WMCreateScreen(display, DefaultScreen(display));
-mainwindow= makeMainwindow(display, screen) ;
-
-menu=makeMenus(screen,menu,submenu);
-
-Mainmenu.window=mainwindow;
-Mainmenu.menu=menu;
-menubutton=makeButtonsTop(mainwindow, &Mainmenu);
-
-WMMapSubwidgets(mainwindow);
-WMMapWidget(mainwindow);
-
-WMScreenMainLoop(screen);
-return 0;
-}
+#include "editmenu.h" /* This must be the MODIFIED .h file */
+#include
+#include
+#include
+#include
+#define WINWIDTH 300
+#define WINHEIGHT 400
+#define MENUWIDTH 85
+#define MENITEMHT 21
+#define LOGPROGRAM "xconsole"
+#define ERRMSGFIFO "/tmp/WINGsWindowfifo"
+#define FIFONAMELEN 20
+#define NOLOGWINDOW (-2) /* value when there is no console window */
+#define FIFOERROR (-1) /* value when there is a problem w/ console */
+#define FIFOLOWESTPOSS 0
+
+
+int windowCounter = 0;
+int fifonr;
+int sibpid;
+char fifofilename[FIFONAMELEN + 5];
+
+struct dataStruct {
+ WMWindow *window;
+ WEditMenu *menu;
+} dataStruct;
+
+
+ /* functions for the message window part: */
+
+void redirectmsg(int sig)
+{
+ // clean up after SIGCHLD, and set fifonr to flag it
+ fifonr = NOLOGWINDOW;
+ if (!access(fifofilename, F_OK | W_OK))
+ unlink(fifofilename);
+ return;
+}
+
+
+int showMessageWindow()
+{
+ sprintf(fifofilename, "%s%i", ERRMSGFIFO, (unsigned short)getpid());
+
+ (void) signal(SIGCHLD, redirectmsg); // clean up if message console is killed
+
+ if (access(fifofilename, F_OK) == -1)
+ fifonr = mknod(fifofilename, 0640|O_EXCL|S_IFIFO, (dev_t)0);
+ else {
+ fifonr = FIFOERROR;
+ wwarning("Fifo file already exists\n");
+ }
+ /* fifonr == FIFOERROR if mknod/mkfifo or access failed, mknod returns -1 on failure */
+
+ if (fifonr != FIFOERROR) {
+ sibpid = fork();
+ if (sibpid == 0) {
+ execlp(LOGPROGRAM, LOGPROGRAM, "-file", fifofilename, "-geometry", "250x400", "-title", "Window Messages", (char *)0);
+ exit(1);
+ } else
+ fifonr = open(fifofilename, O_WRONLY);
+ }
+ return fifonr;
+}
+
+ /* general and menu handling functions */
+
+void closeAll(WMWidget *self, void *data)
+{
+ WMDestroyWidget(self);
+ if (--windowCounter < 1) {
+ if (fifonr >= FIFOLOWESTPOSS)
+ kill(sibpid, SIGTERM);
+ if (!access(fifofilename, F_OK|W_OK))
+ unlink(fifofilename);
+ exit(0);
+ }
+}
+
+
+void menuItemAction(void *self, void *data)
+{
+ if (fifonr < FIFOLOWESTPOSS)
+ fifonr = showMessageWindow(); // try again in case FIFOERROR
+
+ if (fifonr == FIFOERROR) // give up and print to stderr
+ fprintf(stderr, "%i: %s selected\n", getpid(), WGetEditMenuItemTitle(self));
+ else {
+ char textbuffer[100];
+
+ snprintf(textbuffer, sizeof(textbuffer), "%i: %s selected\n", getpid(), WGetEditMenuItemTitle(self));
+ write(fifonr, textbuffer, strlen(textbuffer));
+ }
+}
+
+
+void menuItemCloseAction(void *self, void *data)
+{
+ WMPostNotificationName("WMWindowClose", self, NULL);
+}
+
+
+void getMenu(WMWidget *self, void *data)
+{
+ WMPoint position;
+ struct dataStruct *tmp = (struct dataStruct *) data;
+
+ if (WMGetButtonSelected(self)) {
+ position = WMGetViewScreenPosition(WMWidgetView(tmp->window));
+ WEditMenuShowAt(tmp->menu,
+ (position.x > MENUWIDTH)?(position.x - MENUWIDTH):0,
+ position.y + MENITEMHT, tmp->window);
+ } else {
+ WEditMenuHide(tmp->menu);
+ WDeselectItem(tmp->menu); // remove selection before next pop up
+ }
+}
+
+
+static void notificationHandler(void *self, WMNotification *notif)
+{
+ if(!strcmp("WMWindowClose", WMGetNotificationName(notif)))
+ closeAll(self, NULL);
+ if(!strcmp(WMViewSizeDidChangeNotification, WMGetNotificationName(notif))) {
+ //resize actions
+ WMSize size = WMGetViewSize(WMWidgetView(self));
+ }
+}
+
+ /* main widget creating functions */
+
+WMWindow * makeMainwindow(Display *display, WMScreen *screen)
+{
+ WMWindow *window;
+
+ window = WMCreateWindow(screen, "Menu");
+ WMResizeWidget(window, WINWIDTH, WINHEIGHT);
+ WMSetWindowCloseAction(window, closeAll, NULL);
+ WMAddNotificationObserver(notificationHandler, window, "WMWindowClose", WMWidgetView(window));
+ WMSetViewNotifySizeChanges(WMWidgetView(window), True);
+ WMAddNotificationObserver(notificationHandler, window, WMViewSizeDidChangeNotification, WMWidgetView(window));
+ WMAddNotificationObserver(notificationHandler, window, "WMWindowClose", NULL);
+ WMRealizeWidget(window);
+ return window;
+}
+
+
+WEditMenu * makeMenus(WMScreen *screen, WEditMenu *menu, WEditMenu *submenu)
+{
+ WEditMenuItem *menuitem;
+
+ submenu = WCreateEditMenu(screen, "Submenu");
+ menuitem = WAddMenuItemWithTitle(submenu, "Submenu item");
+ WSetEditMenuItemAction(menuitem, menuItemAction);
+ menuitem = WAddMenuItemWithTitle(submenu, "2nd submenu item");
+ WSetEditMenuItemAction(menuitem, menuItemAction);
+ menuitem = WAddMenuItemWithTitle(submenu, "3rd submenu item");
+ WSetEditMenuItemAction(menuitem, menuItemAction);
+ menu = WCreateEditMenu(screen, "Main menu");
+ menuitem = WAddMenuItemWithTitle(menu, "1st main item");
+ WSetEditMenuItemAction(menuitem, menuItemAction);
+ menuitem = WAddMenuItemWithTitle(menu, "2nd main item");
+ WSetEditMenuItemAction(menuitem, menuItemAction);
+ menuitem = WAddMenuItemWithTitle(menu, "To submenu");
+ WSetEditMenuSubmenu(menu, menuitem, submenu);
+ menuitem = WAddMenuItemWithTitle(menu, "Quit");
+ WSetEditMenuItemAction(menuitem, menuItemCloseAction);
+ WMRealizeWidget(submenu);
+ WMRealizeWidget(menu);
+ return menu;
+}
+
+
+WMButton * makeButtonsTop(WMWidget *window, void *AppData)
+{
+ WMButton *Button;
+
+ Button = WMCreateButton(window, WBTPushOnPushOff);
+ WMSetButtonText(Button, "Menu");
+ WMSetButtonAction(Button, getMenu, AppData);
+ WMMoveWidget(Button, 4, 2);
+ WMRealizeWidget(Button);
+ return Button;
+}
+
+
+int main(int argc, char **argv)
+{
+ Display *display;
+ WMScreen *screen;
+ WMWindow *mainwindow;
+ WEditMenu *submenu, *menu;
+ WEditMenuItem *menuitem;
+ struct dataStruct Mainmenu;
+ WMButton *menubutton;
+
+ fifonr = NOLOGWINDOW;
+
+ WMInitializeApplication("MenuWindow", &argc, argv);
+ display = XOpenDisplay("");
+ screen = WMCreateScreen(display, DefaultScreen(display));
+ mainwindow = makeMainwindow(display, screen);
+
+ menu = makeMenus(screen, menu, submenu);
+
+ Mainmenu.window = mainwindow;
+ Mainmenu.menu = menu;
+ menubutton = makeButtonsTop(mainwindow, &Mainmenu);
+
+ WMMapSubwidgets(mainwindow);
+ WMMapWidget(mainwindow);
+
+ WMScreenMainLoop(screen);
+ return 0;
+}
diff --git a/WINGs_tutorial/SecondWindow.c b/WINGs_tutorial/SecondWindow.c
index db31b4b..55db767 100644
--- a/WINGs_tutorial/SecondWindow.c
+++ b/WINGs_tutorial/SecondWindow.c
@@ -1,11 +1,12 @@
-void closeAll(WMWidget *self,void *data){
- fprintf(stderr,"I've been used!\n");
+void closeAll(WMWidget *self,void *data)
+{
+ fprintf(stderr, "I've been used!\n");
WMDestroyWidget(self);
exit(0);
}
-int main (int argc, char **argv){
-
+int main (int argc, char **argv)
+{
Display *display;
WMScreen *screen;
@@ -14,7 +15,7 @@ int main (int argc, char **argv){
WMInitializeApplication("SecondWin", &argc, argv);
- if (!(display = XOpenDisplay(""))){
+ if (!(display = XOpenDisplay(""))) {
fprintf(stderr, "cannot open display\n");
exit(1);
}
@@ -22,7 +23,7 @@ int main (int argc, char **argv){
win = WMCreateWindow(screen, "");
WMSetWindowCloseAction(win, closeAll, NULL);
- color = WMCreateRGBColor(screen,124<<9,206<<8,162<<8, False);
+ color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
WMSetWidgetBackgroundColor((WMWidget *)win, color);
WMMapWidget(win);
@@ -30,5 +31,5 @@ int main (int argc, char **argv){
WMScreenMainLoop(screen);
-return 0;
+ return 0;
}
diff --git a/WINGs_tutorial/SeventhWindow.c b/WINGs_tutorial/SeventhWindow.c
dissimilarity index 89%
index 75a4b54..d315c6c 100644
--- a/WINGs_tutorial/SeventhWindow.c
+++ b/WINGs_tutorial/SeventhWindow.c
@@ -1,100 +1,97 @@
-#include
-#include
-
-#define HOFF 40
-#define VOFF 160
-#define WINWIDTH 180
-#define WINHEIGHT 300
-
-Display *display;
-WMScreen *screen;
-WMPixmap* pixmap;
-
-struct _pict{
- Drawable dwin;
- XSegment segments[40];
- int seglen;
- } pic;
-
-GC gc, g3;
-
-void closeAction(WMWidget *self,void *data){
- WMDestroyWidget(self);
- exit(0);
-}
-
-void drawProcedure(XEvent *event, void *data){
-
- WMDrawPixmap(pixmap, ((struct _pict*)data)->dwin,HOFF,30);
- XDrawRectangle(display,((struct _pict*)data)->dwin,g3, HOFF,VOFF,100,100);
- XFillRectangle(screen->display, ((struct _pict*)data)->dwin , WMColorGC(screen->white), HOFF, VOFF, 100, 100);
- XDrawSegments(display, ((struct _pict*)data)->dwin, WMColorGC(screen->black), ((struct _pict*)data)->segments, ((struct _pict*)data)->seglen);
- XFlush(display);
- return;
-}
-
-
-int main (int argc, char **argv){
-int i,j;
-WMColor *color;
-WMWindow * win;
-RImage *image;
-struct _pict pict;
-Drawable de;
-
-RColor one, two={0xaf, 0x0f,0xff,0x33};
-one.red=247;
-one.green=251;
-one.blue=107;
-one.alpha=0xff;
-
-
-WMInitializeApplication("DrawWin", &argc, argv);
-display = XOpenDisplay("");
-screen = WMCreateScreen(display, DefaultScreen(display));
-win = WMCreateWindow(screen, "");
-WMResizeWidget(win, WINWIDTH, WINHEIGHT);
-WMSetWindowCloseAction(win, closeAction, NULL);
-WMSetWindowTitle(win,"Graphics");
-color = WMCreateRGBColor(screen,124<<9,206<<8,162<<8, False);
-WMSetWidgetBackgroundColor((WMWidget *)win, color);
- /* end setup main window */
-
-image=RCreateImage( 100,100,0.5);
-RFillImage(image, &two);
-RDrawLine(image, 50,10,90,90,&one);
-RDrawLine(image, 10,90,50,10,&one);
-RDrawLine(image, 10,90,90,90,&one);
-
-g3=WMColorGC(screen->gray);
-XSetLineAttributes(display,g3,3,LineSolid,CapButt,JoinMiter);
-
-pict.segments[1].x1= pict.segments[0].x1=HOFF;
-pict.segments[0].x2=HOFF;
-pict.segments[0].y1=VOFF;
-pict.segments[1].y2= pict.segments[0].y2=VOFF;
-pict.segments[1].x2= HOFF+10;
-pict.segments[1].y1=VOFF+10;
-pict.seglen=2;
-for (i=9;i>0;i--){
- j=2*(10-i);
- pict.segments[j+1].x1= pict.segments[j].x1=HOFF;
- pict.segments[j+1].y2= pict.segments[j].y2=VOFF;
- pict.segments[j].x2= i+pict.segments[j-1].x2;
- pict.segments[j].y1=i+pict.segments[j-1].y1;
- pict.segments[j+1].x2= i+pict.segments[j].x2;
- pict.segments[j+1].y1=i+pict.segments[j].y1;
- pict.seglen+=2;
-};
-
-
-WMRealizeWidget(win);
-
-pict.dwin=W_VIEW_DRAWABLE(WMWidgetView(win));
-pixmap=WMCreatePixmapFromRImage(screen, image,1);
-
-WMCreateEventHandler(WMWidgetView(win), ExposureMask,drawProcedure,&pict);
-
-WMMapWidget(win);
-WMScreenMainLoop(screen);
-}
+#include
+#include
+
+#define HOFF 40
+#define VOFF 160
+#define WINWIDTH 180
+#define WINHEIGHT 300
+
+Display *display;
+WMScreen *screen;
+WMPixmap* pixmap;
+
+struct _pict {
+ Drawable dwin;
+ XSegment segments[40];
+ int seglen;
+} pic;
+
+GC gc, g3;
+
+void closeAction(WMWidget *self,void *data)
+{
+ WMDestroyWidget(self);
+ exit(0);
+}
+
+void drawProcedure(XEvent *event, void *data)
+{
+ struct _pict *p = (struct _pict *) data;
+
+ WMDrawPixmap(pixmap, p->dwin, HOFF, 30);
+ XDrawRectangle(display, p->dwin, g3, HOFF, VOFF, 100, 100);
+ XFillRectangle(screen->display, p->dwin, WMColorGC(screen->white), HOFF, VOFF, 100, 100);
+ XDrawSegments(display, p->dwin, WMColorGC(screen->black), p->segments, p->seglen);
+}
+
+
+int main(int argc, char **argv)
+{
+ int i, j;
+ WMColor *color;
+ WMWindow *win;
+ RImage *image;
+ struct _pict pict;
+ Drawable de;
+
+ RColor one = { 247, 251, 107, 0xFF },
+ two = { 0xAF, 0x0F, 0xFF, 0x33 };
+
+ WMInitializeApplication("DrawWin", &argc, argv);
+ display = XOpenDisplay("");
+ screen = WMCreateScreen(display, DefaultScreen(display));
+ win = WMCreateWindow(screen, "");
+ WMResizeWidget(win, WINWIDTH, WINHEIGHT);
+ WMSetWindowCloseAction(win, closeAction, NULL);
+ WMSetWindowTitle(win, "Graphics");
+ color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
+ WMSetWidgetBackgroundColor((WMWidget *)win, color);
+ /* end setup main window */
+
+ image = RCreateImage(100, 100, 0.5);
+ RFillImage(image, &two);
+ RDrawLine(image, 50, 10, 90, 90, &one);
+ RDrawLine(image, 10, 90, 50, 10, &one);
+ RDrawLine(image, 10, 90, 90, 90, &one);
+
+ g3 = WMColorGC(screen->gray);
+ XSetLineAttributes(display, g3, 3, LineSolid, CapButt, JoinMiter);
+
+ pict.segments[1].x1 = pict.segments[0].x1 = HOFF;
+ pict.segments[0].x2 = HOFF;
+ pict.segments[0].y1 = VOFF;
+ pict.segments[1].y2 = pict.segments[0].y2 = VOFF;
+ pict.segments[1].x2 = HOFF + 10;
+ pict.segments[1].y1 = VOFF + 10;
+ pict.seglen = 2;
+ for (i = 9; i > 0; i--) {
+ j = 2 * (10 - i);
+ pict.segments[j+1].x1 = pict.segments[j].x1 = HOFF;
+ pict.segments[j+1].y2 = pict.segments[j].y2 = VOFF;
+ pict.segments[j ].x2 = i + pict.segments[j-1].x2;
+ pict.segments[j ].y1 = i + pict.segments[j-1].y1;
+ pict.segments[j+1].x2 = i + pict.segments[j ].x2;
+ pict.segments[j+1].y1 = i + pict.segments[j ].y1;
+ pict.seglen += 2;
+ };
+
+ WMRealizeWidget(win);
+
+ pict.dwin = W_VIEW_DRAWABLE(WMWidgetView(win));
+ pixmap = WMCreatePixmapFromRImage(screen, image, 1);
+
+ WMCreateEventHandler(WMWidgetView(win), ExposureMask, drawProcedure, &pict);
+
+ WMMapWidget(win);
+ WMScreenMainLoop(screen);
+}
diff --git a/WINGs_tutorial/SixthWindow.c b/WINGs_tutorial/SixthWindow.c
dissimilarity index 87%
index 7e24581..8be338b 100644
--- a/WINGs_tutorial/SixthWindow.c
+++ b/WINGs_tutorial/SixthWindow.c
@@ -1,58 +1,60 @@
-#include
-#include
-
-#define WINWIDTH 200
-#define WINHEIGHT 300
-
-Display *display;
-WMScreen *screen;
-WMPixmap* pixmap;
-
-void closeAction(WMWidget *self,void *data){
- WMDestroyWidget(self);
- exit(0);
-}
-
-void drawProcedure(XEvent *event, void *data){
- WMDrawPixmap(pixmap, W_VIEW_DRAWABLE(WMWidgetView(data)),30,30);XFlush(display);
-}
-
-
-int main (int argc, char **argv){
-WMColor *color;
-WMWindow * win;
-RImage *image;
-
-RColor one, two={0xaf, 0x0f,0xff,0x33};
-one.red=0x20;
-one.green=0x20;
-one.blue=0x20;
-one.alpha=0xff;
-
-
-WMInitializeApplication("DrawWin", &argc, argv);
-display = XOpenDisplay("");
-screen = WMCreateScreen(display, DefaultScreen(display));
-win = WMCreateWindow(screen, "");
-WMResizeWidget(win, WINWIDTH, WINHEIGHT);
-WMSetWindowCloseAction(win, closeAction, NULL);
-WMSetWindowTitle(win,"Graphics");
-color = WMCreateRGBColor(screen,124<<9,206<<8,162<<8, False);
-WMSetWidgetBackgroundColor((WMWidget *)win, color);
- /* end setup main window */
-
-
-image=RCreateImage( 100,100,.8);
-RFillImage(image, &two);
-RDrawLine(image, 50,10,90,90,&one);
-RDrawLine(image, 10,90,50,10,&one);
-RDrawLine(image, 10,90,90,90,&one);
-
-WMRealizeWidget(win);
-
-pixmap=WMCreatePixmapFromRImage(screen, image,1);
-WMCreateEventHandler(WMWidgetView(win), ExposureMask,drawProcedure,win);
-
-WMMapWidget(win);
-WMScreenMainLoop(screen);
-}
+#include
+#include
+
+#define WINWIDTH 200
+#define WINHEIGHT 300
+
+Display *display;
+WMScreen *screen;
+WMPixmap* pixmap;
+
+void closeAction(WMWidget *self,void *data)
+{
+ WMDestroyWidget(self);
+ exit(0);
+}
+
+void drawProcedure(XEvent *event, void *data)
+{
+ WMDrawPixmap(pixmap, W_VIEW_DRAWABLE(WMWidgetView(data)), 30, 30);
+}
+
+
+int main(int argc, char **argv)
+{
+ WMColor *color;
+ WMWindow * win;
+ RImage *image;
+
+ RColor one, two = { 0xAF, 0x0F, 0xFF, 0x33 };
+ one.red = 0x20;
+ one.green = 0x20;
+ one.blue = 0x20;
+ one.alpha = 0xFF;
+
+ WMInitializeApplication("DrawWin", &argc, argv);
+ display = XOpenDisplay("");
+ screen = WMCreateScreen(display, DefaultScreen(display));
+ win = WMCreateWindow(screen, "");
+ WMResizeWidget(win, WINWIDTH, WINHEIGHT);
+ WMSetWindowCloseAction(win, closeAction, NULL);
+ WMSetWindowTitle(win, "Graphics");
+ color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
+ WMSetWidgetBackgroundColor((WMWidget *)win, color);
+
+ /* end setup main window */
+
+ image = RCreateImage(100, 100, 0.8);
+ RFillImage(image, &two);
+ RDrawLine(image, 50, 10, 90, 90, &one);
+ RDrawLine(image, 10, 90, 50, 10, &one);
+ RDrawLine(image, 10, 90, 90, 90, &one);
+
+ WMRealizeWidget(win);
+
+ pixmap = WMCreatePixmapFromRImage(screen, image, 1);
+ WMCreateEventHandler(WMWidgetView(win), ExposureMask, drawProcedure, win);
+
+ WMMapWidget(win);
+ WMScreenMainLoop(screen);
+}
diff --git a/WINGs_tutorial/ThirdWindow.c b/WINGs_tutorial/ThirdWindow.c
index 218ebfe..572c975 100644
--- a/WINGs_tutorial/ThirdWindow.c
+++ b/WINGs_tutorial/ThirdWindow.c
@@ -1,4 +1,5 @@
-void closeAll(WMWidget *self,void *data){
+void closeAll(WMWidget *self,void *data)
+{
fprintf(stderr, "I've been used!\n");
WMDestroyWidget(self);
exit(0);
@@ -15,26 +16,26 @@ handleEvents(XEvent *event, void *data)
}
}
-int main (int argc, char **argv){
-
- Display *display;
- WMScreen *screen;
+int main(int argc, char **argv)
+{
+ Display *display;
+ WMScreen *screen;
- WMWindow *win;
- WMColor *color;
+ WMWindow *win;
+ WMColor *color;
- WMInitializeApplication("ThirdWindow", &argc, argv);
+ WMInitializeApplication("ThirdWindow", &argc, argv);
- if (!(display = XOpenDisplay(""))){
- fprintf(stderr,"error: cannot open display\n");
- exit(1);
- }
- screen = WMCreateScreen(display, DefaultScreen(display));
+ if (!(display = XOpenDisplay(""))) {
+ fprintf(stderr,"error: cannot open display\n");
+ exit(1);
+ }
+ screen = WMCreateScreen(display, DefaultScreen(display));
win = WMCreateWindow(screen, "");
WMSetWindowCloseAction(win, closeAll, NULL);
- WMCreateEventHandler(WMWidgetView(win), ButtonPressMask,handleEvents, win);
- color = WMCreateRGBColor(screen, 124<<9,206<<8,162<<8, False);
+ WMCreateEventHandler(WMWidgetView(win), ButtonPressMask, handleEvents, win);
+ color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
WMSetWidgetBackgroundColor((WMWidget *)win, color);
WMMapWidget(win);
@@ -42,5 +43,5 @@ int main (int argc, char **argv){
WMScreenMainLoop(screen);
-return 0;
+ return 0;
}
diff --git a/WINGs_tutorial/WINGGraphics.html b/WINGs_tutorial/WINGGraphics.html
index 7edd5f1..c50eeeb 100644
--- a/WINGs_tutorial/WINGGraphics.html
+++ b/WINGs_tutorial/WINGGraphics.html
@@ -17,13 +17,15 @@
The WINGs library has functions to directly draw an image in a label, button or slider. To write to other widgets, there is a function WMDrawPixmap (WMPixmap *pixmap, Drawable d, int x, int y)
. The pixmap can be written to any XLib variable of type Drawable
, at position (x,y). This section shows how it is done to a window. The drawable is retrieved from the widget's view structure by the macro W_VIEW_DRAWABLE(WMView)
. You only call this macro after the widget has been WMRealizeWidget
ed, or there simply will not be a drawable in it. To use it,#include <WINGs/WINGsP.h>
.
Images can be created from within the code itself. The WINGs/wraster library creates a structure for it, by the call RCreateImage
, and there are a few functions to draw a line or segments in it. You would only use this if you like to store the image in memory for some reason. These functions use a colour structure RColor
. There is a conversion function from a WMColor
, but the RColor is a simple structure with four unsigned long members which are the RGB and alpha values. This example shows how a picture is drawn directly into a window, by the defined function drawProcedure
. This function is called by associating Expose
events to it, by using WMCreateEventHandler
on the window's view:
-void drawProcedure(XEvent *event, void *data){
- WMDrawPixmap(pixmap, W_VIEW_DRAWABLE(WMWidgetView(data)),30,30);XFlush(display);
+void drawProcedure(XEvent *event, void *data) {
+ WMDrawPixmap(pixmap, W_VIEW_DRAWABLE(WMWidgetView(data)), 30, 30);
}
-int main (){
- /* code */
-WMCreateEventHandler(WMWidgetView(win), ExposureMask,drawProcedure,win);
- /* */ }
+
+int main() {
+ /* code */
+ WMCreateEventHandler(WMWidgetView(win), ExposureMask, drawProcedure, win);
+ /* */
+}
Try to comment out the line with the event handler function, and to call WMDrawPixmap(pixmap, W_VIEW_DRAWABLE(WMWidgetView(win)),30,30)
directly from main. It won't work. When the WMScreenMainLoop
starts up, there will be an Expose event. The window will react to the event by drawing itself, as specified in the WINGslib routines, but there won't be another call to WMDrawPixmap, unless you programme it yourself.
diff --git a/WINGs_tutorial/WINGMenu.html b/WINGs_tutorial/WINGMenu.html
index f1d1e9f..45d6a82 100644
--- a/WINGs_tutorial/WINGMenu.html
+++ b/WINGs_tutorial/WINGMenu.html
@@ -34,7 +34,7 @@ typedef struct W_EditMenuItem {
For convenience, add this function to editmenu.c, too:
void WSetEditMenuItemAction(WEditMenuItem *item, WMAction *callback)
{
- item->callback= callback;
+ item->callback = callback;
}
We shall make a window with one button which will make the menu pop up. The code to create the menu is as follows. Have editmenu.c and editmenu.h in the same directory as the window application code, insert #include "editmenu.h"
somewhere at the top.
@@ -42,29 +42,31 @@ For convenience, add this function to editmenu.c, too:
WEditMenu *submenu, *menu;
WEditMenuItem * menuitem;
-submenu=WCreateEditMenu(screen,"Submenu");
-menuitem =WAddMenuItemWithTitle(submenu,"Submenu item");
-menu=WCreateEditMenu(screen,"Main menu");
-menuitem = WAddMenuItemWithTitle(menu,"To submenu");
-WSetEditMenuSubmenu(menu, menuitem , submenu);
-menuitem = WAddMenuItemWithTitle(menu,"Main item");
+submenu = WCreateEditMenu(screen, "Submenu");
+menuitem = WAddMenuItemWithTitle(submenu, "Submenu item");
+menu=WCreateEditMenu(screen, "Main menu");
+menuitem = WAddMenuItemWithTitle(menu, "To submenu");
+WSetEditMenuSubmenu(menu, menuitem, submenu);
+menuitem = WAddMenuItemWithTitle(menu, "Main item");
WMRealizeWidget(submenu);
WMRealizeWidget(menu);
The function to map the window w's menu at point (x,y) is WEditMenuShowAt(menu,x,y,w)
. However, it will not show anything unless it is used after the intial window has been mapped. To do this, we use WMSetButtonAction
on a button, and make the WMAction map the menu. We pass it pointers to both the menu and the window, so that we can map the menu in the window's neighbourhood. The WMAction will look like :
void getMenu(WMWidget *self, void *data){
WMPoint position;
- struct datacouple *tmp=(struct datacouple *)data;
- if(WMGetButtonSelected(self)){
- position=WMGetViewScreenPosition(WMWidgetView(tmp->window));
- WEditMenuShowAt(tmp->menu,(position.x>MENUWIDTH)?position.x-MENUWIDTH:0,\
- position.y+MENITEMHT,tmp->window);
- }else
+ struct datacouple *tmp = (struct datacouple *) data;
+
+ if (WMGetButtonSelected(self)) {
+ position = WMGetViewScreenPosition(WMWidgetView(tmp->window));
+ WEditMenuShowAt(tmp->menu, (position.x > MENUWIDTH)?position.x-MENUWIDTH:0,
+ position.y + MENITEMHT, tmp->window);
+ } else
WEditMenuHide(tmp->menu);
}
The used structure is struct datacouple{WMWindow *window; WEditMenu *menu;} datacouple;
. Realize the window before the others. The code with details is here. To compile it, you now type cc -x c EighthWindow.c editmenu.c -lXft -L/usr/X11/lib -L/usr/lib -lWINGs -lwraster -o EighthWindow. editmenu.c is, of course, the modified source file.
To use the callback functions, we need to execute them somewhere. To do this, search the static void selectItem
function in the editmenu.c source. After its last line, insert the line: if (menu->selectedItem->callback) menu->selectedItem->callback(menu->selectedItem,NULL);
. Define the callback before main as, eg.:
-
void menuItemAction(void *self, void *data){
-fprintf(stderr, "Selected\n");}
+
void menuItemAction(void *self, void *data) {
+ fprintf(stderr, "Selected\n");
+}
and add it to the menu items in the main
code with the WSetEditMenuItemAction( menuitem, menuItemAction);
. There is also a little addition to the getMenu function, to reset the menu when we hide it.
The function WCreateEditMenuItem
in editmenu.c associates to ButtonPress events on the menu item widget, the function handleItemClick
. This event handler function calls the function selectItem
when it gets this event, and does a few other things we shall not need any more. The selectItem function goes through a few things. If the clicked menu item is a submenu entry, it checks its location and maps the submenu. At the end of this function we have inserted the line which calls our callback function in case the pointer to it is not NULL
. If the menu has to appear, legacy-style, below a fixed bar in the window's top, we would just need to calculate this position, and also need to hide the menu whenever we drag the window itself. For a free floating menu, the latter is not very important.
diff --git a/WINGs_tutorial/WINGsRemark.html b/WINGs_tutorial/WINGsRemark.html
index f80a0ca..c960f10 100644
--- a/WINGs_tutorial/WINGsRemark.html
+++ b/WINGs_tutorial/WINGsRemark.html
@@ -24,15 +24,17 @@ void closeAll(WMWidget *self,void *data){
A second window should be opened with the existing screen as an argument. After success in opening, you increase windowcounter
by one.
Defining an icon which will be used for your application, and drawing an image in a widget, are quite straightforward. Suppose, there is an XPM-image available, and it is the file /usr/include/pixmaps/picture.xpm. The following code sets an application icon and draws an icon in a label.
-
RContext *ctxt;
-RImage *img;
-WMPixmap *wimg;
- /* code to open screen, window*/
- ctxt=WMScreenRContext(screen);
- img=RLoadXPM(ctxt, "/usr/include/pixmaps/picture.xpm", 0);
+ RContext *ctxt;
+ RImage *img;
+ WMPixmap *wimg;
+
+ /* code to open screen, window*/
+ ctxt = WMScreenRContext(screen);
+ img = RLoadXPM(ctxt, "/usr/include/pixmaps/picture.xpm", 0);
WMSetApplicationIconImage(screen, img);
- wimg= WMCreatePixmapFromRImage(screen, img,0);
- /* code to create a label */
+ wimg = WMCreatePixmapFromRImage(screen, img,0);
+
+ /* code to create a label */
WMSetLabelImagePosition(label, WIPImageOnly);
WMSetLabelImage(label, wimg);
RContext
refers to the X-server's so-called graphics context. This specifies which line width, fill patterns, etc. will be used. That information is not contained in the XPM-file. With WMScreenRContext
, we use the existing context. RLoadXPM
loads the xpm from a file, and stores it as an RImage.
@@ -57,18 +59,18 @@ Display *display;
WMScreen *screen;
int *WMGetModeViewSSize(){
-int *result;
-XF86VidModeModeLine modeline;
-int dotclock_return;
+ int *result;
+ XF86VidModeModeLine modeline;
+ int dotclock_return;
-result=(int *)calloc(8,sizeof(int));
+ result = (int *)calloc(8,sizeof(int));
- XF86VidModeGetModeLine(display,DefaultScreen(display), &dotclock_return,&modeline);
- *result= modeline.hdisplay;
- result[1]= modeline.vdisplay;
- XF86VidModeGetViewPort(display,DefaultScreen(display), result+2,result+3);
- result[4]=WMScreenWidth(screen);
- result[5]=WMScreenHeight(screen);
+ XF86VidModeGetModeLine(display, DefaultScreen(display), &dotclock_return, &modeline);
+ *result = modeline.hdisplay;
+ result[1] = modeline.vdisplay;
+ XF86VidModeGetViewPort(display, DefaultScreen(display), result+2, result+3);
+ result[4] = WMScreenWidth(screen);
+ result[5] = WMScreenHeight(screen);
return result;
}
@@ -90,76 +92,73 @@ meaning that the monitor is running at 1024x768, its upper left corner is at (12
#define FIFOERROR (-1)
#define FIFOLOWESTPOSS 0
-int fifonr=NOLOGWINDOW; /* the fifo nr, or an error value */
+int fifonr = NOLOGWINDOW; /* the fifo nr, or an error value */
int sibpid; /* the child's process ID */
- /* clean up when closing: */
-
-void closeAll(WMWidget *self,void *data){
-
+/* clean up when closing: */
+void closeAll(WMWidget *self,void *data) {
WMDestroyWidget(self);
- if(--windowCounter<1){
- if (fifonr>=FIFOLOWESTPOSS)
- kill(sibpid,SIGTERM);
- if (!access(ERRMSGFIFO,F_OK|W_OK))
+ if(--windowCounter < 1) {
+ if (fifonr >= FIFOLOWESTPOSS)
+ kill(sibpid,SIGTERM);
+ if (!access(ERRMSGFIFO, F_OK | W_OK))
unlink(ERRMSGFIFO);
- exit(0);
- }
+ exit(0);
+ }
}
- /* handle the case the child terminates. Set fifonr and clean up: */
-void redirectmsg(int sig){
+/* Handle the case the child terminates. Set fifonr and clean up: */
+void redirectmsg(int sig) {
- fifonr=NOLOGWINDOW;
- if (!access(ERRMSGFIFO,F_OK|W_OK))
+ fifonr = NOLOGWINDOW;
+ if (!access(ERRMSGFIFO, F_OK | W_OK))
unlink(ERRMSGFIFO);
return;
}
- /* have the log window pop up: */
-
-int showMessageWindow(){
+/* Have the log window pop up: */
+int showMessageWindow() {
-(void) signal(SIGCHLD,redirectmsg); /* use redirectmsg whenever the child process stops */
+ (void) signal(SIGCHLD, redirectmsg); /* use redirectmsg whenever the child process stops */
-if(access(ERRMSGFIFO,F_OK)==-1)
- fifonr=mknod(ERRMSGFIFO,0640|O_EXCL|S_IFIFO,(dev_t)0);
-else
- fifonr=FIFOERROR;
- /* fifonr == FIFOERROR if mkfifo or access failed, for mknod returns -1 on failure */
+ if (access(ERRMSGFIFO, F_OK) == -1)
+ fifonr = mknod(ERRMSGFIFO, 0640|O_EXCL|S_IFIFO, (dev_t)0);
+ else
+ fifonr = FIFOERROR;
+ /* fifonr == FIFOERROR if mkfifo or access failed, for mknod returns -1 on failure */
-if(fifonr!=FIFOERROR){
+ if (fifonr != FIFOERROR) {
+ sibpid = fork();
- sibpid=fork();
-
- if(sibpid==0){
- execlp("xconsole" , "xconsole", "-file",ERRMSGFIFO,"-geometry","250x400", \
- "-title","Application Messages",(char *)0);
- exit(1);
-}
- else
- fifonr=open(ERRMSGFIFO,O_WRONLY);
-}
+ if (sibpid == 0) {
+ execlp("xconsole", "xconsole", "-file", ERRMSGFIFO, "-geometry", "250x400",
+ "-title", "Application Messages", (char *)0);
+ exit(1);
+ } else {
+ fifonr = open(ERRMSGFIFO, O_WRONLY);
+ }
+ }
return fifonr;
}
- /* usage: */
-
-void someActionWithMessage(void *self, void *data){
+/* Usage: */
+void someActionWithMessage(void *self, void *data) {
- if (fifonr<FIFOLOWESTPOSS)
- fifonr=showMessageWindow(); /* (re)start xconsole, or try again in case of FIFOERROR */
+ if (fifonr < FIFOLOWESTPOSS)
+ fifonr = showMessageWindow(); /* (re)start xconsole, or try again in case of FIFOERROR */
- if (fifonr==FIFOERROR) /* if still error, use stderr */
- fprintf(stderr,"%s selected\n", WMgetSomeInformationFrom(self));
- else{
+ if (fifonr == FIFOERROR) /* if still error, use stderr */
+ fprintf(stderr, "%s selected\n", WMgetSomeInformationFrom(self));
+ else {
char textbuffer[100];
- snprintf(textbuffer,99, "%s is the information\n", WMGetSomeInformationFrom(self));
- write(fifonr, textbuffer,strlen(textbuffer));
+
+ snprintf(textbuffer, sizeof(textbuffer), "%s is the information\n",
+ WMGetSomeInformationFrom(self));
+ write(fifonr, textbuffer, strlen(textbuffer));
}
}
diff --git a/WINGs_tutorial/WINGstep1.html b/WINGs_tutorial/WINGstep1.html
index bfbb55b..0c0cccb 100644
--- a/WINGs_tutorial/WINGstep1.html
+++ b/WINGs_tutorial/WINGstep1.html
@@ -17,11 +17,11 @@ The WINGs library allows you to get a window on the screen with a few lines of C
#include <WINGs/WINGs.h>
-int main (int argc, char **argv){
-
- Display *display;
- WMScreen *screen;
- WMWindow *win;
+int main (int argc, char **argv)
+{
+ Display *display;
+ WMScreen *screen;
+ WMWindow *win;
WMInitializeApplication("put-your-app-name-here", &argc, argv);
display = XOpenDisplay("");
diff --git a/WINGs_tutorial/glframe.c b/WINGs_tutorial/glframe.c
dissimilarity index 93%
index 5c86d89..c298b2d 100644
--- a/WINGs_tutorial/glframe.c
+++ b/WINGs_tutorial/glframe.c
@@ -1,283 +1,312 @@
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-#define CONTENTH 300
-#define CONTENTW 300
-#define CONTENTMARGIN 30
-
-
-struct couple{
- WMWindow *window;
- WMFrame *frame;
-} datacouple;
-
-
-float red=252.0/256, green=88.0/256, blue=16.0/256;
-float redb=252.0/256, greenb=242.0/256, blueb=80.0/256;
-
-int Attr[] = { GLX_RGBA,
- GLX_RED_SIZE, 8,
- GLX_GREEN_SIZE, 8,
- GLX_BLUE_SIZE, 8,
- GLX_DEPTH_SIZE, 16,
- GLX_DOUBLEBUFFER,
- None};
-Display * display;
-float alpha=0;
-
-void init(void)
-{
-glClearColor (256/256, 256/256, 256/256, 0.0);
-glPolygonMode(GL_FRONT, GL_FILL);
-glPolygonMode(GL_BACK, GL_FILL);
-glEnable(GL_DEPTH_TEST);
-glShadeModel(GL_SMOOTH);
-
-glEnable(GL_LIGHTING);
-GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
-GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8f, 1.0f };
-GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
-GLfloat position[] = { 2.0f, -0.1f, 2.0f, 1.0f };
-GLfloat position2[] = { -2.0f, -0.26f, -4.0f, 1.0f };
-glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
-glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
-//glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
-glMateriali(GL_FRONT, GL_SHININESS, 98);
-glLightfv(GL_LIGHT0, GL_POSITION, position2);
-//glLightfv(GL_LIGHT1, GL_POSITION, position2);
-
-glEnable(GL_LIGHT0);
-//glEnable(GL_LIGHT1);
-glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
-//glColorMaterial(GL_FRONT, GL_SPECULAR);
-glEnable(GL_COLOR_MATERIAL);
-glShadeModel(GL_SMOOTH);
-glCullFace( GL_BACK );
-glEnable( GL_CULL_FACE );
-
-glEnable(GL_POLYGON_SMOOTH);
-/*glEnable(GL_BLEND);
-glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
-//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);*/
-
-}
-
-void normvector(float a, float aa, float aaa, float b, float bb, float bbb, float c, float cc, float ccc,float *result){
- float v1[3];float v2[3];float tmp;
-
- v1[0]=(b-a);v1[1]=(bb-aa);v1[2]=(bbb-aaa);
- v2[0]=(b-c);v2[1]=(bb-cc);v2[2]=(bbb-ccc);
- result[0]=(v1[1]*v2[2]-v1[2]*v2[1]);
- result[1]=(v1[2]*v2[0]-v1[0]*v2[2]);
- result[2]=(v1[0]*v2[1]-v1[1]*v2[0]);
- tmp=sqrt(result[0]*result[0]+result[1]*result[1]+result[2]*result[2]);
- result[0]/=tmp;
- result[1]/=tmp;
- result[2]/=tmp;
-}
-
-
-void redraw(XEvent * v,void *xw){
-Window win;
-float z[3];
-
-win = *(Window *)xw;
-
-glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-glPushMatrix(); glShadeModel(GL_SMOOTH);
-
-glRotatef(alpha, 0, 1, 0);
-if (alpha > 360) alpha =alpha-360;
-
-glBegin(GL_TRIANGLES);
-
-glColor3f(redb,greenb,blueb);
-normvector(-0.85f, 0.0f, 0.0f,0.0f, 0.0f, 0.85f,0.0f, 0.6f, 0.0f,z);
-glNormal3fv(z);
-glVertex3f(-0.85f, 0.0f, 0.0f);
-glVertex3f(0.0f, 0.0f, 0.85f);
-glVertex3f(0.0f, 0.6f, 0.0f);
-
-normvector(0.0f, 0.0f,0.85f,0.85f, 0.0f, 0.0f,0.0f, 0.60f,0.0f,z);
-glNormal3fv(z);
-glVertex3f(0.0f, 0.0f, 0.85f);
-glVertex3f(0.85f, 0.0f, 0.0f);
-glVertex3f(0.0f, 0.6f, 0.0f);
-
-glColor3f(red,green,blue);
-normvector(0.85f, 0.0f, 0.0f,0.0f, 0.0f, -0.85f,0.0f, 0.6f, 0.0f,z);
-glNormal3fv(z);
-glVertex3f(0.85f, 0.0f, 0.0f);
-glVertex3f(0.0f, 0.0f, -0.85f);
-glVertex3f(0.0f, 0.6f, 0.0f);
-
-normvector(0.0f, 0.0f, -0.85f,-0.85f, 0.0f, 0.0f,0.0f, 0.6f, 0.0f,z);
-glNormal3fv(z);
-glVertex3f(0.0f, 0.0f, -0.85f);
-glVertex3f(-0.85f, 0.0f, 0.0f);
-glVertex3f(0.0f, 0.6f, 0.0f);
-
-glColor3f(redb,greenb,blueb);
-normvector(-0.85f, 0.0f, 0.0f,0.0f, -1.0f, 0.0f,0.0f, 0.0f, 0.85f,z);
-glNormal3fv(z);
-glVertex3f(-0.85f, 0.0f, 0.0f);
-glVertex3f(0.0f, -1.0f, 0.0f);
-glVertex3f(0.0f, 0.0f, 0.85f);
-
-normvector(0.0f, 0.0f, 0.85f, 0.0f, -1.0f, 0.0f,0.85f, 0.0f, 0.0f ,z);
-glNormal3fv(z);
-glVertex3f(0.0f, 0.0f, 0.85f);
-glVertex3f(0.0f, -1.0f, 0.0f);
-glVertex3f(0.85f, 0.0f, 0.0f);
-
-glColor3f(red,green,blue);
-normvector(0.85f, 0.0f, 0.0f,0.0f, -1.0f, 0.0f, 0.0f, 0.0,-0.85f ,z);
-glNormal3fv(z);
-glVertex3f(0.85f, 0.0f, 0.0f);
-glVertex3f(0.0f,-1.0f, 0.0f);
-glVertex3f(0.0f, 0.0f, -0.85f);
-
-normvector(0.0f, 0.0f, -0.85f,0.0f, -1.0f, 0.0f, -0.85f, 0.0f,0.0f ,z);
-glNormal3fv(z);
-glVertex3f(0.0f, 0.0f, -0.85f);
-glVertex3f(0.0f, -1.0f, 0.0f);
-glVertex3f(-0.85f, 0.0f, 0.0f);
-
-glEnd();
-
-glPopMatrix();
-glXSwapBuffers(display, win);
-}
-
-setsize(unsigned int width, unsigned int height)
-{
-glViewport(0, 0, width, height);
-glMatrixMode(GL_PROJECTION);
-glLoadIdentity();
-glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
-glMatrixMode (GL_MODELVIEW);
-}
-
-void DoRotate(void *self,void *xwindow){
- XEvent event;int i=0;
- alpha+=15;
-redraw(NULL,(Window *)xwindow);
-}
-
-void redo(XEvent * event,void *xw){
- switch (event->type)
- {
- case Expose:
- if (event->xexpose.count!=0) break;
- redraw(event,&event->xexpose.window);
- break;
- case ConfigureNotify: setsize(event->xconfigure.width, event->xconfigure.height); // assuming there will be an expose afterwards
- break;
- }
-}
-
-void closeAll(WMWidget *self,void *data){
- WMDestroyWidget(self);
- exit(0);
-}
-
-static void resizeHandler(void *data, WMNotification *notif){
- struct couple *tmp;tmp=(struct couple *)data;
- WMSize size = WMGetViewSize(WMWidgetView(tmp->window));
- WMResizeWidget(tmp->frame, size.width -2*CONTENTMARGIN, size.height-2*CONTENTMARGIN);
-}
-
-void getargs(int argc, char **argv){
-if (argc>3) {
- redb=red=(float)atoi(argv[1])/256;
- greenb=green=(float)atoi(argv[2])/256;
- blueb=blue=(float)atoi(argv[3])/256;
-}
- if (argc>6){
- redb=(float)atoi(argv[4])/256;
- greenb=(float)atoi(argv[5])/256;
- blueb=(float)atoi(argv[6])/256;
- }
-}
-
-int main (int argc, char **argv){
-
-WMFrame *glframe;
-WMScreen *screen;
-WMWindow *window;
-WMButton *Button;
-
-
-/* Xlib and glX variables */
-Window win;
-XVisualInfo *xvVisualInfo;
-Colormap cmColorMap;
-XSetWindowAttributes winAttr;
-GLXContext glXContext;
-
-getargs(argc,argv);
-WMInitializeApplication("GLWindow", &argc, argv);
-display = XOpenDisplay("");
-screen = WMCreateScreen(display, DefaultScreen(display));
-
- if(!glXQueryExtension(display, NULL, NULL)){wwarning("X server does not have GLX\n"); return 0; }
-
-window = WMCreateWindow(screen, "Main");
-WMResizeWidget(window, CONTENTW+2*CONTENTMARGIN, CONTENTH+2*CONTENTMARGIN*CONTENTH/CONTENTW);
-WMSetWindowAspectRatio(window, CONTENTW,CONTENTH,CONTENTW,CONTENTH);
-WMSetWindowCloseAction(window, closeAll, NULL);
-WMSetWindowTitle(window,"GL Frame");
-WMRealizeWidget(window);
-datacouple.window=window;
-WMSetViewNotifySizeChanges(WMWidgetView(window), True);
-WMAddNotificationObserver(resizeHandler, &datacouple, WMViewSizeDidChangeNotification, WMWidgetView(window));
-
-
-glframe = WMCreateFrame(window);
-datacouple.frame=glframe;
-WMResizeWidget(glframe, CONTENTW, CONTENTH);
-WMMoveWidget(glframe, CONTENTMARGIN,CONTENTMARGIN);
-WMRealizeWidget(glframe);
-
-Button=WMCreateButton(window, WBTMomentaryPush);
-WMSetButtonAction(Button, DoRotate,&win);
-WMSetButtonText(Button,"Turn");
-WMMoveWidget(Button, CONTENTMARGIN,2);
-WMRealizeWidget(Button);
-WMMapWidget(Button);
-
-/* get the frame's X window value */
-win =W_VIEW_DRAWABLE(WMWidgetView(glframe));
-WMCreateEventHandler(WMWidgetView(glframe), ExposureMask|StructureNotifyMask,redo,&win);
-
-xvVisualInfo = glXChooseVisual(display, DefaultScreen(display), Attr);
- if(xvVisualInfo == NULL) {wwarning("No visualinfo\n");return 0;}
-
-cmColorMap = XCreateColormap(display,RootWindow(display, DefaultScreen(display)), xvVisualInfo->visual, AllocNone);
-
-winAttr.colormap = cmColorMap;
-winAttr.border_pixel = 0;
-winAttr.background_pixel = 0;
-winAttr.event_mask = ExposureMask | ButtonPressMask |StructureNotifyMask| KeyPressMask;
-
-XChangeWindowAttributes(display,win,CWBorderPixel | CWColormap | CWEventMask,&winAttr);
-glXContext = glXCreateContext(display, xvVisualInfo, None, True);
- if(!glXContext) {wwarning("glX cannot create rendering context\n");return 0;}
-
-glXMakeCurrent(display, win, glXContext);
-
-WMMapWidget(glframe);
-init();
-setsize(CONTENTW,CONTENTH);
-WMMapWidget(window);
-
-WMScreenMainLoop(screen);
-
-return 0;
-}
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#define CONTENTH 300
+#define CONTENTW 300
+#define CONTENTMARGIN 30
+
+
+struct couple {
+ WMWindow *window;
+ WMFrame *frame;
+} datacouple;
+
+
+float red = 252.0/256, green = 88.0/256, blue = 16.0/256;
+float redb = 252.0/256, greenb = 242.0/256, blueb = 80.0/256;
+
+int Attr[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_DEPTH_SIZE, 16,
+ GLX_DOUBLEBUFFER,
+ None
+};
+Display *display;
+float alpha = 0;
+
+void init(void)
+{
+ GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8f, 1.0f };
+ GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
+ GLfloat position[] = { 2.0f, -0.1f, 2.0f, 1.0f };
+ GLfloat position2[] = { -2.0f, -0.26f, -4.0f, 1.0f };
+
+ glClearColor(256.0/256, 256.0/256, 256.0/256, 0.0);
+ glPolygonMode(GL_FRONT, GL_FILL);
+ glPolygonMode(GL_BACK, GL_FILL);
+ glEnable(GL_DEPTH_TEST);
+ glShadeModel(GL_SMOOTH);
+
+ glEnable(GL_LIGHTING);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
+ //glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
+ glMateriali(GL_FRONT, GL_SHININESS, 98);
+ glLightfv(GL_LIGHT0, GL_POSITION, position2);
+ //glLightfv(GL_LIGHT1, GL_POSITION, position2);
+
+ glEnable(GL_LIGHT0);
+ //glEnable(GL_LIGHT1);
+ glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+ //glColorMaterial(GL_FRONT, GL_SPECULAR);
+ glEnable(GL_COLOR_MATERIAL);
+ glShadeModel(GL_SMOOTH);
+ glCullFace(GL_BACK);
+ glEnable(GL_CULL_FACE);
+
+ glEnable(GL_POLYGON_SMOOTH);
+ /*glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
+ //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);*/
+}
+
+void normvector(float a, float aa, float aaa,
+ float b, float bb, float bbb,
+ float c, float cc, float ccc,
+ float *result)
+{
+ float v1[3], v2[3], tmp;
+
+ v1[0] = (b-a); v1[1] = (bb-aa); v1[2] = (bbb-aaa);
+ v2[0] = (b-c); v2[1] = (bb-cc); v2[2] = (bbb-ccc);
+
+ result[0] = (v1[1] * v2[2] - v1[2] * v2[1]);
+ result[1] = (v1[2] * v2[0] - v1[0] * v2[2]);
+ result[2] = (v1[0] * v2[1] - v1[1] * v2[0]);
+
+ tmp = sqrt(result[0] * result[0] + result[1] * result[1] + result[2] * result[2]);
+ result[0] /= tmp;
+ result[1] /= tmp;
+ result[2] /= tmp;
+}
+
+
+void redraw(XEvent * v, void *xw)
+{
+ Window win;
+ float z[3];
+
+ win = *(Window *)xw;
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glPushMatrix();
+ glShadeModel(GL_SMOOTH);
+
+ glRotatef(alpha, 0, 1, 0);
+
+ glBegin(GL_TRIANGLES);
+
+ glColor3f(redb, greenb, blueb);
+ normvector(-0.85f, 0.0f, 0.0f, 0.0f, 0.0f, 0.85f, 0.0f, 0.6f, 0.0f, z);
+ glNormal3fv(z);
+ glVertex3f(-0.85f, 0.0f, 0.0f);
+ glVertex3f(0.0f, 0.0f, 0.85f);
+ glVertex3f(0.0f, 0.6f, 0.0f);
+
+ normvector(0.0f, 0.0f,0.85f, 0.85f, 0.0f, 0.0f, 0.0f, 0.60f,0.0f, z);
+ glNormal3fv(z);
+ glVertex3f(0.0f, 0.0f, 0.85f);
+ glVertex3f(0.85f, 0.0f, 0.0f);
+ glVertex3f(0.0f, 0.6f, 0.0f);
+
+ glColor3f(red, green, blue);
+ normvector(0.85f, 0.0f, 0.0f, 0.0f, 0.0f, -0.85f, 0.0f, 0.6f, 0.0f, z);
+ glNormal3fv(z);
+ glVertex3f(0.85f, 0.0f, 0.0f);
+ glVertex3f(0.0f, 0.0f, -0.85f);
+ glVertex3f(0.0f, 0.6f, 0.0f);
+
+ normvector(0.0f, 0.0f, -0.85f, -0.85f, 0.0f, 0.0f, 0.0f, 0.6f, 0.0f, z);
+ glNormal3fv(z);
+ glVertex3f(0.0f, 0.0f, -0.85f);
+ glVertex3f(-0.85f, 0.0f, 0.0f);
+ glVertex3f(0.0f, 0.6f, 0.0f);
+
+ glColor3f(redb, greenb, blueb);
+ normvector(-0.85f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.85f, z);
+ glNormal3fv(z);
+ glVertex3f(-0.85f, 0.0f, 0.0f);
+ glVertex3f(0.0f, -1.0f, 0.0f);
+ glVertex3f(0.0f, 0.0f, 0.85f);
+
+ normvector(0.0f, 0.0f, 0.85f, 0.0f, -1.0f, 0.0f,0.85f, 0.0f, 0.0f, z);
+ glNormal3fv(z);
+ glVertex3f(0.0f, 0.0f, 0.85f);
+ glVertex3f(0.0f, -1.0f, 0.0f);
+ glVertex3f(0.85f, 0.0f, 0.0f);
+
+ glColor3f(red, green, blue);
+ normvector(0.85f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0, -0.85f, z);
+ glNormal3fv(z);
+ glVertex3f(0.85f, 0.0f, 0.0f);
+ glVertex3f(0.0f,-1.0f, 0.0f);
+ glVertex3f(0.0f, 0.0f, -0.85f);
+
+ normvector(0.0f, 0.0f, -0.85f, 0.0f, -1.0f, 0.0f, -0.85f, 0.0f, 0.0f, z);
+ glNormal3fv(z);
+ glVertex3f(0.0f, 0.0f, -0.85f);
+ glVertex3f(0.0f, -1.0f, 0.0f);
+ glVertex3f(-0.85f, 0.0f, 0.0f);
+
+ glEnd();
+
+ glPopMatrix();
+ glXSwapBuffers(display, win);
+}
+
+setsize(unsigned int width, unsigned int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void DoRotate(void *self, void *xwindow)
+{
+ XEvent event;
+ int i = 0;
+
+ alpha += 15;
+ if (alpha > 360) alpha = alpha - 360;
+
+ redraw(NULL, (Window *)xwindow);
+}
+
+void redo(XEvent * event, void *xw)
+{
+ switch (event->type) {
+ case Expose:
+ if (event->xexpose.count != 0) break;
+ redraw(event, &event->xexpose.window);
+ break;
+
+ case ConfigureNotify:
+ setsize(event->xconfigure.width, event->xconfigure.height); // assuming there will be an expose afterwards
+ break;
+ }
+}
+
+void closeAll(WMWidget *self, void *data)
+{
+ WMDestroyWidget(self);
+ exit(0);
+}
+
+static void resizeHandler(void *data, WMNotification *notif)
+{
+ struct couple *tmp;
+ WMSize size;
+
+ tmp = (struct couple *) data;
+ size = WMGetViewSize(WMWidgetView(tmp->window));
+ WMResizeWidget(tmp->frame, size.width - 2*CONTENTMARGIN, size.height - 2*CONTENTMARGIN);
+}
+
+void getargs(int argc, char **argv)
+{
+ if (argc > 3) {
+ redb = red = (float)atoi(argv[1]) / 256;
+ greenb = green = (float)atoi(argv[2]) / 256;
+ blueb = blue = (float)atoi(argv[3]) / 256;
+ }
+ if (argc > 6) {
+ redb = (float)atoi(argv[4]) / 256;
+ greenb = (float)atoi(argv[5]) / 256;
+ blueb = (float)atoi(argv[6]) / 256;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ WMFrame *glframe;
+ WMScreen *screen;
+ WMWindow *window;
+ WMButton *Button;
+
+ /* Xlib and glX variables */
+ Window win;
+ XVisualInfo *xvVisualInfo;
+ Colormap cmColorMap;
+ XSetWindowAttributes winAttr;
+ GLXContext glXContext;
+
+ getargs(argc, argv);
+ WMInitializeApplication("GLWindow", &argc, argv);
+ display = XOpenDisplay("");
+ screen = WMCreateScreen(display, DefaultScreen(display));
+
+ if(!glXQueryExtension(display, NULL, NULL)) {
+ werror("X server does not have GLX\n");
+ return 0;
+ }
+
+ window = WMCreateWindow(screen, "Main");
+ WMResizeWidget(window, CONTENTW + 2*CONTENTMARGIN, CONTENTH + 2*CONTENTMARGIN*CONTENTH/CONTENTW);
+ WMSetWindowAspectRatio(window, CONTENTW, CONTENTH, CONTENTW, CONTENTH);
+ WMSetWindowCloseAction(window, closeAll, NULL);
+ WMSetWindowTitle(window, "GL Frame");
+ WMRealizeWidget(window);
+ datacouple.window = window;
+ WMSetViewNotifySizeChanges(WMWidgetView(window), True);
+ WMAddNotificationObserver(resizeHandler, &datacouple, WMViewSizeDidChangeNotification, WMWidgetView(window));
+
+ glframe = WMCreateFrame(window);
+ datacouple.frame = glframe;
+ WMResizeWidget(glframe, CONTENTW, CONTENTH);
+ WMMoveWidget(glframe, CONTENTMARGIN, CONTENTMARGIN);
+ WMRealizeWidget(glframe);
+
+ Button = WMCreateButton(window, WBTMomentaryPush);
+ WMSetButtonAction(Button, DoRotate, &win);
+ WMSetButtonText(Button, "Turn");
+ WMMoveWidget(Button, CONTENTMARGIN, 2);
+ WMRealizeWidget(Button);
+ WMMapWidget(Button);
+
+ /* get the frame's X window value */
+ win = W_VIEW_DRAWABLE(WMWidgetView(glframe));
+ WMCreateEventHandler(WMWidgetView(glframe), ExposureMask | StructureNotifyMask, redo, &win);
+
+ xvVisualInfo = glXChooseVisual(display, DefaultScreen(display), Attr);
+ if (xvVisualInfo == NULL) {
+ werror("glX could not find a suitable visual\n");
+ return 0;
+ }
+
+ cmColorMap = XCreateColormap(display, RootWindow(display, DefaultScreen(display)), xvVisualInfo->visual, AllocNone);
+
+ winAttr.colormap = cmColorMap;
+ winAttr.border_pixel = 0;
+ winAttr.background_pixel = 0;
+ winAttr.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask | KeyPressMask;
+
+ XChangeWindowAttributes(display, win, CWBorderPixel | CWColormap | CWEventMask, &winAttr);
+ glXContext = glXCreateContext(display, xvVisualInfo, None, True);
+ if(!glXContext) {
+ werror("glX cannot create rendering context\n");
+ return 0;
+ }
+
+ glXMakeCurrent(display, win, glXContext);
+
+ WMMapWidget(glframe);
+ init();
+ setsize(CONTENTW, CONTENTH);
+ WMMapWidget(window);
+
+ WMScreenMainLoop(screen);
+
+ return 0;
+}
--
2.11.4.GIT