示例#1
0
void LxDcViCtl::usr_paste(CDC* pDC)
{
	section.trace = false;
	if (copy_context.empty())
	{
		draw_complete(pDC);
		return;
	}
	if (section.active())
	{
		LxCommand* section_paste_cmd = new LxCommand();
		section_paste_cmd->add_child_cmd(
			new LxSectionRemoveCmd(section.cursor_begin.get_index_global(), compose_doc.current_phypgh_index(section.cursor_begin),
			section.cursor_end.get_index_global(), compose_doc.current_phypgh_index(section.cursor_end)));
		LxCursor* _cur_begin = section.cursor_begin < section.cursor_end ? &(section.cursor_begin) : &(section.cursor_end);
		section_paste_cmd->add_child_cmd(
			new LxStructuredContextInsertCmd(_cur_begin->get_index_global(),
			compose_doc.current_phypgh_index(*_cur_begin), &copy_context));
		section_paste_cmd->set_dvctl(this);
		section_paste_cmd->Excute(pDC);
		lx_command_mgr.insert_cmd(section_paste_cmd);
	}
	else
	{
		LxCommand* paste_cmd = new LxCommand();
		paste_cmd->add_child_cmd(
			new LxStructuredContextInsertCmd(cursor.get_index_global(),
			compose_doc.current_phypgh_index(cursor), &copy_context));
		paste_cmd->set_dvctl(this);
		paste_cmd->Excute(pDC);
		lx_command_mgr.insert_cmd(paste_cmd);
	}
}
示例#2
0
文件: viewer.cpp 项目: nelk/cs488
bool Viewer::on_expose_event(GdkEventExpose* event) {
  Glib::RefPtr<Gdk::GL::Drawable> gldrawable = get_gl_drawable();

  if (!gldrawable) return false;

  if (!gldrawable->gl_begin(get_gl_context()))
    return false;

  draw_init(get_width(), get_height());

  // Transforms each point by matrix m_perspective * m_view * m_model.
  std::vector<LineSegment4D> lineSegments = rootNode->getTransformedLineSegments();

  renderHomogenousLines(lineSegments);

  // Draw viewport box.
  const Colour BLACK(0);
  set_colour(BLACK);
  const Point2D viewportBL = Point2D(viewportTL[0], viewportBR[1]);
  const Point2D viewportTR = Point2D(viewportBR[0], viewportTL[1]);
  draw_line(viewportTL, viewportBL);
  draw_line(viewportBL, viewportBR);
  draw_line(viewportBR, viewportTR);
  draw_line(viewportTR, viewportTL);

  draw_complete();

  // Swap the contents of the front and back buffers so we see what we
  // just drew. This should only be done if double buffering is enabled.
  gldrawable->swap_buffers();

  gldrawable->gl_end();

  return true;
}
示例#3
0
void LxDcViCtl::usr_select_all(CDC* pDC)
{
	section.trace = false;
	if (document.size() > 0)
	{
		compose_doc.calc_cursor(section.cursor_begin, 0, document.get_pgh(0), pDC);
		compose_doc.calc_cursor(section.cursor_end, document.size(), document.get_pgh(document.pgh_size() - 1), pDC);
		cursor = section.cursor_end;
	}
	draw_complete(pDC);
}
示例#4
0
void LxDcViCtl::usr_backspace(CDC* pDC)
{
	section.trace = false;
	if (!section.active())				//选择区域无效
	{
		if (cursor.head_of_paragraph())		//物理段首
		{
			//该段为第一个物理段 什么也不做
			if (compose_doc.first_phy_paragraph(cursor))
			{
				draw_complete(pDC);
				return;
			}
			else
			{
				//当前物理段为空
				//if ((*cursor.paragraph)->get_phy_paragraph()->empty())
				//{
				//	//删除当前物理段
				//}
				//else
				{
					//和前一个物理段合并
					LxCommand* merge_phypragh_cmd = new LxCommand();
					merge_phypragh_cmd->add_child_cmd(new LxMergeCmd(compose_doc.current_phypgh_index(cursor)));
					merge_phypragh_cmd->set_dvctl(this);
					merge_phypragh_cmd->Excute(pDC);
					lx_command_mgr.insert_cmd(merge_phypragh_cmd);
				}
			}
		}
		else
		{
			LxCommand* backspace_cmd = new LxCommand();
			backspace_cmd->add_child_cmd(new LxSingleRemoveCmd(compose_doc.current_phypgh_index(cursor),
				cursor.get_index_global(), cursor.get_index_inner_paragraph()));
			backspace_cmd->set_dvctl(this);
			backspace_cmd->Excute(pDC);
			lx_command_mgr.insert_cmd(backspace_cmd);
		}
	}
	else                                       //选择区域有效
	{
		LxCommand* section_remove_cmd = new LxCommand();
		section_remove_cmd->add_child_cmd(
			new LxSectionRemoveCmd(section.cursor_begin.get_index_global(), compose_doc.current_phypgh_index(section.cursor_begin),
			section.cursor_end.get_index_global(), compose_doc.current_phypgh_index(section.cursor_end)));
		section_remove_cmd->set_dvctl(this);
		section_remove_cmd->Excute(pDC);
		lx_command_mgr.insert_cmd(section_remove_cmd);
	}
}
示例#5
0
void LxDcViCtl::usr_redo(CDC* pDC)
{
	section.trace = false;
	LxCommand* redo_command = lx_command_mgr.get_redo_cmd();
	if (redo_command != nullptr)
	{
		if (section.active())
		{
			clear_section(pDC, &section);
			section.cursor_begin = cursor;
			section.cursor_end = cursor;
		}
		redo_command->Excute(pDC);
	}
	else
		draw_complete(pDC);
}
示例#6
0
void LxDcViCtl::modify_mouse_vscroll(CDC* pDC, int vdistanse)
{
	if (ViewWindow::GetViewWindowInstance()->height >= compose_doc.total_height())
		return;
	int old_offset_y = ViewWindow::GetViewWindowInstance()->offset_y;
	int new_offset_y = ViewWindow::GetViewWindowInstance()->offset_y - vdistanse;
	if (vdistanse > 0)
	{
		ViewWindow::GetViewWindowInstance()->offset_y = new_offset_y < 0 ? 0 : new_offset_y;
	}
	else
	{
		int offset_y_max = compose_doc.total_height() - ViewWindow::GetViewWindowInstance()->height;
		ViewWindow::GetViewWindowInstance()->offset_y = new_offset_y > offset_y_max ? offset_y_max : new_offset_y;
	}
	if (ViewWindow::GetViewWindowInstance()->offset_y != old_offset_y)
		draw_complete(pDC);
}
示例#7
0
void LxDcViCtl::modify_mouse_hscroll(CDC* pDC, int hdistanse)
{
	if (ViewWindow::GetViewWindowInstance()->width >= compose_doc.total_width())
		return;
	int old_offset_x = ViewWindow::GetViewWindowInstance()->offset_x;
	int new_offset_x = ViewWindow::GetViewWindowInstance()->offset_x - hdistanse;
	if (hdistanse > 0)
	{
		ViewWindow::GetViewWindowInstance()->offset_x = new_offset_x < 0 ? 0 : new_offset_x;
	}
	else
	{
		int offset_x_max = compose_doc.total_width() - ViewWindow::GetViewWindowInstance()->width;
		ViewWindow::GetViewWindowInstance()->offset_x = new_offset_x > offset_x_max ? offset_x_max : new_offset_x;
	}
	if (ViewWindow::GetViewWindowInstance()->offset_x != old_offset_x)
		draw_complete(pDC);
}
示例#8
0
void LxDcViCtl::usr_cut(CDC* pDC)
{
	section.trace = false;
	if (section.active())
	{
		usr_copy();
		LxCommand* section_remove_cmd = new LxCommand();
		section_remove_cmd->add_child_cmd(
			new LxSectionRemoveCmd(section.cursor_begin.get_index_global(), compose_doc.current_phypgh_index(section.cursor_begin),
			section.cursor_end.get_index_global(), compose_doc.current_phypgh_index(section.cursor_end)));
		section_remove_cmd->set_dvctl(this);
		section_remove_cmd->Excute(pDC);
		lx_command_mgr.insert_cmd(section_remove_cmd);
	}
	else
	{
		draw_complete(pDC);
	}
}
示例#9
0
void LxDcViCtl::move_cursor(CDC* pDC, unsigned direction)
{
	switch (direction)
	{
	case VK_LEFT:
	{
		LxParagraphInDocIter pgh_doc_it(&compose_doc, cursor.page, cursor.paragraph);
		size_t cur_gbl_index_old = cursor.get_index_global() - 1;
		Paragraph* phy_pgh = cursor.get_phy_paragraph();
		if (cursor.get_index_inner_paragraph() == 0)
		{
			if (pgh_doc_it == compose_doc.pargraph_begin()) return;
			--pgh_doc_it;
			cur_gbl_index_old++;
			phy_pgh = (*pgh_doc_it)->get_phy_paragraph();
		}
		compose_doc.calc_cursor(cursor, cur_gbl_index_old, phy_pgh, pDC);
	}
		break;
	case VK_RIGHT:
	{
		LxParagraphInDocIter pgh_doc_it(&compose_doc, cursor.page, cursor.paragraph);
		size_t cur_gbl_index_old = cursor.get_index_global() + 1;
		Paragraph* phy_pgh = cursor.get_phy_paragraph();
		if (cursor.get_index_inner_paragraph() == (*(cursor.paragraph))->get_phy_paragraph()->size())
		{
			++pgh_doc_it;
			if (pgh_doc_it == compose_doc.pargraph_end()) return;
			cur_gbl_index_old--;
			phy_pgh = (*pgh_doc_it)->get_phy_paragraph();
		}
		compose_doc.calc_cursor(cursor, cur_gbl_index_old, phy_pgh, pDC);
	}
		break;
	case VK_UP:
	{
		LxRowInDocIter row_doc_it(&compose_doc, cursor.page, cursor.paragraph, cursor.row);
		if (row_doc_it == compose_doc.row_begin()) return;
		--row_doc_it;
		compose_doc.locate(cursor, pDC, cursor.point_x, (*row_doc_it)->get_top_pos() + (*row_doc_it)->get_base_line());
	}
		break;
	case VK_DOWN:
	{
		LxRowInDocIter row_doc_it(&compose_doc, cursor.page, cursor.paragraph, cursor.row);
		++row_doc_it;
		if (row_doc_it == compose_doc.row_end()) return;
		compose_doc.locate(cursor, pDC, cursor.point_x, (*row_doc_it)->get_top_pos() + (*row_doc_it)->get_base_line());
	}
		break;
	default:
		return;
	}
	if (modify_cursor_offset())
	{
		draw_complete(pDC);
	}
	else
	{
		render->hide_caret();
		render->create_caret(cursor.height, cursor.height / 8);
		render->show_caret(&cursor);
	}
}
示例#10
0
文件: viewer.cpp 项目: jemartti/Cubes
bool Viewer::on_expose_event( GdkEventExpose* /*event*/ )
{
	Glib::RefPtr<Gdk::GL::Drawable> gldrawable = get_gl_drawable();

	if ( !gldrawable )
	{
		return false;
	}

	if ( !gldrawable->gl_begin(get_gl_context()) )
	{
		return false;
	}

	// Start drawing
	draw_init( get_width(), get_height() );

	// Transform the world gnomon
	for( int i = 0; i < 4; i += 1 )
	{
		m_gnomonTrans[i] = m_viewing * m_gnomon[i];
	}
	// Draw the world gnomon
	set_colour( Colour(0.1, 0.1, 1.0) );
	draw_line2D( m_gnomonTrans[0], m_gnomonTrans[1] );
	draw_line2D( m_gnomonTrans[0], m_gnomonTrans[2] );
	draw_line2D( m_gnomonTrans[0], m_gnomonTrans[3] );

	// Draw the modelling gnomon
	set_colour( Colour(0.1, 1.0, 0.1) );
	draw_modellingGnomon();

	// Draw the unit cube
	set_colour( Colour(0.1, 0.1, 0.1) );
	draw_unitCube();

	// Initialize the viewport
	if ( !m_viewflag )
	{
		m_viewport[0] = ( Point2D(get_width() * 0.05, get_height() * 0.05) );
		m_viewport[1] = ( Point2D(get_width() * 0.95, get_height() * 0.05) );
		m_viewport[2] = ( Point2D(get_width() * 0.95, get_height() * 0.95) );
		m_viewport[3] = ( Point2D(get_width() * 0.05, get_height() * 0.95) );
		m_viewflag    = true;
	}
	// Draw the viewport
	set_colour( Colour(0.1, 0.1, 0.1) );
	draw_line( m_viewport[0], m_viewport[1] );
	draw_line( m_viewport[1], m_viewport[2] );
	draw_line( m_viewport[2], m_viewport[3] );
	draw_line( m_viewport[3], m_viewport[0] );

	// Finish drawing
	draw_complete();

	// Update the information bar
	update_infobar();

	// Swap the contents of the front and back buffers so we see what we
	// just drew. This should only be done if double buffering is enabled.
	gldrawable->swap_buffers();

	gldrawable->gl_end();

	return true;
}