- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
其中,在下面zetcode , 是否声明了 cairo 上下文 cr?
#include <cairo.h>
#include <gtk/gtk.h>
static void do_drawing(cairo_t *);
struct {
int count;
double coordx[100];
double coordy[100];
} glob;
static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
gpointer user_data)
{
do_drawing(cr);
return FALSE;
}
static void do_drawing(cairo_t *cr)
{
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_set_line_width(cr, 0.5);
int i, j;
for (i = 0; i <= glob.count - 1; i++ ) {
for (j = 0; j <= glob.count - 1; j++ ) {
cairo_move_to(cr, glob.coordx[i], glob.coordy[i]);
cairo_line_to(cr, glob.coordx[j], glob.coordy[j]);
}
}
glob.count = 0;
cairo_stroke(cr);
}
static gboolean clicked(GtkWidget *widget, GdkEventButton *event,
gpointer user_data)
{
if (event->button == 1) {
glob.coordx[glob.count] = event->x;
glob.coordy[glob.count++] = event->y;
}
if (event->button == 3) {
gtk_widget_queue_draw(widget);
}
return TRUE;
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *darea;
glob.count = 0;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
darea = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(window), darea);
gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(darea), "draw",
G_CALLBACK(on_draw_event), NULL);
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window, "button-press-event",
G_CALLBACK(clicked), NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
gtk_window_set_title(GTK_WINDOW(window), "Lines");
gtk_widget_show_all(window);
gtk_main();
return 0;
}
cairo context cr 是否在代码中自动声明并与 darea(绘图的不幸名称)关联area) 当我们调用函数时
g_signal_connect(G_OBJECT(darea), "draw",
G_CALLBACK(on_draw_event), NULL);
?
最佳答案
小部件将发出信号并传递它的内部 cairo 上下文。当您连接一个回调来处理信号时,cairo 上下文由小部件发送,您接收并处理它。
Draw 信号属于 Gtk Widget 类:
gboolean user_function (GtkWidget *widget, CairoContext *cr, gpointer user_data)
This signal is emitted when a widget is supposed to render itself. The widget 's top left corner must be painted at the origin of the passed in context and be sized to the values returned by gtk_widget_get_allocated_width() and gtk_widget_get_allocated_height().
Signal handlers connected to this signal can modify the cairo context passed as cr in any way they like and don't need to restore it. The signal emission takes care of calling cairo_save() before and cairo_restore() after invoking the handler.
The signal handler will get a cr with a clip region already set to the widget's dirty region, i.e. to the area that needs repainting. Complicated widgets that want to avoid redrawing themselves completely can get the full extents of the clip region with gdk_cairo_get_clip_rectangle(), or they can get a finer-grained representation of the dirty region with cairo_copy_clip_rectangle_list().
关于c - cairo 上下文对象 cr 在哪里声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43633012/
我正在使用 Ubuntu 15.04 和 vim-gnome 7.4。 当我运行时: vim --version | grep -i +ruby 它返回: +ruby 基于:Vim Ruby Supp
我正在编写一个测试脚本,它将简单地运行带有几个参数的 *.EXE 文件,然后将结果输出到一个文件。我有一个 *.sh 测试脚本可以正确运行测试(但需要手动更新更多测试)。此脚本中的行如下所示: bla
我想知道之间的区别(如果可能的话提供示例)CR LF (Windows)、LF (Unix) 和 CR (Macintosh) 换行符类型。 最佳答案 CR和LF是控制字符,分别编码为0x0D(十进制
我正在尝试使用 PHP 正则表达式来查找 CR 3492161 或 cr 3492161。我尝试使用以下正则表达式,但它不起作用。请求你的帮助。 :-) 'CR\s/^\d{7}$/' 'CR\h/^
交换换行符(例如通过某些文本编辑器)是否会破坏 javascript 代码? 最佳答案 两个控制字符都是valid line breaks .事实上你甚至不需要换行符。这只是为了更好的可读性。除了在字
这个问题已经有答案了: How to correct variable overwriting misbehavior when parsing output? (3 个回答) 已关闭 5 年前。 我
好的,我计划创建一个文件来存储我将导入到程序中的数据。该程序将为 Linux、Windows 和可能的 Mac 编译。 现在我真正想知道的是,由于这些文件中的换行符,我是否需要这些数据文件略有不同,或
建议以下计划: import java.io.StringReader; import javax.xml.transform.OutputKeys; import javax
我正在尝试将“,”和“\n”放入文件中。所有值都是 0 ,除了 4, 9, 14, 19, 23...我放置 ',' 和 '\n' 但是输出即将到来: 0000,0000,0000,0000,0000
我一直在尝试通过 Python 学习 Open ERP 模块开发。我想出了一个我认为我不理解的源代码。我在浏览时尝试了几个互联网链接,但找不到有用的链接。我非常需要理解这一点。 cr.execute(
我目前正在使用 JSP 生成一些 vCard。我发现一些平台无法识别这些生成的 vCard,除非它们的行由回车符 (CR) 分隔,而 JSP 似乎默认只使用换行符 (LF) 来分隔行。 你们知道有什么
验证用户时出现以下错误:purchase_user@purchase 失败。 MongoDB-CR 身份验证失败。当我通过浏览器访问网络服务时,用户文档中缺少凭据。 但我能够从 mongo 验证 pu
首先我想说我已经阅读了 this post但是我仍然对 CR line terminators 有问题. 有一个文件叫build_test.sh , 我编辑在 leafpad它可以直接显示在 Vim
我最近才开始使用 vim,并且在添加大量有用的插件时玩得很开心。问题是,在设置所有插件期间的某个时候,我没有注意到 enter 键的映射停止正常工作。在插入模式下,当我按下 Enter 键时,如果当前
我正在寻找一种在 vim 中突出显示 ^M(CR) 的方法。 最佳答案 确保文件格式设置为 unix 或 mac 我的是: set fileformats=unix,mac 如果是 DOS,您将看不到
假设我有一个程序(例如在Perl中),将这样的内容写入STDOUT: print "123\t- 456"; print "\r+\n"; 在我的屏幕上,我看到以下结果: 123 + 456
我正在编写一个在特定条件下自动插入一些文本的函数。当我尝试模拟 Enter press 时,我卡在了某个部分。我想出了这个(显而易见的)代码: execute "normal! a\" 问题是它破坏了
我有一个 HTML 页面中的元素。我正在用 JavaScript 向其中写入数据,并想稍后检查用户是否更改了文本。但是,如果数据包含任何回车符,它们似乎会被悄悄删除,因此将从文本区域读取的文本与应该存
各位正则表达式专家, 我有一个充满表达式的平面文件,例如: SELECT * FROM CONVENIENT_ONE_LINE_QUERY "SELECT * FROM THIS_QUERY WHER
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是一名优秀的程序员,十分优秀!