Example #1
0
static VALUE
rg_initialize(VALUE self, VALUE name, VALUE left_gravity)
{
    if (NIL_P(name))
        G_INITIALIZE(self, gtk_text_mark_new(NULL, RVAL2CBOOL(left_gravity)));
    else
        G_INITIALIZE(self, gtk_text_mark_new(RVAL2CSTR(name), RVAL2CBOOL(left_gravity)));
    return Qnil;
}
Example #2
0
extern void show_message_history(const char *history)
{
	GtkTextBuffer *historybuffer = NULL;
	GtkTextIter end;
	GtkTextMark *mark;

	historybuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(history_view) );

	if(history)
	{
		//TODO not checking if historybuffer is non-NULL because I think gtktextview always has a gtktextbuffer
		gtk_text_buffer_set_text( historybuffer, history, -1 );	//-1 cuz text is terminated

		/*scroll down*/
		gtk_text_buffer_get_end_iter( historybuffer, &end );
		mark = gtk_text_mark_new( NULL, FALSE );
		gtk_text_buffer_add_mark( historybuffer, mark, &end );
		gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(history_view), mark, 0, FALSE, 1.0, 1.0 );
	}
	else
	{
		gtk_text_buffer_set_text( historybuffer, "<No recent chats found>", -1 );	//-1 cuz text is terminated
	}

	return;
}
Example #3
0
void snippet_info_create_marks (GuSnippetInfo* info, GuEditor* ec) {
    GList* current = g_list_first (info->einfo);
    GtkTextIter start, end;

    while (current) {
        GuSnippetExpandInfo* einfo = GU_SNIPPET_EXPAND_INFO (current->data);
        gtk_text_buffer_get_iter_at_offset (ec_buffer, &start,
                info->start_offset + einfo->start);
        gtk_text_buffer_get_iter_at_offset (ec_buffer, &end,
                info->start_offset + einfo->start + einfo->len);
        einfo->left_mark = gtk_text_mark_new (NULL, TRUE);
        einfo->right_mark = gtk_text_mark_new (NULL, FALSE);
        gtk_text_buffer_add_mark (ec_buffer, einfo->left_mark, &start);
        gtk_text_buffer_add_mark (ec_buffer, einfo->right_mark, &end);
        current = g_list_next (current);
    }
    slog (L_DEBUG, "Marks created\n");
}
Example #4
0
extern void append_to_history_view( const char *buffer, const char *sender )
{
	GtkTextBuffer *historybuffer = NULL;
	GtkTextIter start;
	GtkTextIter end;
	GtkTextMark *mark;

	char *history = NULL;
	unsigned int char_count;
	char *to_append = NULL;
	gboolean need_newline = TRUE;

	historybuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(history_view));

	/*check for "<No recent chats found>" at the top of historybuffer and remove it*/
	char_count = gtk_text_buffer_get_char_count(historybuffer);
	if( char_count == strlen("<No recent chats found>") )
	{
		gtk_text_buffer_get_bounds( historybuffer, &start, &end );
		//TODO check if history needs to be free()d (look at source of gtk_text_buffer)
		history = gtk_text_buffer_get_text( historybuffer, &start, &end, FALSE );
		if( strcmp( history, "<No recent chats found>" ) == 0 )
		{
			gtk_text_buffer_delete( historybuffer, &start, &end );
			need_newline = FALSE;
		}
		free(history);
	}
	/*"<No recent chats found>" is not or no longer at the top of historybuffer*/
	/*prepend a '\n' to buffer and insert into historybuffer*/
	if(need_newline)
	{
		to_append = calloc( 1 + strlen(sender) + 2 + strlen(buffer) + 1, sizeof(char) );
		*to_append = '\n';
		strncpy( to_append+1, sender, strlen(sender)+1 );
		strncat( to_append, ": ", strlen(": ") );
		strncat( to_append, buffer, strlen(buffer) );
	}
	else
	{
		to_append = calloc( strlen(sender) + 2 + strlen(buffer) + 1, sizeof(char) );
		strncpy( to_append, sender, strlen(sender)+1 );//TODO there was no +1 at first, that's not good or? (~10 lines above there was +1)
		strncat( to_append, ": ", strlen(": ") );
		strncat( to_append, buffer, strlen(buffer) );
	}
	gtk_text_buffer_get_end_iter( historybuffer, &end );
	gtk_text_buffer_insert( historybuffer, &end, to_append, -1 );

	/*scroll down*/
	gtk_text_buffer_get_end_iter( historybuffer, &end );
	mark = gtk_text_mark_new( NULL, FALSE );
	gtk_text_buffer_add_mark( historybuffer, mark, &end );
	gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(history_view), mark, 0, FALSE, 1.0, 1.0 );

	return;
}
Example #5
0
/*#
    @class GtkTextMark
    @brief A position in the buffer preserved across buffer modifications
    @optparam name mark name or nil.
    @optparam left_gravity (boolean) whether the mark should have left gravity (default false)

    You may wish to begin by reading the text widget conceptual overview which gives
    an overview of all the objects and data types related to the text widget and how
    they work together.

    A GtkTextMark is like a bookmark in a text buffer; it preserves a position in
    the text. You can convert the mark to an iterator using gtk_text_buffer_get_iter_at_mark().
    Unlike iterators, marks remain valid across buffer mutations, because their behavior
    is defined when text is inserted or deleted. When text containing a mark is deleted,
    the mark remains in the position originally occupied by the deleted text.
    When text is inserted at a mark, a mark with left gravity will be moved to the
    beginning of the newly-inserted text, and a mark with right gravity will be moved
    to the end.

    Marks are reference counted, but the reference count only controls the validity
    of the memory; marks can be deleted from the buffer at any time with
    gtk_text_buffer_delete_mark(). Once deleted from the buffer, a mark is
    essentially useless.

    Marks optionally have names; these can be convenient to avoid passing the
    GtkTextMark object around.

    Marks are typically created using the gtk_text_buffer_create_mark() function.

    @note Creating a text mark: Add it to a buffer using gtk_text_buffer_add_mark().
    If name is nil, the mark is anonymous; otherwise, the mark can be retrieved by name
    using gtk_text_buffer_get_mark(). If a mark has left gravity, and text is inserted
    at the mark's current location, the mark will be moved to the left of the
    newly-inserted text. If the mark has right gravity (left_gravity = false),
    the mark will end up on the right of newly-inserted text. The standard
    left-to-right cursor is a mark with right gravity (when you type, the cursor
    stays on the right side of the text you're typing).

 */
