/* GUIBEGIN WINDOW , 0, 0, 400, 200, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , RxGdi Example FONT 8, 400, MS Shell Dlg DEND GUIEND */ /* An example of using the RxGDI Add-on DLL to do our own drawing of a graph * in a window. */ /* Load REXX GUI, and also the RxGdi Add-on libraries */ LIBRARY rexxgui, rxgdi /* Raise SYNTAX condition for any error that happens with a RxGdi function */ GdiErr = "SYNTAX" GdiHeading = 1 /* Assume the total units for the Y axis is 10 */ TotalUnits = 10 /* The upper left X and Y positions where to draw our graph */ StartX = 5 StartY = 5 /* The "values" for the months of January, March, and July */ January = 2 March = 5 July = 10 GuiErr = "SYNTAX" GuiHeading = 1 /* Since we'll be doing our own painting of windows, then don't let the * operating system automatically erase the window background. We also * need our PAINT handler called whenever the window is resized, so we * specify the VREDRAW|HREDRAW styles */ GuiWindowDefaults(, , 0, 'VREDRAW|HREDRAW') GuiCreateWindow('NORMAL') Again: DO FOREVER GuiGetMsg() CATCH SYNTAX CONDITION('M') SIGNAL Again CATCH HALT FINALLY GuiDestroyWindow() END RETURN /* Called by Reginald whenever our window needs painting. This handler is * tricky. It should never, never create another window nor display a * message box. All it should ever do is draw to our window. And that's it. */ WM_PAINT: /* Begin our drawing by calling GdiPaint. Pass the handle to our * window where the drawing is to take place. GuiCreateWindow set * the GuiWindow variable to this. We also pass the name of a * variable where we want the Paint handle to be returned. Here * we pass a variable name of "Paint". GdiPaint will also append a * "1" to this name, and set that variable to a Device Context * (which we may need to pass to our Gdi functions). */ GdiPaint('Paint', GuiWindow) /* If any error happens below, let's have a FINALLY so that we * can call GdiPaint to end painting. */ DO /* Erase our window's background. Use a WHITE brush */ GuiGetCtlPlacement(GuiWindow, , , 'Width', 'Height') GdiStockObj("WHITE_BRUSH", "Brush") Brush = GdiSetObj(Paint1, Brush) GdiRect(Paint1, 0, 0, Width, Height) GdiSetObj(Paint1, Brush) /* Get GUI font */ GdiStockObj("GUI_FONT", "FontHandle") /* Select this font into our Device Context */ GdiSetObj(Paint1, FontHandle) /* Get the height of some typical text given our font, and add a little empty space */ GdiText(Paint1, "Ij", , 'Height', 'CALCRECT') Height = Height + 5 /* Get the width of our largest Y axis label */ GdiText(Paint1, TotalUnits, 'Width', , 'CALCRECT') /* Set background drawing mode to TRANSPARENT. The background color isn't used */ GdiBkMode(Paint1) /* Set the text color to Red = 200, Green = 70, Blue = 40. NOTE: The * highest individual value is 255. */ GdiTextColor(Paint1, GdiColorValue(200, 70, 40)) /* Draw the units on the Y axis */ i = 0 DO TotalUnits GdiText(Paint1, TotalUnits - i, StartX, (Height * i) + StartY, '1LINE|RIGHT', Width) i = i + 1 END /* Add a little space between the Y labels and Y axis */ Width = Width + 10 + StartX /* Draw the graph Y axis */ XAxis = (Height * TotalUnits) + StartY GdiLine(Paint1, Width, StartY, Width, XAxis) /* Draw the labels on the X axis */ XAxis = XAxis + 5 JanX = 5 + Width GdiText(Paint1, "January", JanX, XAxis, '1LINE') GdiText(Paint1, "January", 'JanWidth', , 'CALCRECT|1LINE') MarX = 40 + JanX + JanWidth GdiText(Paint1, "March", MarX, XAxis, '1LINE') GdiText(Paint1, "March", 'MarWidth', , 'CALCRECT|1LINE') JulX = 40 + MarX + MarWidth GdiText(Paint1, "July", JulX, XAxis, '1LINE') GdiText(Paint1, "July", 'JulWidth', , 'CALCRECT|1LINE') /* Draw the graph X axis */ XAxis = XAxis - 5 GdiLine(Paint1, Width, XAxis, JulX + JulWidth + 5, XAxis) /* Draw the bars using a DKGRAY_BRUSH brush */ GdiStockObj("DKGRAY_BRUSH", "Brush") Brush = GdiSetObj(Paint1, Brush) /* Draw the january bar. NOTE: Our bar is drawn with a thickness of 20 */ IF JanWidth > 20 THEN JanX = JanX + (JanWidth % 2) - 10 GdiRect(Paint1, JanX, (Height * (TotalUnits - January)) + StartY, JanX + 20, XAxis) /* Draw the march bar */ IF MarWidth > 20 THEN MarX = MarX + (MarWidth % 2) - 10 GdiRect(Paint1, MarX, (Height * (TotalUnits - March)) + StartY, MarX + 20, XAxis) /* Draw the july bar */ IF JulWidth > 20 THEN JulX = JulX + (JulWidth % 2) - 10 GdiRect(Paint1, JulX, (Height * (TotalUnits - July)) + StartY, JulX + 20, XAxis) /* Restore the orig brush */ GdiSetObj(Paint1, Brush) CATCH SYNTAX /* This beep is here to alert us if any of the above calls fail. But * we should NOT display a message box here. Never create another * window or message box within a PAINT handler. If we need to inform * another part of our program about this error, we can do a GuiWake() * with some signal that our main message loop will deduce. */ BEEP() FINALLY /* End our painting */ GdiPaint(Paint) END /* Don't let Rexx Gui process this event. */ RETURN ""