// Find window from coordinates struct Window *WhichWindow( struct Screen *screen, short x, short y, unsigned short flags) { struct Layer *layer; struct Window *window=0; // Lock screen layerinfo if (!(flags&WWF_NO_LOCK)) LockLayerInfo(&screen->LayerInfo); // Find layer if ((layer=WhichLayer(&screen->LayerInfo,x,y))) { // Get window pointer window=layer->Window; } // Unlock if necessary if (!(flags&WWF_NO_LOCK) && (!window || !(flags&WWF_LEAVE_LOCKED))) UnlockLayerInfo(&screen->LayerInfo); return window; }
// Lock screen layerinfo void LockScreenLayer(struct Screen *screen) { // Not already locked? if (!(GUI->flags&GUIF_LAYER_LOCKED)) { // Lock layerinfo LockLayerInfo(&screen->LayerInfo); GUI->flags|=GUIF_LAYER_LOCKED; } }
// Someone pressed the help key void help_get_help(short x,short y,unsigned short qual) { struct Window *window=0; struct Layer *layer; IPCData *ipc=0; // Lock screen layer LockLayerInfo(&GUI->screen_pointer->LayerInfo); // Find which layer the mouse is over if ((layer=WhichLayer(&GUI->screen_pointer->LayerInfo,x,y))) { // Get window pointer window=layer->Window; // Get window ID if (GetWindowID(window)!=WINDOW_UNKNOWN) { // Forbid to get port Forbid(); // Get port if (!(ipc=(IPCData *)GetWindowAppPort(window))) Permit(); } } // Unlock layer UnlockLayerInfo(&GUI->screen_pointer->LayerInfo); // Got a port? if (ipc) { ULONG coords; // Convert coordinates to window-relative x-=window->LeftEdge; y-=window->TopEdge; // Pack into longword coords=((unsigned short)x<<16)|(unsigned short)y; // Send help command IPC_Command(ipc,IPC_HELP,qual,(APTR)coords,0,0); // Enable multitasking now that message has been sent Permit(); } // Otherwise, show generic help else help_show_help(HELP_MAIN,0); }
void *ami_window_at_pointer(int type) { struct Layer *layer; LockLayerInfo(&scrn->LayerInfo); layer = WhichLayer(&scrn->LayerInfo, scrn->MouseX, scrn->MouseY); UnlockLayerInfo(&scrn->LayerInfo); if(layer) return ami_find_gwin_by_id(layer->Window, type); else return NULL; }
// Show font example void font_show_font(font_data *data,BOOL refresh) { struct Rectangle rect; struct Region *region; struct RastPort rp; // Get display rectangle GetObjectRect(data->list,GAD_FONT_DISPLAY,&rect); // Move rectangle in rect.MinX+=3; rect.MinY+=3; rect.MaxX-=3; rect.MaxY-=3; // Copy rastport rp=*data->window->RPort; // Refresh? if (refresh) { LockLayerInfo(&data->window->WScreen->LayerInfo); BeginRefresh(data->window); } // Clear background SetAPen(&rp,DRAWINFO(data->window)->dri_Pens[SHINEPEN]); RectFill(&rp,rect.MinX-1,rect.MinY-1,rect.MaxX+1,rect.MaxY+1); // Refreshing? if (refresh) EndRefresh(data->window,FALSE); // Create region if ((region=NewRegion())) { // Set rectangle OrRectRegion(region,&rect); // Install region InstallClipRegion(data->window->WLayer,region); } // Refreshing? if (refresh) BeginRefresh(data->window); // Got a font? if (data->font) { ULONG flags; short y; struct TextExtent extent; char *ptr,*end; // Set pen and font SetAPen(&rp,DRAWINFO(data->window)->dri_Pens[TEXTPEN]); SetDrMd(&rp,JAM1); SetFont(&rp,data->font); // Get style flags flags=0; if (GetGadgetValue(data->list,GAD_FONT_BOLD)) flags|=FSF_BOLD; if (GetGadgetValue(data->list,GAD_FONT_ITALIC)) flags|=FSF_ITALIC; if (GetGadgetValue(data->list,GAD_FONT_ULINE)) flags|=FSF_UNDERLINED; // Set styles SetSoftStyle(&rp,flags,FSF_BOLD|FSF_ITALIC|FSF_UNDERLINED); // Valid font to draw? if (data->font_text[0]) { // Get end of the string end=data->font_text+strlen(data->font_text); // Initial coordinates y=rect.MinY; // Initialise position if (!(ptr=strchr(data->font_text,'A'))) ptr=data->font_text; Move(&rp,rect.MinX,y+rp.TxBaseline); // Draw until we reach the bottom while (y<rect.MaxY) { // New line if (rp.cp_x>rect.MaxX) { // Bump position y+=rp.TxHeight+1; Move(&rp,rect.MinX,y+rp.TxBaseline); } // Otherwise else { short len,maxlen; // Get text that will fit len= TextFit( &rp, ptr, (maxlen=strlen(ptr)), &extent, 0,1, rect.MaxX-rp.cp_x+1, rp.TxHeight); // Check against length, add extra character if ok if (len<maxlen) ++len; // Draw text Text(&rp,ptr,len); // Bump text position ptr+=len; // End of the string? if (ptr>=end) ptr=data->font_text; } } } } // Finished refreshing? if (refresh) EndRefresh(data->window,TRUE); // Remove region if (region) { InstallClipRegion(data->window->WLayer,0); DisposeRegion(region); } // Unlock layers if we refreshed if (refresh) UnlockLayerInfo(&data->window->WScreen->LayerInfo); }