void C4EditCursor::FrameSelection() { ClearSelection(); C4Object *cobj; C4ObjectLink *clnk; for (clnk=::Objects.First; clnk && (cobj=clnk->Obj); clnk=clnk->Next) if (cobj->Status) if (cobj->OCF & OCF_NotContained) { if (Inside(cobj->GetX(),Min(X,X2),Max(X,X2)) && Inside(cobj->GetY(),Min(Y,Y2),Max(Y,Y2))) AddToSelection(cobj); } OnSelectionChanged(); }
void C4EditCursor::UpdateDropTarget(DWORD dwKeyState) { C4Object *cobj; C4ObjectLink *clnk; DropTarget=NULL; if (dwKeyState & MK_CONTROL) if (Selection.GetObject()) for (clnk=::Objects.First; clnk && (cobj=clnk->Obj); clnk=clnk->Next) if (cobj->Status) if (!cobj->Contained) if (Inside<int32_t>(X-(cobj->GetX()+cobj->Shape.x),0,cobj->Shape.Wdt-1)) if (Inside<int32_t>(Y-(cobj->GetY()+cobj->Shape.y),0,cobj->Shape.Hgt-1)) if (!Selection.GetLink(cobj)) { DropTarget=cobj; break; } }
bool C4EditCursor::DoContextMenu(DWORD dwKeyState) { bool fObjectSelected = !!Selection.ObjectCount(); #ifdef USE_WIN32_WINDOWS POINT point; GetCursorPos(&point); HMENU hContext = GetSubMenu(hMenu,0); SetMenuItemEnable( hContext, IDM_VIEWPORT_DELETE, fObjectSelected && Console.Editing); SetMenuItemEnable( hContext, IDM_VIEWPORT_DUPLICATE, fObjectSelected && Console.Editing); SetMenuItemEnable( hContext, IDM_VIEWPORT_CONTENTS, fObjectSelected && Selection.GetObject()->Contents.ObjectCount() && Console.Editing); SetMenuItemText(hContext,IDM_VIEWPORT_DELETE,LoadResStr("IDS_MNU_DELETE")); SetMenuItemText(hContext,IDM_VIEWPORT_DUPLICATE,LoadResStr("IDS_MNU_DUPLICATE")); SetMenuItemText(hContext,IDM_VIEWPORT_CONTENTS,LoadResStr("IDS_MNU_CONTENTS")); ObjselectDelItems(); C4FindObjectAtPoint pFO(X,Y); C4ValueArray * atcursor; atcursor = pFO.FindMany(::Objects, ::Objects.Sectors); // needs freeing (single object ptr) int itemcount = atcursor->GetSize(); if(itemcount > 0) { const int maxitems = 25; // Maximum displayed objects. if you raise it, also change note with IDM_VPORTDYN_FIRST in resource.h if(itemcount > maxitems) itemcount = maxitems+1; itemsObjselect.resize(itemcount+1); // +1 for a separator itemsObjselect[0].ItemId = IDM_VPORTDYN_FIRST; itemsObjselect[0].Object = NULL; AppendMenu(hContext, MF_SEPARATOR, IDM_VPORTDYN_FIRST, NULL); int i = 1; for(std::vector<ObjselItemDt>::iterator it = itemsObjselect.begin() + 1; it != itemsObjselect.end(); ++it, ++i) { C4Object * obj = (*atcursor)[i-1].getObj(); assert(obj); it->ItemId = IDM_VPORTDYN_FIRST+i; it->Object = obj; AppendMenu(hContext, MF_STRING, it->ItemId, FormatString("%s #%i (%i/%i)", obj->GetName(), obj->Number, obj->GetX(), obj->GetY()).GetWideChar()); } if(atcursor->GetSize() > maxitems) { AppendMenu(hContext, MF_GRAYED, IDM_VPORTDYN_FIRST+maxitems+1, L"..."); itemsObjselect[maxitems+1].ItemId = IDM_VPORTDYN_FIRST+maxitems+1; itemsObjselect[maxitems+1].Object = NULL; } } delete atcursor; int32_t iItem = TrackPopupMenu( hContext, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_NONOTIFY, point.x,point.y, 0, Console.hWindow, NULL); switch (iItem) { case IDM_VIEWPORT_DELETE: Delete(); break; case IDM_VIEWPORT_DUPLICATE: Duplicate(); break; case IDM_VIEWPORT_CONTENTS: GrabContents(); break; case 0: break; default: for(std::vector<ObjselItemDt>::iterator it = itemsObjselect.begin() + 1; it != itemsObjselect.end(); ++it) if(it->ItemId == iItem) { DoContextObjsel(it->Object, (dwKeyState & MK_SHIFT) == 0); break; } break; } ObjselectDelItems(); #else #ifdef WITH_DEVELOPER_MODE gtk_widget_set_sensitive(itemDelete, fObjectSelected && Console.Editing); gtk_widget_set_sensitive(itemDuplicate, fObjectSelected && Console.Editing); gtk_widget_set_sensitive(itemGrabContents, fObjectSelected && Selection.GetObject()->Contents.ObjectCount() && Console.Editing); ObjselectDelItems(); C4FindObjectAtPoint pFO(X,Y); C4ValueArray * atcursor; atcursor = pFO.FindMany(::Objects, ::Objects.Sectors); // needs freeing int itemcount = atcursor->GetSize(); if(itemcount > 0) { itemsObjselect.resize(itemcount+1); // +1 for a separator itemsObjselect[0].MenuItem = gtk_separator_menu_item_new(); itemsObjselect[0].EditCursor = this; gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), itemsObjselect[0].MenuItem); int i = 0; for(std::vector<ObjselItemDt>::iterator it = itemsObjselect.begin() + 1; it != itemsObjselect.end(); ++it, ++i) { it->EditCursor = this; C4Object * obj = (*atcursor)[i].getObj(); assert(obj); it->Object = obj; GtkWidget * wdg = gtk_menu_item_new_with_label(FormatString("%s #%i (%i/%i)", obj->GetName(), obj->Number, obj->GetX(), obj->GetY()).getData()); it->MenuItem = wdg; gtk_menu_shell_append(GTK_MENU_SHELL(menuContext), wdg); g_signal_connect(G_OBJECT(wdg), "activate", G_CALLBACK(OnObjselect), &*it); } } delete atcursor; gtk_widget_show_all(menuContext); gtk_menu_popup(GTK_MENU(menuContext), NULL, NULL, NULL, NULL, 3, 0); #endif #endif return true; }