📄 microwindows_architecture.html
字号:
moving over. If desired, the 7applications programmer can "capture" themouse and receive all mouse move messages by calling SetCapture. ReleaseCapturereturns the processing to normal. In addition, the GetCapture function will returnthe window with capture, if any.</p><h3> 3.5.3 Rectangle andRegion management</h3><p>There are a number of functions that are used for rectangles and regions. Following is the group:</p><p> SetRect Define a rectangle structure<br> SetRectEmpty Define an empty rectangle<br> CopyRect Copy a rectangle<br> IsRectEmpty Return TRUE if empty rectangle<br> InflateRect Enlarge a rectangle<br> OffsetRect Move a rectangle<br> PtInRect Determine if a point is in a rectangle<br> </p><p>A large number of region management routines are defined and declared in the winrgn.cfile. </p><p> </p><h3>4. Nano-X API</h3><p>The Nano-X API was originally designed by David Bell, with his mini-x package for theMINIX operating system. Nano-X is now running on top of the core graphics engineroutines discussed in section 2. Nano-X was designed for a client/serverenvironment, as no pointers to structures are passed to the API routines, instead a callis made to the server to get an ID, which is passed to the API functions and is used toreference the data on the server. In addition, Nano-X is not message-oriented,instead modeled after the X protocol which was designed for speed on systems where theclient and server machines were different.</p><h3> 4.1 Client/Server model</h3><p>In Nano-X, there are two linking mechanisms that can be used for applicationsprograms. In the client/server model, the application program is linked with aclient library that forms a UNIX socket connection with the Nano-X server, a separateprocess. Each application then communicates all parameters over the UNIXsocket. For speed and debugging, it is sometimes desirable to link the applicationdirectly with the server. In this case, a stub library is provided that just passesthe client routines parameters to the server function.</p><p>The Nano-X naming convention uses GrXXX to designate client side callable routines,with a marshalling layer implemented in the files nanox/client.c, nanox/nxproto.c, andnanox/srvnet.c. The client/server network layer currently uses a fast approach tomarshalling the data from the Gr routine into a buffer, and sent all at once to thereceiving stubs in nanox/srvnet.c, before calling the server drawing routines innanox/srvfunc.c. In the linked application scenario, the Nano-X client linksdirectly with the functions in nanox/srvfunc.c, and the nanox/client.c and nanox/srvnet.cfiles are not required.</p><p>A Nano-X application must call GrOpen before calling any other Nano-X function, andcall GrClose before exiting. These functions establish a connection with the serverwhen running the client/server model, and return an error status if the server can't befound or isn't currently running.</p><p>The main loop in a Nano-X application is to create some windows, define the events youwant with GrSelectEvents, and then wait for an event with GrGetNextEvent. If it isdesired to merely check for an event, but not wait if there isn't one, GrCheckNextEventcan be used. GrPeekEvent can be used to examine the next event without removing itfrom the queue.</p><p>When running Nano-X programs in the client/server model, it's currently necessary torun the server first in a shell script, then wait a second, then run theapplication. Some rewriting is needed to fire up the server when an applicationrequires it, I believe.</p><h3> 4.2 Events</h3><p>Nano-X applications specify which events they would like to see on a per-window basisusing GrSelectEvents. Then, in the main loop, the application calls GrGetNextEventand waits for one of the event types selected for in any of the windows. Typically,a switch statement is used to determine what to do after receiving the event. Thisis similar to the Microwindows's API GetMessage/DispatchMessage loop, except that inMicrowindows API, DispatchMessage is used to send the event to the window's handlingprocedure, typically located with the window object. In Nano-X, all the eventhandling code for each of the windows must be placed together in the main event loop,there is no automatic dispatching. Of course, widget sets serve to provideobject-orientation, but this is in addition to the Nano-X API.</p><p>Following are the event types that Nano-X programs can recieve:</p><p> GR_EVENT_TYPE_NONE, ERROR, EXPOSURE, BUTTON_DOWN, BUTTON_UP,MOUSE_ENTER, MOUSE_EXIT, MOUSE_MOTION, MOUSE_POSITION, KEY_UP, KEY_DOWN, FOCUS_IN,FOCUS_OUT, FDINPUT</p><p>Note that Nano-X API provides mouse enter and exit events whereas Microwindows API doesnot. Also, the exposure events are calculated and sent immediately by the server,and not combined and possibly delayed for better paint throughput as in the MicrowindowsAPI.</p><h3> 4.3 Window creation and destruction</h3><p>Windows are created in Nano-X with the GrNewWindow function. Windows can bespecified to be input-only, in which case the GrNewInputWindow function is used. Thewindow border and color is specified in these calls, but will have to be rewritten whenfancier window dressings are required. The return value from these functions is anID that can be used in later calls to get a graphics context or perform windowmanipulation.</p><h3> 4.4 Window showing,hiding and moving</h3><p>Windows are shown by calling the GrMapWindow function, and hidden usingGrUnmapWindow. Mapping a window is required for all ancestors of a window in orderfor it to be visible. The GrRaiseWindow call is used to raise the Z order of awindow, while GrLowerWindow is used to lower the Z order. GrMoveWindow is used tochange the position of a window, and GrResizeWindow is used to resize a window.</p><h3> 4.5 Drawing to a window</h3><p>Nano-X requires both a window ID and a graphics context ID in order to draw to awindow. Nano-X sends expose events to the application when a window needs to beredrawn. Unlike the Microwindows API, Nano-X clients are typically required tocreate their drawing graphics contexts early on and keep them for the duration of theapplication. Like Microwindows though, the graphics contexts record information likethe current background and foreground colors so they don't have to be specified in everygraphics API call.</p><h3> 4.5.1 Graphics contexts</h3><p>To allocate a graphics context for a window, call GrNewGC. On termination, callGrDestroyGC. GrCopyGC can be used to copy on GC to another. GrGetGCInfo isused to retrieve the settings contained in a GC. After creating a graphics context,the server returns a graphics context ID. This is then used as a parameter in allthe graphics drawing API functions. In Nano-X programs, the current clipping regionand window coordinate system aren't stored with the GC, as they are in Microwindows'DCs. This is because, first, Nano-X doesn't support dual coordinate systems fordrawing to the "window dressing" area versus the "user" area of thewindow (window and client coordinates in Microwindows). User programs can't draw theborder area of the window, only a single color and width can be specified. Althoughresembling X, this will have to change, so that widget sets can specify the look and feelof all aspects of the windows they maintain. Since the clipping region isn'tmaintained with the graphics context, but instead with the window data structure, Nano-Xapplications must specify both a window ID and a graphics context ID when calling anygraphics API function. Because of this, many Nano-X applications allocate allgraphics contexts in the beginning of the program, and hold them throughout execution,since the graphics contexts hold only things like foreground color, etc, and no windowinformation. This cannot be done with Microwindows API because the DC's containwindow clipping information and must be released before processing the next message.</p><h3> 4.5.2 Graphics drawingAPI</h3><p>Following are the graphics drawing functions available with Nano-X. LikeMicrowindows API, these all match up eventually to the graphics engine GdXXX routines.</p><p> GrGetGCTextSize Return text width and height information<br> GrClearWindow Clear a window to it's background color<br> GrSetGCForeground Set the foreground color in a graphics context<br> GrSetGCBackground Set the background color in a graphics context<br> GrSetGCUseBackground Set the "use background color" in a graphics context<br> GrSetGCMode Set the drawing mode<br> GrSetGCFont Set the font<br> GrPoint Draw a point in the passed gc's foreground color<br> GrLine Draw a line in the passed gc's foreground color<br> GrRect Draw a rectangle in passed gc's foreground color<br> GrFillRect Fill a rectangle with the passed gc's foreground color<br> GrEllipse &nb
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -