📄 lcd_screen.cpp
字号:
/*
* Copyright (c) 2005 Zhejiang University, P.R.China
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//=============================================================================
/**
* \file Device/LCD/LCD_Screen.cpp
*
* $Id: LCD_Screen.cpp,v 1.1 2005/06/08 08:12:24 qilj Exp $
*
* \author Huacheng Ke <sese_zju@yahoo.com.cn>
*/
//=============================================================================
#include "stdafx.h"
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "Core/System.h"
#include "Core/ConfigFile.h"
#include "Core/Helper.h"
#include "./LCD_Widget.h"
#include "./LCD_Screen.h"
#include "Device/LCDDevice/LCD_Device.h"
namespace LCD {
using Core::Observer;
IMPLEMENT_DYNAMIC_CLASS(LCD_Screen, Observer)
LCD_Screen::LCD_Screen(void)
{
lcd_update_ = false;
enable_ = false;
dc_ = NULL;
dialog_ = NULL;
fb_ = NULL;
width_ = height_ =depth_ =0;
dialog_ = new LCD::LCD_Widget(NULL);
// config();
/*
malloc_fb();
//dialog_ = new LCD::LCD_Widget(NULL);
wxSize size(width_, height_);
dialog_ = new LCD::LCD_Widget(NULL, -1, "LCD", wxDefaultPosition, size, wxDEFAULT_FRAME_STYLE, this);
set_palette();
dc_ = new wxClientDC(dialog_);
//pen_.SetColour(0xff,0xff,0xff); //black
//dc_->SetPen(pen_);
dc_->SetPalette(palette_);
*/
}
void LCD_Screen::enable(Core::u32 width, Core::u32 height, Core::u32 depth)
{
init(width, height, depth);
//malloc_fb();
//dialog_ = new LCD::LCD_Widget();
wxSize size;
size.Set(width_, height_+20);
wxPoint pos(10,10);
//dialog_ = new LCD::LCD_Widget(NULL, 1, "LCD", wxDefaultPosition, size, wxDEFAULT_FRAME_STYLE);
dialog_->SetSize(size);
set_palette();
dc_ = new wxClientDC(dialog_);
//pen_.SetColour(0xff,0xff,0xff); //black
//dc_->SetPen(pen_);
dc_->SetPalette(palette_);
// dialog_->start_timer(1000);
//this->show();
enable_ = true;
}
//LCD_Screen::LCD_Screen(Core::u32 width, Core::u32 height, Core::u32 depth)
//{
// init(width, height, depth);
// //wxPoint pos(-1,-1);
// malloc_fb();
// wxSize size(width, height);
// dialog_ = new LCD::LCD_Widget(NULL, -1, "LCD", wxDefaultPosition, size, wxDEFAULT_FRAME_STYLE);
// dc_ = new wxClientDC(dialog_);
// pen_.SetColour(0xff,0xff,0xff); //black
// dc_->SetPen(pen_);
//}
void LCD_Screen::config()
{
/*std::string arch_name = "ARM";
std::string conf_file = "LCD.conf";
std::string filepath = Core::Host_Machine::gen_fullpath(Core::Host_Machine::get_image_path("ARM"), conf_file);
Core::Wukong_Get_System().load_config(arch_name, conf_file);
Core::Config_File * cf = Core::Wukong_Get_System().get_config();
cf->read("LCD/width", width_);
cf->read("LCD/heigth", height_);
cf->read("LCD/depth", depth_);
cf->read("LCD/base_address", base_addr_);*/
}
LCD_Screen::~LCD_Screen(void)
{
delete dialog_;
}
void LCD_Screen::show(void)
{
if(dialog_)
dialog_->Show(true);
}
void LCD_Screen::hide(void)
{
dialog_->Show(false);
}
void LCD_Screen::update(Core::Part & part)
{
////just for test
/*static bool enable_ = false;
if(!enable_)
enable(320,240,8);
enable_ = true;*/
//draw framebuffer
if(enable_)
{
if (!dialog_->IsShown())
return;
this->fb_ = ((DEVICE::LCD &)part).get_fb();
fresh_screen();
}
return;
//dialog_->SendSizeEvent();
//return;
}
void LCD_Screen::on_create(void)
{
name_ = "LCD_Screen";
}
void LCD_Screen::on_destroy(void)
{
if(dialog_)
delete dialog_;
if(dc_)
delete dc_;
if(fb_)
delete fb_;
}
void LCD_Screen::init(Core::u32 width, Core::u32 height, Core::u32 depth)
{
width_ = width;
height_ = height;
depth_ = depth;
}
void LCD_Screen::draw_pixel(wxCoord x, wxCoord y)
{
//dc_->DrawPoint(x, y);
/*for(int i=0; i<width_; i++)
{
pen_.SetColour(r8b[200],g8b[50],b8b[0]);
dc_->SetPen(pen_);
dc_->DrawPoint(i,y);
}*/
for(int j=0; j<height_; j++)
for(int i=0; i<width_; i++)
{
pen_.SetColour(r8b[fb_[j*width_+i]],g8b[fb_[j*width_+i]],b8b[fb_[j*width_+i]]);
dc_->SetPen(pen_);
dc_->DrawPoint(i,j);
}
}
void LCD_Screen::fresh_screen()
{
//if(1)//if(lcd_update_)
//{
// //fresh screen
// bool f = creat_bitmap();
// if(f == true)
// dc_->DrawBitmap(bitmap_, 0, 0, false);
//}
//draw_pixel(0,0);
for(int j=0; j<height_; j++)
for(int i=0; i<width_; i++)
{
pen_.SetColour(r8b[fb_[j*width_+i]],g8b[fb_[j*width_+i]],b8b[fb_[j*width_+i]]);
dc_->SetPen(pen_);
dc_->DrawPoint(i,j);
}
}
void LCD_Screen::write_fb(Core::u32 addr, Core::u32 data)
{
Core::u32 offset = (addr & ~3) - base_addr_;
Core::u32 pixnum = offset * 8 / depth_; //which number pixel
unsigned char * pos;
if (pixnum < width_*height_)
{
pos = fb_ + pixnum;
for(Core::u32 bit = 0; bit < 32; bit += depth_)
{
unsigned char pix = (data >> bit) % (1 << depth_) ;
*pos++ = pix;
lcd_update_ = true;
}
}
}
void LCD_Screen::malloc_fb()
{
if(!fb_)
fb_ = new unsigned char[width_*height_];
memset(fb_,0,width_*height_);
}
bool LCD_Screen::creat_bitmap()
{
bitmap_.SetPalette(palette_);
return bitmap_.Create(fb_, wxBITMAP_TYPE_XPM ,width_, height_, depth_);
}
void LCD_Screen::set_palette()
{
Core::u32 colors1b[]={0x000000,0xffffff};
Core::u32 colors4b[]={0x000000,0x000080,0x008000,0x008080,0x800000,0x800080,0x808000,0x808080,
0xc0c0c0,0x0000ff,0x00ff00,0x00ffff,0xff0000,0xff00ff,0xffff00,0xffffff};
Core::u32 colors8b[256];
for(int i=0; i<256; i++)
{
colors8b[i]= ((i&0x000000e0)<<16)+((i&0x0000001c)<<11)+((i&0x00000003)<<6);
}
for(int i=0; i<2; i++ )
{
r1b[i] = (colors1b[i] >> 16) & 0xFF;
g1b[i] = (colors1b[i] >> 8) & 0xFF;
b1b[i] = (colors1b[i]) & 0xFF;
}
for(int i=0; i<16; i++)
{
r4b[i] = (colors4b[i] >> 16) & 0xFF;
g4b[i] = (colors4b[i] >> 8) & 0xFF;
b4b[i] = (colors4b[i]) & 0xFF;
}
for(int i=0; i<256; i++)
{
r8b[i] = (colors8b[i] >> 16) & 0xFF;
g8b[i] = (colors8b[i] >> 8) & 0xFF;
b8b[i] = (colors8b[i]) & 0xFF;
}
switch(depth_)
{
case 1:
assert(palette_.Create(2,r1b, g1b,b1b));
break;
case 4:
assert(palette_.Create(16,r4b, g4b,b4b));
break;
case 8:
assert(palette_.Create(256,r8b, g8b,b8b));
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -