comparison src/audacious/ui_skinned_textbox.c @ 2944:3c66c8d03c53 trunk

make what ui_skinned_textbox_resize_relative did in a better way
author Tomasz Mon <desowin@gmail.com>
date Sat, 30 Jun 2007 21:20:49 +0200
parents a8f2c99727eb
children 09c216d437b2
comparison
equal deleted inserted replaced
2943:a8f2c99727eb 2944:3c66c8d03c53
46 }; 46 };
47 47
48 struct _UiSkinnedTextboxPrivate { 48 struct _UiSkinnedTextboxPrivate {
49 GtkWidget *image; 49 GtkWidget *image;
50 GdkGC *gc; 50 GdkGC *gc;
51 gint w;
52 SkinPixmapId skin_index; 51 SkinPixmapId skin_index;
53 GtkWidget *fixed; 52 GtkWidget *fixed;
54 gboolean double_size; 53 gboolean double_size;
55 gboolean scroll_back; 54 gboolean scroll_back;
56 gint nominal_y, nominal_height; 55 gint nominal_y, nominal_height;
267 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); 266 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox);
268 textbox->height = bmp_active_skin->properties.textbox_bitmap_font_height; 267 textbox->height = bmp_active_skin->properties.textbox_bitmap_font_height;
269 textbox->x = x; 268 textbox->x = x;
270 textbox->y = y; 269 textbox->y = y;
271 priv->gc = gc; 270 priv->gc = gc;
272 priv->w = w; 271 textbox->weight = w;
273 priv->scroll_allowed = allow_scroll; 272 priv->scroll_allowed = allow_scroll;
274 priv->scroll_enabled = TRUE; 273 priv->scroll_enabled = TRUE;
275 priv->skin_index = si; 274 priv->skin_index = si;
276 priv->nominal_y = y; 275 priv->nominal_y = y;
277 priv->nominal_height = textbox->height; 276 priv->nominal_height = textbox->height;
278 priv->scroll_timeout = 0; 277 priv->scroll_timeout = 0;
279 278
280 priv->fixed = fixed; 279 priv->fixed = fixed;
281 priv->double_size = FALSE; 280 priv->double_size = FALSE;
282 281
283 gtk_widget_set_size_request(widget, priv->w, textbox->height); 282 gtk_widget_set_size_request(widget, textbox->weight, textbox->height);
284 gtk_fixed_put(GTK_FIXED(priv->fixed), widget, textbox->x, textbox->y); 283 gtk_fixed_put(GTK_FIXED(priv->fixed), widget, textbox->x, textbox->y);
285 } 284 }
286 285
287 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { 286 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation) {
288 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); 287 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget);
304 widget->allocation.width, widget->allocation.height); 303 widget->allocation.width, widget->allocation.height);
305 304
306 textbox->x = widget->allocation.x/(priv->double_size ? 2 : 1); 305 textbox->x = widget->allocation.x/(priv->double_size ? 2 : 1);
307 textbox->y = widget->allocation.y/(priv->double_size ? 2 : 1); 306 textbox->y = widget->allocation.y/(priv->double_size ? 2 : 1);
308 307
309 if (priv->w != widget->allocation.width) { 308 if (textbox->weight != widget->allocation.width) {
310 priv->w = widget->allocation.width; 309 textbox->weight = widget->allocation.width;
311 if (priv->pixmap_text) g_free(priv->pixmap_text); 310 if (priv->pixmap_text) g_free(priv->pixmap_text);
312 priv->pixmap_text = NULL; 311 priv->pixmap_text = NULL;
313 priv->offset = 0; 312 priv->offset = 0;
314 ui_skinned_textbox_redraw(textbox); 313 textbox->redraw = TRUE;
315 } 314 }
316 } 315 }
317 316
318 static gboolean ui_skinned_textbox_textbox_press(GtkWidget *widget, GdkEventButton *event) { 317 static gboolean ui_skinned_textbox_textbox_press(GtkWidget *widget, GdkEventButton *event) {
319 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); 318 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget);
322 if (event->type == GDK_BUTTON_PRESS) { 321 if (event->type == GDK_BUTTON_PRESS) {
323 textbox = UI_SKINNED_TEXTBOX(widget); 322 textbox = UI_SKINNED_TEXTBOX(widget);
324 323
325 if (event->button == 1) { 324 if (event->button == 1) {
326 if (priv->scroll_allowed) { 325 if (priv->scroll_allowed) {
327 if ((priv->pixmap_width > priv->w) && priv->is_scrollable) { 326 if ((priv->pixmap_width > textbox->weight) && priv->is_scrollable) {
328 priv->is_dragging = TRUE; 327 priv->is_dragging = TRUE;
329 textbox->redraw = TRUE; 328 textbox->redraw = TRUE;
330 priv->drag_off = priv->offset; 329 priv->drag_off = priv->offset;
331 priv->drag_x = event->x; 330 priv->drag_x = event->x;
332 } 331 }
359 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); 358 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget);
360 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); 359 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox);
361 360
362 if (priv->is_dragging) { 361 if (priv->is_dragging) {
363 if (priv->scroll_allowed && 362 if (priv->scroll_allowed &&
364 priv->pixmap_width > priv->w) { 363 priv->pixmap_width > textbox->weight) {
365 priv->offset = priv->drag_off - (event->x - priv->drag_x); 364 priv->offset = priv->drag_off - (event->x - priv->drag_x);
366 365
367 while (priv->offset < 0) 366 while (priv->offset < 0)
368 priv->offset = 0; 367 priv->offset = 0;
369 368
370 while (priv->offset > (priv->pixmap_width - priv->w)) 369 while (priv->offset > (priv->pixmap_width - textbox->weight))
371 priv->offset = (priv->pixmap_width - priv->w); 370 priv->offset = (priv->pixmap_width - textbox->weight);
372 371
373 ui_skinned_textbox_redraw(textbox); 372 textbox->redraw = TRUE;
373 ui_skinned_textbox_paint(textbox);
374 } 374 }
375 } 375 }
376 376
377 return FALSE; 377 return FALSE;
378 } 378 }
384 static void ui_skinned_textbox_toggle_doublesize(UiSkinnedTextbox *textbox) { 384 static void ui_skinned_textbox_toggle_doublesize(UiSkinnedTextbox *textbox) {
385 GtkWidget *widget = GTK_WIDGET (textbox); 385 GtkWidget *widget = GTK_WIDGET (textbox);
386 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); 386 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox);
387 priv->double_size = !priv->double_size; 387 priv->double_size = !priv->double_size;
388 388
389 gtk_widget_set_size_request(widget, priv->w*(1+priv->double_size), textbox->height*(1+priv->double_size)); 389 gtk_widget_set_size_request(widget, textbox->weight*(1+priv->double_size), textbox->height*(1+priv->double_size));
390 gtk_widget_set_uposition(widget, textbox->x*(1+priv->double_size), textbox->y*(1+priv->double_size)); 390 gtk_widget_set_uposition(widget, textbox->x*(1+priv->double_size), textbox->y*(1+priv->double_size));
391 391
392 textbox->redraw = TRUE; 392 textbox->redraw = TRUE;
393 } 393 }
394 394
408 if (priv->pixmap) { 408 if (priv->pixmap) {
409 if (skin_get_id() != priv->skin_id) { 409 if (skin_get_id() != priv->skin_id) {
410 priv->skin_id = skin_get_id(); 410 priv->skin_id = skin_get_id();
411 textbox_generate_pixmap(textbox); 411 textbox_generate_pixmap(textbox);
412 } 412 }
413 obj = gdk_pixmap_new(NULL, priv->w, textbox->height, gdk_rgb_get_visual()->depth); 413 obj = gdk_pixmap_new(NULL, textbox->weight, textbox->height, gdk_rgb_get_visual()->depth);
414 src = priv->pixmap; 414 src = priv->pixmap;
415 415
416 cw = priv->pixmap_width - priv->offset; 416 cw = priv->pixmap_width - priv->offset;
417 if (cw > priv->w) 417 if (cw > textbox->weight)
418 cw = priv->w; 418 cw = textbox->weight;
419 gdk_draw_drawable(obj, priv->gc, src, priv->offset, 0, 0, 0, cw, textbox->height); 419 gdk_draw_drawable(obj, priv->gc, src, priv->offset, 0, 0, 0, cw, textbox->height);
420 if (cw < priv->w) 420 if (cw < textbox->weight)
421 gdk_draw_drawable(obj, priv->gc, src, 0, 0, 421 gdk_draw_drawable(obj, priv->gc, src, 0, 0,
422 textbox->x + cw, textbox->y, 422 textbox->x + cw, textbox->y,
423 priv->w - cw, textbox->height); 423 textbox->weight - cw, textbox->height);
424 424
425 if (priv->double_size) { 425 if (priv->double_size) {
426 GdkImage *img, *img2x; 426 GdkImage *img, *img2x;
427 img = gdk_drawable_get_image(obj, 0, 0, priv->w, textbox->height); 427 img = gdk_drawable_get_image(obj, 0, 0, textbox->weight, textbox->height);
428 img2x = create_dblsize_image(img); 428 img2x = create_dblsize_image(img);
429 gtk_image_set(GTK_IMAGE(priv->image), img2x, NULL); 429 gtk_image_set(GTK_IMAGE(priv->image), img2x, NULL);
430 g_object_unref(img2x); 430 g_object_unref(img2x);
431 g_object_unref(img); 431 g_object_unref(img);
432 } else 432 } else
438 } 438 }
439 } 439 }
440 440
441 static void ui_skinned_textbox_redraw(UiSkinnedTextbox *textbox) { 441 static void ui_skinned_textbox_redraw(UiSkinnedTextbox *textbox) {
442 textbox->redraw = TRUE; 442 textbox->redraw = TRUE;
443 gint w, h;
444 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox);
445 gtk_widget_get_size_request(GTK_WIDGET(textbox), &w, &h);
446 if (w != textbox->weight || h != textbox->height)
447 gtk_widget_set_size_request(GTK_WIDGET(textbox), textbox->weight, textbox->height);
443 ui_skinned_textbox_paint(textbox); 448 ui_skinned_textbox_paint(textbox);
444 } 449 }
445 450
446 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) { 451 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) {
447 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); 452 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox);
450 455
451 if (priv->font) { 456 if (priv->font) {
452 gint width; 457 gint width;
453 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL); 458 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL);
454 459
455 if (width <= priv->w) 460 if (width <= textbox->weight)
456 return FALSE; 461 return FALSE;
457 else 462 else
458 return TRUE; 463 return TRUE;
459 } 464 }
460 465
461 if (g_utf8_strlen(textbox->text, -1) * bmp_active_skin->properties.textbox_bitmap_font_width > priv->w) 466 if (g_utf8_strlen(textbox->text, -1) * bmp_active_skin->properties.textbox_bitmap_font_width > textbox->weight)
462 return TRUE; 467 return TRUE;
463 468
464 return FALSE; 469 return FALSE;
465 } 470 }
466 471
538 543
539 length = g_utf8_strlen(pixmaptext, -1); 544 length = g_utf8_strlen(pixmaptext, -1);
540 545
541 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL); 546 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL);
542 547
543 priv->pixmap_width = MAX(width, priv->w); 548 priv->pixmap_width = MAX(width, textbox->weight);
544 priv->pixmap = gdk_pixmap_new(mainwin->window, priv->pixmap_width, 549 priv->pixmap = gdk_pixmap_new(mainwin->window, priv->pixmap_width,
545 textbox->height, 550 textbox->height,
546 gdk_rgb_get_visual()->depth); 551 gdk_rgb_get_visual()->depth);
547 gc = priv->gc; 552 gc = priv->gc;
548 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG); 553 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG);
586 591
587 if (!priv->is_dragging) { 592 if (!priv->is_dragging) {
588 if (priv->scroll_back) priv->offset -= 1; 593 if (priv->scroll_back) priv->offset -= 1;
589 else priv->offset += 1; 594 else priv->offset += 1;
590 595
591 if (priv->offset >= (priv->pixmap_width - priv->w)) { 596 if (priv->offset >= (priv->pixmap_width - textbox->weight)) {
592 priv->scroll_back = TRUE; 597 priv->scroll_back = TRUE;
593 /* There are 1 million microseconds per second */ 598 /* There are 1 million microseconds per second */
594 //g_usleep(1000000); 599 //g_usleep(1000000);
595 } 600 }
596 if (priv->offset <= 0) { 601 if (priv->offset <= 0) {
630 635
631 /* 636 /*
632 * wl is the number of (partial) letters visible. Only makes 637 * wl is the number of (partial) letters visible. Only makes
633 * sense when using skinned font. 638 * sense when using skinned font.
634 */ 639 */
635 wl = priv->w / 5; 640 wl = textbox->weight / 5;
636 if (wl * 5 != priv->w) 641 if (wl * 5 != textbox->weight)
637 wl++; 642 wl++;
638 643
639 length = g_utf8_strlen(textbox->text, -1); 644 length = g_utf8_strlen(textbox->text, -1);
640 645
641 priv->is_scrollable = FALSE; 646 priv->is_scrollable = FALSE;
843 void ui_skinned_textbox_move_relative(GtkWidget *widget, gint x, gint y) { 848 void ui_skinned_textbox_move_relative(GtkWidget *widget, gint x, gint y) {
844 UiSkinnedTextbox *t = UI_SKINNED_TEXTBOX(widget); 849 UiSkinnedTextbox *t = UI_SKINNED_TEXTBOX(widget);
845 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget); 850 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget);
846 gtk_fixed_move(GTK_FIXED(priv->fixed), widget, t->x+x, t->y+y); 851 gtk_fixed_move(GTK_FIXED(priv->fixed), widget, t->x+x, t->y+y);
847 } 852 }
848
849 void ui_skinned_textbox_resize_relative(GtkWidget *widget, gint w, gint h) {
850 UiSkinnedTextbox *t = UI_SKINNED_TEXTBOX(widget);
851 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget);
852 gtk_widget_set_size_request(widget, priv->w+w, t->height+h);
853 }