FALCON_FUNC TextMark::init( VMARG )
{
    Gtk::ArgCheck1 args( vm, "[S,B]" );

    char* name = args.getCString( 0, false );
    gboolean gravity = args.getBoolean( 1, false );

    MYSELF;
    GtkTextMark* mk = gtk_text_mark_new( name, gravity );
    self->setObject( (GObject*) mk );
}
Example #6
0
int main (int argc, char *argv[])
{
    //const std::string creatureDB[]={"pidgeot","gardevoir"}; - For creature catalog~~
    //std::cout<<creatureDB[0];

    /* Initialize GTK+ */
    g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
    gtk_init (&argc, &argv);
    g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

    /* Main window configuration */
    win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_resizable (GTK_WINDOW (win), false);
    gtk_widget_set_size_request(win,windowWidth,windowHeight);
    gtk_container_set_border_width (GTK_CONTAINER (win), 0);
    gtk_window_set_title (GTK_WINDOW (win), "Pokemon");
    gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
    gtk_widget_realize (win);
    g_signal_connect (win, "destroy", gtk_main_quit, NULL);
    gtk_window_set_icon_from_file(GTK_WINDOW(win),"images/winIcon.png",NULL);
    //gtk_window_set_decorated (GTK_WINDOW(win),FALSE); //Óáèðàåò ñòàíäàðòíîå îôîðìëåíèå îêíà windows

    /* Initializing objects */
    zeBigContainer = gtk_box_new (GTK_ORIENTATION_VERTICAL,0);
    zeBigContainerOverlay = gtk_overlay_new();
    topPart = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0);
    topPartCenter = gtk_alignment_new (0.5,0.5,1,1);
    topPartLeft = gtk_box_new (GTK_ORIENTATION_VERTICAL,0);
    topPartCenter = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0);
    topPartRight = gtk_box_new (GTK_ORIENTATION_VERTICAL,0);
    bottomPart = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0);
    buttons = gtk_grid_new ();
    dialogScrollFrame = gtk_scrolled_window_new(NULL,NULL);
    dialogText = gtk_text_view_new ();
    dialogBuffer = gtk_text_buffer_new (NULL);
    button1 = gtk_button_new ();
    button2 = gtk_button_new ();
    button3 = gtk_button_new ();
    button4 = gtk_button_new_with_label ("Restart");
    button5 = gtk_button_new_with_label ("Back to choosing screen");
    topMidPart = gtk_image_new_from_file ("images/topPic.jpg");
    IMGBackground = gtk_image_new_from_file ("images/pokeBackground.jpg");
    leftImage = gtk_image_new_from_file ("images/filler.PNG");
    rightImage = gtk_image_new_from_file ("images/filler.PNG");
    leftBar = gtk_progress_bar_new ();
    rightBar = gtk_progress_bar_new ();

    /* Setting dialogText */
    gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(dialogText), GTK_TEXT_WINDOW_LEFT, 5);
    gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(dialogText), GTK_TEXT_WINDOW_BOTTOM, 20);
    gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(dialogText), GTK_TEXT_WINDOW_TOP, 5);
    gtk_text_view_set_editable(GTK_TEXT_VIEW(dialogText), FALSE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(dialogText), FALSE);
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(dialogText),GTK_WRAP_WORD);

    /* Setting progress bars */
    gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(rightBar),TRUE);
    gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(leftBar),TRUE);
    gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(rightBar),TRUE);

    /* Various initializations */
    gtk_box_set_homogeneous((GtkBox*)topPartCenter,TRUE);
    gtk_box_set_homogeneous((GtkBox*)topPart,TRUE);
    gtk_box_set_homogeneous((GtkBox*)bottomPart,TRUE);
    gtk_box_set_homogeneous((GtkBox*)zeBigContainer,TRUE);
    gtk_grid_set_row_homogeneous((GtkGrid*)buttons,TRUE);
    gtk_grid_set_column_homogeneous((GtkGrid*)buttons,TRUE);
    gtk_grid_set_row_spacing((GtkGrid*)buttons,12);
    gtk_grid_set_column_spacing((GtkGrid*)buttons,12);
    g_object_set (buttons,"margin",12,NULL);
    g_object_set (topPart,"margin",12,NULL);
    gtk_container_set_border_width(GTK_CONTAINER(dialogScrollFrame),5);
    //gtk_box_set_child_packing((GtkBox*)zeBigContainer,bottomPart,gTRUE,gTRUE,100,GTK_PACK_START);
    gtk_text_view_set_buffer (GTK_TEXT_VIEW(dialogText), dialogBuffer);
    gtk_text_buffer_set_text(dialogBuffer, "", -1);
    //gtk_text_buffer_get_iter_at_offset (dialogBuffer, &lastCharIter, -1);
    gtk_text_buffer_get_end_iter(dialogBuffer, &endIter);
    fontDesc = pango_font_description_from_string("Consolas");
    gtk_widget_override_font(dialogText,fontDesc);
    endMark = gtk_text_mark_new ("endMark",FALSE);
    endMark = gtk_text_buffer_get_mark(dialogBuffer,"insert");
    gtk_button_set_always_show_image(GTK_BUTTON(button1),TRUE);
    gtk_button_set_always_show_image(GTK_BUTTON(button2),TRUE);
    gtk_button_set_always_show_image(GTK_BUTTON(button3),TRUE);

    /* Building objects */
    gtk_container_add (GTK_CONTAINER(win),zeBigContainerOverlay);
    gtk_overlay_add_overlay(GTK_OVERLAY(zeBigContainerOverlay),zeBigContainer);
    gtk_container_add (GTK_CONTAINER(zeBigContainerOverlay),IMGBackground);
    gtk_container_add (GTK_CONTAINER(zeBigContainer),topPart);
    gtk_container_add (GTK_CONTAINER(zeBigContainer),bottomPart);
    gtk_container_add (GTK_CONTAINER(topPart),topPartLeft); // Â topPartLeft âñòàâëÿòü ëåâûé áàð
    gtk_container_add (GTK_CONTAINER(topPartLeft),leftBar);
    gtk_container_add (GTK_CONTAINER(topPartLeft),leftImage);
    gtk_container_add (GTK_CONTAINER(topPart),topPartCenter);
    gtk_container_add (GTK_CONTAINER(topPart),topPartRight); // â topPartRight - ïðàâûé...
    gtk_container_add (GTK_CONTAINER(topPartRight),rightBar);
    gtk_container_add (GTK_CONTAINER(topPartRight),rightImage);
    gtk_container_add (GTK_CONTAINER(topPartCenter),topMidPart);
    gtk_container_add (GTK_CONTAINER(bottomPart),dialogScrollFrame);
    gtk_container_add (GTK_CONTAINER(dialogScrollFrame),dialogText);
    gtk_container_add (GTK_CONTAINER(bottomPart),buttons);
    gtk_grid_attach (GTK_GRID(buttons),button1, 1,1,1,1);
    gtk_grid_attach (GTK_GRID(buttons),button2, 1,2,1,1);
    gtk_grid_attach (GTK_GRID(buttons),button3, 1,3,1,1);
    gtk_grid_attach (GTK_GRID(buttons),button4, 1,4,1,1);
    gtk_grid_attach (GTK_GRID(buttons),button5, 1,5,1,1);

    /* Signal connects and some shiatd */
    g_signal_connect(G_OBJECT(button1), "clicked", Cast1, NULL);
    g_signal_connect(G_OBJECT(button2), "clicked", Cast2, NULL);
    g_signal_connect(G_OBJECT(button3), "clicked", Cast3, NULL);
    g_signal_connect(G_OBJECT(button4), "clicked", combatStart, NULL);
    g_signal_connect(G_OBJECT(button5), "clicked", backToChoosingScreen,NULL);

    /* Creature chooser window configuration */ // TO BE CONTINUED..........................................................................
    /* Window creation/configuration (win2) */
    win2win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_resizable (GTK_WINDOW (win2win), false);
    gtk_widget_set_size_request(win2win,windowWidth,windowHeight);
    gtk_window_set_title (GTK_WINDOW (win2win), "Pokemon creature chooser");
    gtk_window_set_position (GTK_WINDOW (win2win), GTK_WIN_POS_CENTER);
    gtk_widget_realize (win2win);
    g_signal_connect (win2win, "destroy", gtk_main_quit, NULL);
    gtk_window_set_icon_from_file(GTK_WINDOW(win2win),"images/winIcon.png",NULL);


    /* Initializing objects (win2) */
    win2topLabel = gtk_image_new_from_file("images/logo.png");
    //win2topLabel = gtk_label_new("");
    //gtk_label_set_markup(GTK_LABEL(win2topLabel),"<small>Small</small><big>Bold</big>");
    win2BigContainer = gtk_grid_new();
    win2BigContainerOverlay = gtk_overlay_new ();
    win2TopPart = gtk_grid_new ();
    win2MiddlePart = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0);
    win2BottomPart = gtk_grid_new();
    win2BackgroundIMG = gtk_image_new_from_file ("images/pokeBackground.jpg");
    win2button1 = gtk_button_new_with_label(">>Switch Screens<<");
    win2button2 = gtk_button_new_with_label("Exit");
    win2buttonReset = gtk_button_new_with_label("Reset");
    win2creatureIcon1 = gtk_button_new();
    win2creatureIcon2 = gtk_button_new();
    win2creatureIcon3 = gtk_button_new();
    win2creatureIcon4 = gtk_button_new();
    win2creatureIcon5 = gtk_button_new();
    win2creatureIcon1IMG = gtk_image_new_from_file("images/ImagePidgeotSmall.png");
    win2creatureIcon2IMG = gtk_image_new_from_file("images/ImageGardevoirSmall.png");
    win2creatureIcon3IMG = gtk_image_new_from_file("images/ImageArcanineSmall.png");
    win2creatureIcon4IMG = gtk_image_new_from_file("images/ImagePikachuSmall.png");
    win2creatureIcon5IMG = gtk_image_new_from_file("images/ImageFishSmall.png");
    win2ImageVersus = gtk_image_new_from_file ("images/versus.png");
    win2MiddleFirst = gtk_image_new_from_file ("images/facelessVoid.png");
    win2MiddleSecond = gtk_image_new_from_file ("images/facelessVoid.png");

    /* Various initializations (win2) */
    gtk_grid_set_row_homogeneous((GtkGrid*)win2BigContainer,TRUE);
    gtk_grid_set_column_homogeneous((GtkGrid*)win2BigContainer,TRUE);
    gtk_grid_set_row_spacing((GtkGrid*)win2BigContainer,12);
    gtk_grid_set_column_spacing((GtkGrid*)win2BigContainer,12);
    //g_object_set (win2BigContainer,"margin",12,NULL);

    gtk_grid_set_row_homogeneous((GtkGrid*)win2BottomPart,TRUE);
    gtk_grid_set_column_homogeneous((GtkGrid*)win2BottomPart,TRUE);
    gtk_grid_set_row_spacing((GtkGrid*)win2BottomPart,12);
    gtk_grid_set_column_spacing((GtkGrid*)win2BottomPart,12);
    g_object_set (win2BottomPart,"margin",12,NULL);

    gtk_grid_set_row_homogeneous((GtkGrid*)win2TopPart,TRUE);
    gtk_grid_set_column_homogeneous((GtkGrid*)win2TopPart,TRUE);
    gtk_grid_set_row_spacing((GtkGrid*)win2TopPart,12);
    gtk_grid_set_column_spacing((GtkGrid*)win2TopPart,12);
    g_object_set (win2TopPart,"margin",12,NULL);

    gtk_box_set_homogeneous(GTK_BOX(win2MiddlePart),TRUE);

    gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon1),TRUE);
    gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon2),TRUE);
    gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon3),TRUE);
    gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon4),TRUE);
    gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon5),TRUE);
    gtk_button_set_image(GTK_BUTTON(win2creatureIcon1),win2creatureIcon1IMG);
    gtk_button_set_image(GTK_BUTTON(win2creatureIcon2),win2creatureIcon2IMG);
    gtk_button_set_image(GTK_BUTTON(win2creatureIcon3),win2creatureIcon3IMG);
    gtk_button_set_image(GTK_BUTTON(win2creatureIcon4),win2creatureIcon4IMG);
    gtk_button_set_image(GTK_BUTTON(win2creatureIcon5),win2creatureIcon5IMG);

    /* Building objects (win2) */
    gtk_container_add (GTK_CONTAINER(win2win),win2BigContainerOverlay);
    gtk_overlay_add_overlay(GTK_OVERLAY(win2BigContainerOverlay),win2BigContainer);
    gtk_container_add (GTK_CONTAINER(win2BigContainerOverlay),win2BackgroundIMG);
    gtk_grid_attach(GTK_GRID(win2BigContainer),win2topLabel,1,1,1,2);//1
    gtk_grid_attach(GTK_GRID(win2BigContainer),win2TopPart,1,2,1,3);//3
    gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon1,1,1,1,1);
    gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon2,2,1,1,1);
    gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon3,3,1,1,1);
    gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon4,4,1,1,1);
    gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon5,5,1,1,1);
    gtk_grid_attach(GTK_GRID(win2BigContainer),win2MiddlePart,1,5,1,3);//3
    gtk_grid_attach(GTK_GRID(win2BigContainer),win2BottomPart,1,8,1,3);//3
    gtk_container_add (GTK_CONTAINER(win2MiddlePart),win2MiddleFirst);
    gtk_container_add (GTK_CONTAINER(win2MiddlePart),win2ImageVersus);
    gtk_container_add (GTK_CONTAINER(win2MiddlePart),win2MiddleSecond);
    gtk_grid_attach (GTK_GRID(win2BottomPart),win2button1, 1,1,3,1);
    gtk_grid_attach (GTK_GRID(win2BottomPart),win2buttonReset,4,1,1,1);
    gtk_grid_attach (GTK_GRID(win2BottomPart),win2button2, 5,1,1,1);

    /* Signal connects (win2) */
    g_signal_connect (G_OBJECT(win2button1),"clicked",win2StartGame,NULL);
    g_signal_connect (G_OBJECT(win2button2),"clicked",gtk_main_quit,NULL);
    g_signal_connect (G_OBJECT(win2creatureIcon1),"clicked",win2pidgeotSelect,NULL);
    g_signal_connect (G_OBJECT(win2creatureIcon2),"clicked",win2gardevoirSelect,NULL);
    g_signal_connect (G_OBJECT(win2creatureIcon3),"clicked",win2arcanineSelect,NULL);
    g_signal_connect (G_OBJECT(win2creatureIcon4),"clicked",win2pikachuSelect,NULL);
    g_signal_connect (G_OBJECT(win2creatureIcon5),"clicked",win2mightyfishSelect,NULL);
    g_signal_connect (G_OBJECT(win2buttonReset),"clicked",win2CharReset,NULL);

    /* Other stuff */
    srand(time(NULL));
    write ("___________________________________________________\n");

    /* Enter the main loop */
    gtk_widget_show_all (win2win);
    gtk_main ();

    return 0;
};