// Normalize alignment static Box *normalize(AlignBox *box) { // Replace (&)(A) by A if (box->nchildren() == 1) { // Replace by single child Box *new_box = (*box)[0]->link(); box->unlink(); return new_box; } // Replace (&)(A, (&)(B, C)) by (&)(A, B, C) bool need_assoc_restructuring = false; for (int i = 0; i < box->nchildren(); i++) { Box *child = (*box)[i]; if (ptr_type_info(box) == ptr_type_info(child)) { need_assoc_restructuring = true; break; } } if (need_assoc_restructuring) { // Replace this box by NEW_ALIGN Box *new_box = box->dup0(); AlignBox *new_align = ptr_cast(AlignBox, new_box); assert(new_align != 0); for (int i = 0; i < box->nchildren(); i++) { Box *child = (*box)[i]; if (ptr_type_info(box) == ptr_type_info(child)) { AlignBox *a = ptr_cast(AlignBox, child); assert(a != 0); for (int j = 0; j < a->nchildren(); j++) *new_align += (*a)[j]; } else *new_align += child; } box->unlink(); return new_align; } return box; }
// Make sure we do not attempt to delete a delay on a destroyed widget void _Delay::DestroyCB(Widget, XtPointer client_data, XtPointer) { _Delay *delay = (_Delay *)client_data; assert(ptr_cast(_Delay, delay)); delay->widget = 0; delay->old_cursor = 0; }
// MARK is a MarkBox in SRC. Find equivalent box in DUP. MarkBox *BoxGraphNode::find_mark(Box *dup, Box *src, Box *mark) { assert (box() != 0); if (mark == 0) return 0; if (src == mark) { MarkBox *dup_mb = ptr_cast(MarkBox, dup); assert(dup_mb != 0); return dup_mb; } // Try Composite children CompositeBox *src_cb = ptr_cast(CompositeBox, src); if (src_cb != 0) { CompositeBox *dup_cb = ptr_cast(CompositeBox, dup); assert(dup_cb != 0); assert(src_cb->nchildren() == dup_cb->nchildren()); for (int i = 0; i < src_cb->nchildren(); i++) { MarkBox *mb = find_mark((*dup_cb)[i], (*src_cb)[i], mark); if (mb) return mb; } return 0; } // Try HatBox child HatBox *src_hb = ptr_cast(HatBox, src); if (src_hb != 0) { HatBox *dup_hb = ptr_cast(HatBox, dup); assert(dup_hb != 0); return find_mark(dup_hb->box(), src_hb->box(), mark); } return 0; }
// Invoke GDB upon rlogin static void InvokeGDBFromShellHP(Agent *source, void *client_data, void *call_data) { DataLength *d = (DataLength *)call_data; bool at_shell_prompt = false; if (d->length >= 1 && d->data[d->length - 1] == '>') { // We got input ending in `>' - probably a prompt. at_shell_prompt = true; } else if (d->length >= 2 && d->data[d->length - 1] == ' ' && ispunct(d->data[d->length - 2])) { // We got input ending in a punctuation character, followed by // a single space - probably a prompt. at_shell_prompt = true; } else { // (Any other prompt choices out there? -AZ) } if (at_shell_prompt) { GDBAgent *gdb = ptr_cast(GDBAgent, source); static bool init_sent = false; if (!init_sent) { // Send the initialization string. if (app_data.rhost_init_commands != 0 && app_data.rhost_init_commands[0] != '\0') { string init = string(app_data.rhost_init_commands) + "\n"; gdb->write(init.chars(), init.length()); } init_sent = true; } else { // Invoke GDB... const string& gdb_call = *((const string *)client_data); gdb->write(gdb_call.chars(), gdb_call.length()); // Echoing should be disabled by now. Echo call manually... XtAppAddTimeOut(XtWidgetToApplicationContext(gdb_w), 0, EchoTextCB, (XtPointer)client_data); // ... and don't get called again. gdb->removeHandler(Input, InvokeGDBFromShellHP, client_data); } } }
void FMPThread::AttachGtaThread(char *s_name) { Log::Debug(L"FMPThread::AttachGtaThread called"); while(*(PDWORD)ADDRESS_ACTIVE_THREAD == 0) Sleep(1); sysArray<GtaThread>* nowThreads = GetThreadsArray(); int i; for(i = 0;i < nowThreads->wCount;i++) { // Проверяем не занят ли слот потока if(nowThreads->pData[i]->RetContext()->nThreadId == 0) break; } if(i == nowThreads->wCount) { return; } strcpy(ThreadName, s_name); m_pOriginalThread = nowThreads->pData[i]; m_nThreadIndex = i; // Цепляем наш GtaThread в этот слот nowThreads->pData[i] = this; // получаем хеш названия GtaThread unsigned int hash; ptr call_this = ptr_cast(ADDRESS_HASH_GET); _asm { mov eax, s_name; call call_this; mov hash, eax; } // Ставим чистую инфу в GtaThread Reset(hash,NULL,0); // Забираем ид потока.. m_context.nThreadId = *(PDWORD)ADDRESS_THREAD_ID; *(PDWORD)ADDRESS_THREAD_ID = m_context.nThreadId + 1; // Говорим игре что у нас есть ещё 1 скрипт *(PDWORD)ADDRESS_SCRIPTS_COUNT++; Log::Debug(L"FMPThread::AttachGtaThread complete"); }
ThreadStates FMPThread::Tick(unsigned int msec) { ptr fn = ptr_cast(ADDRESS_THREAD_TICK); scrThread *thread = this; _asm { push msec; mov ecx, thread; call fn; } return m_context.eThreadState; }
void ArcGraphEdge::makeLine(Widget w, const BoxRegion& exposed, std::ostream& os, const GraphGC& gc) const { HintGraphNode *arc_hint = 0; RegionGraphNode *arc_from = 0; RegionGraphNode *arc_to = 0; bool make_arc = true; if (from()->isHint() && to()->isHint()) { // Edge between two hints make_arc = false; } else if (from()->isHint() && from()->firstTo() != 0) { arc_hint = ptr_cast(HintGraphNode, from()); arc_from = ptr_cast(RegionGraphNode, arc_hint->firstTo()->from()); arc_to = ptr_cast(RegionGraphNode, to()); if (arc_hint == 0 || arc_from == 0 || arc_to == 0 || arc_hint->nextTo(arc_hint->firstTo()) != 0) { // Bad nodes or hint with multiple edges make_arc = false; } } else if (to()->isHint() && to()->firstFrom() != 0) { arc_hint = ptr_cast(HintGraphNode, to()); arc_to = ptr_cast(RegionGraphNode, arc_hint->firstFrom()->to()); arc_from = ptr_cast(RegionGraphNode, from()); if (arc_hint == 0 || arc_from == 0 || arc_to == 0 || arc_hint->nextFrom(arc_hint->firstFrom()) != 0) { // Bad nodes or hint with multiple edges make_arc = false; } } else { // Edge between two ordinary nodes make_arc = false; } if (!make_arc) { if (w != 0) LineGraphEdge::drawLine(w, exposed, gc); else LineGraphEdge::_print(os, gc); return; } BoxPoint pos_from = arc_from->pos(); BoxRegion region_from = arc_from->region(gc); if (arc_from->selected()) { pos_from += gc.offsetIfSelected; region_from.origin() += gc.offsetIfSelected; } BoxPoint pos_to = arc_to->pos(); BoxRegion region_to = arc_to->region(gc); if (arc_to->selected()) { pos_to += gc.offsetIfSelected; region_to.origin() += gc.offsetIfSelected; } BoxPoint pos_hint = arc_hint->pos(); BoxRegion region_hint = arc_hint->region(gc); if (arc_hint->selected()) { pos_hint += gc.offsetIfSelected; region_hint.origin() += gc.offsetIfSelected; } if (pos_hint <= region_from || pos_hint <= region_to) { // Hint within region if (w != 0) LineGraphEdge::drawLine(w, exposed, gc); else LineGraphEdge::_print(os, gc); return; } BoxPoint new_pos_from, new_pos_to, dummy; findLine(pos_from, pos_hint, region_from, region_hint, new_pos_from, dummy, gc); findLine(pos_hint, pos_to, region_hint, region_to, dummy, new_pos_to, gc); pos_from = new_pos_from; pos_to = new_pos_to; // Draw circle segment POS_FROM -> POS_HINT or POS_HINT -> POS_TO // Determine the arc center double cx, cy; bool ok = center(pos_from, pos_hint, pos_to, cx, cy); if (!ok) { // Nodes form a line if (w != 0) LineGraphEdge::drawLine(w, exposed, gc); else LineGraphEdge::_print(os, gc); return; } // Determine radius (easy when you have the center) double radius = hypot(cx - pos_to[X], cy - pos_to[Y]); // Determine start and path of arc double alpha_from = -atan2(pos_from[Y] - cy, pos_from[X] - cx); double alpha_hint = -atan2(pos_hint[Y] - cy, pos_hint[X] - cx); double alpha_to = -atan2(pos_to[Y] - cy, pos_to[X] - cx); const int base = 360 * 64; int angle_from = (int(alpha_from * base / (PI * 2.0)) + base) % base; int angle_to = (int(alpha_to * base / (PI * 2.0)) + base) % base; int angle_hint = (int(alpha_hint * base / (PI * 2.0)) + base) % base; int path_from_hint = (base + angle_hint - angle_from) % base; int path_hint_to = (base + angle_to - angle_hint) % base; if (abs(path_from_hint) > base / 2) path_from_hint = (path_from_hint - base) % base; if (abs(path_hint_to) > base / 2) path_hint_to = (path_hint_to - base) % base; if (sgn(path_from_hint) * sgn(path_hint_to) == -1) { // Hint is not between FROM and TO if (w != 0) LineGraphEdge::drawLine(w, exposed, gc); else LineGraphEdge::_print(os, gc); return; } int angle, path; if (to()->isHint()) { angle = angle_from; path = path_from_hint; } else { angle = angle_hint; path = path_hint_to; } if (w != 0) { XDrawArc(XtDisplay(w), XtWindow(w), gc.edgeGC, int(cx - radius), int(cy - radius), unsigned(radius) * 2, unsigned(radius) * 2, angle, path); } else if (gc.printGC->isPostScript()) { BoxCoordinate line_width = 1; int arc_start = angle / 64; int arc_extend = path / 64; int start, end; if (arc_extend > 0) { start = (720 - arc_start - arc_extend) % 360; end = (720 - arc_start) % 360; } else { start = (720 - arc_start) % 360; end = (720 - arc_start - arc_extend) % 360; } os << start << " " << end << " " << int(radius) << " " << int(radius) << " " << int(cx) << " " << int(cy) << " " << line_width << " arc*\n"; } else if (gc.printGC->isFig()) { // We draw the entire arc in one stroke. if (from()->isHint()) { BoxCoordinate line_width = 1; os << ARCARROWHEAD1 << line_width << ARCARROWHEAD2; if (path > 0) os << ARCCOUNTERCLOCKWISE; else os << ARCCLOCKWISE; os << ARCARROWHEAD3 << cx << " " << cy << " " << pos_from[X] << " " << pos_from[Y] << " " << pos_hint[X] << " " << pos_hint[Y] << " " << pos_to[X] << " " << pos_to[Y] << " " << ARCARROWHEAD4; } } if (from()->isHint()) { // Draw arrow head at POS_TO double alpha = atan2(pos_to[Y] - cy, pos_to[X] - cx); if (w != 0) { if (path > 0) alpha += PI / 2.0; else alpha -= PI / 2.0; drawArrowHead(w, exposed, gc, pos_to, alpha); } else if (gc.printGC->isPostScript()) { if (path > 0) alpha -= PI / 2.0; else alpha += PI / 2.0; os << gc.arrowAngle << " " << gc.arrowLength << " " << (360 + int(alpha * 360.0 / (PI * 2.0))) % 360 << " " << pos_to[X] << " " << pos_to[Y] << " arrowhead*\n"; } } if (to()->isHint() && annotation() != 0) { if (w != 0) { annotation()->draw(w, to()->pos(), exposed, gc); } else { annotation()->_print(os, to()->pos(), gc); } } }