Ejemplo n.º 1
0
BOOL COFSNcDlg2::LoadWindow(IXMLDOMNode *pXmlRoot, CRect &r, CRect &rMin, CRect &rMax)
{
	ASSERT(pXmlRoot != NULL);
	
	CComPtr<IXMLDOMNode> pWindow = NULL;
	CComBSTR bs, bsBgPath;
	LoadSkins skin;
	long nErrorCode = 0;
	IStreamPtr pStream = NULL;
	CPaintDC dc(this);
	WCHAR *szNULL = L"\0x00";
	
	pXmlRoot->selectSingleNode(CComBSTR(L"Window"), &pWindow);
	if(pWindow)
	{
		// Load window size
		bs.Empty();
		SelectChildNode(pWindow, CComBSTR(L"XLen"), NULL, &bs);
		if(bs.m_str != NULL)
			r.right = r.left + wcstol(bs.m_str, &szNULL, 10);
		bs.Empty();
		SelectChildNode(pWindow, CComBSTR(L"YLen"), NULL, &bs);
		if(bs.m_str != NULL)
			r.bottom = r.top + wcstol(bs.m_str, &szNULL, 10);

		// Load min size
		LoadRect(pWindow, _T("MinSize"), rMin);
		// Load max size
		LoadRect(pWindow, _T("MaxSize"), rMax);
		
		// Load regions for corners
		DeleteObject(m_rgnTL);
		DeleteObject(m_rgnTR);
		DeleteObject(m_rgnBL);
		DeleteObject(m_rgnBR);
		m_rgnTL = m_rgnTR = m_rgnBL = m_rgnBR = NULL;
		LoadRegion(pWindow, _T("TL"), &m_rgnTL);
		LoadRegion(pWindow, _T("TR"), &m_rgnTR);
		LoadRegion(pWindow, _T("BL"), &m_rgnBL);
		LoadRegion(pWindow, _T("BR"), &m_rgnBR);
		
		CenterRect(r);
		AdjustRect(r);
		// Try Fix Focus behavior [7/23/2002]
		SetWindowPos(NULL, r.left, r.top, r.Width(), r.Height(), SWP_NOZORDER|SWP_NOACTIVATE);

		// Load background image
		m_bBackgroundPicture = (LoadPictures(pWindow) > 0);

		//pWindow->Release();
	}
	
	return TRUE;
}
Ejemplo n.º 2
0
/*******************************************************************************

  Function : DDV_DrawSequenceName()
  
  Purpose : draw the name of the sequence (left column of the DDV panel)
  
  Parameters : GrData; graphical data (font size, etc)
				ScaleStyle;style of the ParaG scale
				top, left; coord to start the draw
  
  Return value : none

*******************************************************************************/
static void  DDV_DrawSequenceName(UnDViewerGraphDataPtr GrData,ParaGPtr pgp,
	Int2 top,Int2 left,Int4 cur_row,Int4 CurEditRow,Int4 CurMasterRow)
{
SeqIdPtr  sip = NULL;
RecT      rc;
Int2      x,y,decal=1,size;/*text position/size*/
Char      szAccess[21];
BioseqPtr bsp;

	/*get a name*/	
    bsp = BioseqLockById(pgp->sip);
    if(bsp) {
        sip = SeqIdFindBestAccession(bsp->id);
        BioseqUnlock(bsp);
    }
	if (!sip)
		sip = SeqIdFindBest(pgp->sip, 0);
	SeqIdWrite(sip, szAccess,PRINTID_TEXTID_ACCESSION, 20);   

	/*compute position*/
	if (pgp->ScaleStyle==SCALE_POS_TOP) decal++;
	
	/*draw name*/
	size=StringWidth(szAccess);
	x=left/*-GrData->udv_scale.cxLeftScale*/-size;
	y=top+decal*GrData->udv_font.LineHeight;
	MoveTo(x,y);
	if (cur_row==CurEditRow){
		Magenta();
	}
	PaintString (szAccess);
	if (cur_row==CurMasterRow){
		Blue();
		MoveTo(x,y);
		LineTo(x+size,y);
	}
	/*draw a little box (for selection a full sequence)*/
	left+=GrData->udv_font.cxChar;
	top+=GrData->udv_font.cxChar/2;
	LoadRect(&rc,left,top,left+GrData->udv_font.cxChar,
		top+GrData->udv_font.cxChar);	
	Blue();
	PaintOval(&rc);
	Black();
}
Ejemplo n.º 3
0
bool SIFSpritesSect::LoadFrame(SIFFrame *frame, int ndirs, \
					const uint8_t **data, const uint8_t *data_end)
{
	// sets defaults for un-specified/default fields
	memset(frame, 0, sizeof(SIFFrame));
	
	for(int d=0;d<ndirs;d++)
	{
		SIFDir *dir = &frame->dir[d];
		LoadPoint(&dir->sheet_offset, data, data_end);
		
		int t;
		for(;;)
		{
			t = read_U8(data, data_end);
			if (t == S_DIR_END) break;
			
			switch(t)
			{
				case S_DIR_DRAW_POINT: LoadPoint(&dir->drawpoint, data, data_end); break;
				case S_DIR_ACTION_POINT: LoadPoint(&dir->actionpoint, data, data_end); break;
				case S_DIR_ACTION_POINT_2: LoadPoint(&dir->actionpoint2, data, data_end); break;
				
				case S_DIR_PF_BBOX:
					LoadRect(&dir->pf_bbox, data, data_end);
				break;
				
				default:
					NX_LOG("SIFSpriteSect::LoadFrame: encountered unknown optional field type %d\n", t);
				return 1;
			}
		}
	}
	
	return 0;
}
Ejemplo n.º 4
0
bool SIFSpritesSect::Decode(const uint8_t *data, int datalen, \
						  SIFSprite *sprites, int *nsprites_out, int maxsprites)
{
const uint8_t *data_end = data + (datalen - 1);
int i, f, nsprites;
	
	nsprites = read_U16(&data, data_end);
	if (nsprites_out) *nsprites_out = nsprites;
	
	if (nsprites >= maxsprites)
	{
		NX_ERR("SIFSpritesSect::Decode: too many sprites in file (nsprites=%d, maxsprites=%d)\n", nsprites, maxsprites);
		return 1;
	}
	
	NX_LOG("SIFSpritesSect: loading %d sprites\n", nsprites);
	for(i=0;i<nsprites;i++)
	{
		if (data > data_end)
		{
			NX_ERR("SIFSpritesSect::Decode: section corrupt: overran end of data\n");
			return 1;
		}
		
		// read sprite-level fields
		sprites[i].w = read_U8(&data, data_end);
		sprites[i].h = read_U8(&data, data_end);
		sprites[i].spritesheet = read_U8(&data, data_end);
		
		sprites[i].nframes = read_U8(&data, data_end);
		sprites[i].ndirs = read_U8(&data, data_end);
		
		if (sprites[i].ndirs > SIF_MAX_DIRS)
		{
			NX_ERR("SIFSpritesSect::Decode: SIF_MAX_DIRS exceeded on sprite %d (ndirs=%d)\n", i, sprites[i].ndirs);
			return 1;
		}
		
		LoadRect(&sprites[i].bbox, &data, data_end);
		LoadRect(&sprites[i].solidbox, &data, data_end);
		
		LoadPoint(&sprites[i].spawn_point, &data, data_end);
		
		LoadPointList(&sprites[i].block_l, &data, data_end);
		LoadPointList(&sprites[i].block_r, &data, data_end);
		LoadPointList(&sprites[i].block_u, &data, data_end);
		LoadPointList(&sprites[i].block_d, &data, data_end);
		
		// malloc enough space to hold the specified number
		// of apple fritters, i mean, frames.
		sprites[i].frame = (SIFFrame *)malloc(sizeof(SIFFrame) * sprites[i].nframes);
		
		// then load all frames
		for(f=0;f<sprites[i].nframes;f++)
		{
			if (LoadFrame(&sprites[i].frame[f], sprites[i].ndirs, &data, data_end))
				return 1;
		}
	}
	
	return 0;
}
Ejemplo n.º 5
0
bool GuiPage::Load(
	const std::string & path,
	const std::string & texpath,
	const float hwratio,
	const GuiLanguage & lang,
	const Font & font,
	const StrSignalMap & vsignalmap,
	const StrVecSlotMap & vnactionmap,
	const StrSlotMap & vactionmap,
	IntSlotMap nactionmap,
	SlotMap actionmap,
	ContentManager & content,
	std::ostream & error_output)
{
	Clear();

	Config pagefile;
	if (!pagefile.load(path))
	{
		error_output << "Couldn't find GUI page file: " << path << std::endl;
		return false;
	}

	if (!pagefile.get("", "name", name, error_output))
		return false;

	//error_output << "Loading " << path << std::endl;

	// load widgets and controls
	active_control = 0;
	std::map<std::string, GuiWidget*> widgetmap;			// labels, images, sliders
	std::map<std::string, GuiWidgetList*> widgetlistmap;	// labels, images lists
	std::vector<Config::const_iterator> controlit;			// control iterator cache
	std::vector<Config::const_iterator> controlnit;			// control list iterator cache
	std::vector<GuiControlList*> controllists;				// control list cache
	for (Config::const_iterator section = pagefile.begin(); section != pagefile.end(); ++section)
	{
		if (section->first.empty()) continue;

		Rect r = LoadRect(pagefile, section, hwratio);
		float x0 = r.x - r.w * 0.5;
		float y0 = r.y - r.h * 0.5;
		float x1 = r.x + r.w * 0.5;
		float y1 = r.y + r.h * 0.5;

		GuiWidget * widget = 0;

		// load widget(list)
		std::string value;
		if (pagefile.get(section, "text", value))
		{
			std::string alignstr;
			float fontsize = 0.03;
			pagefile.get(section, "fontsize", fontsize);
			pagefile.get(section, "align", alignstr);

			int align = 0;
			if (alignstr == "right") align = 1;
			else if (alignstr == "left") align = -1;

			float scaley = fontsize;
			float scalex = fontsize * hwratio;

			GuiLabelList * widget_list = 0;
			if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, widget_list))
			{
				// connect with the value list
				StrVecSlotMap::const_iterator vni = vnactionmap.find(value);
				if (vni != vnactionmap.end())
				{
					StrSignalMap::const_iterator vsi = vsignalmap.find(value + ".update");
					if (vsi != vsignalmap.end())
					{
						widget_list->update_list.connect(*vsi->second);
						vni->second->connect(widget_list->get_values);
					}
				}

				// init drawable
				widget_list->SetupDrawable(node, font, align, scalex, scaley, r.z);

				widgetlistmap[section->first] = widget_list;
				widget = widget_list;
			}
			else
			{
				// none is reserved for empty text string
				if (value == "none")
					value.clear();
				else
					value = lang(value);

				GuiLabel * new_widget = new GuiLabel();
				new_widget->SetupDrawable(
					node, font, align, scalex, scaley,
					r.x, r.y, r.w, r.h, r.z);

				ConnectAction(value, vsignalmap, new_widget->set_value);

				std::string name;
				if (pagefile.get(section, "name", name))
					labels[name] = new_widget;

				widgetmap[section->first] = new_widget;
				widget = new_widget;
			}
		}
		else if (pagefile.get(section, "image", value))
		{
			std::string slider, ext, path = texpath;
			pagefile.get(section, "path", path);
			pagefile.get(section, "ext", ext);

			GuiImageList * widget_list = 0;
			if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, widget_list))
			{
				// init drawable
				widget_list->SetupDrawable(node, content, path, ext, r.z);

				// connect with the value list
				StrVecSlotMap::const_iterator vni = vnactionmap.find(value);
				if (vni != vnactionmap.end())
				{
					StrSignalMap::const_iterator vsi = vsignalmap.find(value + ".update");
					if (vsi != vsignalmap.end())
					{
						widget_list->update_list.connect(*vsi->second);
						vni->second->connect(widget_list->get_values);
					}
				}
				else
				{
					// special case of list containing the same image?
					widget_list->SetImage(value);
				}

				widgetlistmap[section->first] = widget_list;
				widget = widget_list;
			}
			else if (pagefile.get(section, "slider", slider))
			{
				bool fill = false;
				pagefile.get(section, "fill", fill);

				TextureInfo texinfo;
				texinfo.mipmap = false;
				texinfo.repeatu = false;
				texinfo.repeatv = false;
				std::tr1::shared_ptr<Texture> tex;
				content.load(tex, texpath, value, texinfo);

				float radius = 0.0;
				if (pagefile.get(section, "radius", radius))
				{
					float start_angle(0), end_angle(2 * M_PI);
					pagefile.get(section, "start-angle", start_angle);
					pagefile.get(section, "end-angle", end_angle);

					GuiRadialSlider * new_widget = new GuiRadialSlider();
					new_widget->SetupDrawable(
						node, tex,
						r.x, r.y, r.w, r.h, r.z,
						start_angle, end_angle, radius,
						hwratio, fill, error_output);

					ConnectAction(slider, vsignalmap, new_widget->set_value);
					widget = new_widget;
				}
				else
				{
					GuiSlider * new_widget = new GuiSlider();
					new_widget->SetupDrawable(
						node, tex,
						r.x, r.y, r.w, r.h, r.z,
						fill, error_output);

					ConnectAction(slider, vsignalmap, new_widget->set_value);
					widget = new_widget;
				}

				widgetmap[section->first] = widget;
			}
			else
			{
				GuiImage * new_widget = new GuiImage();
				new_widget->SetupDrawable(
					node, content, path, ext,
					r.x, r.y, r.w, r.h, r.z);

				ConnectAction(value, vsignalmap, new_widget->set_image);

				widgetmap[section->first] = new_widget;
				widget = new_widget;
			}
		}

		// set widget properties (connect property slots)
		if (widget)
		{
			std::string val;
			if (pagefile.get(section, "visible", val))
				ConnectAction(val, vsignalmap, widget->set_visible);
			if (pagefile.get(section, "opacity", val))
				ConnectAction(val, vsignalmap, widget->set_opacity);
			if (pagefile.get(section, "color", val))
				ConnectAction(val, vsignalmap, widget->set_color);
			if (pagefile.get(section, "hue", val))
				ConnectAction(val, vsignalmap, widget->set_hue);
			if (pagefile.get(section, "sat", val))
				ConnectAction(val, vsignalmap, widget->set_sat);
			if (pagefile.get(section, "val", val))
				ConnectAction(val, vsignalmap, widget->set_val);

			widgets.push_back(widget);
		}

		// load controls
		bool focus;
		if (pagefile.get(section, "focus", focus))
		{
			GuiControl * control = 0;
			GuiControlList * control_list = 0;
			if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, control_list))
			{
				// register control list scroll actions
				actionmap[section->first + ".scrollf"] = &control_list->scroll_fwd;
				actionmap[section->first + ".scrollr"] = &control_list->scroll_rev;

				// connect with item list
				if (pagefile.get(section, "list", value))
				{
					StrSignalMap::const_iterator vsu = vsignalmap.find(value + ".update");
					StrSignalMap::const_iterator vsn = vsignalmap.find(value + ".nth");
					if (vsu != vsignalmap.end() && vsn != vsignalmap.end())
					{
						control_list->update_list.connect(*vsu->second);
						control_list->set_nth.connect(*vsn->second);
					}
					else
					{
						error_output << value << " is not a list." << std::endl;
					}
				}

				control = control_list;
				controlnit.push_back(section);
				controllists.push_back(control_list);
			}
			else
			{
				control = new GuiControl();
				controlit.push_back(section);
				controls.push_back(control);
			}
			control->SetRect(x0, y0, x1, y1);

			if (focus)
				active_control = control;
		}
	}

	// load control actions (connect control signals)

	// parse control event actions with values(arguments)
	typedef std::pair<std::string, Slot2<int, const std::string &>*> ActionValn;
	typedef std::pair<std::string, Slot1<const std::string &>*> ActionVal;
	std::set<ActionValn> action_valn_set;
	std::set<ActionVal> action_val_set;
	std::string actionstr;
	for (size_t i = 0; i < controlit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::signal_names.size(); ++j)
		{
			if (pagefile.get(controlit[i], GuiControl::signal_names[j], actionstr))
				ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
					action_val_set, action_valn_set);
		}
	}
	for (size_t i = 0; i < controlnit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::signal_names.size(); ++j)
		{
			if (pagefile.get(controlnit[i], GuiControl::signal_names[j], actionstr))
				ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
					action_val_set, action_valn_set);
		}
	}

	// parse page event actions with values
	if (pagefile.get("", "onfocus", actionstr))
		ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
			action_val_set, action_valn_set);

	if (pagefile.get("", "oncancel", actionstr))
		ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
			action_val_set, action_valn_set);

	// register controls, so that they can be activated by control events
	control_set.reserve(controlit.size() + controlnit.size());
	RegisterControls(controlit, controls, this, control_set, actionmap);
	RegisterControls(controlnit, controllists, this, control_set, actionmap);

	// register action calls with a parameter, so that they can be signaled by controls
	RegisterActions(lang, action_val_set, action_set, actionmap);
	RegisterActions(lang, action_valn_set, action_setn, nactionmap);

	// connect control signals with their actions
	for (size_t i = 0; i < controlit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::EVENTNUM; ++j)
		{
			if (pagefile.get(controlit[i], GuiControl::signal_names[j], actionstr))
				ConnectActions(actionstr, actionmap, controls[i]->m_signal[j]);
		}
		for (size_t j = 0; j < GuiControl::EVENTVNUM; ++j)
		{
			if (pagefile.get(controlit[i], GuiControl::signal_names[GuiControl::EVENTNUM + j], actionstr))
				ConnectActions(actionstr, vactionmap, controls[i]->m_signalv[j]);
		}
	}
	for (size_t i = 0; i < controlnit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::EVENTNUM; ++j)
		{
			if (pagefile.get(controlnit[i], GuiControl::signal_names[j], actionstr))
			{
				ConnectActions(actionstr, actionmap, controllists[i]->m_signal[j]);
				ConnectActions(actionstr, nactionmap, controllists[i]->m_signaln[j]);
			}
		}
	}

	// connect page event signals with their actions
	if (pagefile.get("", "onfocus", actionstr))
		ConnectActions(actionstr, actionmap, onfocus);

	if (pagefile.get("", "oncancel", actionstr))
		ConnectActions(actionstr, actionmap, oncancel);

	controls.insert(controls.end(), controllists.begin(), controllists.end());

	// set active control
	if (!active_control && !controls.empty())
		active_control = controls[0];

	// enable active control
	if (active_control)
		active_control->Signal(GuiControl::FOCUS);

	// set default control
	default_control = active_control;

	return true;
}
Ejemplo n.º 6
0
BOOL COFSNcDlg2::LoadProgress(IXMLDOMNode *pXmlRoot, LPCTSTR szName, CMcProgress *pMcProgress, BOOL bVisible)
{
	BOOL bResult = FALSE;
	LoadSkins skin;
	long nErrorCode = 0;
	HRESULT hr = S_OK;
	CString strErrorMessage;
	IStreamPtr pStream1 = NULL, pStream2 = NULL;
	CComPtr<IXMLDOMNode> pProgress = NULL;
	CComBSTR bs;
	_bstr_t bsImagePath;
	long x=0, y=0, cx=0, cy=0;
	WCHAR *szNULL = L"\0x00";
	
	pMcProgress->ShowWindow(SW_HIDE);

	bs.Empty();
	bs = L"Progress[@Name='";
	bs += szName;
	bs += L"']";
	pXmlRoot->selectSingleNode(bs, &pProgress);
	if(pProgress)
	{
		bResult = TRUE;
		// Get button coordinates
		bs.Empty();
		SelectChildNode(pProgress, CComBSTR(L"XPos"), NULL, &bs);
		if(bs.m_str != NULL)
			x = wcstol(bs.m_str, &szNULL, 10);
		bs.Empty();
		SelectChildNode(pProgress, CComBSTR(L"YPos"), NULL, &bs);
		if(bs.m_str != NULL)
			y = wcstol(bs.m_str, &szNULL, 10);
		bs.Empty();
		SelectChildNode(pProgress, CComBSTR(L"XLen"), NULL, &bs);
		if(bs.m_str != NULL)
			cx = wcstol(bs.m_str, &szNULL, 10);
		bs.Empty();
		SelectChildNode(pProgress, CComBSTR(L"YLen"), NULL, &bs);
		if(bs.m_str != NULL)
			cy = wcstol(bs.m_str, &szNULL, 10);
		
		// Load button picture
		bs.Empty();
		SelectChildNode(pProgress, CComBSTR(L"Image[@Name='Empty']"), NULL, &bs);
		if(bs.m_str != NULL)
		{
			bsImagePath = bstr_t(IBN_SCHEMA);
			bsImagePath += (LPCTSTR)GetCurrentSkin();
			bsImagePath += bs.m_str;
			skin.Load(bsImagePath, &pStream1, &nErrorCode);
#ifdef _DEVELOVER_VERSION_L1
			if(pStream1 == NULL || nErrorCode) 
			{
				strErrorMessage = "Skin Error: Can't Load Image ( ";
				strErrorMessage += (char*)bsImagePath;
				strErrorMessage +=" )";
				AfxMessageBox(strErrorMessage);
			}
#endif
		}
		bs.Empty();
		SelectChildNode(pProgress, CComBSTR(L"Image[@Name='Full']"), NULL, &bs);
		if(bs.m_str != NULL)
		{
			bsImagePath = bstr_t(IBN_SCHEMA);
			bsImagePath += (LPCTSTR)GetCurrentSkin();
			bsImagePath += bs.m_str;
			skin.Load(bsImagePath, &pStream2, &nErrorCode);
#ifdef _DEVELOVER_VERSION_L1
			if(pStream2 == NULL || nErrorCode) 
			{
				strErrorMessage = "Skin Error: Can't Load Image ( ";
				strErrorMessage += (char*)bsImagePath;
				strErrorMessage +=" )";
				AfxMessageBox(strErrorMessage);
			}
#endif
		}
		
		CRect rFull;
		rFull.SetRectEmpty();
		LoadRect(pProgress, _T("RectFull"), rFull);

		if(pStream1 != NULL && pStream2 != NULL && !rFull.IsRectEmpty())
			pMcProgress->LoadBitmapsFromStream((LPUNKNOWN)pStream1, (LPUNKNOWN)pStream2, rFull.left, rFull.top, rFull.Width(), rFull.Height());
			
		UINT nFlags = SWP_NOZORDER;
			
		if(bVisible)
			nFlags |= SWP_SHOWWINDOW;

		pMcProgress->SetWindowPos(NULL, x, y, cx, cy, nFlags);
		
		// Load settings for resize
		//LoadResizeSettings(pButton, pBtn->m_hWnd);
		CComPtr<IXMLDOMNode> pResize = NULL;
		
		pProgress->selectSingleNode(CComBSTR(L"Resize"), &pResize);
		if(pResize)
		{
			long tlcx, tlcy, brcx, brcy;
			
			GetNodeAttributeAsLong(pResize, _bstr_t("TLCX"), &tlcx, 10);
			GetNodeAttributeAsLong(pResize, _bstr_t("TLCY"), &tlcy, 10);
			GetNodeAttributeAsLong(pResize, _bstr_t("BRCX"), &brcx, 10);
			GetNodeAttributeAsLong(pResize, _bstr_t("BRCY"), &brcy, 10);
			
			if(tlcx || tlcy || brcx || brcy)
				AddAnchor((CWnd*)pMcProgress, CSize(tlcx, tlcy), CSize(brcx, brcy));
			
			//pResize->Release();
		}
		
		
		//pProgress->Release();
	}
	return bResult;
}