搜索
bottom↓
回复: 5

DC绘图问题请教!

[复制链接]

出0入0汤圆

发表于 2010-9-2 14:09:04 | 显示全部楼层 |阅读模式

第一次点击滚动条时的显示 (原文件名:第一次点滚动条.JPG)


第二次点击滚动条时的显示,注意和以前的显示重叠了 (原文件名:第二次点滚动条.JPG)

DC绘图部分代码:
           if(info_bar_value<=info_total_index_number-MAX_INFO_INDEX_DISPLAY_NUMBER)//剩余还多余10项
        {
                dc = rtgui_dc_begin_drawing(info_search_view);
                if(dc==RT_NULL)
                   return RT_FALSE;

                //开始绘制之前要清除原来的显示内容//用背景色写一遍
                rect.x1=20;
                rect.x2=60;
                rect.y1=20;
                rect.y2=40;

                for(loop=0;loop<10;loop++)
                {
                   //从当前info_bar_value开始显示,从info_bar_value0开始

                        rect.y1=rect.y2+10;
                        rect.y2=rect.y1+20;
                        tmp=contact_info[info_bar_value+loop].index;
                    //绘制前要清空原来显示的内容
                        strcpy(content,"    ");//此局因不知如何设置当前DC前景色,而采用空字符绘制
                        rtgui_dc_draw_text(dc,content,&rect);
                        itoa(tmp,content);
                        rtgui_dc_draw_text(dc,content,&rect);

                }
                rtgui_dc_end_drawing(dc);
        }

问题1:第一次点击滚动条后DC绘图显示数字正常,但是第二次点击滚动条时再次绘图显示数字第二次的显示会与第一次的重合。
      
       是因为空的字符没有绘制吗?

问题2:为解决上述问题,应该用当前DC的背景色绘制以前显示过的内容,如何设置当前DC的前景色呢?rtgui_dc_set_color(dc,color)
     
      用最新版本的RT-GUI发现没有这个函数了!

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

发表于 2010-9-2 22:47:12 | 显示全部楼层
回复【楼主位】neilxiang
-----------------------------------------------------------------------
我用window实现简单的移动功能,楼主可以试用这种方式.

#include "demo_view.h"
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/checkbox.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/textbox.h>

static rtgui_win_t *win1;

void move_all_widget(int heigth,rt_bool_t isUp)
{
    rtgui_rect_t current_rect;
        rtgui_list_t *node;

    rtgui_list_foreach(node, &(RTGUI_CONTAINER(win1)->children))
        {
                rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);               
                current_rect.x1 =widget->extent.x1;
                current_rect.x2 =widget->extent.x2;

                if ( isUp == RT_TRUE )
                {
                   current_rect.y1 =widget->extent.y1 - heigth;
                   current_rect.y2 =widget->extent.y2 - heigth;
                }
                else
                {
                   current_rect.y1 =widget->extent.y1 + heigth;
                   current_rect.y2 =widget->extent.y2 + heigth;                  
                }

                rtgui_widget_set_rect(widget, &current_rect);       
        }
}

static void move_up(struct rtgui_widget* widget, rtgui_event_t* event)
{
    move_all_widget(25,RT_TRUE);
        rtgui_widget_update(RTGUI_WIDGET(win1));       
}

static void move_down(struct rtgui_widget* widget, rtgui_event_t* event)
{
    move_all_widget(25,RT_FALSE);
        rtgui_widget_update(RTGUI_WIDGET(win1));       
}

/*创建非模态window*/
void create_new_window1(rtgui_widget_t *widget)
{
    int i;
    char* arrayName[10];
    rtgui_checkbox_t* checkbox;
    rtgui_toplevel_t *parent;       
   
    rtgui_rect_t rect_label,rect_size = {0, 0, 240, 120};
   
    arrayName[0]="test 1";
        arrayName[1]="test 2";
        arrayName[2]="test 3";
        arrayName[3]="test 4";
        arrayName[4]="test 5";
        arrayName[5]="test 6";
        arrayName[6]="test 7";
        arrayName[7]="test 8";
        arrayName[8]="test 9";
        arrayName[9]="test 10";        

   parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));

   /* 创建一个窗口,风格为无标题及无边框 */
   win1 = rtgui_win_create(parent,
      "Table", &rect_size, RTGUI_WIN_STYLE_NO_TITLE);

   rtgui_rect_moveto(&rect_size, 0, 45);

   rtgui_win_set_rect(win1,&rect_size);   

   rect_label.x1=5;
   rect_label.x2=100;
   rect_label.y1=rect_size.y1;
   rect_label.y2=rect_label.y1+20;

   for (i=0; i < 10; i++ )
   {      
      checkbox = rtgui_checkbox_create(arrayName,RT_FALSE);         
      rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect_label);       
      rtgui_container_add_child(RTGUI_CONTAINER(win1), RTGUI_WIDGET(checkbox));

          rect_label.y1=rect_label.y2+ 5;
      rect_label.y2=rect_label.y1+20;
   }   
         

   /* 非模态显示窗口 */
   rtgui_win_show(win1, RT_FALSE);   
}

rtgui_view_t *test_move(rtgui_workbench_t* workbench)
{
   rtgui_view_t *view1;
   rtgui_button_t *button;
   rtgui_textbox_t* text;  

   rtgui_rect_t widget_rect;

   view1 = demo_view(workbench, "test");
   
   demo_view_get_rect(view1, &widget_rect);
   widget_rect.x1 = 5;
   widget_rect.x2 = widget_rect.x1 + 50;
   widget_rect.y1 = 170;
   widget_rect.y2 = widget_rect.y1 + 20;
   
   button = rtgui_button_create("窗口");
   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));
   rtgui_button_set_onbutton(button, create_new_window1);

   widget_rect.x1 = widget_rect.x2 + 10;
   widget_rect.x2 += 50;
   
   button = rtgui_button_create("上移");
   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));
   rtgui_button_set_onbutton(button, move_up);
   
    widget_rect.x1 = widget_rect.x2 + 10;
   widget_rect.x2 += 50;
   
   button = rtgui_button_create("下移");
   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));
   rtgui_button_set_onbutton(button, move_down);         

   return view1;
}

出0入0汤圆

 楼主| 发表于 2010-9-3 08:29:35 | 显示全部楼层
回复【1楼】gavin_li
-----------------------------------------------------------------------

如果不用DC绘图而是用控件,那一切显示就是正常的!

如果用DC绘图确实存在我所说的上述问题!

出0入0汤圆

发表于 2010-9-3 12:26:15 | 显示全部楼层
前面仅调用rtgui_dc_draw_text来显示文本?这个方式显示文本是不重新绘制底色的,所以在使用这个前最好先把背景给擦除了。

出0入0汤圆

发表于 2010-9-4 12:17:13 | 显示全部楼层
你們是如何用windows 來Simulate 的??

出0入0汤圆

发表于 2010-9-4 14:47:15 | 显示全部楼层
应当是用mini2440的模拟器吧.我试一下看看.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-6-2 18:57

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表